Skip to content

Commit dc5e323

Browse files
Release 4.16.0 (#103)
1 parent 0549c9f commit dc5e323

15 files changed

+132
-33
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
)
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.15.0"),
20+
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.16.0"),
2121
.package(url: "https://github.com/kean/Nuke.git", from: "10.0.0"),
2222
.package(url: "https://github.com/kean/NukeUI.git", from: "0.7.0")
2323
],
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Copyright © 2022 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import StreamChat
6+
import SwiftUI
7+
8+
/// Factory for creating channel controllers.
9+
class ChannelControllerFactory {
10+
11+
@Injected(\.chatClient) var chatClient
12+
13+
private var currentChannelController: ChatChannelController?
14+
15+
/// Creates a channel controller with the provided channel id.
16+
/// - Parameter channelId: the channel's id.
17+
/// - Returns: `ChatChannelController`
18+
func makeChannelController(for channelId: ChannelId) -> ChatChannelController {
19+
if let currentChannelController = currentChannelController, channelId == currentChannelController.cid {
20+
return currentChannelController
21+
}
22+
let controller = chatClient.channelController(for: channelId)
23+
currentChannelController = controller
24+
return controller
25+
}
26+
27+
/// Clears the current active channel controller.
28+
func clearCurrentController() {
29+
currentChannelController = nil
30+
}
31+
}

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public struct ChatChannelView<Factory: ViewFactory>: View, KeyboardReadable {
1212

1313
@StateObject private var viewModel: ChatChannelViewModel
1414

15+
@Environment(\.presentationMode) var presentationMode
16+
1517
@State private var messageDisplayInfo: MessageDisplayInfo?
1618
@State private var keyboardShown = false
1719
@State private var tabBarAvailable: Bool = false
@@ -134,6 +136,11 @@ public struct ChatChannelView<Factory: ViewFactory>: View, KeyboardReadable {
134136
.onDisappear {
135137
viewModel.onViewDissappear()
136138
}
139+
.onChange(of: presentationMode.wrappedValue, perform: { newValue in
140+
if newValue.isPresented == false {
141+
viewModel.onViewDissappear()
142+
}
143+
})
137144
.background(
138145
isIphone ?
139146
Color.clear.background(
@@ -157,3 +164,10 @@ public struct ChatChannelView<Factory: ViewFactory>: View, KeyboardReadable {
157164
return bottomPadding
158165
}
159166
}
167+
168+
extension PresentationMode: Equatable {
169+
170+
public static func == (lhs: PresentationMode, rhs: PresentationMode) -> Bool {
171+
lhs.isPresented == rhs.isPresented
172+
}
173+
}

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
9797
scrollToMessage: ChatMessage? = nil
9898
) {
9999
self.channelController = channelController
100-
if InjectedValues[\.utils].shouldSyncChannelControllerOnAppear(channelController) {
100+
if InjectedValues[\.utils].shouldSyncChannelControllerOnAppear(channelController)
101+
&& messageController == nil {
101102
channelController.synchronize()
102103
}
103104
if let messageController = messageController {
@@ -433,6 +434,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
433434

434435
deinit {
435436
messageCachingUtils.clearCache()
437+
if messageController == nil {
438+
utils.channelControllerFactory.clearCurrentController()
439+
}
436440
}
437441
}
438442

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
130130
.offset(x: min(self.offsetX, maximumHorizontalSwipeDisplacement))
131131
.simultaneousGesture(
132132
DragGesture(
133-
minimumDistance: utils.messageListConfig.messageDisplayOptions.minimumSwipeGestureDistance,
133+
minimumDistance: minimumSwipeDistance,
134134
coordinateSpace: .local
135135
)
136136
.updating($offset) { (value, gestureState, _) in
@@ -264,7 +264,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
264264
return
265265
}
266266

267-
if horizontalTranslation > 0 {
267+
if horizontalTranslation >= minimumSwipeDistance {
268268
offsetX = horizontalTranslation
269269
} else {
270270
offsetX = 0
@@ -278,6 +278,10 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
278278
}
279279
}
280280

281+
private var minimumSwipeDistance: CGFloat {
282+
utils.messageListConfig.messageDisplayOptions.minimumSwipeGestureDistance
283+
}
284+
281285
private func setOffsetX(value: CGFloat) {
282286
withAnimation(.interpolatingSpring(stiffness: 170, damping: 20)) {
283287
self.offsetX = value

Sources/StreamChatSwiftUI/ChatChannel/MessageList/VideoAttachmentView.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ public struct VideoAttachmentsList: View {
6363
let width: CGFloat
6464

6565
public var body: some View {
66-
ForEach(message.videoAttachments, id: \.self) { attachment in
67-
VideoAttachmentView(
68-
attachment: attachment,
69-
message: message,
70-
width: width
71-
)
72-
.withUploadingStateIndicator(
73-
for: attachment.uploadingState,
74-
url: attachment.videoURL
75-
)
66+
VStack {
67+
ForEach(message.videoAttachments, id: \.self) { attachment in
68+
VideoAttachmentView(
69+
attachment: attachment,
70+
message: message,
71+
width: width
72+
)
73+
.withUploadingStateIndicator(
74+
for: attachment.uploadingState,
75+
url: attachment.videoURL
76+
)
77+
}
7678
}
7779
}
7880
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ extension ViewFactory {
174174

175175
public func makeChannelDestination() -> (ChannelSelectionInfo) -> ChatChannelView<Self> {
176176
{ [unowned self] selectionInfo in
177-
let controller = chatClient.channelController(
178-
for: selectionInfo.channel.cid,
179-
messageOrdering: .topToBottom
180-
)
177+
let controller = InjectedValues[\.utils]
178+
.channelControllerFactory
179+
.makeChannelController(for: selectionInfo.channel.cid)
181180
return ChatChannelView(
182181
viewFactory: self,
183182
channelController: controller,
@@ -188,10 +187,9 @@ extension ViewFactory {
188187

189188
public func makeMessageThreadDestination() -> (ChatChannel, ChatMessage) -> ChatChannelView<Self> {
190189
{ [unowned self] channel, message in
191-
let channelController = chatClient.channelController(
192-
for: channel.cid,
193-
messageOrdering: .topToBottom
194-
)
190+
let channelController = InjectedValues[\.utils]
191+
.channelControllerFactory
192+
.makeChannelController(for: channel.cid)
195193
let messageController = chatClient.messageController(
196194
cid: channel.cid,
197195
messageId: message.id

Sources/StreamChatSwiftUI/Utils.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Utils {
2626

2727
var messageCachingUtils = MessageCachingUtils()
2828
var messageListDateUtils: MessageListDateUtils
29+
var channelControllerFactory = ChannelControllerFactory()
2930

3031
public init(
3132
dateFormatter: DateFormatter = .makeDefault(),

StreamChatSwiftUI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Pod::Spec.new do |spec|
1919

2020
spec.framework = "Foundation", "UIKit", "SwiftUI"
2121

22-
spec.dependency "StreamChat", "~> 4.15.0"
22+
spec.dependency "StreamChat", "~> 4.16.0"
2323
spec.dependency "Nuke", "~> 10.0"
2424
spec.dependency "SwiftyGif", "~> 5.0"
2525
spec.dependency "NukeUI", "~> 0.7.0"

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
8434E58127707F19001E1B83 /* GridPhotosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434E58027707F19001E1B83 /* GridPhotosView.swift */; };
4848
8434E583277088D9001E1B83 /* TitleWithCloseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */; };
4949
844CC60E2811378D0006548D /* ComposerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844CC60D2811378D0006548D /* ComposerConfig.swift */; };
50+
844D1D6628510304000CCCB9 /* ChannelControllerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844D1D6528510304000CCCB9 /* ChannelControllerFactory.swift */; };
51+
844D1D682851DE58000CCCB9 /* ChannelControllerFactory_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844D1D672851DE58000CCCB9 /* ChannelControllerFactory_Tests.swift */; };
5052
844EF8ED2809AACD00CC82F9 /* NoContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844EF8EC2809AACD00CC82F9 /* NoContentView.swift */; };
5153
84507C98281AC40F0081DDC2 /* AddUsersViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84507C97281AC40F0081DDC2 /* AddUsersViewModel_Tests.swift */; };
5254
84507C9A281ACCD70081DDC2 /* AddUsersView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84507C99281ACCD70081DDC2 /* AddUsersView_Tests.swift */; };
@@ -421,6 +423,8 @@
421423
8434E58027707F19001E1B83 /* GridPhotosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridPhotosView.swift; sourceTree = "<group>"; };
422424
8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleWithCloseButton.swift; sourceTree = "<group>"; };
423425
844CC60D2811378D0006548D /* ComposerConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposerConfig.swift; sourceTree = "<group>"; };
426+
844D1D6528510304000CCCB9 /* ChannelControllerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelControllerFactory.swift; sourceTree = "<group>"; };
427+
844D1D672851DE58000CCCB9 /* ChannelControllerFactory_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelControllerFactory_Tests.swift; sourceTree = "<group>"; };
424428
844EF8EC2809AACD00CC82F9 /* NoContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoContentView.swift; sourceTree = "<group>"; };
425429
84507C97281AC40F0081DDC2 /* AddUsersViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddUsersViewModel_Tests.swift; sourceTree = "<group>"; };
426430
84507C99281ACCD70081DDC2 /* AddUsersView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddUsersView_Tests.swift; sourceTree = "<group>"; };
@@ -954,6 +958,7 @@
954958
8465FD2D2746A95600AF091E /* ChatChannelView.swift */,
955959
8465FD302746A95600AF091E /* ChatChannelViewModel.swift */,
956960
84DEC8E72760EABC00172876 /* ChatChannelDataSource.swift */,
961+
844D1D6528510304000CCCB9 /* ChannelControllerFactory.swift */,
957962
8465FD2E2746A95600AF091E /* ChannelHeader */,
958963
8465FCFD2746A95600AF091E /* MessageList */,
959964
8465FD0F2746A95600AF091E /* Composer */,
@@ -1380,6 +1385,7 @@
13801385
847305BA28241D8D004AC770 /* ChatChannelHeader_Tests.swift */,
13811386
847305BC28243D25004AC770 /* WebView_Tests.swift */,
13821387
84BB4C4D284115C200CBE004 /* MessageListDateUtils_Tests.swift */,
1388+
844D1D672851DE58000CCCB9 /* ChannelControllerFactory_Tests.swift */,
13831389
);
13841390
path = ChatChannel;
13851391
sourceTree = "<group>";
@@ -1660,6 +1666,7 @@
16601666
8465FDC02746A95700AF091E /* ChatChannelList.swift in Sources */,
16611667
84DEC8EC27611CAE00172876 /* SendInChannelView.swift in Sources */,
16621668
8465FD9F2746A95700AF091E /* ChatChannelExtensions.swift in Sources */,
1669+
844D1D6628510304000CCCB9 /* ChannelControllerFactory.swift in Sources */,
16631670
8465FD882746A95700AF091E /* SendMessageButton.swift in Sources */,
16641671
8465FDC82746A95700AF091E /* ChatChannelListItem.swift in Sources */,
16651672
8465FDA62746A95700AF091E /* LazyView.swift in Sources */,
@@ -1873,6 +1880,7 @@
18731880
84C94CE227578B92007FE2B9 /* UserPayload.swift in Sources */,
18741881
8421BCEC27A400E8000F977D /* ReactionsUsersView_Tests.swift in Sources */,
18751882
84C94CD327578B92007FE2B9 /* ChatMessageFileAttachment_Mock.swift in Sources */,
1883+
844D1D682851DE58000CCCB9 /* ChannelControllerFactory_Tests.swift in Sources */,
18761884
84E57C4E281037B2002213C1 /* AssertJSONEqual.swift in Sources */,
18771885
84B439E127C6B2F100C04C99 /* MessageCachingUtils_Tests.swift in Sources */,
18781886
8423C346277D9BFF0092DCF1 /* TestCommandsConfig.swift in Sources */,
@@ -2357,8 +2365,8 @@
23572365
isa = XCRemoteSwiftPackageReference;
23582366
repositoryURL = "https://github.com/GetStream/stream-chat-swift.git";
23592367
requirement = {
2360-
kind = upToNextMajorVersion;
2361-
minimumVersion = 4.15.0;
2368+
branch = 4.16.0;
2369+
kind = branch;
23622370
};
23632371
};
23642372
848399E6275FB3BE003075E4 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = {

0 commit comments

Comments
 (0)