yamill / react-native-orientation

Listen to device orientation changes in react-native and set preferred orientation on screen to screen basis.
https://www.npmjs.com/package/react-native-orientation
ISC License
1.72k stars 809 forks source link

Orintentation problems with iOS16 #411

Open Girum opened 1 year ago

Girum commented 1 year ago

Hi! After update to iOS16, some functionallities dont work sometimes. The package will be updated?

nartco commented 1 year ago

Up,same issue

bishalfan commented 1 year ago

+1

Girum commented 1 year ago

I changed to react-native-orientation-locker and it works fine! But now android has a problem: I'm using react-native-video lib. When I change the orientation, or even change something, the video reloads

minhpham1203 commented 1 year ago

I changed to react-native-orientation-locker and it works fine! But now android has a problem: I'm using react-native-video lib. When I change the orientation, or even change something, the video reloads Hi @Girum , I am using react-native-orientation-locker, but the callback function is not called in addOrientationListener. So I can not check the orientation. Any solution? Thank you!

Girum commented 1 year ago

Hi @minhpham1203 . HEre works perfectly.

Orientation.addOrientationListener(orientationChange)

return () => {
  Orientation.removeOrientationListener(orientationChange)
};
const orientationChange = (orientation) => {
        if(orientation == 'LANDSCAPE-RIGHT' || orientation ==  'LANDSCAPE-LEFT') {
           ...

        } else if (orientation == 'PORTRAIT') {
            ...
        }
    }

The only change I made is that dont exists the enum "LANDASCAPE". I had to set the conditions to "LANDASCAPE_LEFT" and "LANDASCAPE_RIGHT"

@minhpham1203 afeter another test, it not works too... =(. We have to ask in the react-native-orientation-locker github

It fires the if(orientation == 'LANDSCAPE-RIGHT' || orientation == 'LANDSCAPE-LEFT'), but not work in another functions inside of this if

gramiro commented 1 year ago

Hey guys, here's a PR with a fix for iOS16 orientation :)

vinceplusplus commented 1 year ago

if you are still building with iOS 15 sdk, could try going into Orientation.m, and add

[UIViewController attemptRotationToDeviceOrientation];

below every

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: ... ] forKey:@"orientation"];

that should work on iOS 16

veerabhadrasajjan commented 1 year ago

Hey guys, here's a PR with a fix for iOS16 orientation :)

The package will be updated?

codal-mpawar commented 1 year ago

Hey guys, here's a PR with a fix for iOS16 orientation :)

any update on this? @gramiro @vinceplusplus @Girum @veerabhadrasajjan

kesha-antonov commented 1 year ago

I think we need to take ownership of this package or use some stable fork since this lib wasn't updated for 5 years. I think it's unlikely it'll be updated in the future

gramiro commented 1 year ago

@codal-mpawar I'm not the owner of the library so I guess we need to do what @kesha-antonov is proposing. As a temporary solution I'm just patching my projects.

codal-mpawar commented 1 year ago

@gramiro it's working locally but it's not working on the release mode.

below is patch package. diff --git a/node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.m b/node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.m index 15e9927..67940a4 100644 --- a/node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.m +++ b/node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.m @@ -39,15 +39,38 @@ + (BOOL)requiresMainQueueSetup return YES; }

+- (void)dispatchOrientationChangeEvent:(UIDeviceOrientation)orientation {

@@ -192,11 +205,7 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation { NSLog(@"Locked to Landscape Left");

endif

 [Orientation setOrientation:UIInterfaceOrientationMaskLandscapeLeft];
pawansharmaAccolite commented 1 year ago

if you are still building with iOS 15 sdk, could try going into Orientation.m, and add

[UIViewController attemptRotationToDeviceOrientation];

below every

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: ... ] forKey:@"orientation"];

that should work on iOS 16

can you confirm that is working in real device not in simulator

vinceplusplus commented 1 year ago

@pawansharmaAccolite, yes, it is

pawansharmaAccolite commented 1 year ago

yes same here i made this patch its working fine at local but when i hit on pipeline its not working

vinceplusplus commented 1 year ago

@pawansharmaAccolite if it’s working locally probably you haven’t had the patch applied on the pipeline. you will need to either fork this repo and add the change or use something like https://www.npmjs.com/package/patch-package to check in locally applied patches to your app repo. Also if it’s the fix I mentioned, i think it will only work if you are building with Xcode 14/iOS 15 sdk, so make sure your pipeline is using the same setup

pawansharmaAccolite commented 1 year ago

@pawansharmaAccolite if it’s working locally probably you haven’t had the patch applied on the pipeline. you will need to either fork this repo and add the change or use something like https://www.npmjs.com/package/patch-package to check in locally applied patches to your app repo. Also if it’s the fix I mentioned, i think it will only work if you are building with Xcode 14/iOS 15 sdk, so make sure your pipeline is using the same setup

yes i face same issue in pipeline but guys i am okay with that it does not work on ios 16 but it should work on ios 14 and 15 because. my pipeline using xcode 13.1 to deploy but still i don't understand why its not working in real device i don't have access of real device which have ios 14 or 15. Only device i have is ios 16

that's why i asked for help that its really working in real device which have ios 14 or 15

codal-mpawar commented 1 year ago

if you are still building with iOS 15 sdk, could try going into Orientation.m, and add

[UIViewController attemptRotationToDeviceOrientation];

below every

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: ... ] forKey:@"orientation"];

that should work on iOS 16

@vinceplusplus Can you please share more info because i added with this way and its not working on released mode.

poojasolanki9569 commented 1 year ago

Pipeline should have the same setup (macOS version (13.1) and xcode (14.2)), then it is working fine locally as well as on real devices.

nriccar commented 1 year ago

Any fixes?

ou2s commented 1 year ago

@codal-mpawar thanks for the fix.

FYI, this line causes occasional crashes : UIWindowScene *scene = (UIWindowScene *)array[0];

Crash: *** -[__NSArrayI_Transfer objectAtIndexedSubscript:]: index 0 beyond bounds for empty array

I think it's because I call this function when the app is still initialising.

tipaniclayr30 commented 1 year ago

do you already have a solution for this? Im also experiencing it huhuhu

maoyuhu commented 1 year ago

hey,guys,i have solved the problem for iOS 16 system,and it work fine in ios 16 system. in Orientation.m i add this code

1.0 //适配iOS16系统 -(void)adapterIOS16SystemWithOrientation:(UIInterfaceOrientationMask)Orientation{ if (@available(iOS 16.0, )) { UIWindow originalKeyWindow = [[UIApplication sharedApplication] keyWindow]; if (originalKeyWindow != nil) { [originalKeyWindow.rootViewController setNeedsUpdateOfSupportedInterfaceOrientations]; NSArray array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; UIWindowScene scene = (UIWindowScene )array[0]; UIWindowSceneGeometryPreferencesIOS geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:Orientation]; [scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { NSLog(@"error---%@", error.description); }]; } } }

2.0 and call where needed ,for example: RCT_EXPORT_METHOD(lockToLandscapeRight) {

if DEBUG

NSLog(@"Locked to Landscape Right");

endif

[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
    [Orientation setOrientation:UIInterfaceOrientationMaskLandscapeRight];

  //    // this seems counter intuitive
      [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
      [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
    [self adapterIOS16SystemWithOrientation:UIInterfaceOrientationMaskLandscapeRight];

}]; } 3.0 it work fine good luck

ou2s commented 1 year ago

do you already have a solution for this? Im also experiencing it huhuhu

@tipaniclayr30 Sorry you didn't tag me, so I didn't see your question. I just added a safeguard:

NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
if (array.count > 0) {
      UIWindowScene *scene = (UIWindowScene *)array[0];
      [UIViewController attemptRotationToDeviceOrientation];
       UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:maskOrientation];
       [scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {}];
 }
taongocson commented 4 months ago

I've added: react-native-orientation-locker then in file App.js import Orientation from "react-native-orientation-locker";

useEffect(() => { Orientation.lockToPortrait(); return () => { Orientation.unlockAllOrientations(); }; }, []);