Ran Greenberg 7 years ago
parent
commit
abc6bb7113
3 changed files with 42 additions and 10 deletions
  1. 14
    9
      ios/RNNBridgeModule.m
  2. 18
    0
      playground/e2e/app.test.js
  3. 10
    1
      playground/src/containers/ModalScreen.js

+ 14
- 9
ios/RNNBridgeModule.m View File

@@ -57,14 +57,16 @@ RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout)
57 57
 
58 58
 RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId)
59 59
 {
60
-	UIViewController *root = [[RNN instance].store findContainerForId:containerId];
60
+	UIViewController *modalToDismiss = [[RNN instance].store findContainerForId:containerId];
61 61
 	
62
-	if (root) {
62
+	if (modalToDismiss) {
63 63
 		UIViewController *topVC = [self topPresentedVC];
64 64
 		
65
-		if (root == topVC) {
66
-			[root dismissViewControllerAnimated:YES completion:nil];
67
-			[self removeNextModal];
65
+		if (modalToDismiss == topVC) {
66
+			[modalToDismiss dismissViewControllerAnimated:YES completion:^{
67
+				[self removeNextModal];
68
+
69
+			}];
68 70
 		}
69 71
 		else {
70 72
 			[[RNN instance].store.modalsToDismissArray addObject:containerId];
@@ -77,10 +79,13 @@ RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId)
77 79
 	UIViewController *vc = [[RNN instance].store findContainerForId:nextContainerId];
78 80
 	
79 81
 	if (vc) {
80
-		[vc dismissViewControllerAnimated:YES completion:^{
81
-			[[RNN instance].store.modalsToDismissArray removeObject:nextContainerId];
82
-			[self removeNextModal];
83
-		}];
82
+		UIViewController *topVC = [self topPresentedVC];
83
+		if (vc == topVC) {
84
+			[vc dismissViewControllerAnimated:YES completion:^{
85
+				[[RNN instance].store.modalsToDismissArray removeObject:nextContainerId];
86
+				[self removeNextModal];
87
+			}];
88
+		}
84 89
 	}
85 90
 }
86 91
 

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

@@ -96,6 +96,24 @@ describe('app', () => {
96 96
     elementByLabel('Dismiss Modal').tap();
97 97
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
98 98
   });
99
+  
100
+  it('dismiss some modal by id deep in the stack', () => {
101
+    elementByLabel('Show Modal').tap();
102
+    expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
103
+    elementByLabel('Show Modal').tap();
104
+    expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
105
+    elementByLabel('Show Modal').tap();
106
+    expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
107
+  
108
+    elementByLabel('Dismiss First In Stack').tap();
109
+    expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
110
+    
111
+    elementByLabel('Dismiss Modal').tap();
112
+    expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
113
+    
114
+    elementByLabel('Dismiss Modal').tap();
115
+    expect(elementByLabel('React Native Navigation!')).toBeVisible();
116
+  });
99 117
 });
100 118
 
101 119
 describe('reload app', () => {

+ 10
- 1
playground/src/containers/ModalScreen.js View File

@@ -17,6 +17,7 @@ class ModalScreen extends Component {
17 17
     this.onClickDismissPreviousModal = this.onClickDismissPreviousModal.bind(this);
18 18
     this.onClickDismissUnknownModal = this.onClickDismissUnknownModal.bind(this);
19 19
     this.onClickDismissAllPreviousModals = this.onClickDismissAllPreviousModals.bind(this);
20
+    this.onClickDismissFirstInStack = this.onClickDismissFirstInStack.bind(this);
20 21
   }
21 22
   render() {
22 23
     return (
@@ -28,6 +29,7 @@ class ModalScreen extends Component {
28 29
         <Button title="Dismiss Unknown Modal" onPress={this.onClickDismissUnknownModal} />
29 30
         {this.getPreviousModalId() ? (<Button title="Dismiss Previous Modal" onPress={this.onClickDismissPreviousModal} />) : undefined}
30 31
         {this.props.previousModalIds ? (<Button title="Dismiss ALL Previous Modals" onPress={this.onClickDismissAllPreviousModals} />) : undefined}
32
+        {this.props.previousModalIds ? (<Button title="Dismiss First In Stack" onPress={this.onClickDismissFirstInStack} />) : undefined}
31 33
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
32 34
         
33 35
       </View>
@@ -39,7 +41,7 @@ class ModalScreen extends Component {
39 41
       name: 'navigation.playground.ModalScreen',
40 42
       passProps: {
41 43
         modalPosition: this.getModalPosition() + 1,
42
-        previousModalIds: _.concat([], this.props.previousModalIds, this.props.id)
44
+        previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.id)
43 45
       }
44 46
     });
45 47
   }
@@ -59,7 +61,14 @@ class ModalScreen extends Component {
59 61
   onClickDismissAllPreviousModals() {
60 62
     _.forEach(this.props.previousModalIds, (id) => Navigation.dismissModal(id));
61 63
   }
64
+  
65
+  
66
+  onClickDismissFirstInStack() {
67
+    console.log('RANG', 'getFirstInStackModalId', _.head(this.props.previousModalIds));;
68
+    Navigation.dismissModal(_.head(this.props.previousModalIds));
69
+  }
62 70
 
71
+  
63 72
   getModalPosition() {
64 73
     return (this.props.modalPosition || 1);
65 74
   }