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

Screen with WebView crashes App during navigation #9061

Closed
chongma opened this issue Nov 13, 2020 · 16 comments
Closed

Screen with WebView crashes App during navigation #9061

chongma opened this issue Nov 13, 2020 · 16 comments

Comments

@chongma
Copy link

chongma commented Nov 13, 2020

Current Behavior

  • What code are you running and what is happening?

Navigating to a screen which contains a WebView crashes the whole app with no stack trace. Disabling animations on the screen fixes the problem e.g. <Stack.Screen ... options={{animationEnabled: false}} />

Expected Behavior

  • What do you expect should be happening?

It should navigate

Your Environment

software version
iOS or Android Android
@react-navigation/native 5.8.9
@react-navigation/stack 5.12.6
react-native-gesture-handler 1.7.0
react-native-safe-area-context 3.1.4
react-native-screens 2.10.1
react-native 5.8.9
expo 39.0.3
node 12.19.0
npm or yarn npm
@github-actions
Copy link

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/stack (found: 5.12.16, latest: 5.12.6)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@chongma
Copy link
Author

chongma commented Nov 13, 2020

Sorry that was a typo. It is version 5.12.6

@WoLewicki
Copy link
Member

Do you use enableScreens()? If so, the issue with WebView should have been resolved in software-mansion/react-native-screens#607 and should be available from react-native-screens v. 2.12.0.

@chongma
Copy link
Author

chongma commented Nov 13, 2020

@WoLewicki No I never used enableScreens() unless it is on by default?

@WoLewicki
Copy link
Member

@chongma it depends on how you created the project. You can check if enableScreens() is present in your index.js or somewhere else in your code.

@satya164
Copy link
Member

See the workaround here #9067 (comment)

@avinashd3
Copy link

Current Behavior

  • What code are you running and what is happening?

Navigating to a screen which contains a WebView crashes the whole app with no stack trace. Disabling animations on the screen fixes the problem e.g. <Stack.Screen ... options={{animationEnabled: false}} />

Expected Behavior

  • What do you expect should be happening?

It should navigate

Your Environment

software version
iOS or Android Android
@react-navigation/native 5.8.9
@react-navigation/stack 5.12.6
react-native-gesture-handler 1.7.0
react-native-safe-area-context 3.1.4
react-native-screens 2.10.1
react-native 5.8.9
expo 39.0.3
node 12.19.0
npm or yarn npm

Hi Matthew(chongma),
I was getting the app crash while navigating and after applying the property {{animationEnabled: false}}, the issue got resolved.
Thanks for the solution.

Regards,
Avinash

@github-actions
Copy link

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.

@reza-madani
Copy link

@chongma
<Stack.Screen ... options={{animationEnabled: false}} /> -> That's solved my problem. thanks.
In react-navigation >= 6.x use <Stack.Screen ... options={{animation:'none'}} />

@1Jesper1
Copy link

1Jesper1 commented Oct 1, 2021

Thanks @rezareact That worked, on IOS and Android!
When does this problem get fixed?

@andmau90
Copy link

the solution works on my android, but is possible that the crash occurs only on some devices with com.google.android.webview instead of devices with com.android.chrome?

riquedev referenced this issue in riquedev/mobile Jun 20, 2022
@lennartkloock
Copy link

@chongma Thank you for your workaround! Seems to still be an issue

@vtwigge1000
Copy link

@lennartkloock We tried all proposed solutions and were still getting crashes on certain Android devices. This is what we did to fix it temporarily:

Use the useIsFocused hook to render the WebView conditionally.

const isFocused = useIsFocused();

{isFocused && (
          <WebView
            ...
           />
 )}

We had one screen where we had to wrap the parent component (instead of the child component containing the WebView) in isFocused to avoid a crash. This is not an optimal solution, but fortunately we didn't experience any noticeable decline in performance.

@josequintana94
Copy link

Solved with:

<Stack.Screen options={{animationEnabled: false}} name="MainScreen" component={MainScreen} />

@fabriziocucci
Copy link

fabriziocucci commented Jul 29, 2023

The only reasonable workarounds I've found acceptable (without disabling the animations on the stack screen) are:

  • using the useIsFocused hook to conditionally render the WebView (as mentioned here):
const isFocused = useIsFocused();
// ...
return (isFocused && (<WebView ... />)
  • setting androidLayerType="software" on the WebView component (as mentioned here):
<WebView androidLayerType="software" ... />

NOTE: I could see some noticeable performance regression with the latter option, so I'd suggest to try the former first!

@stydeveloper
Copy link

options={{animation:'none'}}

Issue resolved

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