Browse Source

added support for popToRoot, setTitle, testID

talkol 8 years ago
parent
commit
1641496c17

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

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

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

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

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

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

+ 1
- 1
package.json View File

21
     "react-native": ">=0.19.0"
21
     "react-native": ">=0.19.0"
22
   },
22
   },
23
   "dependencies": {
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 View File

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

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

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
 function navigatorSetButtons(navigator, navigatorEventID, params) {
177
 function navigatorSetButtons(navigator, navigatorEventID, params) {
166
   if (params.leftButtons) {
178
   if (params.leftButtons) {
167
     const buttons = params.leftButtons.slice(); // clone
179
     const buttons = params.leftButtons.slice(); // clone
225
   startSingleScreenApp,
237
   startSingleScreenApp,
226
   navigatorPush,
238
   navigatorPush,
227
   navigatorPop,
239
   navigatorPop,
240
+  navigatorPopToRoot,
228
   showModal,
241
   showModal,
229
   dismissModal,
242
   dismissModal,
230
-  navigatorSetButtons
243
+  navigatorSetButtons,
244
+  navigatorSetTitle
231
 }
245
 }