Browse Source

iOS - handle store when pop and pop to root

Ran Greenberg 7 years ago
parent
commit
772b1c790f

+ 10
- 5
lib/ios/RNNNavigationStackManager.m View File

@@ -35,17 +35,22 @@
35 35
 	UIViewController *toVC = [_store findContainerForId:toContainerId];
36 36
 	
37 37
 	if (vc && toVC) {
38
-		NSArray *popedVCs = [nvc popToViewController:toVC animated:YES];
39
-		for (UIViewController *popedVC in popedVCs) {
40
-			[_store removeContainerByViewControllerInstance:popedVC];
41
-		}
38
+		NSArray *poppedVCs = [nvc popToViewController:toVC animated:YES];
39
+		[self removePopedViewControllers:poppedVCs];
42 40
 	}
43 41
 }
44 42
 
45 43
 -(void) popToRoot:(NSString*)containerId {
46 44
 	UIViewController* vc = [_store findContainerForId:containerId];
47 45
 	UINavigationController* nvc = [vc navigationController];
48
-	[nvc popToRootViewControllerAnimated:YES];
46
+	NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:YES];
47
+	[self removePopedViewControllers:poppedVCs];
48
+}
49
+
50
+-(void)removePopedViewControllers:(NSArray*)viewControllers {
51
+	for (UIViewController *popedVC in viewControllers) {
52
+		[_store removeContainerByViewControllerInstance:popedVC];
53
+	}
49 54
 }
50 55
 
51 56
 @end

+ 2
- 0
lib/ios/RNNStore.h View File

@@ -9,6 +9,8 @@
9 9
 -(void) removeContainer:(NSString*)containerId;
10 10
 -(void) removeContainerByViewControllerInstance:(UIViewController*)containerInstance;
11 11
 
12
+-(NSString*)containerKeyForInstance:(UIViewController*)instance;
13
+
12 14
 -(void) setReadyToReceiveCommands:(BOOL)isReady;
13 15
 -(BOOL) isReadyToReceiveCommands;
14 16
 

+ 44
- 61
playground/ios/playgroundTests/RNNNavigationStackManagerTest.m View File

@@ -1,5 +1,4 @@
1 1
 #import <XCTest/XCTest.h>
2
-//#import <objc/runtime.h>
3 2
 #import "RNNStore.h"
4 3
 #import "RNNNavigationStackManager.h"
5 4
 
@@ -13,91 +12,75 @@
13 12
 	return self.willReturnVCs;
14 13
 }
15 14
 
15
+-(NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
16
+	return self.willReturnVCs;
17
+}
18
+
16 19
 @end
17 20
 
18 21
 
19 22
 @interface RNNNavigationStackManagerTest : XCTestCase
20 23
 
24
+@property (nonatomic, strong) RNNStore *store;
25
+@property (nonatomic, strong) RNNNavigationStackManager *uut;
26
+@property (nonatomic, strong) MockUINavigationController *nvc;
27
+@property (nonatomic, strong) UIViewController *vc1;
28
+@property (nonatomic, strong) UIViewController *vc2;
29
+@property (nonatomic, strong) UIViewController *vc3;
30
+
21 31
 @end
22 32
 
23 33
 @implementation RNNNavigationStackManagerTest
24 34
 
25 35
 - (void)setUp {
26 36
     [super setUp];
37
+	self.store = [RNNStore new];
38
+	self.uut = [[RNNNavigationStackManager alloc] initWithStore:self.store];
39
+	
40
+	self.nvc = [[MockUINavigationController alloc] init];
41
+	self.vc1 = [UIViewController new];
42
+	self.vc2 = [UIViewController new];
43
+	self.vc3 = [UIViewController new];
44
+	NSArray *vcArray = @[self.vc1, self.vc2, self.vc3];
45
+	[self.nvc setViewControllers:vcArray];
46
+	
47
+	[self.store setContainer:self.vc1 containerId:@"vc1"];
48
+	[self.store setContainer:self.vc2 containerId:@"vc2"];
49
+	[self.store setContainer:self.vc3 containerId:@"vc3"];
50
+	
27 51
 	
28 52
 }
29 53
 
30 54
 
31
-- (void)testPop {
32
-	RNNStore *store = [RNNStore new];
33
-	RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
55
+- (void)testPop_removeTopVCFromStore {
56
+	[self.uut pop:@"vc3"];
34 57
 	
35
-	UINavigationController *nvc = [[UINavigationController alloc] init];
36
-	
37
-	UIViewController *vc1 = [UIViewController new];
38
-	UIViewController *vc2 = [UIViewController new];
58
+	XCTAssertNil([self.store findContainerForId:@"vc3"]);
59
+	XCTAssertNotNil([self.store findContainerForId:@"vc2"]);
60
+	XCTAssertNotNil([self.store findContainerForId:@"vc1"]);
61
+}
39 62
 
63
+- (void)testPopToSpecificVC_removeAllPopedVCFromStore {
64
+	self.nvc.willReturnVCs = @[self.vc2, self.vc3];
65
+	[self.uut popTo:@"vc1" fromContainerId:@"vc3"];
40 66
 	
41
-	NSArray *vcArray = @[vc1, vc2];
42
-	[nvc setViewControllers:vcArray];
43
-	[store setContainer:vc1 containerId:@"vc1"];
44
-	[store setContainer:vc2 containerId:@"vc2"];
45
-	[uut pop:@"vc2"];
46
-	
47
-	XCTAssertNil([store findContainerForId:@"vc2"]);
48
-	XCTAssertNotNil([store findContainerForId:@"vc1"]);
67
+	XCTAssertNil([self.store findContainerForId:@"vc2"]);
68
+	XCTAssertNil([self.store findContainerForId:@"vc3"]);
69
+	XCTAssertNotNil([self.store findContainerForId:@"vc1"]);
49 70
 	
50 71
 }
51 72
 
52
-- (void)testPopTo_singleVc {
53
-	RNNStore *store = [RNNStore new];
54
-	RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
55
-	
56
-	UIViewController *vc1 = [UIViewController new];
57
-	UIViewController *vc2 = [UIViewController new];
58
-	UIViewController *vc3 = [UIViewController new];
59
-	MockUINavigationController *nvc = [[MockUINavigationController alloc] initWithRootViewController:vc1];
60
-	[nvc pushViewController:vc2 animated:NO];
61
-	[nvc pushViewController:vc3 animated:NO];
62
-	nvc.willReturnVCs = @[vc2, vc3];
63
-	
64
-	[store setContainer:vc1 containerId:@"vc1"];
65
-	[store setContainer:vc2 containerId:@"vc2"];
66
-	[store setContainer:vc3 containerId:@"vc3"];
67
-	[uut popTo:@"vc1" fromContainerId:@"vc3"];
68
-	
69
-	XCTAssertNil([store findContainerForId:@"vc2"]);
70
-	XCTAssertNotNil([store findContainerForId:@"vc1"]);
73
+- (void)testPopToRoot_removeAllTopVCsFromStore {
74
+	self.nvc.willReturnVCs = @[self.vc2, self.vc3];
75
+	[self.uut popToRoot:@"vc3"];
71 76
 	
77
+	XCTAssertNil([self.store findContainerForId:@"vc2"]);
78
+	XCTAssertNil([self.store findContainerForId:@"vc3"]);
79
+	XCTAssertNotNil([self.store findContainerForId:@"vc1"]);
80
+
72 81
 }
73 82
 
74 83
 
75
-//- (void)testPopTo {
76
-//	RNNStore *store = [RNNStore new];
77
-//	RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
78
-//	
79
-//	UINavigationController *nvc = [[UINavigationController alloc] init];
80
-//	
81
-//	UIViewController *vc1 = [UIViewController new];
82
-//	UIViewController *vc2 = [UIViewController new];
83
-//	UIViewController *vc3 = [UIViewController new];
84
-//	UIViewController *vc4 = [UIViewController new];
85
-//	
86
-//	NSArray *vcArray = @[vc1, vc2, vc3, vc4];
87
-//	[nvc setViewControllers:vcArray];
88
-//	[store setContainer:vc1 containerId:@"vc1"];
89
-//	[store setContainer:vc2 containerId:@"vc2"];
90
-//	[store setContainer:vc3 containerId:@"vc3"];
91
-//	[store setContainer:vc4 containerId:@"vc4"];
92
-//	[store setContainer:nvc containerId:@"nvc"];
93
-//	
94
-//	[uut popTo:@"vc1" fromContainerId:@"vc4"];
95
-//	
96
-//	XCTAssertNil([store findContainerForId:@"vc4"]);
97
-//	XCTAssertNil([store findContainerForId:@"vc3"]);
98
-//	XCTAssertNil([store findContainerForId:@"vc2"]);
99
-//	
100
-//}
101 84
 
102 85
 
103 86
 @end