fix nav wheel snaping
This commit is contained in:
parent
2599d8cc40
commit
ad8a680b76
1 changed files with 5 additions and 2 deletions
|
|
@ -108,8 +108,11 @@ struct WheelNavBar: View {
|
|||
}
|
||||
}
|
||||
.onEnded { value in
|
||||
let velocity = value.predictedEndTranslation.width / itemSpacing
|
||||
let calcIndex = Double(selectedIndex) - Double(value.translation.width / itemSpacing) - (velocity * 0.2)
|
||||
// Momentum = how far the gesture would coast past the finger's release point.
|
||||
// Cap it to one tab so a hard flick can't skip several tabs.
|
||||
let momentum = value.predictedEndTranslation.width - value.translation.width
|
||||
let cappedMomentum = min(max(momentum, -itemSpacing), itemSpacing)
|
||||
let calcIndex = Double(selectedIndex) - Double((value.translation.width + cappedMomentum * 0.5) / itemSpacing)
|
||||
let targetIndex = min(max(Int(round(calcIndex)), 0), tabs.count - 1)
|
||||
|
||||
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue