diff --git a/tg_test/WheelNavBar.swift b/tg_test/WheelNavBar.swift index 65f3215..66c2612 100644 --- a/tg_test/WheelNavBar.swift +++ b/tg_test/WheelNavBar.swift @@ -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)) {