0

I have problem with Views that have onTapGesture and are placed inside ScollView This onTapGesture is not always reacting to tap gesture. I need to tap precisely on such view. It seems like there is conflict with ScrollView drag?

I've tried

highPriorityGesture 
onTapGesture
gesture(DragGesture(minimumDistance:0).onChange { })
gesture(TapGesture().onEnded { }) 

Views have contentShape(Rectangle()) added to them

It somtimes works ok sometimes doesn't. On simulature it most of the time works ok, on physical device it is much worse.

            ScrollViewReader { proxy in
                HStack(spacing: spacing) {
                    ForEach(0 ..< elements.count, id: \.self) { i in
                        Text(elements[i])
                            .fixedSize()
                            .contentShape(Rectangle())
                            .onTapGesture {
                                withAnimation {
                                    selectedElement = i
                                }
                            }
                    }
jps
  • 20,041
  • 15
  • 75
  • 79
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143

1 Answers1

0

I couldn't reproduce the behavior that you describe with that example code, but maybe you could try the following modifier in case another gesture is operating at the same time:

.simultaneousGesture(TapGesture().onEnded({
              selectedElement = 1
            }))