Browse Source

Ios orientation (#820)

iOS support orientation changes
Ran 7 years ago
parent
commit
62cd096e8f

+ 7
- 1
ios/RCCDrawerController/RCCDrawerController.m View File

@@ -4,6 +4,7 @@
4 4
 #import "RCCDrawerHelper.h"
5 5
 #import <React/RCTConvert.h>
6 6
 #import "RCCManagerModule.h"
7
+#import "UIViewController+Rotation.h"
7 8
 
8 9
 #define RCCDRAWERCONTROLLER_ANIMATION_DURATION 0.33f
9 10
 
@@ -12,7 +13,9 @@
12 13
 
13 14
 @synthesize drawerStyle = _drawerStyle;
14 15
 
15
-
16
+-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
17
+    return [self supportedControllerOrientations];
18
+}
16 19
 
17 20
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
18 21
 {
@@ -66,6 +69,9 @@
66 69
                                                
67 70
     self.view.backgroundColor = [UIColor clearColor];
68 71
     
72
+    [self setRotation:props];
73
+    
74
+    
69 75
     if (!self) return nil;
70 76
     return self;
71 77
 }

+ 9
- 1
ios/RCCDrawerController/RCCTheSideBarManagerViewController.m View File

@@ -10,7 +10,7 @@
10 10
 #import "RCCViewController.h"
11 11
 #import "RCCDrawerHelper.h"
12 12
 #import <React/RCTConvert.h>
13
-
13
+#import "UIViewController+Rotation.h"
14 14
 
15 15
 @interface RCCTheSideBarManagerViewController () <TheSidebarControllerDelegate>
16 16
 
@@ -39,6 +39,12 @@
39 39
     return _overlayButton;
40 40
 }
41 41
 
42
+
43
+-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
44
+    return [self supportedControllerOrientations];
45
+}
46
+
47
+
42 48
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge {
43 49
     
44 50
     if ([children count] < 1) return nil;
@@ -73,6 +79,8 @@
73 79
     [self setAnimationType:props[@"animationType"]];
74 80
     [self setStyle];
75 81
     
82
+    [self setRotation:props];
83
+    
76 84
     return self;
77 85
 }
78 86
 

+ 9
- 0
ios/RCCNavigationController.m View File

@@ -5,12 +5,18 @@
5 5
 #import <React/RCTConvert.h>
6 6
 #import <objc/runtime.h>
7 7
 #import "RCCTitleViewHelper.h"
8
+#import "UIViewController+Rotation.h"
8 9
 
9 10
 @implementation RCCNavigationController
10 11
 
11 12
 NSString const *CALLBACK_ASSOCIATED_KEY = @"RCCNavigationController.CALLBACK_ASSOCIATED_KEY";
12 13
 NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSOCIATED_ID";
13 14
 
15
+
16
+-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
17
+  return [self supportedControllerOrientations];
18
+}
19
+
14 20
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
15 21
 {
16 22
   NSString *component = props[@"component"];
@@ -44,6 +50,9 @@ NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSO
44 50
                    props:props
45 51
                    style:navigatorStyle];
46 52
   
53
+
54
+  [self setRotation:props];
55
+  
47 56
   return self;
48 57
 }
49 58
 

+ 8
- 0
ios/RCCTabBarController.m View File

@@ -4,6 +4,7 @@
4 4
 #import "RCCManager.h"
5 5
 #import "RCTHelpers.h"
6 6
 #import <React/RCTUIManager.h>
7
+#import "UIViewController+Rotation.h"
7 8
 
8 9
 @interface RCTUIManager ()
9 10
 
@@ -15,6 +16,11 @@
15 16
 
16 17
 @implementation RCCTabBarController
17 18
 
19
+
20
+-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
21
+  return [self supportedControllerOrientations];
22
+}
23
+
18 24
 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
19 25
   id queue = [[RCCManager sharedInstance].getBridge uiManager].methodQueue;
20 26
   dispatch_async(queue, ^{
@@ -150,6 +156,8 @@
150 156
 
151 157
   // replace the tabs
152 158
   self.viewControllers = viewControllers;
159
+  
160
+  [self setRotation:props];
153 161
 
154 162
   return self;
155 163
 }

+ 6
- 0
ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

@@ -8,6 +8,7 @@
8 8
 
9 9
 /* Begin PBXBuildFile section */
10 10
 		260804DB1CE0D9D20094DBA1 /* RCCToolBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 260804DA1CE0D9D20094DBA1 /* RCCToolBar.m */; };
11
+		261108801E6C495400BF5D98 /* UIViewController+Rotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 2611087F1E6C495400BF5D98 /* UIViewController+Rotation.m */; };
11 12
 		26AFF3F51D7EEE2400CBA211 /* RCCTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */; };
12 13
 		CC84A19E1C1A0C4E00B3A6A2 /* RCCManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */; };
13 14
 		CC84A19F1C1A0C4E00B3A6A2 /* RCCManagerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1961C1A0C4E00B3A6A2 /* RCCManagerModule.m */; };
@@ -50,6 +51,8 @@
50 51
 /* Begin PBXFileReference section */
51 52
 		260804D91CE0D9D20094DBA1 /* RCCToolBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCToolBar.h; sourceTree = "<group>"; };
52 53
 		260804DA1CE0D9D20094DBA1 /* RCCToolBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCToolBar.m; sourceTree = "<group>"; };
54
+		2611087E1E6C495400BF5D98 /* UIViewController+Rotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIViewController+Rotation.h"; path = "../UIViewController+Rotation.h"; sourceTree = "<group>"; };
55
+		2611087F1E6C495400BF5D98 /* UIViewController+Rotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIViewController+Rotation.m"; path = "../UIViewController+Rotation.m"; sourceTree = "<group>"; };
53 56
 		26AFF3F31D7EEE2400CBA211 /* RCCTitleViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCTitleViewHelper.h; sourceTree = "<group>"; };
54 57
 		26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCTitleViewHelper.m; sourceTree = "<group>"; };
55 58
 		CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManager.h; sourceTree = "<group>"; };
@@ -227,6 +230,8 @@
227 230
 		D8D779951D04B7180050CFEA /* Helpers */ = {
228 231
 			isa = PBXGroup;
229 232
 			children = (
233
+				2611087E1E6C495400BF5D98 /* UIViewController+Rotation.h */,
234
+				2611087F1E6C495400BF5D98 /* UIViewController+Rotation.m */,
230 235
 				D8D779961D04B7180050CFEA /* RCTHelpers.h */,
231 236
 				D8D779971D04B7180050CFEA /* RCTHelpers.m */,
232 237
 				26AFF3F31D7EEE2400CBA211 /* RCCTitleViewHelper.h */,
@@ -312,6 +317,7 @@
312 317
 				CC84A1A21C1A0C4E00B3A6A2 /* RCCViewController.m in Sources */,
313 318
 				D85082E91CBCF54200FDB961 /* SidebarWunderlistAnimation.m in Sources */,
314 319
 				D85082E11CBCF54200FDB961 /* RCCDrawerHelper.m in Sources */,
320
+				261108801E6C495400BF5D98 /* UIViewController+Rotation.m in Sources */,
315 321
 				D85082FE1CBCF8A800FDB961 /* MMDrawerVisualState.m in Sources */,
316 322
 				D85082FD1CBCF8A800FDB961 /* MMDrawerController.m in Sources */,
317 323
 				D85082E41CBCF54200FDB961 /* SidebarAnimation.m in Sources */,

+ 17
- 0
ios/UIViewController+Rotation.h View File

@@ -0,0 +1,17 @@
1
+//
2
+//  UIViewController+Rotation.h
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Ran Greenberg on 05/03/2017.
6
+//  Copyright © 2017 artal. All rights reserved.
7
+//
8
+
9
+#import <UIKit/UIKit.h>
10
+
11
+@interface UIViewController (Rotation)
12
+
13
+
14
+-(void)setRotation:(NSDictionary*)style;
15
+-(UIInterfaceOrientationMask)supportedControllerOrientations;
16
+
17
+@end

+ 63
- 0
ios/UIViewController+Rotation.m View File

@@ -0,0 +1,63 @@
1
+//
2
+//  UIViewController+Rotation.m
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Ran Greenberg on 05/03/2017.
6
+//  Copyright © 2017 artal. All rights reserved.
7
+//
8
+
9
+#import "UIViewController+Rotation.h"
10
+#import <objc/runtime.h>
11
+
12
+static NSString *const ORIENTATION =            @"orientation";
13
+
14
+static NSString *const ORIENTATION_PORTRAIT =   @"portrait";
15
+static NSString *const ORIENTATION_LANDSCAPE =  @"landscape";
16
+static NSString *const ORIENTATION_AUTO =       @"auto";      // defualt
17
+
18
+
19
+@interface UIViewController (Rotation)
20
+
21
+@property (nonatomic, strong) NSString *orientation;
22
+
23
+@end
24
+
25
+@implementation UIViewController (Rotation)
26
+
27
+
28
+-(NSString*)orientation {
29
+    return objc_getAssociatedObject(self, @selector(orientation));
30
+}
31
+
32
+-(void)setOrientation:(NSString*)newOrientation {
33
+    objc_setAssociatedObject(self, @selector(orientation), newOrientation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
34
+}
35
+
36
+
37
+#pragma mark - Public API
38
+
39
+
40
+-(void)setRotation:(NSDictionary*)props {
41
+    NSString *orientation = props[@"style"][ORIENTATION];
42
+    if (!orientation) {
43
+        orientation = props[@"appStyle"][ORIENTATION];
44
+    }
45
+    if (orientation) {
46
+        self.orientation = orientation;
47
+    }
48
+}
49
+
50
+
51
+-(UIInterfaceOrientationMask)supportedControllerOrientations {
52
+    if ([self.orientation isEqualToString:ORIENTATION_PORTRAIT]) {
53
+        return UIInterfaceOrientationMaskPortrait;
54
+    }
55
+    else if ([self.orientation isEqualToString:ORIENTATION_LANDSCAPE]) {
56
+        return UIInterfaceOrientationMaskLandscape;
57
+    }
58
+    
59
+    return UIInterfaceOrientationMaskAll;
60
+}
61
+
62
+
63
+@end

+ 5
- 1
src/deprecated/platformSpecificDeprecated.ios.js View File

@@ -56,6 +56,7 @@ function startTabBasedApp(params) {
56 56
                                type={params.drawer.type ? params.drawer.type : 'MMDrawer'}
57 57
                                animationType={params.drawer.animationType ? params.drawer.animationType : 'slide'}
58 58
                                style={params.drawer.style}
59
+                               appStyle={params.appStyle}
59 60
           >
60 61
             {this.renderBody()}
61 62
           </DrawerControllerIOS>
@@ -66,7 +67,8 @@ function startTabBasedApp(params) {
66 67
       return (
67 68
         <TabBarControllerIOS
68 69
           id={controllerID + '_tabs'}
69
-          style={params.tabsStyle}>
70
+          style={params.tabsStyle}
71
+          appStyle={params.appStyle}>
70 72
           {
71 73
             params.tabs.map(function(tab, index) {
72 74
               return (
@@ -144,6 +146,7 @@ function startSingleScreenApp(params) {
144 146
                                type={params.drawer.type ? params.drawer.type : 'MMDrawer'}
145 147
                                animationType={params.drawer.animationType ? params.drawer.animationType : 'slide'}
146 148
                                style={params.drawer.style}
149
+                               appStyle={params.appStyle}
147 150
           >
148 151
             {this.renderBody()}
149 152
           </DrawerControllerIOS>
@@ -166,6 +169,7 @@ function startSingleScreenApp(params) {
166 169
           style={navigatorStyle}
167 170
           leftButtons={navigatorButtons.leftButtons}
168 171
           rightButtons={navigatorButtons.rightButtons}
172
+          appStyle={params.appStyle}
169 173
         />
170 174
       );
171 175
     }