Simultaneous Gestures on a view and a base view

I recognized that it is not possible to build a view where the user can simultaneously interact with one subview's gesture modifier and also another view's standard touch behaviour (for instance Slider, Stepper or TextField) while it is however possible to interact with two sliders at once or apply a gesture to a slider which will result in all gesture handlers being fired.


The little view below shows an image that is draggable and next to it two sliders.

✅ Both sliders can be used at the same time.

✅ It is also possible to start dragging the slider and then start dragging the the image.

❌ It is however not possible to start dragging the image and then interact with the Sliders in any way.

✅ It is possible to add a gestures to the sliders that will be called, but then I would need to reimplement all the logic that the sliders already have.


struct ContentView: View {
  @State var v1: Double = 0.5
  @State var v2: Double = 0.5
  @State var draggedOffset = CGSize.zero

  var body: some View {
    HStack() {
      Image(systemName: "ellipsis.circle.fill")
        .font(Font.system(size: 32))
        .padding(32)
        .offset(self.draggedOffset)
        .gesture(
          DragGesture(minimumDistance: 12.0, coordinateSpace: .global)
            .onChanged { value in
              self.draggedOffset = value.translation
            }
            .onEnded { value in
              self.draggedOffset = .zero
            }
          )
      VStack() {
        Slider(value: $v1)
        Slider(value: $v2)
      }
    }
  }
}


Is there some sort of method that needs to be called so that the touches will be passed through to the sliders?

Replies

There are APIs to specify that a gesture be allowed to run simultaneously with another, but you need both gestures to set that up. Without any way of accessing the gesture used for the sliders, I don't see how that's possible.


I strongly recommend filing a bug on this one, and to include a screen recording showing the behavior; if you're reproducing on-device, there's a control you can add to Control Center (swipe-down from top-right of screen) that will trigger a screen recording. See Preferences -> Control Center -> Customize Controls to add it. The recording should be added to your Photos, IIRC, or otherwise will be accessible via the Xcode Devices panel.


Include a link to this page, so that if there's a simple way to do what you need the engineer might reply here directly.