Comments (25)
Hey guys, here's a PR with a fix for iOS16 orientation :)
from react-native-orientation.
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.
Hey guys, here's a PR with a fix for iOS16 orientation :)
The package will be updated?
from react-native-orientation.
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.
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.
Up,same issue
from react-native-orientation.
+1
from react-native-orientation.
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.
Hey guys, here's a PR with a fix for iOS16 orientation :)
any update on this? @gramiro @vinceplusplus @Girum @veerabhadrasajjan
from react-native-orientation.
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.
@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.
@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];
-
} else {
[self lockToOrientationWithMask:UIInterfaceOrientationMaskLandscapeRight interfaceOrientation:UIInterfaceOrientationLandscapeRight deviceOrientation:UIDeviceOrientationLandscapeRight];
- [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.
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.
@pawansharmaAccolite, yes, it is
from react-native-orientation.
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.
@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 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.
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.
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.
Any fixes?
from react-native-orientation.
@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.
do you already have a solution for this?
Im also experiencing it huhuhu
from react-native-orientation.
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.
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)
- App crashes on start (Android Version Android 8.0 (SDK 26)) HOT 1
- App can not compile HOT 2
- Task :react-native-orientation:verifyReleaseResources FAILED HOT 15
- Orientation.lockToPortrait() throw a error HOT 2
- Bugs and no Maintanance! (iOS)
- Landscape orientation to particular screen HOT 1
- Unlock all orientations
- Fix compileSdkVersion and buildToolsVersion HOT 1
- How to lock orientation for iPhone: Portrait and for iPad: Landscape. it should not be changed after rotate screen HOT 1
- add compatibility for Gradle 7.0.0+ on React Native 0.68.1 HOT 2
- Is this package still be maintained? HOT 1
- Android Builds Fail Could not find method compile() for arguments [project ':react-native-orientation'] HOT 4
- Change compile with api in build.gradle HOT 1
- IOS 16.1.1 deviceOrientationDidChange method is not called HOT 8
- Orientation is not working in real device which ios 14+ HOT 5
- fix android build.gradle HOT 1
- ry
- Correcao de erro ao compilar com react-native 0.70.6
- Issue in performing orientation in ios HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-orientation.