Skip to content

Commit 9a0e85c

Browse files
iOS 18 fixes for the swipeable channel list item (#601)
1 parent 896c118 commit 9a0e85c

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public struct MessageDisplayOptions {
136136
overlayDateLabelSize: CGFloat = 40,
137137
lastInGroupHeaderSize: CGFloat = 0,
138138
newMessagesSeparatorSize: CGFloat = 50,
139-
minimumSwipeGestureDistance: CGFloat = 10,
139+
minimumSwipeGestureDistance: CGFloat = 20,
140140
currentUserMessageTransition: AnyTransition = .identity,
141141
otherUserMessageTransition: AnyTransition = .identity,
142142
shouldAnimateReactions: Bool = true,

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelSwipeableListItem.swift

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
4141
private var trailingRightButtonTapped: (ChatChannel) -> Void
4242
private var trailingLeftButtonTapped: (ChatChannel) -> Void
4343
private var leadingButtonTapped: (ChatChannel) -> Void
44+
45+
@State private var verticalScrolling = false
4446

4547
public init(
4648
factory: Factory,
@@ -76,7 +78,7 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
7678
.offset(x: self.offsetX)
7779
.simultaneousGesture(
7880
DragGesture(
79-
minimumDistance: 10,
81+
minimumDistance: 20,
8082
coordinateSpace: .local
8183
)
8284
.updating($offset) { (value, gestureState, _) in
@@ -85,7 +87,11 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
8587
width: value.location.x - value.startLocation.x,
8688
height: value.location.y - value.startLocation.y
8789
)
88-
90+
91+
if abs(value.translation.height) > abs(value.translation.width) && !verticalScrolling {
92+
verticalScrolling = true
93+
}
94+
8995
if diff == .zero {
9096
gestureState = .zero
9197
} else {
@@ -98,7 +104,8 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
98104
if offset == .zero {
99105
// gesture ended or cancelled
100106
dragEnded()
101-
} else {
107+
verticalScrolling = false
108+
} else if !verticalScrolling {
102109
dragChanged(to: offset.width)
103110
}
104111
})
@@ -122,7 +129,19 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
122129
}
123130

124131
private var showTrailingSwipeActions: Bool {
125-
!(trailingSwipeActions is EmptyView)
132+
#if DEBUG
133+
let view = factory.makeTrailingSwipeActionsView(
134+
channel: channel,
135+
offsetX: offsetX,
136+
buttonWidth: buttonWidth,
137+
swipedChannelId: $swipedChannelId,
138+
leftButtonTapped: trailingLeftButtonTapped,
139+
rightButtonTapped: trailingRightButtonTapped
140+
)
141+
return !(view is EmptyView)
142+
#else
143+
return !(trailingSwipeActions is EmptyView)
144+
#endif
126145
}
127146

128147
private var leadingSwipeActions: some View {
@@ -136,7 +155,18 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
136155
}
137156

138157
private var showLeadingSwipeActions: Bool {
139-
!(leadingSwipeActions is EmptyView)
158+
#if DEBUG
159+
let view = factory.makeLeadingSwipeActionsView(
160+
channel: channel,
161+
offsetX: offsetX,
162+
buttonWidth: buttonWidth,
163+
swipedChannelId: $swipedChannelId,
164+
buttonTapped: leadingButtonTapped
165+
)
166+
return !(view is EmptyView)
167+
#else
168+
return !(leadingSwipeActions is EmptyView)
169+
#endif
140170
}
141171

142172
private func dragChanged(to value: CGFloat) {

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ extension ViewFactory {
111111
swipedChannelId: Binding<String?>,
112112
leftButtonTapped: @escaping (ChatChannel) -> Void,
113113
rightButtonTapped: @escaping (ChatChannel) -> Void
114-
) -> some View {
114+
) -> TrailingSwipeActionsView {
115115
TrailingSwipeActionsView(
116116
channel: channel,
117117
offsetX: offsetX,
@@ -127,7 +127,7 @@ extension ViewFactory {
127127
buttonWidth: CGFloat,
128128
swipedChannelId: Binding<String?>,
129129
buttonTapped: (ChatChannel) -> Void
130-
) -> some View {
130+
) -> EmptyView {
131131
EmptyView()
132132
}
133133

0 commit comments

Comments
 (0)