Browse Source

ios - popToRoot fixed #891

Ran Greenberg 7 years ago
parent
commit
3b03bccf03

+ 4
- 0
ios/RNNBridgeModule.m View File

34
 	[_commandsHandler popTo:containerId toContainerId:toContainerId];
34
 	[_commandsHandler popTo:containerId toContainerId:toContainerId];
35
 }
35
 }
36
 
36
 
37
+RCT_EXPORT_METHOD(popToRoot:(NSString*)containerId) {
38
+	[_commandsHandler popToRoot:containerId];
39
+}
40
+
37
 RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout) {
41
 RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout) {
38
 	[_commandsHandler showModal:layout];
42
 	[_commandsHandler showModal:layout];
39
 }
43
 }

+ 2
- 0
ios/RNNCommandsHandler.h View File

16
 
16
 
17
 -(void) popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId;
17
 -(void) popTo:(NSString*)containerId toContainerId:(NSString*)toContainerId;
18
 
18
 
19
+-(void) popToRoot:(NSString*)containerId;
20
+
19
 -(void) showModal:(NSDictionary*)layout;
21
 -(void) showModal:(NSDictionary*)layout;
20
 
22
 
21
 -(void) dismissModal:(NSString*)containerId;
23
 -(void) dismissModal:(NSString*)containerId;

+ 5
- 0
ios/RNNCommandsHandler.m View File

49
 	[_navigationStackManager popTo:containerId toContainerId:toContainerId];
49
 	[_navigationStackManager popTo:containerId toContainerId:toContainerId];
50
 }
50
 }
51
 
51
 
52
+-(void) popToRoot:(NSString*)containerId {
53
+	[self assertReady];
54
+	[_navigationStackManager popToRoot:containerId];
55
+}
56
+
52
 -(void) showModal:(NSDictionary*)layout {
57
 -(void) showModal:(NSDictionary*)layout {
53
 	[self assertReady];
58
 	[self assertReady];
54
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
59
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];

+ 1
- 0
ios/RNNNavigationStackManager.h View File

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

+ 6
- 0
ios/RNNNavigationStackManager.m View File

40
 	}
40
 	}
41
 }
41
 }
42
 
42
 
43
+-(void) popToRoot:(NSString*)containerId {
44
+	UIViewController* vc = [_store findContainerForId:containerId];
45
+	UINavigationController* nvc = [vc navigationController];
46
+	[nvc popToRootViewControllerAnimated:YES];
47
+}
48
+
43
 @end
49
 @end

+ 8
- 0
playground/e2e/app.test.js View File

72
     await elementByLabel('Pop To Stack Position 1').tap();
72
     await elementByLabel('Pop To Stack Position 1').tap();
73
     await expect(elementByLabel('Stack Position: 1')).toBeVisible();
73
     await expect(elementByLabel('Stack Position: 1')).toBeVisible();
74
   });
74
   });
75
+
76
+  it('pop to root', async () => {
77
+    await elementByLabel('Push').tap();
78
+    await elementByLabel('Push').tap();
79
+    await elementByLabel('Push').tap();
80
+    await elementByLabel('Pop To Root').tap();
81
+    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
82
+  });
75
 });
83
 });
76
 
84
 
77
 describe('modal', () => {
85
 describe('modal', () => {

+ 6
- 0
playground/src/containers/PushedScreen.js View File

16
     this.onClickPop = this.onClickPop.bind(this);
16
     this.onClickPop = this.onClickPop.bind(this);
17
     this.onClickPopPrevious = this.onClickPopPrevious.bind(this);
17
     this.onClickPopPrevious = this.onClickPopPrevious.bind(this);
18
     this.onClickPopToFirstPosition = this.onClickPopToFirstPosition.bind(this);
18
     this.onClickPopToFirstPosition = this.onClickPopToFirstPosition.bind(this);
19
+    this.onClickPopToRoot = this.onClickPopToRoot.bind(this);
19
   }
20
   }
20
   render() {
21
   render() {
21
     const stackPosition = this.getStackPosition();
22
     const stackPosition = this.getStackPosition();
26
         <Button title="Push" onPress={this.onClickPush} />
27
         <Button title="Push" onPress={this.onClickPush} />
27
         <Button title="Pop" onPress={this.onClickPop} />
28
         <Button title="Pop" onPress={this.onClickPop} />
28
         <Button title="Pop Previous" onPress={this.onClickPopPrevious} />
29
         <Button title="Pop Previous" onPress={this.onClickPopPrevious} />
30
+        <Button title="Pop To Root" onPress={this.onClickPopToRoot} />
29
         {stackPosition > 2 && <Button title="Pop To Stack Position 1" onPress={this.onClickPopToFirstPosition} />}
31
         {stackPosition > 2 && <Button title="Pop To Stack Position 1" onPress={this.onClickPopToFirstPosition} />}
30
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
32
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
31
       </View>
33
       </View>
54
     Navigation.on(this.props.id).popTo(this.props.previousScreenIds[0]);
56
     Navigation.on(this.props.id).popTo(this.props.previousScreenIds[0]);
55
   }
57
   }
56
 
58
 
59
+  onClickPopToRoot() {
60
+    Navigation.on(this.props.id).popToRoot();
61
+  }
62
+
57
   getStackPosition() {
63
   getStackPosition() {
58
     return this.props.stackPosition || 1;
64
     return this.props.stackPosition || 1;
59
   }
65
   }