i use createNativeStackNavigator from 'react-native-screens/native-stack';
i have one problem in two cases:
first is when i fixed orientation: dont work.
secont when i use wonday/react-native-orientation-locker has the same problem orientation dont fixed.
if i donte use react native screens the orientation fixed was ok.
i force fix orientation with calling react native locker every page with timeout 100ms and ok but, i would like no need use this pratice.
Could you provide a simple example that we could reproduce this issue?
@kacperkapusciak Same here. Just simply create a createNativeStackNavigator with two screens with
android:screenOrientation="portrait"
in AndroidManifest.xml wouldn't work to fix the orientation.
@misaku
The issue is in ScreenStackHeaderConfig.java line 47
, change it to:
private int mScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
works for me.
Can you check if changing this line: https://github.com/software-mansion/react-native-screens/blob/master/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java#L176 to if ((getScreenFragment() == null || !getScreenFragment().hasChildScreenWithConfig(getScreen())) && mScreenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { fixes your issue?
Hi @WoLewicki,
On my side I was able to reproduce a similar issue:
android:screenOrientation="portrait" but since we upgraded react-native-screens, on Android the orientation isn't fixed anymore.adding what you mentioned in
No issues on iOS.
@WoLewicki The one line ScreenStackHeaderConfig.java fixed my problem, orientation is now locked again. Cheers!
@WoLewicki Your patch fixed the issue on my end as well.
@kacperkapusciak Same here. Just simply create a createNativeStackNavigator with two screens with
android:screenOrientation="portrait"in AndroidManifest.xml wouldn't work to fix the orientation.
i try this but not work
@misaku
The issue is in ScreenStackHeaderConfig.java line 47
, change it to:private int mScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;works for me.
I will try to do this, but I would like to change the orientation at a specific time, for example, when I open the camera,
@kacperkapusciak thx to help to fix, i will try to do and i will provide porject case to simulate this case.
Can you check if adding changes from https://github.com/software-mansion/react-native-screens/pull/860 also resolves the issue? It should prevent setting the orientation if it was not done explicitly by the user via a prop.
hi @WoLewicki i test withe the change, and this solution fix the problem, thx to help
i will close when fix merge =)
any idea when it is merge fix solution?
It will be merged after the PR is thoroughly tested. You can always use patch-package to apply the changes in your project before they are merged and released.
I am running into a similar but different issue. On android the default orientation is not being respected, meaning the orientation is not rotating depending on the user's system settings when set to default (or not set), and vice versa if set to all. I'm looking to not force the orientation to lock or all, but only respect what the device settings are. This behaves fine on iOS. The patch in the ScreenStackHeaderConfig doesn't address it unfortunately.
After this PR: https://github.com/software-mansion/react-native-screens/pull/863 is released, it should work in the way that until you don't set the orientation on any screen, the system settings should be used. Although if you set the orientation by using a prop, then react-native-screens will be the one managing it. You can try and patch-package that PR to see if it is what you need. It is a big one though cause it makes the status bar and orientation props usable in all navigators of react-navigation.
@jp928 - How did you actually implement this fix?
Did you fork, make the change, then just point to it from package.json...or did you need to run some build step?
@kacperkapusciak Same here. Just simply create a createNativeStackNavigator with two screens with
android:screenOrientation="portrait"in AndroidManifest.xml wouldn't work to fix the orientation.
I can't for the life of me get this fixed for Android, I've tried:
private int mScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;screenOrientation: "portrait_up" in screenOptions on the top most navigatorNothing works. I'm on Expo SDK 41 Managed.
Here is a minimal reproduced test case for Expo. Can anyone get this working even with an ugly hack?
@Aryk if you are using Expo managed workflow, you cannot change the native code since it is compiled into your Expo Go application. That is why any of the changes in the native code won't be applied in your app.
@WoLewicki - FYI I was trying to get it working through EAS builds.
While I was doing it I had to yarn cache clear and then rm yarn.lock and then yarn
Somehow...that caused the "screenOrientation" param to start working again, so I can use that fix without complicating my workflow.
Only updating ScreenStackHeaderConfig didnt work for me. I also had to do the 2nd change mentioned by @Almouro to get it to work.
I will close it since #863 is merged and should resolve the issue. You can try adding the newest master to your repo and see that if you do not change the orientation in any of the screens, react-native-screens shouldn't update it anyhow.
Most helpful comment
It will be merged after the PR is thoroughly tested. You can always use patch-package to apply the changes in your project before they are merged and released.