-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
detachInactiveScreens={true} cause onScroll of previous tab screen triggered in react navigation v6 bottom tab #1183
Comments
update |
This behavior was introduced as a fix for unresponsive items of the scrollView when navigating away while it is still scrolling, you can see more info here: #594. I am not sure if there is an easy way to make it work correctly without this code. Maybe you could stop subscribing to the scroll events on |
Thanks for your reply, Actually my case is more complex then trigger scrollview on previous screen, let me explain I have used memo or pure component to get the best performance, and add a infinite scroll function on it, the grid works good and even with infinite loading 1000 items it doesn't trigger "VirtualizedList: You have a large list that is slow to update " But, the grid will trigger this warning, only on one situation, when switching screen on tabs you can see my https://snack.expo.dev/@robertli93/bugdemo in this repo, the 2 flatlist inside only renders a small amount of 20 items and if you scroll the masonry grid down or up, not warning is triggered But when you do the following, the error will be triggered, quite consistently
this happen in expo or bare rn apps basically when u switch back and forth 3 times, 3 errors throws My initial guess is that this must be related to scrolling triggered when screen changed, and when i delete the code related to the fix mentioned by you, it doesn't throw error anymore But this fix seems important for interaction, is there any way to add a little fix so that I can use this fix and get rid of error at the same time, can we first stop the scroll, then change the page with a little time delay to fix it? really appreciate you reply and your team's work, |
The easiest solution is something similar to what I proposed in the previous comment. You can use |
The problem is even if you don't add any scroll listeners to any of the Flatlist, the error will be throw when coming back and forth between tabs 3 times you can visit my expo https://snack.expo.dev/@robertli93/bugdemo and video All flat list in the example has no scroll related listeners I guess this is caused by the native side invoking scrollViewDidEndDecelerating on the parent and nested Child Flatlist together? But I didn't why this bug is triggered when going back to and forth 3 times. Practically, this warning is shown why the screen is changed to other screen, so I guess it will not be noticed by user But I am not sure if this will cause any un noticed bugs and performance issues for these nested flat list structures |
It is warning from here: https://github.com/facebook/react-native/blob/afe0c1daea0aaf7b40b7ded08d6eb6d45b17099c/Libraries/Lists/VirtualizedList.js#L1614. It is probably triggered because |
Thanks for ur reply, the warning is trigger by 4 calculations, on each internal _onScroll Event
Let me explain step by step
5.this._scrollMetrics get updated with these value
so this time, the warning is triggered, even if there is no any performance issue at all, its just some calculation problem, as Facebook React Time assume people will not trigger the native scrollViewDidEndDecelerating alone That's it, this warning will show even on an optimized single flatlist I think we should add explanation so that user will not get confused with this warning when they are switch tabs with flatlist? It is because this error will be triggered even with a single flatlist |
Thanks for investigating it deeply @lclrobert2020 ! Do you mean some exact place where we should add this explanation? I think we could add it to |
I also think that Common problems is a good place to add it to |
If you have some time and will, could you make such PR, so we could link this issue to the PR and close it in such way? |
Added explanation of #1183 to Common Problems section.
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
Workflow
exist both expo or bare react native project
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"
}
}
The text was updated successfully, but these errors were encountered: