Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 1.2.0 addOrientationListener not working on android #139

Closed
webyonet opened this issue Aug 19, 2020 · 14 comments · Fixed by #140
Closed

version 1.2.0 addOrientationListener not working on android #139

webyonet opened this issue Aug 19, 2020 · 14 comments · Fixed by #140

Comments

@webyonet
Copy link

v1.2.0 addOrientationListener does not work on android device and continues to rotate even if Auto-rotate button is turned off. None of these issues occurred in v1.1.8

RN: 0.61.5
Android: 10

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Aug 25, 2020

Hey @webyonet, 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!

@VankataMitov
Copy link

@r0b0t3d It doesn`t work for me at the first launch of the app but if I close the app and open again, it works properly.
As @webyonet said, none of these issues occurred in version 1.1.8.

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Aug 26, 2020

@VankataMitov Thanks for your information. Basically, there is no difference between launch, the callback is registered when application created. So it must works on first launch too.
Anyway, I will try to reproduce with your information.

@WaterCityFlame
Copy link

I was experiencing an issue like this earlier. I would attempt to listen for orientation changes and on android, the callback would run when the component mounted but not after that.

I didn't try closing and re-opening the app, so can't tell you how that went. My work around was to use addDeviceOrientationListener instead, which worked. Both functions worked on iOS.

I don't know what the difference is between addDeviceOrientationListener and addOrientationListener since they seem to be functionally equivalent, at least in my use case. Is there documentation on that? I didn't see any.

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Aug 27, 2020

@WaterCityFlame

  • addOrientationListener: will listen orientation changes based on device configuration. If your application just allow portrait mode (android:screenOrientation="portrait") or Auto rotate turn off, you won't see events in this case.
    image

  • addDeviceOrientationListener: will listen orientation changes based on sensors. So, it won't depend on above conditions

@WaterCityFlame
Copy link

@r0b0t3d thanks for explaining that. addDeviceOrientationListener sounds like it works for my use case even given those differences, so that's good.

The fact remains that I wasn't getting addOrientationListener events on Android even when it was working on iOS. I'll try to find time to get more specific information on what was & wasn't working for me later, see if I can get you a reliable reproduction.

@dinhtrumdieu
Copy link

dinhtrumdieu commented Sep 12, 2020

v1.2.0 addDeviceOrientationListener not working on IOS device when Auto-rotate turn off .

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Sep 12, 2020

@dinhtrumdieu
Actually, in 1.2.0, there was no change for addDeviceOrientationListener in iOS. You can check release note below.

  1. Add support for lockAllOrientationsButUpsideDown (Add support for lockAllOrientationsButUpsideDown #110)
  2. Ignore on web and desktop (ignore on web and desktop #115)
  3. Fix for not finding @ReactModule (Fix for not finding @ReactModule  #125)
  4. Fix unlockAllOrientations on Android (Fix unlockAllOrientations on Android #133)
  5. Implement ActivityLifecycleCallbacks on Android ([Android] implement ActivityLifecycleCallbacks #131)

So, in your case, I think you should check the previous version to see whether it works or not. If you find it is the problem with 1.2.0, you can open another issue to keep track. This issue should just for android.

I am going to work on this issue for Android. Hopefully can fix this weekend.

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Sep 12, 2020

@webyonet @VankataMitov If you have time, please help to check #140 to see whether this issue is fixed. Thanks

@dinhtrumdieu
Copy link

@r0b0t3d I want to listen to orientation changes when the AUTO rotate turn off. The fact that I wasn't getting addDeviceOrientationListener on IOS even when it was working on Android

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Sep 14, 2020

If that is the case, you should open an issue with addDeviceOrientationListener for iOS. So someone can look at it when they have time including me.

@kbooz
Copy link

kbooz commented Sep 21, 2020

Are you guys going to generate a new release based on this fix? (:

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Sep 21, 2020

@wonday Could you consider to make a patch release for this?

@IgorGanapolsky
Copy link

IgorGanapolsky commented Jun 18, 2024

This is actually still happening with v1.7.0. When I run jest tests, it fails with:

TypeError: _reactNativeOrientationLocker.default.addOrientationListener is not a function

  19 |     };
  20 |
> 21 |     Orientation.addOrientationListener(orientationDidChange);
     |                 ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants