react-native-orientation-locker icon indicating copy to clipboard operation
react-native-orientation-locker copied to clipboard

Version 1.2.0 does not pass in _onOrientationDidChange

Open bobdeprez opened this issue 5 years ago • 4 comments

Hello,

react-native-orientation-locker module in our project got updated to version 1.2.0, we were using version 1.1.8 before. Since the update when the app rotates we do not pass in _onOrientationDidChange, is this a known issue? I do not see any errors while building and running the app. When the app starts it also is getting the orientation from Orientation.getOrientation() For now I will continue to use 1.1.8

The project uses RN 0.62.2.

If more info is needed please let me know.

bobdeprez avatar Aug 06 '20 15:08 bobdeprez

Hey @bobdeprez , there is breaking changes in 1.2.0 related to #131. Please add this code to onCreate of MainApplication

registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance());

Could you please check if it works. Thanks!

r0b0t3d avatar Aug 25 '20 14:08 r0b0t3d

Hello, this does not work, still _orientationDidChange is not called when changing orientation. I use Orientation.addOrientationListener, I do a lockToPortrait for a small device and do unlockAllOrientations for a large device. If I use addDeviceOrientationListener instead of addOrientationListner, the detection of rotation works even without the line 'registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance());' in the MainApplication.java, but that is not a solution because you cannot lock to portrait.

As said above this works perfectly fine in version 1.1.8 but it does not in 1.2.0. If you need more info, I will gladly provide it.

bobdeprez avatar Aug 28 '20 06:08 bobdeprez

I have the same problem, addOrientationListener not work at all:

    onOrientationChange = orientation => {
        console.log('orientation', orientation);
        console.log('isLocked', Orientation.isLocked());

        if (orientation === 'UNKNOWN') return;
        if (orientation === 'PORTRAIT-UPSIDEDOWN') return;
        if (orientation === this.state.orientation) return;
        console.log(`orientation from ${this.state.orientation} change to ${orientation}`);

        this.setState({orientation, isPortrait: !orientation.startsWith('LANDSCAPE')});
    };

    componentDidMount() {
        Orientation.unlockAllOrientations();
        Orientation.addOrientationListener(this.onOrientationChange);
    }

    componentWillUnmount() {
        Orientation.lockToPortrait();
        Orientation.removeOrientationListener(this.onOrientationChange);
    }

someok avatar Oct 02 '20 11:10 someok

#140 fix this issue, but hasn't released yet. You can try master branch to see whether it works. Thanks!

r0b0t3d avatar Oct 02 '20 11:10 r0b0t3d