From ad8a680b7642b148e37b7f8802e2c7c524ebd388 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 25 Oct 2026 20:33:04 +0800 Subject: [PATCH] fix nav wheel snaping --- tg_test/WheelNavBar.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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)) {