Ran Greenberg преди 7 години
родител
ревизия
569592cb3c

+ 4
- 0
ios/RNNBridgeModule.m Целия файл

@@ -30,6 +30,10 @@ RCT_EXPORT_METHOD(pop:(NSString*)containerId) {
30 30
 	[_commandsHandler pop:containerId];
31 31
 }
32 32
 
33
+RCT_EXPORT_METHOD(popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId) {
34
+	[_commandsHandler popTo:containerId toContainerId:toContainerId];
35
+}
36
+
33 37
 RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout) {
34 38
 	[_commandsHandler showModal:layout];
35 39
 }

+ 2
- 0
ios/RNNCommandsHandler.h Целия файл

@@ -14,6 +14,8 @@
14 14
 
15 15
 -(void) pop:(NSString*)containerId;
16 16
 
17
+-(void) popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId;
18
+
17 19
 -(void) showModal:(NSDictionary*)layout;
18 20
 
19 21
 -(void) dismissModal:(NSString*)containerId;

+ 5
- 0
ios/RNNCommandsHandler.m Целия файл

@@ -44,6 +44,11 @@
44 44
 	[_navigationStackManager pop:containerId];
45 45
 }
46 46
 
47
+-(void) popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId {
48
+	[self assertReady];
49
+	[_navigationStackManager popTo:containerId toContainerId:toContainerId];
50
+}
51
+
47 52
 -(void) showModal:(NSDictionary*)layout {
48 53
 	[self assertReady];
49 54
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];

+ 1
- 0
ios/RNNNavigationStackManager.h Целия файл

@@ -8,5 +8,6 @@
8 8
 
9 9
 -(void)push:(UIViewController*)newTop onTop:(NSString*)containerId;
10 10
 -(void)pop:(NSString*)containerId;
11
+-(void)popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId;
11 12
 
12 13
 @end

+ 15
- 3
ios/RNNNavigationStackManager.m Целия файл

@@ -12,20 +12,32 @@
12 12
 
13 13
 -(void)push:(UIViewController *)newTop onTop:(NSString *)containerId {
14 14
 	UIViewController *vc = [_store findContainerForId:containerId];
15
-	[[vc navigationController] pushViewController:newTop animated:true];
15
+	[[vc navigationController] pushViewController:newTop animated:YES];
16 16
 }
17 17
 
18 18
 -(void)pop:(NSString *)containerId {
19 19
 	UIViewController* vc = [_store findContainerForId:containerId];
20 20
 	UINavigationController* nvc = [vc navigationController];
21 21
 	if ([nvc topViewController] == vc) {
22
-		[nvc popViewControllerAnimated:true];
22
+		[nvc popViewControllerAnimated:YES];
23 23
 	} else {
24 24
 		NSMutableArray * vcs = nvc.viewControllers.mutableCopy;
25 25
 		[vcs removeObject:vc];
26
-		[nvc setViewControllers:vcs animated:true];
26
+		[nvc setViewControllers:vcs animated:YES];
27 27
 	}
28 28
 	[_store removeContainer:containerId];
29 29
 }
30 30
 
31
+-(void) popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId {
32
+	UIViewController *vc = [_store findContainerForId:containerId];
33
+	UINavigationController *nvc = [vc navigationController];
34
+	
35
+	UIViewController *toVC = [_store findContainerForId:toContainerId];
36
+	
37
+	if (vc && toVC) {
38
+		[nvc popToViewController:toVC animated:YES];
39
+		// TODO - remove the poped vcs from store
40
+	}
41
+}
42
+
31 43
 @end

+ 9
- 0
playground/e2e/app.test.js Целия файл

@@ -63,6 +63,15 @@ describe('screen stack', () => {
63 63
     await elementByLabel('Pop').tap();
64 64
     await expect(elementByLabel('React Native Navigation!')).toBeVisible();
65 65
   });
66
+
67
+  it('pop to specific id', async () => {
68
+    await elementByLabel('Push').tap();
69
+    await elementByLabel('Push').tap();
70
+    await elementByLabel('Push').tap();
71
+    await expect(elementByLabel('Stack Position: 3')).toBeVisible();
72
+    await elementByLabel('Pop To Stack Position 1').tap();
73
+    await expect(elementByLabel('Stack Position: 1')).toBeVisible();
74
+  })
66 75
 });
67 76
 
68 77
 describe('modal', () => {

+ 8
- 1
playground/src/containers/PushedScreen.js Целия файл

@@ -15,15 +15,18 @@ class PushedScreen extends Component {
15 15
     this.onClickPush = this.onClickPush.bind(this);
16 16
     this.onClickPop = this.onClickPop.bind(this);
17 17
     this.onClickPopPrevious = this.onClickPopPrevious.bind(this);
18
+    this.onClickPopToFirstPosition = this.onClickPopToFirstPosition.bind(this);
18 19
   }
19 20
   render() {
21
+    const stackPosition = this.getStackPosition();
20 22
     return (
21 23
       <View style={styles.root}>
22 24
         <Text style={styles.h1}>{`Pushed Screen`}</Text>
23
-        <Text style={styles.h2}>{`Stack Position: ${this.getStackPosition()}`}</Text>
25
+        <Text style={styles.h2}>{`Stack Position: ${stackPosition}`}</Text>
24 26
         <Button title="Push" onPress={this.onClickPush} />
25 27
         <Button title="Pop" onPress={this.onClickPop} />
26 28
         <Button title="Pop Previous" onPress={this.onClickPopPrevious} />
29
+        {stackPosition === 3 && <Button title="Pop To Stack Position 1" onPress={this.onClickPopToFirstPosition} />}
27 30
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
28 31
       </View>
29 32
     );
@@ -47,6 +50,10 @@ class PushedScreen extends Component {
47 50
     Navigation.on(_.last(this.props.previousScreenIds)).pop();
48 51
   }
49 52
 
53
+  onClickPopToFirstPosition() {
54
+    Navigation.on(this.props.id).popTo(this.props.previousScreenIds[0]);
55
+  }
56
+
50 57
   getStackPosition() {
51 58
     return this.props.stackPosition || 1;
52 59
   }