onmyway133 / blog

🍁 What you don't know is what you haven't learned
https://onmyway133.com/
MIT License
669 stars 33 forks source link

How to prevent wheel Picker conflict with DragGesture in SwiftUI #836

Open onmyway133 opened 2 years ago

onmyway133 commented 2 years ago

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())