Skip to content

fix(tab-bar): eliminate duplicate highlight animation on tab press#148

Open
palmtown wants to merge 2 commits intotorgeadelin:masterfrom
palmtown:141-Prevent-Tab-Animation-Replys-On-Tab-Click
Open

fix(tab-bar): eliminate duplicate highlight animation on tab press#148
palmtown wants to merge 2 commits intotorgeadelin:masterfrom
palmtown:141-Prevent-Tab-Animation-Replys-On-Tab-Click

Conversation

@palmtown
Copy link

Description:
This pull request fixes a bug where tapping a tab would trigger the highlight spring animation twice—once immediately on press and again from a stale effect—resulting in a rapid “replay.” By consolidating the animation into a single useEffect and tracking the previous tab index, we ensure the spring only runs once per actual tab change.


What’s Changed:

  • Removed all inline animation(animatedPos).start() calls from:
    • onPress
    • onLongPress
    • initial mount effect
  • Added a single useEffect that:
    1. Watches state.index
    2. Uses a useRef (previousIndex) to detect real index changes
    3. Resets (animatedPos.setValue(0)) and then springs to 1 only when the tab truly changes
    4. Updates prevPos in the spring’s completion callback for correct dot positioning
  • Ensures no animation on Android back-press or redundant renders

Steps to Verify:

  1. Run the demo app on iOS and Android.
  2. Tap each tab—observe exactly one smooth highlight animation per press.
  3. Rotate the device—confirm no regressions in layout or animation.
  4. On Android, press the hardware back button—ensure no unexpected dot movement.

Related Issues:
Closes #141 – “Tab highlight animation replays on tab click”

palmtown and others added 2 commits May 29, 2025 16:37
Merge upstream changes from torgeadelin:master into palmtown:master
Previously, tapping a tab would trigger the highlight spring animation twice—once immediately and again from a stale effect—resulting in a rapid “replay.” This change:

- Removes all inline `animation(animatedPos).start()` calls from press, long-press, and mount handlers
- Introduces a single `useEffect` watching `state.index`
- Uses a `useRef` to track the previous index and only fire the spring when the index truly changes
- Updates `prevPos` in the spring’s completion callback so the dot always animates from the correct start

This ensures a single smooth transition per tab press.
@github-actions
Copy link

github-actions bot commented Oct 1, 2025

Stale pull request message

@oivoodoo
Copy link

oivoodoo commented Oct 15, 2025

@palmtown it works for me well. thank you for PR!

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-10-15.at.11.44.04.mp4

@alperengozum
Copy link

@palmtown this fix works for my project Sleepwell. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab Highlight Animation Replays on Tab Click

3 participants