Skip to content

Commit fdb86a7

Browse files
committed
Revert "Fix scrolling in the message list when presented with a sheet on iOS 26"
This reverts commit 0926cc2.
1 parent 577eea9 commit fdb86a7

File tree

3 files changed

+35
-56
lines changed

3 files changed

+35
-56
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
- `MentionUsersView`
1616
- `ParticipantInfoView`
1717
- `ChatThreadListItem`
18-
- Fix scrolling in the message list when presented with a sheet on iOS 26 [#1065](https://github.com/GetStream/stream-chat-swiftui/pull/1065)
1918
- Fix reading messages from muted users [#1063](https://github.com/GetStream/stream-chat-swiftui/pull/1063)
2019

2120
# [4.94.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.94.0)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
1010
@StateObject var messageViewModel: MessageViewModel
1111
@Environment(\.channelTranslationLanguage) var translationLanguage
1212
@Environment(\.highlightedMessageId) var highlightedMessageId
13-
@Environment(\.messageListSwipe) var messageListSwipe
1413

1514
@Injected(\.fonts) private var fonts
1615
@Injected(\.colors) private var colors
@@ -33,6 +32,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
3332
@State private var computeFrame = false
3433
@State private var offsetX: CGFloat = 0
3534
@State private var offsetYAvatar: CGFloat = 0
35+
@GestureState private var offset: CGSize = .zero
3636

3737
private let replyThreshold: CGFloat = 60
3838
private var paddingValue: CGFloat {
@@ -129,9 +129,6 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
129129
.onChange(of: computeFrame, perform: { _ in
130130
frame = proxy.frame(in: .global)
131131
})
132-
.onChange(of: messageListSwipe, perform: { messageListSwipe in
133-
handleMessageListSwipe(messageListSwipe, geometry: proxy)
134-
})
135132
}
136133
)
137134
.onTapGesture(count: 2) {
@@ -143,6 +140,40 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
143140
handleGestureForMessage(showsMessageActions: true)
144141
})
145142
.offset(x: min(self.offsetX, maximumHorizontalSwipeDisplacement))
143+
.simultaneousGesture(
144+
DragGesture(
145+
minimumDistance: minimumSwipeDistance,
146+
coordinateSpace: .local
147+
)
148+
.updating($offset) { (value, gestureState, _) in
149+
guard messageViewModel.isSwipeToQuoteReplyPossible else {
150+
return
151+
}
152+
// Using updating since onEnded is not called if the gesture is canceled.
153+
let diff = CGSize(
154+
width: value.location.x - value.startLocation.x,
155+
height: value.location.y - value.startLocation.y
156+
)
157+
158+
if diff == .zero {
159+
gestureState = .zero
160+
} else {
161+
gestureState = value.translation
162+
}
163+
}
164+
)
165+
.onChange(of: offset, perform: { _ in
166+
if !channel.config.quotesEnabled {
167+
return
168+
}
169+
170+
if offset == .zero {
171+
// gesture ended or cancelled
172+
setOffsetX(value: 0)
173+
} else {
174+
dragChanged(to: offset.width)
175+
}
176+
})
146177
.accessibilityElement(children: .contain)
147178
.accessibilityIdentifier("MessageView")
148179

@@ -320,18 +351,6 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
320351
private var messageListConfig: MessageListConfig {
321352
utils.messageListConfig
322353
}
323-
324-
private func handleMessageListSwipe(_ messageListSwipe: MessageListSwipe?, geometry: GeometryProxy) {
325-
guard messageViewModel.isSwipeToQuoteReplyPossible else { return }
326-
guard let messageListSwipe else { return }
327-
// The view is moving during the swipe handling, therefore we skip the contains check if it is in progress
328-
guard offsetX > 0 || geometry.frame(in: .global).contains(messageListSwipe.startLocation) else { return }
329-
if messageListSwipe.horizontalOffset == 0 {
330-
setOffsetX(value: 0)
331-
} else {
332-
dragChanged(to: messageListSwipe.horizontalOffset)
333-
}
334-
}
335354

336355
private func dragChanged(to value: CGFloat) {
337356
let horizontalTranslation = value

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
3636
@State private var scrollDirection = ScrollDirection.up
3737
@State private var unreadMessagesBannerShown = false
3838
@State private var unreadButtonDismissed = false
39-
@State private var messageListSwipe: MessageListSwipe?
4039

4140
private var messageRenderingUtil = MessageRenderingUtil.shared
4241
private var skipRenderingMessageIds = [String]()
@@ -192,7 +191,6 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
192191
isLast: !showsLastInGroupInfo && message == messages.last
193192
)
194193
.environment(\.channelTranslationLanguage, channel.membership?.language)
195-
.environment(\.messageListSwipe, messageListSwipe)
196194
.onAppear {
197195
if index == nil {
198196
index = messageListDateUtils.index(for: message, in: messages)
@@ -312,20 +310,6 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
312310
}
313311
}
314312
}
315-
.if(channel.config.quotesEnabled, transform: { view in
316-
view.simultaneousGesture(
317-
DragGesture(
318-
minimumDistance: utils.messageListConfig.messageDisplayOptions.minimumSwipeGestureDistance,
319-
coordinateSpace: .global
320-
)
321-
.onChanged { value in
322-
messageListSwipe = MessageListSwipe(startLocation: value.startLocation, horizontalOffset: value.translation.width)
323-
}
324-
.onEnded { value in
325-
messageListSwipe = MessageListSwipe(startLocation: value.startLocation, horizontalOffset: 0)
326-
}
327-
)
328-
})
329313
.accessibilityIdentifier("MessageListScrollView")
330314
}
331315

@@ -667,15 +651,6 @@ private struct MessageViewModelKey: EnvironmentKey {
667651
static let defaultValue: MessageViewModel? = nil
668652
}
669653

670-
private struct MessageListSwipeKey: EnvironmentKey {
671-
static let defaultValue: MessageListSwipe? = nil
672-
}
673-
674-
struct MessageListSwipe: Equatable {
675-
let startLocation: CGPoint
676-
let horizontalOffset: CGFloat
677-
}
678-
679654
extension EnvironmentValues {
680655
var channelTranslationLanguage: TranslationLanguage? {
681656
get {
@@ -694,18 +669,4 @@ extension EnvironmentValues {
694669
self[MessageViewModelKey.self] = newValue
695670
}
696671
}
697-
698-
/// Propagates the drag state to message items.
699-
///
700-
/// - Important: Since iOS 26 simultaneous gestures do not update ancestors.
701-
/// The gesture handler should be attached to the ScrollView and then propagating
702-
/// the state to items which decide if the drag should be handled.
703-
var messageListSwipe: MessageListSwipe? {
704-
get {
705-
self[MessageListSwipeKey.self]
706-
}
707-
set {
708-
self[MessageListSwipeKey.self] = newValue
709-
}
710-
}
711672
}

0 commit comments

Comments
 (0)