Skip to content

Commit 7032e72

Browse files
committed
Add background color when a channel is selected on iPad
1 parent 5f74c95 commit 7032e72

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public struct ChannelList<Factory: ViewFactory>: View {
108108

109109
/// LazyVStack displaying list of channels.
110110
public struct ChannelsLazyVStack<Factory: ViewFactory>: View {
111+
@Injected(\.colors) private var colors
111112

112113
private var factory: Factory
113114
var channels: LazyCachedMapCollection<ChatChannel>
@@ -170,6 +171,11 @@ public struct ChannelsLazyVStack<Factory: ViewFactory>: View {
170171
trailingSwipeLeftButtonTapped: trailingSwipeLeftButtonTapped,
171172
leadingSwipeButtonTapped: leadingSwipeButtonTapped
172173
)
174+
.background(factory.makeChannelListItemBackground(
175+
colors: colors,
176+
channel: channel,
177+
isSelected: selectedChannel?.channel.id == channel.id
178+
))
173179
.onAppear {
174180
if let index = channels.firstIndex(where: { chatChannel in
175181
chatChannel.id == channel.id

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,19 @@ extension ViewFactory {
9999
Color(colors.background)
100100
.edgesIgnoringSafeArea(.bottom)
101101
}
102-
102+
103+
public func makeChannelListItemBackground(
104+
colors: ColorPalette,
105+
channel: ChatChannel,
106+
isSelected: Bool
107+
) -> some View {
108+
if isSelected && isIPad {
109+
return Color(colors.background6)
110+
}
111+
112+
return Color(colors.background)
113+
}
114+
103115
public func makeChannelListDividerItem() -> some View {
104116
Divider()
105117
}

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public protocol ViewFactory: AnyObject {
6565
/// - Returns: view shown as a background of the channel list.
6666
func makeChannelListBackground(colors: ColorPalette) -> ChannelListBackground
6767

68+
associatedtype ChannelListItemBackground: View
69+
/// Creates the background for the channel list item.
70+
/// - Parameter colors: The colors palette used in the SDK.
71+
/// - Parameter channel: The channel which the item view belongs to.
72+
/// - Parameter isSelected: Whether the current item is selected or not.
73+
/// - Returns: The view shown as a background of the channel list item.
74+
func makeChannelListItemBackground(
75+
colors: ColorPalette,
76+
channel: ChatChannel,
77+
isSelected: Bool
78+
) -> ChannelListItemBackground
79+
6880
associatedtype ChannelListDividerItem: View
6981
/// Creates the channel list divider item.
7082
func makeChannelListDividerItem() -> ChannelListDividerItem

0 commit comments

Comments
 (0)