Giter Site home page Giter Site logo

Comments (25)

gramiro avatar gramiro commented on June 2, 2024 9

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

from react-native-orientation.

Girum avatar Girum commented on June 2, 2024 2

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

from react-native-orientation.

veerabhadrasajjan avatar veerabhadrasajjan commented on June 2, 2024 2

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

The package will be updated?

from react-native-orientation.

Girum avatar Girum commented on June 2, 2024 1

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

from react-native-orientation.

vinceplusplus avatar vinceplusplus commented on June 2, 2024 1

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

from react-native-orientation.

nartco avatar nartco commented on June 2, 2024

Up,same issue

from react-native-orientation.

bishalfan avatar bishalfan commented on June 2, 2024

+1

from react-native-orientation.

minhpham1203 avatar minhpham1203 commented on June 2, 2024

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!

from react-native-orientation.

codal-mpawar avatar codal-mpawar commented on June 2, 2024

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

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

from react-native-orientation.

kesha-antonov avatar kesha-antonov commented on June 2, 2024

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

from react-native-orientation.

gramiro avatar gramiro commented on June 2, 2024

@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.

from react-native-orientation.

codal-mpawar avatar codal-mpawar commented on June 2, 2024

@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 {

  • [self.bridge.eventDispatcher sendDeviceEventWithName:@"specificOrientationDidChange"
  •                                            body:@{@"specificOrientation": [self getSpecificOrientationStr:orientation]}];
    
  • [self.bridge.eventDispatcher sendDeviceEventWithName:@"orientationDidChange"
  •                                            body:@{@"orientation": [self getOrientationStr:orientation]}];
    

+}
+
+- (void)lockToOrientationWithMask:(UIInterfaceOrientationMask)maskOrientation interfaceOrientation:(UIInterfaceOrientation)interfaceOrientation deviceOrientation:(UIDeviceOrientation)deviceOrientation {

  • if (@available(iOS 16, *)) {
    +#ifdef __IPHONE_16_0
  •    dispatch_sync(dispatch_get_main_queue(), ^{
    
  •        NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
    
  •        UIWindowScene *scene = (UIWindowScene *)array[0];
    
  •        [UIViewController attemptRotationToDeviceOrientation];
    
  •        UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:maskOrientation];
    
  •        [scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {}];
    
  •    });
    
  •    [self dispatchOrientationChangeEvent:deviceOrientation];
    

+#endif

  • } else {
  •    [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
    
  •        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
  •        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:interfaceOrientation] forKey:@"orientation"];
    
  •    }];
    
  • }
    +}
  • (void)deviceOrientationDidChange:(NSNotification *)notification
    {
  • UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
  • [self.bridge.eventDispatcher sendDeviceEventWithName:@"specificOrientationDidChange"
  •                                          body:@{@"specificOrientation": [self getSpecificOrientationStr:orientation]}];
    
  • [self.bridge.eventDispatcher sendDeviceEventWithName:@"orientationDidChange"
  •                                          body:@{@"orientation": [self getOrientationStr:orientation]}];
    
  • UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
  • [self dispatchOrientationChangeEvent:orientation];
    }
  • (NSString *)getOrientationStr: (UIDeviceOrientation)orientation {
    @@ -156,12 +179,8 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
    #if DEBUG
    NSLog(@"Locked to Portrait");
    #endif
  • [Orientation setOrientation:UIInterfaceOrientationMaskPortrait];
  • [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
  • [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  • [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
  • }];
  • [Orientation setOrientation:UIInterfaceOrientationMaskPortrait];
  • [self lockToOrientationWithMask:UIInterfaceOrientationMaskPortrait interfaceOrientation:UIInterfaceOrientationPortrait deviceOrientation:UIDeviceOrientationPortrait];
    }

RCT_EXPORT_METHOD(lockToLandscape)
@@ -172,17 +191,11 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSString *orientationStr = [self getSpecificOrientationStr:orientation];
if ([orientationStr isEqualToString:@"LANDSCAPE-LEFT"]) {

  • [Orientation setOrientation:UIInterfaceOrientationMaskLandscape];
  • [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
  •  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
  •  [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
    
  • }];
  •  [Orientation setOrientation:UIInterfaceOrientationMaskLandscapeRight];
    
  •  [self lockToOrientationWithMask:UIInterfaceOrientationMaskLandscapeRight interfaceOrientation:UIInterfaceOrientationLandscapeRight deviceOrientation:UIDeviceOrientationLandscapeRight];
    
    } else {
  • [Orientation setOrientation:UIInterfaceOrientationMaskLandscape];
  • [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
  •  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
  •  [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
    
  • }];
  •  [Orientation setOrientation:UIInterfaceOrientationMaskLandscapeLeft];
    
  •  [self lockToOrientationWithMask:UIInterfaceOrientationMaskLandscapeLeft interfaceOrientation:UIInterfaceOrientationLandscapeLeft deviceOrientation:UIDeviceOrientationLandscapeLeft];
    
    }
    }

@@ -192,11 +205,7 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
NSLog(@"Locked to Landscape Left");
#endif
[Orientation setOrientation:UIInterfaceOrientationMaskLandscapeLeft];

  • [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
  •    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
  •    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
    
  • }];
  • [self lockToOrientationWithMask:UIInterfaceOrientationMaskLandscapeLeft interfaceOrientation:UIInterfaceOrientationLandscapeLeft deviceOrientation:UIDeviceOrientationLandscapeLeft];
    }

RCT_EXPORT_METHOD(lockToLandscapeRight)
@@ -204,13 +213,8 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
#if DEBUG
NSLog(@"Locked to Landscape Right");
#endif

  • [Orientation setOrientation:UIInterfaceOrientationMaskLandscapeRight];
  • [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
  • // this seems counter intuitive
  • [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  • [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
  • }];
  • [Orientation setOrientation:UIInterfaceOrientationMaskLandscapeRight];
  • [self lockToOrientationWithMask:UIInterfaceOrientationMaskLandscapeRight interfaceOrientation:UIInterfaceOrientationLandscapeRight deviceOrientation:UIDeviceOrientationLandscapeRight];
    }

RCT_EXPORT_METHOD(unlockAllOrientations)
@@ -218,9 +222,9 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
#if DEBUG
NSLog(@"Unlock All Orientations");
#endif

  • UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    [Orientation setOrientation:UIInterfaceOrientationMaskAllButUpsideDown];
    -// AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    -// delegate.orientation = 3;
  • [self lockToOrientationWithMask:UIInterfaceOrientationMaskAllButUpsideDown interfaceOrientation:UIInterfaceOrientationMaskAllButUpsideDown deviceOrientation:orientation];
    }
  • (NSDictionary *)constantsToExport

from react-native-orientation.

pawansharmaAccolite avatar pawansharmaAccolite commented on June 2, 2024

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

from react-native-orientation.

vinceplusplus avatar vinceplusplus commented on June 2, 2024

@pawansharmaAccolite, yes, it is

from react-native-orientation.

pawansharmaAccolite avatar pawansharmaAccolite commented on June 2, 2024

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

from react-native-orientation.

vinceplusplus avatar vinceplusplus commented on June 2, 2024

@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

from react-native-orientation.

pawansharmaAccolite avatar pawansharmaAccolite commented on June 2, 2024

@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

from react-native-orientation.

codal-mpawar avatar codal-mpawar commented on June 2, 2024

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.

from react-native-orientation.

poojasolanki9569 avatar poojasolanki9569 commented on June 2, 2024

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.

from react-native-orientation.

nriccar avatar nriccar commented on June 2, 2024

Any fixes?

from react-native-orientation.

ou2s avatar ou2s commented on June 2, 2024

@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.

from react-native-orientation.

tipaniclayr30 avatar tipaniclayr30 commented on June 2, 2024

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

from react-native-orientation.

maoyuhu avatar maoyuhu commented on June 2, 2024

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

from react-native-orientation.

ou2s avatar ou2s commented on June 2, 2024

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) {}];
 }

from react-native-orientation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.