Skip to content

Commit ba27fd2

Browse files
committed
MinimumSwipeGestureDistance + MaximumHorizontalSwipeDisplacement
1 parent 544a71c commit ba27fd2

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Possibility to view channel info on channel options
88
- Date separators in the message list
99
- ChatUserNamer to customize user name on typing indicator
10+
- minimumSwipeGestureDistance to control swipe sensitivity
1011

1112
### 🐞 Fixed
1213
- Bug about link attachments not opening when the URL was missing the scheme

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
127127
handleGestureForMessage(showsMessageActions: true)
128128
}
129129
})
130-
.offset(x: self.offsetX)
130+
.offset(x: min(self.offsetX, maximumHorizontalSwipeDisplacement))
131131
.simultaneousGesture(
132132
DragGesture(
133-
minimumDistance: 10,
133+
minimumDistance: utils.messageListConfig.messageDisplayOptions.minimumSwipeGestureDistance,
134134
coordinateSpace: .local
135135
)
136136
.updating($offset) { (value, gestureState, _) in
@@ -219,6 +219,10 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
219219
messageListConfig.messageDisplayOptions.otherUserMessageTransition
220220
)
221221
}
222+
223+
private var maximumHorizontalSwipeDisplacement: CGFloat {
224+
replyThreshold + 20
225+
}
222226

223227
private var isMessagePinned: Bool {
224228
message.pinDetails != nil

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public struct MessageDisplayOptions {
7676
let showAuthorName: Bool
7777
let animateChanges: Bool
7878
let dateLabelSize: CGFloat
79+
let minimumSwipeGestureDistance: CGFloat
7980
let currentUserMessageTransition: AnyTransition
8081
let otherUserMessageTransition: AnyTransition
8182
var messageLinkDisplayResolver: (ChatMessage) -> [NSAttributedString.Key: Any]
@@ -86,6 +87,7 @@ public struct MessageDisplayOptions {
8687
showAuthorName: Bool = true,
8788
animateChanges: Bool = true,
8889
overlayDateLabelSize: CGFloat = 40,
90+
minimumSwipeGestureDistance: CGFloat = 15,
8991
currentUserMessageTransition: AnyTransition = .identity,
9092
otherUserMessageTransition: AnyTransition = .identity,
9193
messageLinkDisplayResolver: @escaping (ChatMessage) -> [NSAttributedString.Key: Any] = MessageDisplayOptions
@@ -96,6 +98,7 @@ public struct MessageDisplayOptions {
9698
self.showMessageDate = showMessageDate
9799
self.animateChanges = animateChanges
98100
dateLabelSize = overlayDateLabelSize
101+
self.minimumSwipeGestureDistance = minimumSwipeGestureDistance
99102
self.currentUserMessageTransition = currentUserMessageTransition
100103
self.otherUserMessageTransition = otherUserMessageTransition
101104
self.messageLinkDisplayResolver = messageLinkDisplayResolver

docusaurus/docs/iOS/swiftui/components/message-list.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,20 @@ var body: some Scene {
252252
ChatChannelListView(viewFactory: CustomFactory.shared)
253253
}
254254
}
255-
```
255+
```
256+
257+
## Minimum Swipe Gesture Distance For Replying to Messages
258+
259+
The minimum swipe gesture distance needed to trigger a reply response can be personalized. This allows to fine tune the overall message list experience.
260+
261+
This setup is done when the `StreamChat` object is being created, usually at the start of the app (e.g. in the `AppDelegate`).
262+
263+
Here's an example usage:
264+
265+
```swift
266+
let messageDisplayOptions = MessageDisplayOptions(minimumSwipeGestureDistance: 20)
267+
let messageListConfig = MessageListConfig(messageDisplayOptions: messageDisplayOptions)
268+
let utils = Utils(messageListConfig: messageListConfig)
269+
270+
let streamChat = StreamChat(chatClient: chatClient, utils: utils)
271+
```

0 commit comments

Comments
 (0)