Sfoglia il codice sorgente

added support for popToRoot, setTitle, testID

talkol 8 anni fa
parent
commit
1641496c17

+ 7
- 0
example/src/screens/PushedScreen.js Vedi File

@@ -34,6 +34,10 @@ class PushedScreen extends Screen {
34 34
           <Text style={styles.button}>Pop Screen</Text>
35 35
         </TouchableOpacity>
36 36
 
37
+        <TouchableOpacity onPress={ this.onPopToRootPress.bind(this) }>
38
+          <Text style={styles.button}>Pop To Root</Text>
39
+        </TouchableOpacity>
40
+
37 41
       </View>
38 42
     );
39 43
   }
@@ -52,6 +56,9 @@ class PushedScreen extends Screen {
52 56
   onPopPress() {
53 57
     this.navigator.pop();
54 58
   }
59
+  onPopToRootPress() {
60
+    this.navigator.popToRoot();
61
+  }
55 62
 }
56 63
 
57 64
 const styles = StyleSheet.create({

+ 9
- 0
example/src/screens/SecondTabScreen.js Vedi File

@@ -24,9 +24,18 @@ class SecondTabScreen extends Screen {
24 24
           <Text style={styles.button}>Change Buttons</Text>
25 25
         </TouchableOpacity>
26 26
 
27
+        <TouchableOpacity onPress={ this.onChangeTitlePress.bind(this) }>
28
+          <Text style={styles.button}>Change Title</Text>
29
+        </TouchableOpacity>
30
+
27 31
       </View>
28 32
     );
29 33
   }
34
+  onChangeTitlePress() {
35
+    this.navigator.setTitle({
36
+      title: Math.round(Math.random() * 100000).toString()
37
+    });
38
+  }
30 39
   onChangeButtonsPress() {
31 40
     let buttons;
32 41
     if (this.buttonsCounter % 3 == 0) {

+ 2
- 1
example/src/screens/StyledScreen.js Vedi File

@@ -25,7 +25,8 @@ class StyledScreen extends Screen {
25 25
   static navigatorButtons = {
26 26
     rightButtons: [{
27 27
       icon: require('../../img/navicon_edit.png'),
28
-      id: 'compose'
28
+      id: 'compose',
29
+      testID: 'e2e_is_awesome'
29 30
     }]
30 31
   };
31 32
   constructor(props) {

+ 1
- 1
package.json Vedi File

@@ -21,6 +21,6 @@
21 21
     "react-native": ">=0.19.0"
22 22
   },
23 23
   "dependencies": {
24
-    "react-native-controllers": "^1.2.1"
24
+    "react-native-controllers": "^1.2.2"
25 25
   }
26 26
 }

+ 6
- 0
src/Screen.js Vedi File

@@ -13,6 +13,9 @@ class Navigator {
13 13
   pop(params = {}) {
14 14
     return platformSpecific.navigatorPop(this, params);
15 15
   }
16
+  popToRoot(params = {}) {
17
+    return platformSpecific.navigatorPopToRoot(this, params);
18
+  }
16 19
   showModal(params = {}) {
17 20
     return Navigation.showModal(params);
18 21
   }
@@ -23,6 +26,9 @@ class Navigator {
23 26
     const navigatorEventID = this.screenInstance.listenOnNavigatorEvents();
24 27
     return platformSpecific.navigatorSetButtons(this, navigatorEventID, params);
25 28
   }
29
+  setTitle(params = {}) {
30
+    return platformSpecific.navigatorSetTitle(this, params);
31
+  }
26 32
 }
27 33
 
28 34
 export default class Screen extends Component {

+ 15
- 1
src/platformSpecific.ios.js Vedi File

@@ -162,6 +162,18 @@ function navigatorPop(navigator, params) {
162 162
   });
163 163
 }
164 164
 
165
+function navigatorPopToRoot(navigator, params) {
166
+  Controllers.NavigationControllerIOS(navigator.navigatorID).popToRoot({
167
+    animated: params.animated
168
+  });
169
+}
170
+
171
+function navigatorSetTitle(navigator, params) {
172
+  Controllers.NavigationControllerIOS(navigator.navigatorID).setTitle({
173
+    title: params.title
174
+  });
175
+}
176
+
165 177
 function navigatorSetButtons(navigator, navigatorEventID, params) {
166 178
   if (params.leftButtons) {
167 179
     const buttons = params.leftButtons.slice(); // clone
@@ -225,7 +237,9 @@ export default platformSpecific = {
225 237
   startSingleScreenApp,
226 238
   navigatorPush,
227 239
   navigatorPop,
240
+  navigatorPopToRoot,
228 241
   showModal,
229 242
   dismissModal,
230
-  navigatorSetButtons
243
+  navigatorSetButtons,
244
+  navigatorSetTitle
231 245
 }