Skip to content

Commit

Permalink
Solves an error with rotation if the screen is already rotated in iOS (
Browse files Browse the repository at this point in the history
  • Loading branch information
josepbordesjove authored and stoneman1 committed Dec 30, 2017
1 parent ed1ac2e commit d9a6d77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Add the following to your project's `AppDelegate.m`:
// ...
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
return [Orientation getOrientation];
}
Expand Down
5 changes: 5 additions & 0 deletions iOS/RCTOrientation/Orientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
#endif
[Orientation setOrientation:UIInterfaceOrientationMaskPortrait];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
}];

Expand All @@ -173,11 +174,13 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
if ([orientationStr isEqualToString:@"LANDSCAPE-LEFT"]) {
[Orientation setOrientation:UIInterfaceOrientationMaskLandscape];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
}];
} else {
[Orientation setOrientation:UIInterfaceOrientationMaskLandscape];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}];
}
Expand All @@ -190,6 +193,7 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
#endif
[Orientation setOrientation:UIInterfaceOrientationMaskLandscapeLeft];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}];

Expand All @@ -203,6 +207,7 @@ - (NSString *)getSpecificOrientationStr: (UIDeviceOrientation)orientation {
[Orientation setOrientation:UIInterfaceOrientationMaskLandscapeRight];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
// this seems counter intuitive
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
}];

Expand Down

0 comments on commit d9a6d77

Please sign in to comment.