@@ -6,7 +6,7 @@ import StreamChat
6
6
import SwiftUI
7
7
8
8
/// Chat channel cell that is swipeable.
9
- public struct ChatChannelSwipeableListItem < Factory: ViewFactory > : View {
9
+ public struct ChatChannelSwipeableListItem < Factory: ViewFactory , ChannelListItem : View > : View {
10
10
@Injected ( \. colors) private var colors
11
11
12
12
@State private var offsetX : CGFloat = 0
@@ -33,46 +33,28 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory>: View {
33
33
private let addWidthMargin : CGFloat = 5
34
34
35
35
private var factory : Factory
36
+ private var channelListItem : ChannelListItem
36
37
private var channel : ChatChannel
37
- private var channelName : String
38
- private var avatar : UIImage
39
- private var onlineIndicatorShown : Bool
40
- @Binding private var selectedChannel : ChatChannel ?
41
- private var channelDestination : ( ChatChannel ) -> Factory . ChannelDestination
42
- private var disabled = false
43
- private var onItemTap : ( ChatChannel ) -> Void
44
38
private var trailingRightButtonTapped : ( ChatChannel ) -> Void
45
39
private var trailingLeftButtonTapped : ( ChatChannel ) -> Void
46
40
private var leadingButtonTapped : ( ChatChannel ) -> Void
47
41
48
42
internal init (
49
43
factory: Factory ,
44
+ channelListItem: ChannelListItem ,
50
45
currentChannelId: Binding < String ? > ,
51
46
channel: ChatChannel ,
52
- channelName: String ,
53
- avatar: UIImage ,
54
- onlineIndicatorShown: Bool ,
55
- disabled: Bool = false ,
56
- selectedChannel: Binding < ChatChannel ? > ,
57
- channelDestination: @escaping ( ChatChannel ) -> Factory . ChannelDestination ,
58
- onItemTap: @escaping ( ChatChannel ) -> Void ,
59
47
trailingRightButtonTapped: @escaping ( ChatChannel ) -> Void ,
60
48
trailingLeftButtonTapped: @escaping ( ChatChannel ) -> Void ,
61
49
leadingSwipeButtonTapped: @escaping ( ChatChannel ) -> Void
62
50
) {
63
51
self . factory = factory
52
+ self . channelListItem = channelListItem
64
53
self . channel = channel
65
- self . channelName = channelName
66
- self . avatar = avatar
67
- self . onlineIndicatorShown = onlineIndicatorShown
68
- self . channelDestination = channelDestination
69
- self . disabled = disabled
70
- self . onItemTap = onItemTap
71
54
self . trailingRightButtonTapped = trailingRightButtonTapped
72
55
self . trailingLeftButtonTapped = trailingLeftButtonTapped
73
56
leadingButtonTapped = leadingSwipeButtonTapped
74
57
_currentChannelId = currentChannelId
75
- _selectedChannel = selectedChannel
76
58
}
77
59
78
60
public var body : some View {
@@ -83,36 +65,27 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory>: View {
83
65
leadingSwipeActions
84
66
}
85
67
86
- ChatChannelNavigatableListItem (
87
- channel: channel,
88
- channelName: channelName,
89
- avatar: avatar,
90
- onlineIndicatorShown: onlineIndicatorShown,
91
- disabled: disabled,
92
- selectedChannel: $selectedChannel,
93
- channelDestination: channelDestination,
94
- onItemTap: onItemTap
95
- )
96
- . offset ( x: self . offsetX)
97
- . simultaneousGesture (
98
- DragGesture (
99
- minimumDistance: 10 ,
100
- coordinateSpace: . local
101
- )
102
- . updating ( $offset) { ( value, gestureState, _) in
103
- // Using updating since onEnded is not called if the gesture is canceled.
104
- let diff = CGSize (
105
- width: value. location. x - value. startLocation. x,
106
- height: value. location. y - value. startLocation. y
68
+ channelListItem
69
+ . offset ( x: self . offsetX)
70
+ . simultaneousGesture (
71
+ DragGesture (
72
+ minimumDistance: 10 ,
73
+ coordinateSpace: . local
107
74
)
75
+ . updating ( $offset) { ( value, gestureState, _) in
76
+ // Using updating since onEnded is not called if the gesture is canceled.
77
+ let diff = CGSize (
78
+ width: value. location. x - value. startLocation. x,
79
+ height: value. location. y - value. startLocation. y
80
+ )
108
81
109
- if diff == . zero {
110
- gestureState = . zero
111
- } else {
112
- gestureState = value. translation
82
+ if diff == . zero {
83
+ gestureState = . zero
84
+ } else {
85
+ gestureState = value. translation
86
+ }
113
87
}
114
- }
115
- )
88
+ )
116
89
}
117
90
. onChange ( of: offset, perform: { _ in
118
91
if offset == . zero {
0 commit comments