question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Since 0.68.2-6) App crashing when a Touchable is mounted with hasTVPreferredFocus in a Stack.Screen (react-navigation)

See original GitHub issue

Description

Following the changes made with that commit: https://github.com/react-native-tvos/react-native-tvos/commit/11a974fb0258e67e268655eb1cd4763330ed8c19, our app crashes when we have a Touchable with hasTVPreferredFocus={true} that is mounted at the same time as the route/screen it’s in.

We are using react-navigation / react-native-screens with createNativeStackNavigator.

If you delay the mounting of that component (ie: by 1 sec), it won’t crash.

The error we get is a bit random.

  • In our project, we get this error:
ERROR: failed to load 'RawCamera' bundle: 'dlopen(/System/Library/CoreServices/RawCamera.bundle/RawCamera, 0x0101): tried: '/Users/leon/Library/Developer/Xcode/DerivedData/PlaySuisse-elyoxlzilfvivoavqmgdfcyghbfn/Build/Products/Debug-appletvsimulator/RawCamera' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/tvOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection/RawCamera' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/tvOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/CoreServices/RawCamera.bundle/RawCamera' (no such file), '/System/Library/CoreServices/RawCamera.bundle/RawCamera' (no such file)'
  • In the example project linked below we don’t have any obvious error in the logs.

Version

0.68.2-6

Output of npx react-native info

System:

OS: macOS 12.3.1 CPU: (8) arm64 Apple M1 Memory: 125.94 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries:

Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node Yarn: 1.22.17 - /opt/homebrew/bin/yarn CocoaPods: 1.11.3 - /opt/homebrew/bin/pod

iOS SDK:

Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 IDEs:

Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild

Steps to reproduce

Here is an example project to reproduce the bug: example-app.zip Check App.js

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
leonchabbeycommented, Sep 16, 2022

You should be able to see the issue in this example: ModalFreezeExample.zip

If the button inside RightPanel has its hasTVPreferredFocus prop set to true when the modal becomes visible, you will see the freeze. Set it to false, the animations will be smooth again.

1reaction
douglowdercommented, Sep 7, 2022

Found the fix: https://github.com/douglowder/TVInputDemo/blob/master/patches/react-native%2B0.68.2-6.patch

I apologize for making an obvious error in the implementation of that method.

Also, I strongly recommend that navigation screens using hasTVPreferredFocus should implement navigation focus listeners, and do not allow hasTVPreferredFocus to be true unless the screen is showing. The above sample app shows how to do this. See this hook:

https://github.com/douglowder/TVInputDemo/blob/master/src/navigation/useNavigationFocus.ts

and this example component where the second button gets preferred focus on TV:

https://github.com/douglowder/TVInputDemo/blob/master/src/screens/SimpleButtonExample.tsx

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash on Android with react-navigation stack #309 - GitHub
When I navigate to this specific screen the app is crashing. It works fine on iOS and it works fine if I comment...
Read more >
Expo React Native app with React Navigation 5, crashes on ...
I know it's the Navigator as I tried with single screens and it doesn't crash. I already dived every issue related. Checked the...
Read more >
Stack Navigator | React Navigation
Stack Navigator provides a way for your app to transition between screens where each new screen is placed on top of a stack....
Read more >
createStackNavigator - React Navigation - Netlify
Provides a way for your app to transition between screens where each new screen is placed on top of a stack.
Read more >
react-native-screens - npm
On Android the View state is not persisted consistently across Activity restarts, which can lead to crashes in those cases. It is recommended...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found