Browse Source

add appStyle support for iOS (Android already support) 🤖 (#1772)

Ran Greenberg 7 years ago
parent
commit
9ad3baa4a4

+ 2
- 0
ios/RCCManager.h View File

11
 -(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions;
11
 -(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions;
12
 -(RCTBridge*)getBridge;
12
 -(RCTBridge*)getBridge;
13
 -(UIWindow*)getAppWindow;
13
 -(UIWindow*)getAppWindow;
14
+-(void)setAppStyle:(NSDictionary*)appStyle;
15
+-(NSDictionary*)getAppStyle;
14
 
16
 
15
 -(void)registerController:(UIViewController*)controller componentId:(NSString*)componentId componentType:(NSString*)componentType;
17
 -(void)registerController:(UIViewController*)controller componentId:(NSString*)componentId componentType:(NSString*)componentType;
16
 -(id)getControllerWithId:(NSString*)componentId componentType:(NSString*)componentType;
18
 -(id)getControllerWithId:(NSString*)componentId componentType:(NSString*)componentType;

+ 13
- 0
ios/RCCManager.m View File

8
 @property (nonatomic, strong) NSMutableDictionary *modulesRegistry;
8
 @property (nonatomic, strong) NSMutableDictionary *modulesRegistry;
9
 @property (nonatomic, strong) RCTBridge *sharedBridge;
9
 @property (nonatomic, strong) RCTBridge *sharedBridge;
10
 @property (nonatomic, strong) NSURL *bundleURL;
10
 @property (nonatomic, strong) NSURL *bundleURL;
11
+@property (nonatomic, strong, readwrite) NSDictionary *globalAppStyle;
11
 @end
12
 @end
12
 
13
 
13
 @implementation RCCManager
14
 @implementation RCCManager
53
 {
54
 {
54
   id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
55
   id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
55
   appDelegate.window.rootViewController = nil;
56
   appDelegate.window.rootViewController = nil;
57
+  [self setAppStyle:nil];
56
   [self clearModuleRegistry];
58
   [self clearModuleRegistry];
57
 }
59
 }
58
 
60
 
238
   return window;
240
   return window;
239
 }
241
 }
240
 
242
 
243
+-(NSDictionary*)getAppStyle
244
+{
245
+  return [NSDictionary dictionaryWithDictionary:self.globalAppStyle];
246
+}
247
+
248
+-(void)setAppStyle:(NSDictionary*)appStyle
249
+{
250
+  self.globalAppStyle = [NSDictionary dictionaryWithDictionary:appStyle];
251
+}
252
+
253
+
241
 #pragma mark - RCTBridgeDelegate methods
254
 #pragma mark - RCTBridgeDelegate methods
242
 
255
 
243
 - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
256
 - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge

+ 6
- 0
ios/RCCManagerModule.m View File

229
     
229
     
230
     // first clear the registry to remove any refernece to the previous controllers
230
     // first clear the registry to remove any refernece to the previous controllers
231
     [[RCCManager sharedInstance] clearModuleRegistry];
231
     [[RCCManager sharedInstance] clearModuleRegistry];
232
+    [[RCCManager sharedInstance] setAppStyle:nil];
233
+    
234
+    NSDictionary *appStyle = layout[@"props"][@"appStyle"];
235
+    if (appStyle) {
236
+        [[RCCManager sharedIntance] setAppStyle:appStyle];
237
+    }
232
     
238
     
233
     // create the new controller
239
     // create the new controller
234
     UIViewController *controller = [RCCViewController controllerWithLayout:layout globalProps:modifiedGloablProps bridge:[[RCCManager sharedInstance] getBridge]];
240
     UIViewController *controller = [RCCViewController controllerWithLayout:layout globalProps:modifiedGloablProps bridge:[[RCCManager sharedInstance] getBridge]];

+ 3
- 1
ios/RCCViewController.m View File

178
   self.edgesForExtendedLayout = UIRectEdgeNone; // default
178
   self.edgesForExtendedLayout = UIRectEdgeNone; // default
179
   self.automaticallyAdjustsScrollViewInsets = NO; // default
179
   self.automaticallyAdjustsScrollViewInsets = NO; // default
180
   
180
   
181
-  self.navigatorStyle = [NSMutableDictionary dictionaryWithDictionary:navigatorStyle];
181
+  self.navigatorStyle = [NSMutableDictionary dictionaryWithDictionary:[[RCCManager sharedInstance] getAppStyle]];
182
+  [self.navigatorStyle addEntriesFromDictionary:navigatorStyle];
183
+
182
   
184
   
183
   [self setStyleOnInit];
185
   [self setStyleOnInit];
184
   
186
   

+ 2
- 2
ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

59
 		26714EAB1EB0E9D3009F4D52 /* RCCCustomTitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCCustomTitleView.m; sourceTree = "<group>"; };
59
 		26714EAB1EB0E9D3009F4D52 /* RCCCustomTitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCCustomTitleView.m; sourceTree = "<group>"; };
60
 		26AFF3F31D7EEE2400CBA211 /* RCCTitleViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCCTitleViewHelper.h; path = Helpers/RCCTitleViewHelper.h; sourceTree = "<group>"; };
60
 		26AFF3F31D7EEE2400CBA211 /* RCCTitleViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCCTitleViewHelper.h; path = Helpers/RCCTitleViewHelper.h; sourceTree = "<group>"; };
61
 		26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCCTitleViewHelper.m; path = Helpers/RCCTitleViewHelper.m; sourceTree = "<group>"; };
61
 		26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCCTitleViewHelper.m; path = Helpers/RCCTitleViewHelper.m; sourceTree = "<group>"; };
62
-2DCD49981F33AAC30035123A /* RCCCustomBarButtonItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCCCustomBarButtonItem.m; path = RCCCustomBarButtonItem.m; sourceTree = "<group>"; };
63
-		2DCD49991F33AAC30035123A /* RCCCustomBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCCCustomBarButtonItem.h; path = RCCCustomBarButtonItem.h; sourceTree = "<group>"; };
62
+		2DCD49981F33AAC30035123A /* RCCCustomBarButtonItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCCustomBarButtonItem.m; sourceTree = "<group>"; };
63
+		2DCD49991F33AAC30035123A /* RCCCustomBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCCustomBarButtonItem.h; sourceTree = "<group>"; };
64
 		CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManager.h; sourceTree = "<group>"; };
64
 		CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManager.h; sourceTree = "<group>"; };
65
 		CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RCCManager.m; sourceTree = "<group>"; tabWidth = 2; };
65
 		CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RCCManager.m; sourceTree = "<group>"; tabWidth = 2; };
66
 		CC84A1951C1A0C4E00B3A6A2 /* RCCManagerModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManagerModule.h; sourceTree = "<group>"; };
66
 		CC84A1951C1A0C4E00B3A6A2 /* RCCManagerModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManagerModule.h; sourceTree = "<group>"; };

+ 2
- 0
src/deprecated/controllers/index.js View File

1
 /*eslint-disable*/
1
 /*eslint-disable*/
2
+var _ = require('lodash');
2
 var OriginalReactNative = require('react-native');
3
 var OriginalReactNative = require('react-native');
3
 var RCCManager = OriginalReactNative.NativeModules.RCCManager;
4
 var RCCManager = OriginalReactNative.NativeModules.RCCManager;
4
 var NativeAppEventEmitter = OriginalReactNative.NativeAppEventEmitter;
5
 var NativeAppEventEmitter = OriginalReactNative.NativeAppEventEmitter;
125
       if (controller === undefined) return;
126
       if (controller === undefined) return;
126
       var layout = controller.render();
127
       var layout = controller.render();
127
       _validateDrawerProps(layout);
128
       _validateDrawerProps(layout);
129
+      _processProperties(_.get(layout, 'props.appStyle', {}));
128
       RCCManager.setRootController(layout, animationType, passProps);
130
       RCCManager.setRootController(layout, animationType, passProps);
129
     }
131
     }
130
   },
132
   },