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

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

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

+ 9
- 0
ios/RCCNavigationController.m View File

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

+ 8
- 0
ios/RCCTabBarController.m View File

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

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

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

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

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

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