yogevbd 6 年前
父节点
当前提交
3f079f4c41

+ 1
- 1
lib/ios/RNNBridgeManager.m 查看文件

@@ -76,7 +76,7 @@
76 76
 	id<RNNRootViewCreator> rootViewCreator = [[RNNReactRootViewCreator alloc] initWithBridge:bridge];
77 77
 	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:rootViewCreator eventEmitter:eventEmitter andBridge:bridge];
78 78
 	
79
-	_commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory eventEmitter:eventEmitter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:[RNNOverlayManager new] mainWindow:[UIApplication sharedApplication].keyWindow];
79
+	_commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory eventEmitter:eventEmitter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:[RNNOverlayManager new] sharedApplication:[UIApplication sharedApplication]];
80 80
 	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:_commandsHandler];
81 81
 
82 82
 	return [@[bridgeModule,eventEmitter] arrayByAddingObjectsFromArray:[self extraModulesFromDelegate]];

+ 1
- 1
lib/ios/RNNCommandsHandler.h 查看文件

@@ -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 mainWindow:(UIWindow *)mainWindow;
12
+- (instancetype)initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory eventEmitter:(RNNEventEmitter *)eventEmitter stackManager:(RNNNavigationStackManager *)stackManager modalManager:(RNNModalManager *)modalManager overlayManager:(RNNOverlayManager *)overlayManager sharedApplication:(UIApplication *)sharedApplication;
13 13
 
14 14
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
15 15
 

+ 7
- 2
lib/ios/RNNCommandsHandler.m 查看文件

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

+ 19
- 2
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m 查看文件

@@ -8,6 +8,20 @@
8 8
 #import "RNNErrorHandler.h"
9 9
 #import <OCMock/OCMock.h>
10 10
 
11
+@interface MockUIApplication : NSObject
12
+
13
+-(UIWindow *)keyWindow;
14
+
15
+@end
16
+
17
+@implementation MockUIApplication
18
+
19
+- (UIWindow *)keyWindow {
20
+	return [UIWindow new];
21
+}
22
+
23
+@end
24
+
11 25
 @interface MockUINavigationController : RNNNavigationController
12 26
 @property (nonatomic, strong) NSArray* willReturnVCs;
13 27
 @end
@@ -33,6 +47,7 @@
33 47
 @property (nonatomic, strong) RNNRootViewController* vc3;
34 48
 @property (nonatomic, strong) MockUINavigationController* nvc;
35 49
 @property (nonatomic, strong) id mainWindow;
50
+@property (nonatomic, strong) id sharedApplication;
36 51
 @property (nonatomic, strong) id controllerFactory;
37 52
 @property (nonatomic, strong) id overlayManager;
38 53
 @property (nonatomic, strong) id eventEmmiter;
@@ -43,12 +58,13 @@
43 58
 
44 59
 - (void)setUp {
45 60
 	[super setUp];
61
+	self.sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
46 62
 	self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]];
47 63
 	self.store = [OCMockObject partialMockForObject:[[RNNStore alloc] init]];
48 64
 	self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
49 65
 	self.overlayManager = [OCMockObject partialMockForObject:[RNNOverlayManager new]];
50 66
 	self.controllerFactory = [OCMockObject partialMockForObject:[[RNNControllerFactory alloc] initWithRootViewCreator:nil eventEmitter:self.eventEmmiter andBridge:nil]];
51
-	self.uut = [[RNNCommandsHandler alloc] initWithStore:self.store controllerFactory:self.controllerFactory eventEmitter:self.eventEmmiter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:self.overlayManager mainWindow:self.mainWindow];
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];
52 68
 	self.vc1 = [RNNRootViewController new];
53 69
 	self.vc2 = [RNNRootViewController new];
54 70
 	self.vc3 = [RNNRootViewController new];
@@ -57,6 +73,7 @@
57 73
 	[self.store setComponent:self.vc1 componentId:@"vc1"];
58 74
 	[self.store setComponent:self.vc2 componentId:@"vc2"];
59 75
 	[self.store setComponent:self.vc3 componentId:@"vc3"];
76
+	OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow);
60 77
 }
61 78
 
62 79
 
@@ -75,7 +92,7 @@
75 92
 -(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{
76 93
 	NSMutableArray* skipMethods = [NSMutableArray new];
77 94
 	
78
-	[skipMethods addObject:@"initWithStore:controllerFactory:eventEmitter:stackManager:modalManager:overlayManager:mainWindow:"];
95
+	[skipMethods addObject:@"initWithStore:controllerFactory:eventEmitter:stackManager:modalManager:overlayManager:sharedApplication:"];
79 96
 	[skipMethods addObject:@"assertReady"];
80 97
 	[skipMethods addObject:@"removePopedViewControllers:"];
81 98
 	[skipMethods addObject:@".cxx_destruct"];