@@ -12,6 +12,7 @@ public struct ChannelList<Factory: ViewFactory>: View {
12
12
var channels : LazyCachedMapCollection < ChatChannel >
13
13
@Binding var selectedChannel : ChatChannel ?
14
14
@Binding var currentChannelId : String ?
15
+ private var scrollable : Bool
15
16
private var onlineIndicatorShown : ( ChatChannel ) -> Bool
16
17
private var imageLoader : ( ChatChannel ) -> UIImage
17
18
private var onItemTap : ( ChatChannel ) -> Void
@@ -27,6 +28,7 @@ public struct ChannelList<Factory: ViewFactory>: View {
27
28
channels: LazyCachedMapCollection < ChatChannel > ,
28
29
selectedChannel: Binding < ChatChannel ? > ,
29
30
currentChannelId: Binding < String ? > ,
31
+ scrollable: Bool = true ,
30
32
onlineIndicatorShown: @escaping ( ChatChannel ) -> Bool ,
31
33
imageLoader: @escaping ( ChatChannel ) -> UIImage ,
32
34
onItemTap: @escaping ( ChatChannel ) -> Void ,
@@ -48,38 +50,115 @@ public struct ChannelList<Factory: ViewFactory>: View {
48
50
self . trailingSwipeRightButtonTapped = trailingSwipeRightButtonTapped
49
51
self . trailingSwipeLeftButtonTapped = trailingSwipeLeftButtonTapped
50
52
self . leadingSwipeButtonTapped = leadingSwipeButtonTapped
53
+ self . scrollable = scrollable
51
54
_selectedChannel = selectedChannel
52
55
_currentChannelId = currentChannelId
53
56
}
54
57
55
58
public var body : some View {
56
- ScrollView {
57
- LazyVStack ( spacing: 0 ) {
58
- ForEach ( channels) { channel in
59
- factory. makeChannelListItem (
60
- channel: channel,
61
- channelName: channelNaming ( channel) ,
62
- avatar: imageLoader ( channel) ,
63
- onlineIndicatorShown: onlineIndicatorShown ( channel) ,
64
- disabled: currentChannelId == channel. id,
65
- selectedChannel: $selectedChannel,
66
- swipedChannelId: $currentChannelId,
67
- channelDestination: channelDestination,
68
- onItemTap: onItemTap,
69
- trailingSwipeRightButtonTapped: trailingSwipeRightButtonTapped,
70
- trailingSwipeLeftButtonTapped: trailingSwipeLeftButtonTapped,
71
- leadingSwipeButtonTapped: leadingSwipeButtonTapped
72
- )
73
- . onAppear {
74
- if let index = channels. firstIndex ( where: { chatChannel in
75
- chatChannel. id == channel. id
76
- } ) {
77
- onItemAppear ( index)
78
- }
59
+ Group {
60
+ if scrollable {
61
+ ScrollView {
62
+ channelsVStack
63
+ }
64
+ } else {
65
+ channelsVStack
66
+ }
67
+ }
68
+ }
69
+
70
+ private var channelsVStack : some View {
71
+ ChannelsLazyVStack (
72
+ factory: factory,
73
+ channels: channels,
74
+ selectedChannel: $selectedChannel,
75
+ currentChannelId: $currentChannelId,
76
+ onlineIndicatorShown: onlineIndicatorShown,
77
+ imageLoader: imageLoader,
78
+ onItemTap: onItemTap,
79
+ onItemAppear: onItemAppear,
80
+ channelNaming: channelNaming,
81
+ channelDestination: channelDestination,
82
+ trailingSwipeRightButtonTapped: trailingSwipeRightButtonTapped,
83
+ trailingSwipeLeftButtonTapped: trailingSwipeLeftButtonTapped,
84
+ leadingSwipeButtonTapped: leadingSwipeButtonTapped
85
+ )
86
+ }
87
+ }
88
+
89
+ /// LazyVStack displaying list of channels.
90
+ struct ChannelsLazyVStack < Factory: ViewFactory > : View {
91
+
92
+ private var factory : Factory
93
+ var channels : LazyCachedMapCollection < ChatChannel >
94
+ @Binding var selectedChannel : ChatChannel ?
95
+ @Binding var currentChannelId : String ?
96
+ private var onlineIndicatorShown : ( ChatChannel ) -> Bool
97
+ private var imageLoader : ( ChatChannel ) -> UIImage
98
+ private var onItemTap : ( ChatChannel ) -> Void
99
+ private var onItemAppear : ( Int ) -> Void
100
+ private var channelNaming : ( ChatChannel ) -> String
101
+ private var channelDestination : ( ChatChannel ) -> Factory . ChannelDestination
102
+ private var trailingSwipeRightButtonTapped : ( ChatChannel ) -> Void
103
+ private var trailingSwipeLeftButtonTapped : ( ChatChannel ) -> Void
104
+ private var leadingSwipeButtonTapped : ( ChatChannel ) -> Void
105
+
106
+ init (
107
+ factory: Factory ,
108
+ channels: LazyCachedMapCollection < ChatChannel > ,
109
+ selectedChannel: Binding < ChatChannel ? > ,
110
+ currentChannelId: Binding < String ? > ,
111
+ onlineIndicatorShown: @escaping ( ChatChannel ) -> Bool ,
112
+ imageLoader: @escaping ( ChatChannel ) -> UIImage ,
113
+ onItemTap: @escaping ( ChatChannel ) -> Void ,
114
+ onItemAppear: @escaping ( Int ) -> Void ,
115
+ channelNaming: @escaping ( ChatChannel ) -> String ,
116
+ channelDestination: @escaping ( ChatChannel ) -> Factory . ChannelDestination ,
117
+ trailingSwipeRightButtonTapped: @escaping ( ChatChannel ) -> Void ,
118
+ trailingSwipeLeftButtonTapped: @escaping ( ChatChannel ) -> Void ,
119
+ leadingSwipeButtonTapped: @escaping ( ChatChannel ) -> Void
120
+ ) {
121
+ self . factory = factory
122
+ self . channels = channels
123
+ self . onItemTap = onItemTap
124
+ self . onItemAppear = onItemAppear
125
+ self . channelNaming = channelNaming
126
+ self . channelDestination = channelDestination
127
+ self . imageLoader = imageLoader
128
+ self . onlineIndicatorShown = onlineIndicatorShown
129
+ self . trailingSwipeRightButtonTapped = trailingSwipeRightButtonTapped
130
+ self . trailingSwipeLeftButtonTapped = trailingSwipeLeftButtonTapped
131
+ self . leadingSwipeButtonTapped = leadingSwipeButtonTapped
132
+ _selectedChannel = selectedChannel
133
+ _currentChannelId = currentChannelId
134
+ }
135
+
136
+ public var body : some View {
137
+ LazyVStack ( spacing: 0 ) {
138
+ ForEach ( channels) { channel in
139
+ factory. makeChannelListItem (
140
+ channel: channel,
141
+ channelName: channelNaming ( channel) ,
142
+ avatar: imageLoader ( channel) ,
143
+ onlineIndicatorShown: onlineIndicatorShown ( channel) ,
144
+ disabled: currentChannelId == channel. id,
145
+ selectedChannel: $selectedChannel,
146
+ swipedChannelId: $currentChannelId,
147
+ channelDestination: channelDestination,
148
+ onItemTap: onItemTap,
149
+ trailingSwipeRightButtonTapped: trailingSwipeRightButtonTapped,
150
+ trailingSwipeLeftButtonTapped: trailingSwipeLeftButtonTapped,
151
+ leadingSwipeButtonTapped: leadingSwipeButtonTapped
152
+ )
153
+ . onAppear {
154
+ if let index = channels. firstIndex ( where: { chatChannel in
155
+ chatChannel. id == channel. id
156
+ } ) {
157
+ onItemAppear ( index)
79
158
}
80
-
81
- Divider ( )
82
159
}
160
+
161
+ Divider ( )
83
162
}
84
163
}
85
164
}
0 commit comments