Closed adamivancza closed 4 months ago
Hey! 👋
It looks like you've omitted a few important sections from the issue template.
Please complete Snack or a link to a repository section.
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
Hi @adamivancza, have you found a solution for this crash? We have the same problem with CarPlay. I saw this comment of yours, have you tried if it also solves our problem?
@nicomontanari the second one doesn't seem to happen anymore for us. We've updated to 6.37.0 recently which might fixed this. But the first one is still happening, but very rarely. Didn't find a solution yet.
@adamivancza ok thank you 😥 If we find a solution I'll tell you! :)
@nicomontanari awesome, thank you :)
We are experiencing the same issue when trying to connect to CarPlay without opening the iPhone app. [RNSScreenWindowTraits enforceDesiredDeviceOrientation]_block_invoke
Not the best solution, but I finally decided to turn off react native screens in my project:
import { enableScreens } from 'react-native-screens';
enableScreens(false);
My app works now good in Carplay and in my iPhone.
Hi @adamivancza, thanks for submitting this issue! Yes, the problem definitely lies on screen orientation, since the stack trace you provided reveals the calls for the orientation-related methods. Is it possible to create a minimal reproduction that covers your specific case? If not, then I'll need more information about your environment - could you give me an overview of how your navigation stack is structured (also, are there nested stacks, how does your screen look like and what is the presentation of this screen, is this brownfield app? (React native loaded on a Fragment / only in subpart of view hierarchy)?
@mursang good catch. Just out of curiosity, do you use react-navigation in your app? I am afraid that if we would apply your change in our app it could crash
hey @nicomontanari,
yes, I am using react navigation:
"react-native": "0.71.13",
"@react-navigation/bottom-tabs": "6.5.8",
"@react-navigation/native": "6.1.7",
"@react-navigation/stack": "5.14.9",
"react-native-screens": "3.27.0",
and nothing seems to have changed in my app after applying that line of code :)
Hi @adamivancza, thanks for submitting this issue! Yes, the problem definitely lies on screen orientation, since the stack trace you provided reveals the calls for the orientation-related methods. Is it possible to create a minimal reproduction that covers your specific case? If not, then I'll need more information about your environment - could you give me an overview of how your navigation stack is structured (also, are there nested stacks, how does your screen look like and what is the presentation of this screen, is this brownfield app? (React native loaded on a Fragment / only in subpart of view hierarchy)?
@tboba I wasn't able to repro the app myself but I can share the breadcrumbs that bugsnag collects in case that helps. This is a fully react-native app.
app displays a full screen modal using react-navigation then these are the further breadcrumbs from bugsnag. seems like app is backgrounded while the modal is being displayed. then I assume while the app is backgrounded the device orientation changes?
I can confirm that it also seems to happen for our users when the app is in the background:
We're seeing the first one over here as well (objectAtIndexedSubscript
).
We are experiencing the same issue when trying to connect to CarPlay without opening the iPhone app. [RNSScreenWindowTraits enforceDesiredDeviceOrientation]_block_invoke
We got the same error when trying to open the CarPlay app with the iPhone app closed.
[CPTemplateApplicationScene requestGeometryUpdateWithPreferences:errorHandler:]: unrecognized selector sent to instance 0x12372f590
I'm not an objective-c expert, but I think I found the source of the bug.
In RNSScreenWindowTraits.mm
the scene get type casted to UIWindowScene
.
But when opening the CarPlay app, the scene at array[0]
is in our case a CPTemplateApplicationScene
if (@available(iOS 16.0, *)) {
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = (UIWindowScene *)array[0];
UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:orientationMask];
[scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError *_Nonnull error){}];
If I add a check like this before the above code the app is not crashing
if (![array[0] isKindOfClass:[UIWindowScene class]]) { return; }
Thanks for doing the leg work on this @casperolesen. That check makes the app work correctly on CarPlay, but we need to add additional handling for when an app is opened on device after it is opened on CarPlay.
Here is a complete patch for the orientation issue.
diff --git a/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm b/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm
index e8a717e..ea3b2a7 100644
--- a/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm
+++ b/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm
@@ -178,7 +178,21 @@
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_0
if (@available(iOS 16.0, *)) {
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
- UIWindowScene *scene = (UIWindowScene *)array[0];
+
+ // when an app supports multiple scenes (e.g. CarPlay), it is possible that
+ // UIWindowScene is not the first scene, or it may not be present at all
+ UIWindowScene *scene = nil;
+ for (id connectedScene in array) {
+ if ([connectedScene isKindOfClass:[UIWindowScene class]]) {
+ scene = connectedScene;
+ break;
+ }
+ }
+
+ if (scene == nil) {
+ return;
+ }
+
UIWindowSceneGeometryPreferencesIOS *geometryPreferences =
[[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:orientationMask];
[scene requestGeometryUpdateWithPreferences:geometryPreferences
Hi @adamivancza, could you check if the patch submitted above fixes both of the crashes?
yep @tboba - will try it out and let you know. I'll need ~2 weeks to check on Bugsnag if it is all good.
Re-opening it, since the PR had a fixes
comment, but I hope this will be closed soon 😅
Hi @adamivancza! Do you have any updates, regarding this issue?
hey @tboba! sooo sorry but I forgot about this 😅 I've updated our version to 3.30.0 which has the same fix. We will release this update to our users next Monday so I can give you updates sometime next week!
@adamivancza Great! Keep me updated 😄
@tboba the fix seems to work - can't see this crash anymore
@adamivancza Great to hear that! Let's close this issue then 😄
Description
I've noticed 2 crashes in our app related to this library. I'm pasting the crash reports from Bugsnag.
Crash 1
Possible cause
App is backgrounded then possibly change orientation? I only saw this issue on iOS 16.5.1 so it might be related to this certain iOS version?
Crashlog
Crash 2
Possible cause
This function seems to be running into an infinite loop. We're displaying a modal screen prior to this crash so I assume that might be the cause. Found this existing bug report too: https://github.com/software-mansion/react-native-screens/issues/1678
Crashlog
Steps to reproduce
Sadly not entirely sure
Snack or a link to a repository
-
Screens version
3.22.1
React Native version
0.71.8
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Paper (Old Architecture)
Build type
Release mode
Device
Real device
Device model
any iPhone
Acknowledgements
Yes