Procházet zdrojové kódy

Pass mainWindow to commandsHandler (#4407)

Initialize and pass mainWindow to commandsHandler
Yogev Ben David před 6 roky
rodič
revize
b40f8eda6e
No account linked to committer's email address

+ 1
- 1
lib/ios/RNNBridgeManager.h Zobrazit soubor

@@ -7,7 +7,7 @@ typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props, RCTBri
7 7
 
8 8
 @interface RNNBridgeManager : NSObject <RCTBridgeDelegate>
9 9
 
10
-- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate;
10
+- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate mainWindow:(UIWindow *)mainWindow;
11 11
 
12 12
 - (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback;
13 13
 

+ 7
- 4
lib/ios/RNNBridgeManager.m Zobrazit soubor

@@ -21,21 +21,24 @@
21 21
 	NSDictionary* _launchOptions;
22 22
 	id<RNNBridgeManagerDelegate> _delegate;
23 23
 	RCTBridge* _bridge;
24
-
24
+	UIWindow* _mainWindow;
25
+	
25 26
 	RNNStore* _store;
26 27
 
27 28
 	RNNCommandsHandler* _commandsHandler;
28 29
 }
29 30
 
30
-- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
31
+- (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate mainWindow:(UIWindow *)mainWindow {
31 32
 	if (self = [super init]) {
33
+		_mainWindow = mainWindow;
32 34
 		_jsCodeLocation = jsCodeLocation;
33 35
 		_launchOptions = launchOptions;
34 36
 		_delegate = delegate;
35 37
 		
36 38
 		_store = [RNNStore new];
37 39
 		_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:_launchOptions];
38
-
40
+		
41
+		
39 42
 		[[NSNotificationCenter defaultCenter] addObserver:self
40 43
 												 selector:@selector(onJavaScriptLoaded)
41 44
 													 name:RCTJavaScriptDidLoadNotification
@@ -76,7 +79,7 @@
76 79
 	id<RNNRootViewCreator> rootViewCreator = [[RNNReactRootViewCreator alloc] initWithBridge:bridge];
77 80
 	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:rootViewCreator eventEmitter:eventEmitter andBridge:bridge];
78 81
 	
79
-	_commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory eventEmitter:eventEmitter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:[RNNOverlayManager new] sharedApplication:[UIApplication sharedApplication]];
82
+	_commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory eventEmitter:eventEmitter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:[RNNOverlayManager new] mainWindow:_mainWindow];
80 83
 	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:_commandsHandler];
81 84
 
82 85
 	return [@[bridgeModule,eventEmitter] arrayByAddingObjectsFromArray:[self extraModulesFromDelegate]];

+ 1
- 1
lib/ios/RNNCommandsHandler.h Zobrazit soubor

@@ -9,7 +9,7 @@
9 9
 
10 10
 @interface RNNCommandsHandler : NSObject
11 11
 
12
-- (instancetype)initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory eventEmitter:(RNNEventEmitter *)eventEmitter stackManager:(RNNNavigationStackManager *)stackManager modalManager:(RNNModalManager *)modalManager overlayManager:(RNNOverlayManager *)overlayManager sharedApplication:(UIApplication *)sharedApplication;
12
+- (instancetype)initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory eventEmitter:(RNNEventEmitter *)eventEmitter stackManager:(RNNNavigationStackManager *)stackManager modalManager:(RNNModalManager *)modalManager overlayManager:(RNNOverlayManager *)overlayManager mainWindow:(UIWindow *)mainWindow;
13 13
 
14 14
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
15 15
 

+ 2
- 7
lib/ios/RNNCommandsHandler.m Zobrazit soubor

@@ -34,11 +34,10 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
34 34
 	RNNOverlayManager* _overlayManager;
35 35
 	RNNNavigationStackManager* _stackManager;
36 36
 	RNNEventEmitter* _eventEmitter;
37
-	UIApplication* _sharedApplication;
38 37
 	UIWindow* _mainWindow;
39 38
 }
40 39
 
41
-- (instancetype)initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory eventEmitter:(RNNEventEmitter *)eventEmitter stackManager:(RNNNavigationStackManager *)stackManager modalManager:(RNNModalManager *)modalManager overlayManager:(RNNOverlayManager *)overlayManager sharedApplication:(UIApplication *)sharedApplication {
40
+- (instancetype)initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory eventEmitter:(RNNEventEmitter *)eventEmitter stackManager:(RNNNavigationStackManager *)stackManager modalManager:(RNNModalManager *)modalManager overlayManager:(RNNOverlayManager *)overlayManager mainWindow:(UIWindow *)mainWindow {
42 41
 	self = [super init];
43 42
 	_store = store;
44 43
 	_controllerFactory = controllerFactory;
@@ -47,7 +46,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
47 46
 	_modalManager.delegate = self;
48 47
 	_stackManager = stackManager;
49 48
 	_overlayManager = overlayManager;
50
-	_sharedApplication = sharedApplication;
49
+	_mainWindow = mainWindow;
51 50
 	return self;
52 51
 }
53 52
 
@@ -56,10 +55,6 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
56 55
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
57 56
 	[self assertReady];
58 57
 	
59
-	if (!_mainWindow) {
60
-		_mainWindow = _sharedApplication.keyWindow;
61
-	}
62
-	
63 58
 	[_modalManager dismissAllModalsAnimated:NO];
64 59
 	[_store removeAllComponentsFromWindow:_mainWindow];
65 60
 	

+ 1
- 1
lib/ios/RNNSplashScreen.h Zobrazit soubor

@@ -3,6 +3,6 @@
3 3
 
4 4
 @interface RNNSplashScreen : UIViewController
5 5
 
6
-+(void)show;
6
++(void)showOnWindow:(UIWindow *)window;
7 7
 
8 8
 @end

+ 1
- 5
lib/ios/RNNSplashScreen.m Zobrazit soubor

@@ -4,11 +4,7 @@
4 4
 
5 5
 @implementation RNNSplashScreen
6 6
 
7
-+(void)show {
8
-	
9
-	UIApplication.sharedApplication.delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
10
-	UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
11
-	
7
++ (void)showOnWindow:(UIWindow *)window {
12 8
 	CGRect screenBounds = [UIScreen mainScreen].bounds;
13 9
 	UIViewController *viewController = nil;
14 10
 	

+ 12
- 2
lib/ios/ReactNativeNavigation.m Zobrazit soubor

@@ -55,8 +55,18 @@
55 55
 }
56 56
 
57 57
 -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
58
-	self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate];
59
-	[RNNSplashScreen show];
58
+	UIWindow* mainWindow = [self initializeKeyWindow];
59
+	
60
+	self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate mainWindow:mainWindow];
61
+	[RNNSplashScreen showOnWindow:mainWindow];
62
+}
63
+
64
+- (UIWindow *)initializeKeyWindow {
65
+	UIWindow* keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
66
+	keyWindow.backgroundColor = [UIColor whiteColor];
67
+	UIApplication.sharedApplication.delegate.window = keyWindow;
68
+	
69
+	return keyWindow;
60 70
 }
61 71
 
62 72
 @end

+ 2
- 3
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m Zobrazit soubor

@@ -58,13 +58,12 @@
58 58
 
59 59
 - (void)setUp {
60 60
 	[super setUp];
61
-	self.sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
62 61
 	self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]];
63 62
 	self.store = [OCMockObject partialMockForObject:[[RNNStore alloc] init]];
64 63
 	self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
65 64
 	self.overlayManager = [OCMockObject partialMockForObject:[RNNOverlayManager new]];
66 65
 	self.controllerFactory = [OCMockObject partialMockForObject:[[RNNControllerFactory alloc] initWithRootViewCreator:nil eventEmitter:self.eventEmmiter andBridge:nil]];
67
-	self.uut = [[RNNCommandsHandler alloc] initWithStore:self.store controllerFactory:self.controllerFactory eventEmitter:self.eventEmmiter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:self.overlayManager sharedApplication:_sharedApplication];
66
+	self.uut = [[RNNCommandsHandler alloc] initWithStore:self.store controllerFactory:self.controllerFactory eventEmitter:self.eventEmmiter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:self.overlayManager mainWindow:_mainWindow];
68 67
 	self.vc1 = [RNNRootViewController new];
69 68
 	self.vc2 = [RNNRootViewController new];
70 69
 	self.vc3 = [RNNRootViewController new];
@@ -92,7 +91,7 @@
92 91
 -(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{
93 92
 	NSMutableArray* skipMethods = [NSMutableArray new];
94 93
 	
95
-	[skipMethods addObject:@"initWithStore:controllerFactory:eventEmitter:stackManager:modalManager:overlayManager:sharedApplication:"];
94
+	[skipMethods addObject:@"initWithStore:controllerFactory:eventEmitter:stackManager:modalManager:overlayManager:mainWindow:"];
96 95
 	[skipMethods addObject:@"assertReady"];
97 96
 	[skipMethods addObject:@"removePopedViewControllers:"];
98 97
 	[skipMethods addObject:@".cxx_destruct"];