yogevbd 6 years ago
parent
commit
3f079f4c41

+ 1
- 1
lib/ios/RNNBridgeManager.m View File

76
 	id<RNNRootViewCreator> rootViewCreator = [[RNNReactRootViewCreator alloc] initWithBridge:bridge];
76
 	id<RNNRootViewCreator> rootViewCreator = [[RNNReactRootViewCreator alloc] initWithBridge:bridge];
77
 	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:rootViewCreator eventEmitter:eventEmitter andBridge:bridge];
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
 	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:_commandsHandler];
80
 	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:_commandsHandler];
81
 
81
 
82
 	return [@[bridgeModule,eventEmitter] arrayByAddingObjectsFromArray:[self extraModulesFromDelegate]];
82
 	return [@[bridgeModule,eventEmitter] arrayByAddingObjectsFromArray:[self extraModulesFromDelegate]];

+ 1
- 1
lib/ios/RNNCommandsHandler.h View File

9
 
9
 
10
 @interface RNNCommandsHandler : NSObject
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
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
14
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
15
 
15
 

+ 7
- 2
lib/ios/RNNCommandsHandler.m View File

34
 	RNNOverlayManager* _overlayManager;
34
 	RNNOverlayManager* _overlayManager;
35
 	RNNNavigationStackManager* _stackManager;
35
 	RNNNavigationStackManager* _stackManager;
36
 	RNNEventEmitter* _eventEmitter;
36
 	RNNEventEmitter* _eventEmitter;
37
+	UIApplication* _sharedApplication;
37
 	UIWindow* _mainWindow;
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
 	self = [super init];
42
 	self = [super init];
42
 	_store = store;
43
 	_store = store;
43
 	_controllerFactory = controllerFactory;
44
 	_controllerFactory = controllerFactory;
46
 	_modalManager.delegate = self;
47
 	_modalManager.delegate = self;
47
 	_stackManager = stackManager;
48
 	_stackManager = stackManager;
48
 	_overlayManager = overlayManager;
49
 	_overlayManager = overlayManager;
49
-	_mainWindow = mainWindow;
50
+	_sharedApplication = sharedApplication;
50
 	return self;
51
 	return self;
51
 }
52
 }
52
 
53
 
55
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
56
 - (void)setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
56
 	[self assertReady];
57
 	[self assertReady];
57
 	
58
 	
59
+	if (!_mainWindow) {
60
+		_mainWindow = _sharedApplication.keyWindow;
61
+	}
62
+	
58
 	[_modalManager dismissAllModalsAnimated:NO];
63
 	[_modalManager dismissAllModalsAnimated:NO];
59
 	[_store removeAllComponentsFromWindow:_mainWindow];
64
 	[_store removeAllComponentsFromWindow:_mainWindow];
60
 	
65
 	

+ 19
- 2
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m View File

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