|
| 1 | +--- |
| 2 | +id: navigation-crash |
| 3 | +title: Crash when used with react-navigation |
| 4 | +--- |
| 5 | + |
| 6 | +The YoutubePlayer causes a crash immediately on navigating to another screen, and also sometimes when navigating to the screen that contains the component. |
| 7 | + |
| 8 | +:::info |
| 9 | +This will happen if you have any webviews inside a screen. |
| 10 | + |
| 11 | +This is not exclusive to the youtube player. |
| 12 | +::: |
| 13 | + |
| 14 | +## Solutions |
| 15 | + |
| 16 | +:::tip Pick one that fits your need |
| 17 | +Don't try to implement ALL of them. |
| 18 | +::: |
| 19 | + |
| 20 | +### 1. Tweak react-navigation config |
| 21 | + |
| 22 | +#### use a transition animations that only involves translations. ([documentation](https://reactnavigation.org/docs/stack-navigator/#pre-made-configs)) |
| 23 | + |
| 24 | +```jsx |
| 25 | +<Stack.Screen |
| 26 | + component={ScreenWithWebview} |
| 27 | + options={{ |
| 28 | + cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS, |
| 29 | + }} |
| 30 | +/> |
| 31 | +``` |
| 32 | + |
| 33 | +#### disable transition animations on screens that have the youtube player. ([documentation](https://reactnavigation.org/docs/stack-navigator/#animationenabled)) |
| 34 | + |
| 35 | +```jsx |
| 36 | +<Stack.Screen |
| 37 | + component={ScreenWithWebview} |
| 38 | + options={{ |
| 39 | + animationEnabled: false, |
| 40 | + }} |
| 41 | +/> |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. Tweak webview props |
| 45 | + |
| 46 | +#### change webview opacity to `0.99` ([issue comment](https://github.com/LonelyCpp/react-native-youtube-iframe/issues/110#issuecomment-779848787)) |
| 47 | + |
| 48 | +```jsx |
| 49 | +<YoutubePlayer |
| 50 | + webViewStyle={{opacity: 0.99}} |
| 51 | + // |
| 52 | + {...otherProps} |
| 53 | +/> |
| 54 | +``` |
| 55 | + |
| 56 | +#### set `renderToHardwareTextureAndroid` ([issue comment](https://github.com/react-native-webview/react-native-webview/issues/811#issuecomment-748611465)) |
| 57 | + |
| 58 | +```jsx |
| 59 | +<YoutubePlayer |
| 60 | + webViewProps={{ |
| 61 | + renderToHardwareTextureAndroid: true, |
| 62 | + }} |
| 63 | + // |
| 64 | + {...otherProps} |
| 65 | +/> |
| 66 | +``` |
| 67 | + |
| 68 | +#### tweak `androidLayerType` ([issue comment](https://github.com/LonelyCpp/react-native-youtube-iframe/issues/110#issuecomment-786603325)) |
| 69 | + |
| 70 | +```jsx |
| 71 | +<YoutubePlayer |
| 72 | + webViewProps={{ |
| 73 | + androidLayerType: |
| 74 | + Platform.OS === 'android' && Platform.Version <= 22 ? 'hardware' : 'none', |
| 75 | + }} |
| 76 | + // |
| 77 | + {...otherProps} |
| 78 | +/> |
| 79 | +``` |
| 80 | + |
| 81 | +### github threads to follow |
| 82 | + |
| 83 | +- [issue #110](https://github.com/LonelyCpp/react-native-youtube-iframe/issues/110) |
| 84 | +- [issue #101](https://github.com/LonelyCpp/react-native-youtube-iframe/issues/101) |
| 85 | +- [rn-webview issue #811](https://github.com/react-native-webview/react-native-webview/issues/811) |
0 commit comments