Skip to content

Commit 54cc2a7

Browse files
authored
[SWUI-90] Custom Channel List Dividers (#13)
* Add divider option to ViewFactory with default implementation * Use factory method of divider in ChatChannelList * Added documentation for the divider
1 parent d58573b commit 54cc2a7

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct ChannelsLazyVStack<Factory: ViewFactory>: View {
158158
}
159159
}
160160

161-
Divider()
161+
factory.makeChannelListDividerItem()
162162
}
163163
}
164164
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ extension ViewFactory {
9292
)
9393
}
9494

95+
public func makeChannelListDividerItem() -> some View {
96+
Divider()
97+
}
98+
9599
public func makeTrailingSwipeActionsView(
96100
channel: ChatChannel,
97101
offsetX: CGFloat,

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public protocol ViewFactory: AnyObject {
5959
leadingSwipeButtonTapped: @escaping (ChatChannel) -> Void
6060
) -> ChannelListItemType
6161

62+
associatedtype ChannelListDividerItem: View
63+
/// Creates the channel list divider item.
64+
func makeChannelListDividerItem() -> ChannelListDividerItem
65+
6266
associatedtype MoreActionsView: View
6367
/// Creates the more channel actions view.
6468
/// - Parameters:

docusaurus/docs/iOS/swiftui/components/helper-views.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,31 @@ In the channel list item creation method, you are provided with several paramete
102102
- `trailingSwipeLeftButtonTapped`: called when the left button of the trailing swiped area is tapped.
103103
- `leadingSwipeButtonTapped`: called when the button of the leading swiped area is tapped.
104104

105-
The last three parameters have no effect if you have specified `EmptyView` for the leading and trailing swipe area of a channel list item. By default, the leading area returns `EmptyView`. In the following section, we will see how these areas can be customized.
105+
The last three parameters have no effect if you have specified `EmptyView` for the leading and trailing swipe area of a channel list item. By default, the leading area returns `EmptyView`. In one of the following sections, we will see how these areas can be customized.
106+
107+
## Changing the Divider of the Chat Channel List
108+
109+
It is not only possible to swap the channel list items itself but also to customize the divider between the items. You can do that by implementing `makeChannelListDividerItem` in the `ViewFactory`. The only requisite is that the item you return needs to be a `View`, which offers you all the freedom you need.
110+
111+
The default implementation uses a simple `Divider` and looks like this:
112+
113+
```swift
114+
public func makeChannelListDividerItem() -> some View {
115+
Divider()
116+
}
117+
```
118+
119+
If you want your list to not have a divider whatsoever, you can simply return an `EmptyView` here.
120+
121+
Remember to always inject your custom view factory in your view hierarchy:
122+
123+
```swift
124+
var body: some Scene {
125+
WindowGroup {
126+
ChatChannelListView(viewFactory: CustomViewFactory.shared)
127+
}
128+
}
129+
```
106130

107131
## Customizing the Leading and Trailing Areas
108132

0 commit comments

Comments
 (0)