Pārlūkot izejas kodu

refactoring a bunch of ios stuff

Daniel Zlotin 7 gadus atpakaļ
vecāks
revīzija
765754a26c

+ 12
- 1
lib/ios/RNNCommandsHandler.m Parādīt failu

@@ -37,6 +37,7 @@
37 37
 
38 38
 -(void) setOptions:(NSString*)containerId options:(NSDictionary*)options {
39 39
 	[self assertReady];
40
+	
40 41
 	UIViewController* vc = [_store findContainerForId:containerId];
41 42
 	if([vc isKindOfClass:[RNNRootViewController class]]) {
42 43
 		RNNRootViewController* rootVc = (RNNRootViewController*)vc;
@@ -47,38 +48,45 @@
47 48
 
48 49
 -(void) push:(NSString*)containerId layout:(NSDictionary*)layout {
49 50
 	[self assertReady];
51
+	
50 52
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
51 53
 	[_navigationStackManager push:newVc onTop:containerId];
52 54
 }
53 55
 
54 56
 -(void) pop:(NSString*)containerId {
55 57
 	[self assertReady];
58
+	
56 59
 	[_navigationStackManager pop:containerId];
57 60
 }
58 61
 
59 62
 -(void) popTo:(NSString*)containerId {
60 63
 	[self assertReady];
64
+	
61 65
 	[_navigationStackManager popTo:containerId];
62 66
 }
63 67
 
64 68
 -(void) popToRoot:(NSString*)containerId {
65 69
 	[self assertReady];
70
+	
66 71
 	[_navigationStackManager popToRoot:containerId];
67 72
 }
68 73
 
69 74
 -(void) showModal:(NSDictionary*)layout {
70 75
 	[self assertReady];
76
+	
71 77
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
72 78
 	[_modalManager showModal:newVc];
73 79
 }
74 80
 
75 81
 -(void) dismissModal:(NSString*)containerId {
76 82
 	[self assertReady];
83
+	
77 84
 	[_modalManager dismissModal:containerId];
78 85
 }
79 86
 
80 87
 -(void) dismissAllModals {
81 88
 	[self assertReady];
89
+	
82 90
 	[_modalManager dismissAllModals];
83 91
 }
84 92
 
@@ -86,7 +94,10 @@
86 94
 
87 95
 -(void) assertReady {
88 96
 	if (!_store.isReadyToReceiveCommands) {
89
-		@throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
97
+		[[NSException exceptionWithName:@"BridgeNotLoadedError"
98
+								reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called."
99
+							  userInfo:nil]
100
+		 raise];
90 101
 	}
91 102
 }
92 103
 

+ 1
- 0
lib/ios/RNNNavigationOptions.h Parādīt failu

@@ -8,6 +8,7 @@
8 8
 @property (nonatomic, strong) NSNumber* statusBarHidden;
9 9
 @property (nonatomic, strong) NSString* title;
10 10
 
11
+-(instancetype)init;
11 12
 -(instancetype)initWithDict:(NSDictionary *)navigationOptions;
12 13
 
13 14
 -(void)applyOn:(UIViewController*)viewController;

+ 9
- 5
lib/ios/RNNNavigationOptions.m Parādīt failu

@@ -3,13 +3,17 @@
3 3
 
4 4
 @implementation RNNNavigationOptions
5 5
 
6
+-(instancetype)init {
7
+	return [self initWithDict:@{}];
8
+}
6 9
 
7 10
 -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
8
-	self = [super init];
9
-	self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
10
-	self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
11
-	self.title = [navigationOptions objectForKey:@"title"];
12
-	self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
11
+	if(self = [super init]) {
12
+		self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
13
+		self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
14
+		self.title = [navigationOptions objectForKey:@"title"];
15
+		self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
16
+	}
13 17
 	return self;
14 18
 }
15 19
 

+ 10
- 5
lib/ios/RNNRootViewController.m Parādīt failu

@@ -13,7 +13,11 @@
13 13
 
14 14
 @implementation RNNRootViewController
15 15
 
16
--(instancetype)initWithName:(NSString*)name withOptions:(RNNNavigationOptions*)options withContainerId:(NSString*)containerId rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter*)eventEmitter {
16
+-(instancetype)initWithName:(NSString*)name
17
+				withOptions:(RNNNavigationOptions*)options
18
+			withContainerId:(NSString*)containerId
19
+			rootViewCreator:(id<RNNRootViewCreator>)creator
20
+			   eventEmitter:(RNNEventEmitter*)eventEmitter {
17 21
 	self = [super init];
18 22
 	self.containerId = containerId;
19 23
 	self.containerName = name;
@@ -30,6 +34,11 @@
30 34
 	return self;
31 35
 }
32 36
 
37
+-(void)viewWillAppear:(BOOL)animated{
38
+	[super viewWillAppear:animated];
39
+	[self.navigationOptions applyOn:self];
40
+}
41
+
33 42
 - (BOOL)prefersStatusBarHidden {
34 43
 	return [self.navigationOptions.statusBarHidden boolValue]; // || self.navigationController.isNavigationBarHidden;
35 44
 }
@@ -44,10 +53,6 @@
44 53
 	[self.eventEmitter sendContainerStop:self.containerId];
45 54
 }
46 55
 
47
--(void)viewWillAppear:(BOOL)animated{
48
-	[super viewWillAppear:animated];
49
-	[self.navigationOptions applyOn:self];
50
-}
51 56
 /**
52 57
  *	fix for #877, #878
53 58
  */

+ 27
- 37
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m Parādīt failu

@@ -7,14 +7,8 @@
7 7
 
8 8
 @interface RNNCommandsHandlerTest : XCTestCase
9 9
 
10
-@property (nonatomic, strong) id<RNNRootViewCreator> creator;
11
-@property (nonatomic, strong) NSString* pageName;
12
-@property (nonatomic, strong) NSString* containerId;
13
-@property (nonatomic, strong) id emitter;
14 10
 @property (nonatomic, strong) RNNStore* store;
15
-@property (nonatomic, strong) RNNNavigationOptions* options;
16
-@property (nonatomic, strong) RNNRootViewController* viewController;
17
-@property (nonatomic, strong) RNNCommandsHandler* cmdHandler;
11
+@property (nonatomic, strong) RNNCommandsHandler* uut;
18 12
 
19 13
 @end
20 14
 
@@ -22,31 +16,21 @@
22 16
 
23 17
 - (void)setUp {
24 18
 	[super setUp];
25
-	self.creator = [[RNNTestRootViewCreator alloc] init];
26
-	self.pageName = @"somename";
27
-	self.containerId = @"cntId";
28
-	self.emitter = nil;
29
-	self.options = [[RNNNavigationOptions alloc] initWithDict:@{@"title" : @"static title"}];
30
-	self.store = [RNNStore new];
31
-	self.viewController = [[RNNRootViewController alloc] initWithName:self.pageName withOptions:self.options withContainerId:self.containerId rootViewCreator:self.creator eventEmitter:self.emitter];
32
-	[self.store setReadyToReceiveCommands:true];
33
-	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
34
-	[self.store setContainer:self.viewController containerId:self.containerId];
35
-	self.cmdHandler = [[RNNCommandsHandler alloc] initWithStore:self.store controllerFactory:nil];
19
+	self.store = [[RNNStore alloc] init];
20
+	self.uut = [[RNNCommandsHandler alloc] initWithStore:self.store controllerFactory:nil];
36 21
 }
37 22
 
38 23
 
39 24
 - (void)testAssertReadyForEachMethodThrowsExceptoins {
40
-	RNNStore *store = [RNNStore new];
41
-	[store setReadyToReceiveCommands:NO];
42
-	RNNCommandsHandler *uut = [[RNNCommandsHandler alloc] initWithStore:store controllerFactory:nil];
43
-	
44
-	NSArray* methods = [self getPublicMethodNamesForObject:uut];
25
+	NSArray* methods = [self getPublicMethodNamesForObject:self.uut];
45 26
 	
46 27
 	for (NSString* methodName in methods) {
28
+		
29
+		__strong id uut = self.uut;
47 30
 		SEL s = NSSelectorFromString(methodName);
48 31
 		IMP imp = [uut methodForSelector:s];
49 32
 		void (*func)(id, SEL) = (void *)imp;
33
+		
50 34
 		XCTAssertThrowsSpecificNamed(func(uut,s), NSException, @"BridgeNotLoadedError");
51 35
 	}
52 36
 }
@@ -68,7 +52,7 @@
68 52
 		NSString *methodName = [NSString stringWithUTF8String:sel_getName(method_getName(mlist[i]))];
69 53
 		
70 54
 		// filter skippedMethods
71
-		if (![skipMethods containsObject:methodName]) {
55
+		if (methodName && ![skipMethods containsObject:methodName]) {
72 56
 			[result addObject:methodName];
73 57
 		}
74 58
 	}
@@ -76,22 +60,28 @@
76 60
 	return result;
77 61
 }
78 62
 
79
--(void)testDynamicTopBarBackgroundColor_validColor {
80
-	NSDictionary* dictFromJs = @{@"topBarBackgroundColor" :@(0xFFFF0000)};
81
-	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
82
-	[self.cmdHandler setOptions:self.containerId options:dictFromJs];
83
-	XCTAssertTrue([self.viewController.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
84
-}
85
-
86 63
 -(void)testDynamicStylesMergeWithStaticStyles {
64
+	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] init];
65
+	[initialOptions setTitle:@"the title"];
66
+	RNNRootViewController* vc = [[RNNRootViewController alloc] initWithName:@"name"
67
+																withOptions:initialOptions
68
+															withContainerId:@"containerId"
69
+															rootViewCreator:[[RNNTestRootViewCreator alloc] init]
70
+															   eventEmitter:nil];
71
+	UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:vc];
72
+	[vc viewWillAppear:false];
73
+	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
74
+	
75
+	[self.store setReadyToReceiveCommands:true];
76
+	[self.store setContainer:vc containerId:@"containerId"];
77
+	
87 78
 	NSDictionary* dictFromJs = @{@"topBarBackgroundColor" :@(0xFFFF0000)};
88 79
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
89
-	[self.cmdHandler setOptions:self.containerId options:dictFromJs];
90
-	XCTAssertTrue([self.viewController.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
91
-	XCTAssertTrue([self.viewController.navigationItem.title isEqual:@"static title"]);
80
+	
81
+	[self.uut setOptions:@"containerId" options:dictFromJs];
82
+	
83
+	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
84
+	XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
92 85
 }
93 86
 
94
-
95
-
96
-
97 87
 @end