Skip to content

Commit 7dad1d4

Browse files
authored
Add Utils.channelListConfig.showChannelListDividerOnLastItem (#869)
* Add `Utils.channelListConfig.showChannelListDividerOnLastItem` * Update CHANGELOG.md
1 parent 5d8f6aa commit 7dad1d4

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

CHANGELOG.md

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

44
# Upcoming
55

6+
### ✅ Added
7+
- Add `Utils.channelListConfig.showChannelListDividerOnLastItem` [#869](https://github.com/GetStream/stream-chat-swiftui/pull/869)
8+
69
### 🐞 Fixed
710
- Fix tapping on invisible areas on iOS 26 [#868](https://github.com/GetStream/stream-chat-swiftui/pull/868)
811

Sources/StreamChatSwiftUI/ChatChannelList/ChannelListConfig.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ import Foundation
66

77
/// A configuration for channel lists.
88
public struct ChannelListConfig {
9-
public init(messageRelativeDateFormatEnabled: Bool = false) {
9+
public init(
10+
messageRelativeDateFormatEnabled: Bool = false,
11+
showChannelListDividerOnLastItem: Bool = true
12+
) {
1013
self.messageRelativeDateFormatEnabled = messageRelativeDateFormatEnabled
14+
self.showChannelListDividerOnLastItem = showChannelListDividerOnLastItem
1115
}
1216

1317
/// If true, the timestamp format depends on the time passed.
1418
///
1519
/// Different date formats are used for today, yesterday, last 7 days, and older dates.
1620
public var messageRelativeDateFormatEnabled: Bool
21+
22+
/// A boolean indicating whether the channel list should show a divider
23+
/// on the last item.
24+
///
25+
/// By default, all items in the channel list have a divider, including the last item.
26+
public var showChannelListDividerOnLastItem: Bool
1727
}

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public struct ChannelList<Factory: ViewFactory>: View {
109109
/// LazyVStack displaying list of channels.
110110
public struct ChannelsLazyVStack<Factory: ViewFactory>: View {
111111
@Injected(\.colors) private var colors
112+
@Injected(\.utils) private var utils
112113

113114
private var factory: Factory
114115
var channels: LazyCachedMapCollection<ChatChannel>
@@ -183,7 +184,11 @@ public struct ChannelsLazyVStack<Factory: ViewFactory>: View {
183184
}
184185
}
185186

186-
factory.makeChannelListDividerItem()
187+
let isLastItem = channels.last?.cid == channel.cid
188+
let shouldRenderLastItemDivider = utils.channelListConfig.showChannelListDividerOnLastItem
189+
if !isLastItem || (isLastItem && shouldRenderLastItemDivider) {
190+
factory.makeChannelListDividerItem()
191+
}
187192
}
188193

189194
factory.makeChannelListFooterView()

StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListView_Tests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,41 @@ class ChatChannelListView_Tests: StreamChatTestCase {
3939
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
4040
}
4141

42+
func test_chatChannelListView_showChannelListDividerOnLastItem_snapshot() {
43+
// Given
44+
let controller = ChatChannelListController_Mock.mock(client: chatClient)
45+
controller.simulateInitial(
46+
channels: [
47+
.mock(cid: .unique, name: "Test 1"),
48+
.mock(cid: .unique, name: "Test 2"),
49+
.mock(cid: .unique, name: "Test 3")
50+
],
51+
state: .initialized
52+
)
53+
54+
// When enabled
55+
let utils = Utils(channelListConfig: .init(showChannelListDividerOnLastItem: true))
56+
streamChat = StreamChat(chatClient: chatClient, utils: utils)
57+
let view = ChatChannelListView(
58+
viewFactory: DefaultViewFactory.shared,
59+
channelListController: controller
60+
)
61+
.applyDefaultSize()
62+
// Then
63+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision), named: "enabled")
64+
65+
// When disabled
66+
let utilsWithoutLastItemDivider = Utils(channelListConfig: .init(showChannelListDividerOnLastItem: false))
67+
streamChat = StreamChat(chatClient: chatClient, utils: utilsWithoutLastItemDivider)
68+
let viewWithoutLastItemDivider = ChatChannelListView(
69+
viewFactory: DefaultViewFactory.shared,
70+
channelListController: controller
71+
)
72+
.applyDefaultSize()
73+
// Then
74+
assertSnapshot(matching: viewWithoutLastItemDivider, as: .image(perceptualPrecision: precision), named: "disabled")
75+
}
76+
4277
func test_chatChannelListViewSansNavigation_snapshot() {
4378
// Given
4479
let controller = makeChannelListController()

0 commit comments

Comments
 (0)