Good day everyone!
On Xcode 26 apple make worse Gesture's now!
So now my hack doesn't work.
But, for iOS 26 I found a new hack, so I updated my prevous solution:
public extension View {
func resetTappedButtonWhenScrolled() -> some View {
modifier(ResetTappedButtonWhenScrolled())
}
}
private struct ResetTappedButtonWhenScrolled: ViewModifier {
@State private var isScrolling = false
@ViewBuilder func body(content: Content) -> some View {
if #available(iOS 18, *) {
content
.disabled(isScrolling)
.background(ScrollGestureObserver(isScrolling: $isScrolling))
} else {
content
}
}
}
private struct ScrollGestureObserver: UIViewRepresentable {
@Binding var isScrolling: Bool
func makeCoordinator() -> Coordinator {
Coordinator(isScrolling: $isScrolling)
}
func makeUIView(context: Context) -> UIView {
let view = UIView()
DispatchQueue.main.async {
if let scrollView = view.enclosingScrollView() {
scrollView.panGestureRecognizer.addTarget(
context.coordinator,
action: #selector(Coordinator.handlePan(_:)),
)
}
}
return view
}
func updateUIView(_ uiView: UIView, context: Context) {}
}
private extension ScrollGestureObserver {
final class Coordinator: NSObject {
@Binding var isScrolling: Bool
init(isScrolling: Binding<Bool>) {
_isScrolling = isScrolling
}
@objc func handlePan(_ gesture: UIPanGestureRecognizer) {
switch gesture.state {
case .began, .changed:
if !isScrolling {
isScrolling = true
}
case .ended, .cancelled, .failed:
if isScrolling {
isScrolling = false
}
default:
break
}
}
}
}
private extension UIView {
func enclosingScrollView() -> UIScrollView? {
sequence(first: superview, next: { $0?.superview })
.compactMap { $0 as? UIScrollView }
.first
}
}