浏览代码

ios - pop

Ran Greenberg 7 年前
父节点
当前提交
031e30d83c
共有 4 个文件被更改,包括 34 次插入16 次删除
  1. 5
    6
      ios/RNNBridgeModule.m
  2. 1
    0
      ios/RNNStore.h
  3. 10
    5
      ios/RNNStore.m
  4. 18
    5
      playground/ios/playgroundTests/RNNStoreTest.m

+ 5
- 6
ios/RNNBridgeModule.m 查看文件

@@ -27,21 +27,20 @@ RCT_EXPORT_METHOD(setRoot:(NSDictionary*)layout)
27 27
 RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
28 28
 {
29 29
 	[self assertReady];
30
-	//TODO implement correctly
31 30
 	RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
32 31
 	UIViewController *newVc = [factory createLayout:layout];
32
+	UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
33 33
 	
34
-	id vc = [[RNN instance].store findContainerForId:containerId];
35
-	
36
-	[[vc navigationController]pushViewController:newVc animated:true];
34
+	[[vc navigationController] pushViewController:newVc animated:true];
37 35
 }
38 36
 
39 37
 RCT_EXPORT_METHOD(pop:(NSString*)containerId)
40 38
 {
41 39
 	[self assertReady];
42
-	//TODO implement correctly
43
-	id vc = [UIApplication.sharedApplication.delegate.window.rootViewController childViewControllers][0];
40
+	UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
41
+	
44 42
 	[[vc navigationController] popViewControllerAnimated:true];
43
+	[[RNN instance].store removeContainer:containerId];
45 44
 }
46 45
 
47 46
 - (void)assertReady

+ 1
- 0
ios/RNNStore.h 查看文件

@@ -14,5 +14,6 @@
14 14
 
15 15
 - (UIViewController*)findContainerForId:(NSString*)containerId;
16 16
 - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId;
17
+- (void)removeContainer:(NSString*)containerId;
17 18
 
18 19
 @end

+ 10
- 5
ios/RNNStore.m 查看文件

@@ -31,16 +31,21 @@
31 31
 
32 32
 
33 33
 - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
34
-	if (!containerId) {
35
-		return;
36
-	}
37
-	
34
+
38 35
 	UIViewController *existingVewController = [self findContainerForId:containerId];
39 36
 	if (existingVewController) {
40
-		@throw [NSException exceptionWithName:@"MultipleContainerId" reason:[@"Container id already exists " stringByAppendingString:containerId] userInfo:nil];	}
37
+		@throw [NSException exceptionWithName:@"MultipleContainerId" reason:[@"Container id already exists " stringByAppendingString:containerId] userInfo:nil];
38
+	}
41 39
 	
42 40
 	[self.containerStore setObject:viewController forKey:containerId];
43 41
 }
44 42
 
45 43
 
44
+- (void)removeContainer:(NSString*)containerId {
45
+	[self.containerStore removeObjectForKey:containerId];
46
+}
47
+
48
+
49
+
50
+
46 51
 @end

+ 18
- 5
playground/ios/playgroundTests/RNNStoreTest.m 查看文件

@@ -40,16 +40,15 @@
40 40
 	XCTAssertNotEqualObjects(vc2, ans);
41 41
 }
42 42
 
43
-- (void)testFindContainerForId_setNilContainerId {
43
+- (void)testSetContainer_setNilContainerId {
44 44
 	NSString *containerId1 = nil;
45 45
 	UIViewController *vc1 = [UIViewController new];
46
-	[self.store setContainer:vc1 containerId:containerId1];
46
+	XCTAssertThrows([self.store setContainer:vc1 containerId:containerId1]);
47
+	XCTAssertNil([self.store findContainerForId:containerId1]);
47 48
 	
48
-	UIViewController *ans = [self.store findContainerForId:containerId1];
49
-	XCTAssertNil(ans);
50 49
 }
51 50
 
52
-- (void)testFindContainerForId_setDoubleContainerId {
51
+- (void)testSetContainer_setDoubleContainerId {
53 52
 	NSString *containerId1 = @"cntId1";
54 53
 	
55 54
 	UIViewController *vc1 = [UIViewController new];
@@ -62,6 +61,20 @@
62 61
 	XCTAssertThrows([self.store setContainer:vc2 containerId:containerId1]);
63 62
 }
64 63
 
64
+- (void)testRemoveContainer_removeExistContainer {
65
+	NSString *containerId1 = @"cntId1";
66
+	UIViewController *vc1 = [UIViewController new];
67
+	
68
+	[self.store setContainer:vc1 containerId:containerId1];
69
+	
70
+	UIViewController *ans = [self.store findContainerForId:containerId1];
71
+	XCTAssertEqualObjects(vc1, ans);
72
+	
73
+	[self.store removeContainer:containerId1];
74
+	
75
+	XCTAssertNil([self.store findContainerForId:containerId1]);
76
+}
77
+
65 78
 
66 79
 
67 80
 @end