Browse Source

added resetTo

talkol 9 years ago
parent
commit
836f3a351a
3 changed files with 41 additions and 0 deletions
  1. 10
    0
      example/src/screens/PushedScreen.js
  2. 3
    0
      src/Screen.js
  3. 28
    0
      src/platformSpecific.ios.js

+ 10
- 0
example/src/screens/PushedScreen.js View File

38
           <Text style={styles.button}>Pop To Root</Text>
38
           <Text style={styles.button}>Pop To Root</Text>
39
         </TouchableOpacity>
39
         </TouchableOpacity>
40
 
40
 
41
+        <TouchableOpacity onPress={ this.onResetToPress.bind(this) }>
42
+          <Text style={styles.button}>Reset To</Text>
43
+        </TouchableOpacity>
44
+
41
       </View>
45
       </View>
42
     );
46
     );
43
   }
47
   }
59
   onPopToRootPress() {
63
   onPopToRootPress() {
60
     this.navigator.popToRoot();
64
     this.navigator.popToRoot();
61
   }
65
   }
66
+  onResetToPress() {
67
+    this.navigator.resetTo({
68
+      title: "New Root",
69
+      screen: "example.PushedScreen"
70
+    });
71
+  }
62
 }
72
 }
63
 
73
 
64
 const styles = StyleSheet.create({
74
 const styles = StyleSheet.create({

+ 3
- 0
src/Screen.js View File

16
   popToRoot(params = {}) {
16
   popToRoot(params = {}) {
17
     return platformSpecific.navigatorPopToRoot(this, params);
17
     return platformSpecific.navigatorPopToRoot(this, params);
18
   }
18
   }
19
+  resetTo(params = {}) {
20
+    return platformSpecific.navigatorResetTo(this, params);
21
+  }
19
   showModal(params = {}) {
22
   showModal(params = {}) {
20
     return Navigation.showModal(params);
23
     return Navigation.showModal(params);
21
   }
24
   }

+ 28
- 0
src/platformSpecific.ios.js View File

202
   });
202
   });
203
 }
203
 }
204
 
204
 
205
+function navigatorResetTo(navigator, params) {
206
+  if (!params.screen) {
207
+    console.error('Navigator.resetTo(params): params.screen is required');
208
+    return;
209
+  }
210
+  const screenInstanceID = utils.getRandomId();
211
+  const {
212
+    navigatorStyle,
213
+    navigatorButtons,
214
+    navigatorEventID
215
+  } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
216
+  const passProps = Object.assign({}, params.passProps);
217
+  passProps.navigatorID = navigator.navigatorID;
218
+  passProps.screenInstanceID = screenInstanceID;
219
+  passProps.navigatorEventID = navigatorEventID;
220
+  passProps.listenForEvents = !!(navigatorButtons.leftButtons || navigatorButtons.rightButtons);
221
+  Controllers.NavigationControllerIOS(navigator.navigatorID).resetTo({
222
+    title: params.title,
223
+    component: params.screen,
224
+    animated: params.animated,
225
+    passProps: passProps,
226
+    style: navigatorStyle,
227
+    leftButtons: navigatorButtons.leftButtons,
228
+    rightButtons: navigatorButtons.rightButtons
229
+  });
230
+}
231
+
205
 function navigatorSetTitle(navigator, params) {
232
 function navigatorSetTitle(navigator, params) {
206
   Controllers.NavigationControllerIOS(navigator.navigatorID).setTitle({
233
   Controllers.NavigationControllerIOS(navigator.navigatorID).setTitle({
207
     title: params.title
234
     title: params.title
280
   navigatorPush,
307
   navigatorPush,
281
   navigatorPop,
308
   navigatorPop,
282
   navigatorPopToRoot,
309
   navigatorPopToRoot,
310
+  navigatorResetTo,
283
   showModal,
311
   showModal,
284
   dismissModal,
312
   dismissModal,
285
   navigatorSetButtons,
313
   navigatorSetButtons,