Skip to content

fix: Reset offset to 0 on swipe end to prevent indicator jump#12664

Open
AlexCernik wants to merge 1 commit into
react-navigation:mainfrom
AlexCernik:main
Open

fix: Reset offset to 0 on swipe end to prevent indicator jump#12664
AlexCernik wants to merge 1 commit into
react-navigation:mainfrom
AlexCernik:main

Conversation

@AlexCernik
Copy link
Copy Markdown

@AlexCernik AlexCernik commented Jun 30, 2025

Summary

When swiping between tabs, especially in React Native's New Architecture or on some devices, the offset value may retain a small negative or positive value (e.g. -0.02) even after the swipe ends. This causes a visual glitch where the indicator briefly "jumps" backward before settling on the correct tab.

This PR resets offset to 0 when pageScrollState becomes "idle", ensuring that the final position is stable and that the indicator aligns correctly with the selected tab.

Changes

  • Added offset.setValue(0); to onPageScrollStateChanged when state is 'idle'

Why

To prevent the tab indicator from jumping slightly backward after swiping, improving visual consistency. #12493

Notes

This fix has no functional side effects and only affects the visual animation when the swipe ends.

Tested on:

  • React Native 0.79.4
  • Fabric enabled
  • Android
@github-actions
Copy link
Copy Markdown

Hey @AlexCernik! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our contribution guidelines.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 30, 2025

Deploy Preview for react-navigation-example ready!

Name Link
🔨 Latest commit b8794d9
🔍 Latest deploy log https://app.netlify.com/projects/react-navigation-example/deploys/6863106b653b9c000866e4b2
😎 Deploy Preview https://deploy-preview-12664--react-navigation-example.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@AlexCernik AlexCernik changed the title Fix: Reset offset to 0 on swipe end to prevent indicator jump fix: Reset offset to 0 on swipe end to prevent indicator jump Jun 30, 2025
Copy link
Copy Markdown
Member

@satya164 satya164 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @AlexCernik

This seems like a bug in react-native-pager-view. Can you open a bug report there?

I'd rather not add a workaround and get the actual bug fixed instead.

@santhosh-umapathi-wikifolio
Copy link
Copy Markdown

And the change does not fix the problem, still it occurs. also some flickers on the tab indicator on tab press

@tom-richtr
Copy link
Copy Markdown

tom-richtr commented Nov 6, 2025

I can confirm that the bug is still present even with the proposed changes.
However I can confirm that refactoring to reanimated could fix the behaviour
See the changes mentioned in
#12646
https://github.com/hoangtrunnam/react-navigation/tree/merge_dev

@AlexCernik
Copy link
Copy Markdown
Author

To test the fix, update react-native-tab-view/lib/module/PagerViewAdapter.js with the proposed solution.

@scole-rbi
Copy link
Copy Markdown

To test the fix, update react-native-tab-view/lib/module/PagerViewAdapter.js with the proposed solution.

  • offset.setValue(0) fix from this PR significantly reduces indicator jump

  • some residual stutter remains but the indicator no longer misaligns after settling.

  • also found that removing the start CSS property from TabBarIndicator (which conflicts with the animated translateX during re-renders) further improves the result when combined with this fix

Note: the issue is reproducible on slow swipes too -- it's amplified by heavy screen content

  • confirmed with minimal test app (same libraries, lightweight content) that jank does not appear, and that with a fully custom React.memo-blocked tab bar that the issue persists -- proving it originates in the native onPageScroll offset pipeline, not tab bar rendering

Tested: RN 0.81.5, Fabric, Android, Expo SDK 54, react-native-tab-view 4.3.0, react-native-pager-view 6.9.1

@troZee
Copy link
Copy Markdown

troZee commented Apr 11, 2026

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