blog icon indicating copy to clipboard operation
blog copied to clipboard

How to prevent wheel Picker conflict with DragGesture in SwiftUI

Open onmyway133 opened this issue 3 years ago • 0 comments

If we have a Picker inside a View that has DragGesture, chances are when we scroll the wheel, the DragGesture is detected too

To prevent this, we can attach a dummy DragGesture to our Picker

Picker("", selection: $number) {
    ForEach(FavoriteNumbers.allCases) { number in
        Text(number.name)
    }
}
.pickerStyle(WheelPickerStyle())
.gesture(DragGesture())

onmyway133 avatar Aug 05 '21 13:08 onmyway133