Browse Source

added resetTo

talkol 8 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,6 +38,10 @@ class PushedScreen extends Screen {
38 38
           <Text style={styles.button}>Pop To Root</Text>
39 39
         </TouchableOpacity>
40 40
 
41
+        <TouchableOpacity onPress={ this.onResetToPress.bind(this) }>
42
+          <Text style={styles.button}>Reset To</Text>
43
+        </TouchableOpacity>
44
+
41 45
       </View>
42 46
     );
43 47
   }
@@ -59,6 +63,12 @@ class PushedScreen extends Screen {
59 63
   onPopToRootPress() {
60 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 74
 const styles = StyleSheet.create({

+ 3
- 0
src/Screen.js View File

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

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

@@ -202,6 +202,33 @@ function navigatorPopToRoot(navigator, params) {
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 232
 function navigatorSetTitle(navigator, params) {
206 233
   Controllers.NavigationControllerIOS(navigator.navigatorID).setTitle({
207 234
     title: params.title
@@ -280,6 +307,7 @@ export default platformSpecific = {
280 307
   navigatorPush,
281 308
   navigatorPop,
282 309
   navigatorPopToRoot,
310
+  navigatorResetTo,
283 311
   showModal,
284 312
   dismissModal,
285 313
   navigatorSetButtons,