I installed this with RN 0.42.0, and tried to lock the screen as portrait by Orientation.lockToPortrait(); in the componentDidMount function, but it seems didn't lock my screen as portrait, does anyone has this problem?
react-native link after yarn adddid you face this error before ?
constructor OrientationPackage in class OrientationPackage cannot be applied to given types;
new OrientationPackage()
^
required: Activity
found: no arguments
@safweb89, I just use this library few days ago
I'm on RN 0.42. I left all orientations open in XCode settings.
In my entrypoint component I have :
componentDidMount() {
// Only a few specific views allor landscape and they are responsible
// for unlocking and relocking the orientation
Orientation.lockToPortrait();
}
In a component that allows unlocking temporarily :
```
componentDidMount() {
Orientation.unlockAllOrientations();
}
componentWillUnmount() {
Orientation.lockToPortrait();
}
```
You'll see a trace in your react-native log when it locks and unlocks successfully, too.
@wellyshen Can you post some code?
Did you also check the manual linking process to make sure the auto-link didn't miss any steps?
@dozel
What I did is :
react-native linkimport Orientation from 'react-native-orientationcomponentDidMount () {
Orientation.lockToPortrait();
}
After all the settings, I run my iOS simulator and click cmd + right or cmd + left, the screen won't locked on landscape.
OK, I will try the manual set up and see what's going on.
@dozel I have tried to set up the library with xCode manually, but it still can't work.
BTW I'm using react-navigation, is that matter?
any solution for this?
i have same issue
I just tested again and it is working as expected on my side. Maybe post to stack overflow ?
@ibussieres when you set Orientation.lockToPortrait() it indeed gets locked (if user rotate the device,nothing changes) or it just changes the orientarion to portrait and user can rotate it back to landscape? Because this had been my scenario, the function just rotate but doesn't lock.
If everything is working fine for you, would you mind share your AppDelegate? Thanks
When I set Orientation.lockToPortrait() and turn the phone to landscape, nothing moves. Elements are still displayed as if the phone was in portrait. Working both on iOS and Android.
@ibussieres I still can't have the orientation lock working. I have given more information in this issue: https://github.com/yamill/react-native-orientation/issues/136#issuecomment-290323551
Would you mind take a look at it, please?
Thanks
@safweb89 I'm getting the same error as you upon compile too. Did you get to solve the issue?
npm install --save react-native-orientation will fail
npm install --save react-native-orientation@https://github.com/yamill/react-native-orientation.git succeeded
I don't think the author has updated NPM
@Lizhooh Can it work in 0.44.0?
@wellyshen 0.43.4 ok, 0.44.0 hasn't tried yet
I use the Android, IOS temporarily unclear
Using react native 0.44.0 on IOS
running react-native link after installing the package works as expected
@Joe312341 How did you install the library? Through npm install --save react-native-orientation@https://github.com/yamill/react-native-orientation.git or npm install --save react-native-orientation?
npm install --save react-native-orientation
@Joe312341 Could you mind to share your setup steps or some code?
@wellyshen I tested it with a fresh App on IOS, no special setup
I solved my issue for Android. After running npm link the new OrientationPackage() was added twice on MainApplication.java so I just removed the redundancy. This package works for me on RN 0.43.4.
I'm running RN 0.42 & tried both npm & the git repo - doesn't work. However, this does.
componentDidMount() {
Orientation.addOrientationListener(() => Orientation.lockToPortrait());
}
Except this locked all views. I'm using RN 0.42 & react-navigation with a tabbar
Hi Guys, I fellow the updated instruction of README to install this library on RN 0.44.0, now it works :)
@wellyshen glad it worked out
Most helpful comment
@wellyshen glad it worked out