React-native-orientation: Android: Orientation Change Event not firing if Orientation is locked

Created on 17 Jul 2017  路  11Comments  路  Source: yamill/react-native-orientation

Hi,

my app orientation is locked on Portrait,
on iOS I can add and receive , orientation change events even when orientation is locked.

But on Android, orientation change events are not firing if orientation is locked.

Can we fire orientation events event if the orientation is locked?

Most helpful comment

Oh, if all you want is the ability to free up the view to move portrait/landscape, then just make sure your native Android code allows for that, and run a unlockAllOrientations() in componentWillMount of the view. As a side, in order to control my application, I explicitly lockPortrait() in my entry-point View, and only unlock them for views that need landscape access as well.

All 11 comments

+1

@aschwizzy710 @facuescobar currently the package doesn't support this. If orientation is locked, it doesn't fire orientation changes on Android. It's a known caveat and PRs are highly encouraged.

So I do use an orientation lock, but it is on a specific component and I unlock the orientation in componentWillUnmount() on that component which is locked.

Is that the cause for the orientation being permanently locked on Android? @andrerfneves

Try unlockAllOrientations() as well as lockLandscape() in componentWillMount of the next view. That way it will unlock and re-lock it correctly. Maybe the willUnmount call is not affecting it.

Well, I am not trying to lock it to landscape. I just want it to rotate to landscape when the phone orientation is changed and change back freely when it is changed back to portrait. I will try unlockAllOrientations in the componentWillMount of the next view.

Oh, if all you want is the ability to free up the view to move portrait/landscape, then just make sure your native Android code allows for that, and run a unlockAllOrientations() in componentWillMount of the view. As a side, in order to control my application, I explicitly lockPortrait() in my entry-point View, and only unlock them for views that need landscape access as well.

Excellent - it worked! I appreciate your feedback. @andrerfneves

@aschwizzy710 glad it worked. Closing this for now.

Hey @andrerfneves - how do you go about calling lockPortrait() in your entry point view (to control the app as you mentioned) if you need that view to be landscape responsive as well?

In that case just unlockAllOrientations at your entry point and it should behave accordingly.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings