Skip to content

detachInactiveScreens={true} cause onScroll of previous tab screen triggered in react navigation v6 bottom tab #1183

Closed
@lclrobert2020

Description

@lclrobert2020

Description

#10063 of react navigation
This bug only occurs in IOS, not for android
For example,
when you have a <Tab.Navigator> with two <Tab.Screen>
Let say you are currently on a Screen, say Screen 1, you have a with a onScroll props and a callback inside Screen 1,
When you press the Tab Bar Icon and jump to other Tab Screen, say Screen 2,
When the Screen 2 is shown and rendered,
The onScroll pf Screen 1 is magically called without any reason,
The same applies to onMomentumScrollEnd
if you set detachInactiveScreens={false} in the Tab Navigator
this problem will not occur

But for android,
this problem doesn't exist at all, no matter if detachInactiveScreens is set to true or false

Screenshots

Steps To Reproduce

1.go to my expo repo
2. press the tab bar to change screen
3. you will see the previous screen onScroll is called when the tab screen is changed

Expected behavior

Both IOS and Android should not call previous tab screen onScroll
This cause some issue as some of my tab screen has onScroll listener on it

Actual behavior

In IOS, you will see the previous screen onScroll is called when the tab screen is changed

Reproduction

https://snack.expo.dev/@robertli93/bug

Platform

  • iOS
  • Android
  • Web
  • Windows
  • tvOS

Workflow

exist both expo or bare react native project

  • [ X] Managed workflow
  • [ X] Bare workflow

Package versions

{
"dependencies": {
"react-native-screens": "~3.4.0",
"react-native-tab-view": "^3.0.0",
"@react-navigation/stack": "6.0.11",
"react-native-pager-view": "5.0.12",
"react-native-reanimated": "~2.2.0",
"@react-navigation/native": "6.0.2",
"@react-navigation/elements": "1.0.4",
"react-native-gesture-handler": "~1.10.2",
"@react-navigation/bottom-tabs": "6.0.9",
"react-native-safe-area-context": "3.2.0"
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions