Browse Source

support dismissModal by id

Ran Greenberg 7 years ago
parent
commit
dc5ffecad7
3 changed files with 24 additions and 7 deletions
  1. 9
    7
      ios/RNNBridgeModule.m
  2. 9
    0
      playground/e2e/app.test.js
  3. 6
    0
      playground/src/containers/ModalScreen.js

+ 9
- 7
ios/RNNBridgeModule.m View File

@@ -61,15 +61,17 @@ RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout)
61 61
 
62 62
 RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId)
63 63
 {
64
-	UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController;
65
-	while(root.presentedViewController) {
66
-		root = root.presentedViewController;
67
-	}
68
-
64
+	UIViewController *root = [[RNN instance].store findContainerForId:containerId];
69 65
 	
70
-	[root dismissViewControllerAnimated:YES completion:^{
66
+	//	while(root.presentedViewController) {
67
+	//		root = root.presentedViewController;
68
+	//	}
69
+	if (root) {
71 70
 		
72
-	}];
71
+		[root dismissViewControllerAnimated:YES completion:^{
72
+			
73
+		}];
74
+	}
73 75
 }
74 76
 
75 77
 - (void)assertReady

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

@@ -61,6 +61,15 @@ describe('app', () => {
61 61
     elementByLabel('Dismiss Modal').tap();
62 62
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
63 63
   });
64
+  
65
+  it('dismiss unknown screen id', () => {
66
+    elementByLabel('Show Modal').tap();
67
+    expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
68
+    elementByLabel('Dismiss Unknown Modal').tap();
69
+    expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
70
+    elementByLabel('Dismiss Modal').tap();
71
+    expect(elementByLabel('React Native Navigation!')).toBeVisible();
72
+  });
64 73
 
65 74
   xit('dismiss modal by id', () => {
66 75
     elementByLabel('Show Modal').tap();

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

@@ -14,6 +14,7 @@ class ModalScreen extends Component {
14 14
     this.onClickShowModal = this.onClickShowModal.bind(this);
15 15
     this.onClickDismissModal = this.onClickDismissModal.bind(this);
16 16
     this.onClickDismissPreviousModal = this.onClickDismissPreviousModal.bind(this);
17
+    this.onClickDismissUnknownModal = this.onClickDismissUnknownModal.bind(this);
17 18
   }
18 19
   render() {
19 20
     return (
@@ -22,8 +23,10 @@ class ModalScreen extends Component {
22 23
         <Text style={styles.footer}>{`Modal Stack Position: ${this.getModalPosition()}`}</Text>
23 24
         <Button title="Show Modal" onPress={this.onClickShowModal} />
24 25
         <Button title="Dismiss Modal" onPress={this.onClickDismissModal} />
26
+        <Button title="Dismiss Unknown Modal" onPress={this.onClickDismissUnknownModal} />
25 27
         {this.props.previousModalId ? (<Button title="Dismiss Previous Modal" onPress={this.onClickDismissPreviousModal} />) : undefined}
26 28
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
29
+        
27 30
       </View>
28 31
     );
29 32
   }
@@ -45,6 +48,9 @@ class ModalScreen extends Component {
45 48
   onClickDismissPreviousModal() {
46 49
     Navigation.dismissModal(this.props.previousModalId);
47 50
   }
51
+  onClickDismissUnknownModal() {
52
+    Navigation.dismissModal('unknown');
53
+  }
48 54
 
49 55
   getModalPosition() {
50 56
     return (this.props.modalPosition || 1);