Skip to content

Commit 20dfa96

Browse files
Channel list automatic channel selection disabled for compact iPad screen size
1 parent 1f7ade8 commit 20dfa96

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99

1010
### 🐞 Fixed
1111
- Channel actions popup wrong appearance using a custom `NavigationView`
12+
- Channel list automatic channel selection disabled for compact iPad screen size
1213

1314
# [4.28.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.28.0)
1415
_February 28, 2023_

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListView.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ extension ChatChannelListView where Factory == DefaultViewFactory {
171171
}
172172

173173
public struct ChatChannelListContentView<Factory: ViewFactory>: View {
174+
175+
@Environment(\.horizontalSizeClass) var horizontalSizeClass
174176

175177
private var viewFactory: Factory
176178
@ObservedObject private var viewModel: ChatChannelListViewModel
@@ -232,6 +234,11 @@ public struct ChatChannelListContentView<Factory: ViewFactory>: View {
232234
trailingSwipeLeftButtonTapped: viewModel.onMoreTapped(channel:),
233235
leadingSwipeButtonTapped: { _ in /* No leading button by default. */ }
234236
)
237+
.onAppear {
238+
if horizontalSizeClass == .regular {
239+
viewModel.preselectChannelIfNeeded()
240+
}
241+
}
235242
}
236243

237244
viewFactory.makeChannelListStickyFooterView()

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
241241
hideTabBar = false
242242
}
243243
}
244+
245+
public func preselectChannelIfNeeded() {
246+
if isIPad && selectedChannel == nil && utils.messageListConfig.iPadSplitViewEnabled {
247+
selectedChannel = channels.first?.channelSelectionInfo
248+
}
249+
}
244250

245251
// MARK: - private
246252

@@ -296,7 +302,6 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
296302
self.updateChannels()
297303
}
298304
self.checkForDeeplinks()
299-
self.setInitialChannelIfSplitView()
300305
}
301306
}
302307
}
@@ -359,12 +364,6 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
359364
channels = controller?.channels ?? LazyCachedMapCollection<ChatChannel>()
360365
}
361366

362-
private func setInitialChannelIfSplitView() {
363-
if isIPad && selectedChannel == nil && utils.messageListConfig.iPadSplitViewEnabled {
364-
selectedChannel = channels.first?.channelSelectionInfo
365-
}
366-
}
367-
368367
private func handleChannelAppearance() {
369368
if !queuedChannelsChanges.isEmpty && selectedChannel == nil {
370369
channels = queuedChannelsChanges

0 commit comments

Comments
 (0)