reports icon indicating copy to clipboard operation
reports copied to clipboard

FB14688465: ScrollView gesture ignored when `DragGesture` used by subview

Open Sjmarf opened this issue 6 months ago • 0 comments

  • Date: 2024-08-06
  • Resolution: Open
  • Area: SwiftUI
  • OS: iOS 18 dev beta 5
  • Type: Incorrect/Unexpected Behavior
  • Keywords:

Description

I have a view with a horizontal DragGesture. The ScrollView that my view is contained within ignores scroll up/down gestures. This behavior is new in iOS 18 (I have tested dev betas 4 & 5). Example code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        ScrollView {
            ForEach(0..<20) { n in
                TileView(color: n % 2 == 0 ? .red : .blue)
            }
        }
    }
}

struct TileView: View {
    @GestureState var dragState: CGFloat = .zero
    
    let color: Color
    
    var body: some View {
        color
            .frame(height: 100)
            .gesture(
                DragGesture(
                    minimumDistance: 10,
                    coordinateSpace: .global
                )
                .updating($dragState) { value, state, _ in
                    state = value.translation.width
                }
            )
            .offset(x: dragState)
    }
}

See attached video of the above script running on iOS 17.5 (left) and iOS 18 dev beta 5 (right).

In the above example, the scroll gesture is always ignored. In my actual app, scroll gestures are only sometimes ignored.

Built using Xcode beta 5, happens on a sim (22A5326g) and on my physical device (22A5326f).

Files

https://github.com/user-attachments/assets/a8923fce-2a92-4276-b351-83c327680a26

Sjmarf avatar Aug 06 '24 20:08 Sjmarf