Yogev B 6 years ago
parent
commit
e6a43036fc
No account linked to committer's email address

+ 4
- 2
lib/ios/RNNBridgeManager.h View File

@@ -1,10 +1,12 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <React/RCTBridge.h>
3
-#import "ReactNativeNavigation.h"
3
+#import "RNNBridgeManagerDelegate.h"
4
+
5
+typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props, RCTBridge* bridge);
4 6
 
5 7
 @interface RNNBridgeManager : NSObject <RCTBridgeDelegate>
6 8
 
7
-- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions;
9
+- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate;
8 10
 
9 11
 - (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback;
10 12
 

+ 12
- 2
lib/ios/RNNBridgeManager.m View File

@@ -18,6 +18,7 @@
18 18
 @implementation RNNBridgeManager {
19 19
 	NSURL* _jsCodeLocation;
20 20
 	NSDictionary* _launchOptions;
21
+	id<RNNBridgeManagerDelegate> _delegate;
21 22
 	RCTBridge* _bridge;
22 23
 
23 24
 	RNNStore* _store;
@@ -25,10 +26,11 @@
25 26
 	RNNCommandsHandler* _commandsHandler;
26 27
 }
27 28
 
28
-- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
29
+- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
29 30
 	if (self = [super init]) {
30 31
 		_jsCodeLocation = jsCodeLocation;
31 32
 		_launchOptions = launchOptions;
33
+		_delegate = delegate;
32 34
 		
33 35
 		_store = [RNNStore new];
34 36
 		_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:_launchOptions];
@@ -53,6 +55,14 @@
53 55
 	[_store registerExternalComponent:name callback:callback];
54 56
 }
55 57
 
58
+- (NSArray *)extraModulesFromDelegate {
59
+	if ([_delegate respondsToSelector:@selector(extraModulesForBridge:)]) {
60
+		return [_delegate extraModulesForBridge:_bridge];
61
+	}
62
+	
63
+	return nil;
64
+}
65
+
56 66
 # pragma mark - RCTBridgeDelegate
57 67
 
58 68
 - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
@@ -67,7 +77,7 @@
67 77
 	_commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory eventEmitter:eventEmitter];
68 78
 	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:_commandsHandler];
69 79
 
70
-	return @[bridgeModule,eventEmitter];
80
+	return [@[bridgeModule,eventEmitter] arrayByAddingObjectsFromArray:[self extraModulesFromDelegate]];
71 81
 }
72 82
 
73 83
 # pragma mark - JavaScript & Bridge Notifications

+ 5
- 0
lib/ios/RNNBridgeManagerDelegate.h View File

@@ -0,0 +1,5 @@
1
+@protocol RNNBridgeManagerDelegate <NSObject>
2
+
3
+- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge;
4
+
5
+@end

+ 3
- 0
lib/ios/ReactNativeNavigation.h View File

@@ -1,6 +1,7 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <UIKit/UIKit.h>
3 3
 #import <React/RCTBridge.h>
4
+#import "RNNBridgeManagerDelegate.h"
4 5
 
5 6
 typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props, RCTBridge* bridge);
6 7
 
@@ -8,6 +9,8 @@ typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props, RCTBri
8 9
 
9 10
 + (void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions;
10 11
 
12
++ (void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate;
13
+
11 14
 + (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback;
12 15
 
13 16
 + (RCTBridge *)getBridge;

+ 9
- 1
lib/ios/ReactNativeNavigation.m View File

@@ -19,6 +19,10 @@
19 19
 	[[ReactNativeNavigation sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions];
20 20
 }
21 21
 
22
++(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
23
+	[[ReactNativeNavigation sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate];
24
+}
25
+
22 26
 + (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback {
23 27
 	[[ReactNativeNavigation sharedInstance].bridgeManager registerExternalComponent:name callback:callback];
24 28
 }
@@ -43,7 +47,11 @@
43 47
 }
44 48
 
45 49
 -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
46
-	self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions];
50
+	[self bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:nil];
51
+}
52
+
53
+-(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
54
+	self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate];
47 55
 	[RNNSplashScreen show];
48 56
 }
49 57
 

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

@@ -65,6 +65,7 @@
65 65
 		5016E8F020209690009D4F7C /* RNNCustomTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5016E8EE2020968F009D4F7C /* RNNCustomTitleView.m */; };
66 66
 		50175CD1207A2AA1004FE91B /* RNNComponentOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50175CCF207A2AA1004FE91B /* RNNComponentOptions.h */; };
67 67
 		50175CD2207A2AA1004FE91B /* RNNComponentOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */; };
68
+		502CB43A20CBCA180019B2FE /* RNNBridgeManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
68 69
 		50415CBA20553B8E00BB682E /* RNNScreenTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50415CB820553B8E00BB682E /* RNNScreenTransition.h */; };
69 70
 		50415CBB20553B8E00BB682E /* RNNScreenTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 50415CB920553B8E00BB682E /* RNNScreenTransition.m */; };
70 71
 		50451D052042DAEB00695F00 /* RNNPushAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 50451D032042DAEB00695F00 /* RNNPushAnimation.h */; };
@@ -270,6 +271,7 @@
270 271
 		5016E8EE2020968F009D4F7C /* RNNCustomTitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNCustomTitleView.m; sourceTree = "<group>"; };
271 272
 		50175CCF207A2AA1004FE91B /* RNNComponentOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNComponentOptions.h; sourceTree = "<group>"; };
272 273
 		50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNComponentOptions.m; sourceTree = "<group>"; };
274
+		502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBridgeManagerDelegate.h; sourceTree = "<group>"; };
273 275
 		50415CB820553B8E00BB682E /* RNNScreenTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNScreenTransition.h; sourceTree = "<group>"; };
274 276
 		50415CB920553B8E00BB682E /* RNNScreenTransition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNScreenTransition.m; sourceTree = "<group>"; };
275 277
 		50451D032042DAEB00695F00 /* RNNPushAnimation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNPushAnimation.h; sourceTree = "<group>"; };
@@ -692,6 +694,7 @@
692 694
 				268692811E5054F800E2C612 /* RNNStore.m */,
693 695
 				7B4928061E70415400555040 /* RNNCommandsHandler.h */,
694 696
 				7B4928071E70415400555040 /* RNNCommandsHandler.m */,
697
+				502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */,
695 698
 				7BD721F31E2D3AA100724059 /* Bridge */,
696 699
 				7B1E4C4B1E2D173700C3A525 /* Controllers */,
697 700
 				263905881E4C6F440023D7D3 /* RNNSideMenu */,
@@ -825,6 +828,7 @@
825 828
 				504AFE641FFE53070076E904 /* RNNOptions.h in Headers */,
826 829
 				263905B91E4C6F440023D7D3 /* RCCDrawerController.h in Headers */,
827 830
 				263905B31E4C6F440023D7D3 /* MMDrawerVisualState.h in Headers */,
831
+				502CB43A20CBCA180019B2FE /* RNNBridgeManagerDelegate.h in Headers */,
828 832
 				50451D092042E20600695F00 /* RNNTransitionsOptions.h in Headers */,
829 833
 				5048862D20BE976D000908DE /* RNNLayoutOptions.h in Headers */,
830 834
 				E8A5CD621F49114F00E89D0D /* RNNElement.h in Headers */,