소스 검색

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
 RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
27
 RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
28
 {
28
 {
29
 	[self assertReady];
29
 	[self assertReady];
30
-	//TODO implement correctly
31
 	RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
30
 	RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
32
 	UIViewController *newVc = [factory createLayout:layout];
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
 RCT_EXPORT_METHOD(pop:(NSString*)containerId)
37
 RCT_EXPORT_METHOD(pop:(NSString*)containerId)
40
 {
38
 {
41
 	[self assertReady];
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
 	[[vc navigationController] popViewControllerAnimated:true];
42
 	[[vc navigationController] popViewControllerAnimated:true];
43
+	[[RNN instance].store removeContainer:containerId];
45
 }
44
 }
46
 
45
 
47
 - (void)assertReady
46
 - (void)assertReady

+ 1
- 0
ios/RNNStore.h 파일 보기

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

+ 10
- 5
ios/RNNStore.m 파일 보기

31
 
31
 
32
 
32
 
33
 - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
33
 - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
34
-	if (!containerId) {
35
-		return;
36
-	}
37
-	
34
+
38
 	UIViewController *existingVewController = [self findContainerForId:containerId];
35
 	UIViewController *existingVewController = [self findContainerForId:containerId];
39
 	if (existingVewController) {
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
 	[self.containerStore setObject:viewController forKey:containerId];
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
 @end
51
 @end

+ 18
- 5
playground/ios/playgroundTests/RNNStoreTest.m 파일 보기

40
 	XCTAssertNotEqualObjects(vc2, ans);
40
 	XCTAssertNotEqualObjects(vc2, ans);
41
 }
41
 }
42
 
42
 
43
-- (void)testFindContainerForId_setNilContainerId {
43
+- (void)testSetContainer_setNilContainerId {
44
 	NSString *containerId1 = nil;
44
 	NSString *containerId1 = nil;
45
 	UIViewController *vc1 = [UIViewController new];
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
 	NSString *containerId1 = @"cntId1";
52
 	NSString *containerId1 = @"cntId1";
54
 	
53
 	
55
 	UIViewController *vc1 = [UIViewController new];
54
 	UIViewController *vc1 = [UIViewController new];
62
 	XCTAssertThrows([self.store setContainer:vc2 containerId:containerId1]);
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
 @end
80
 @end