Skip to content

Commit 44d9077

Browse files
committed
Fine tune swipe when scrolling up and down
1 parent f20bb76 commit 44d9077

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,14 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
323323

324324
private func handleMessageListSwipe(_ messageListSwipe: MessageListSwipe?, geometry: GeometryProxy) {
325325
guard messageViewModel.isSwipeToQuoteReplyPossible else { return }
326-
guard let messageListSwipe else { return }
326+
guard let messageListSwipe else {
327+
setOffsetX(value: 0)
328+
return
329+
}
330+
if quotedMessage == message {
331+
setOffsetX(value: 0)
332+
return
333+
}
327334
// The view is moving during the swipe handling, therefore we skip the contains check if it is in progress
328335
guard offsetX > 0 || geometry.frame(in: .global).contains(messageListSwipe.startLocation) else { return }
329336
if messageListSwipe.horizontalOffset == 0 {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,14 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
319319
coordinateSpace: .global
320320
)
321321
.onChanged { value in
322+
guard value.velocity == .zero || abs(value.velocity.width) > abs(value.velocity.height) else { return }
322323
guard abs(value.translation.width) > abs(value.translation.height) else { return }
323324
guard value.translation.width != messageListSwipe?.horizontalOffset else { return }
324325
messageListSwipe = MessageListSwipe(startLocation: value.startLocation, horizontalOffset: value.translation.width)
325326
}
326-
.onEnded { value in
327+
.onEnded { _ in
327328
guard let offset = messageListSwipe?.horizontalOffset, offset != 0 else { return }
328-
messageListSwipe = MessageListSwipe(startLocation: value.startLocation, horizontalOffset: 0)
329+
messageListSwipe = nil
329330
}
330331
)
331332
})

0 commit comments

Comments
 (0)