Skip to content
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

GestureHandler already initialized for root view #7148

Closed
ethantran opened this issue May 28, 2019 · 18 comments
Closed

GestureHandler already initialized for root view #7148

ethantran opened this issue May 28, 2019 · 18 comments

Comments

@ethantran
Copy link

I will occasionally get this error, but I am not sure how to reproduce it. All I know is that it is related to the stack navigator and how it implements react native gesture handler. When I switch it to another navigator like bottom tab, it does not throw error. I can only prevent the error temporarily by closing the app and opening it back up.

Platform: Android

"react": "16.8.3",
"react-native": "0.59.5",
"react-native-gesture-handler": "^1.2.1",
"react-navigation": "3.9.1"
const MainNavigator = createBottomTabNavigator({
  Home: {
    screen: HomeScreen
  }
});
export const AppContainer = createAppContainer(MainNavigator);
@satya164
Copy link
Member

satya164 commented Jul 8, 2019

Closing due to no repro. If this still occurs with the latest versions, please open a new issue with a repro.

@satya164 satya164 closed this as completed Jul 8, 2019
@AilsonFreire
Copy link

I am having the same problem. I don´t know why.

@Nagibaba
Copy link

Nagibaba commented Sep 6, 2019

I restarted Metro Bundler. Error gone

@SwordElucidator
Copy link

Any update?

@mikebouwmans
Copy link

mikebouwmans commented Oct 3, 2019

I have this error aswell at random times. Cant seem te reproduce it manually.

satya164 referenced this issue in react-navigation/stack Oct 22, 2019
I can't think of a scenario a screen would unmount when opening.
So it's probably a safe-bet to always call onClose.

Fixes #136
@angel-luis
Copy link

Same here, after restart Expo the error gone. I didn't touch the code.

Just developing a starter project with latest RN and RNN@next.

@web-2017
Copy link

just restart your app on device, Metro Bundler, error should gone

@satya164 satya164 transferred this issue from react-navigation/stack Feb 24, 2020
@grantgeorge
Copy link

grantgeorge commented Aug 6, 2020

We're getting this crash in production builds. Open to suggestions on how to debug this in that env

@danmaas
Copy link

danmaas commented Aug 6, 2020

@grantgeorge I too have been fighting this in production. It's been affecting ~1% of sessions among my Android users on recent production builds.

I am not 100% sure, but my investigation so far points to a possible bad interaction between react-native-gesture-handler and the default behavior of the Android hardware back button in React Native (which destroys the app's MainActivity, while leaving much of the Java and JavaScript context intact, and results in a second instance of MainActivity spawning when the app is brought to the foreground again). I have noticed several bugs in various React Native libraries where the root cause lies in code that does not handle this scenario properly, and I suspect that might be the case here too.

I am currently testing this possible fix, which prevents the app's MainActivity from being destroyed and re-created as often: https://stackoverflow.com/a/60360452
(though I'm using launchMode="singleTask", not "singleTop")

My suspicion is that something goes haywire in terms of the MainActivity lifecycle and the UI elements it manages, maybe due to incomplete handling of onHostDestroy()/onHostResume(), or a race condition between JavaScript and native Java code.

Note, I am still on react-navigation 3.13, so I'm not 100% sure this applies to more recent versions. I have a pretty heavy-duty navigation setup with many nested tabs, stacks, and switches, so I'm probably stressing the react-navigation code too.

@grantgeorge
Copy link

@danmaas thanks for sharing that. Glad I'm not alone!

If it's helpful, I've found that this crash and similarly related crashes to gesture handler and/or react-navigation occur after a user has downloaded a CodePush update and the sync at least started. That's about as far as I've gotten with this and I'm doing some more digging later.

From your example, my hypothesis is that users are downloading & syncing the CodePush update which shows a white screen and trying to exit that flow by clicking hardware back.

@danmaas
Copy link

danmaas commented Aug 6, 2020

Interesting, thanks for the info. I am also using CodePush, although only in "ON_NEXT_RESTART" install mode, so the bundle update doesn't happen during normal app usage.

I haven't seen any new crashes since deploying the MainActivity changes above, but it's a little too early to be sure.

@danmaas
Copy link

danmaas commented Aug 9, 2020

It's been a couple more days and I have not seen any more cases of this GestureHandler crash after making the changes to MainActivity as described above.

@grantgeorge
Copy link

thanks @danmaas . Followed your suggestion and haven't seen the error since. Cheers!

@vthunetcompany
Copy link

Although folks above have been saying that restarting the Metro Bundler would fix itself, I had to take it further and rebuild Android/iOS apps with npx to actually see it being fixed

@github-actions
Copy link

github-actions bot commented Sep 7, 2021

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@faisalakram381
Copy link

Just restart the Metro Bundler

@namchinn
Copy link

Exit from everything and restart all again. This fixed my error.

@NewCoder2023
Copy link

This fixed my error: npm install --save react-native-gesture-handler

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

No branches or pull requests