Browse Source

add support for caller definition of navigatorButtons

talkol 8 years ago
parent
commit
df57a4989c
2 changed files with 13 additions and 5 deletions
  1. 10
    5
      README.md
  2. 3
    0
      src/platformSpecific.ios.js

+ 10
- 5
README.md View File

@@ -150,7 +150,8 @@ Navigation.startTabBasedApp({
150 150
       icon: require('../img/one.png'), // local image asset for the tab icon unselected state (optional)
151 151
       selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional)
152 152
       title: 'Screen One', // title of the screen as appears in the nav bar (optional)
153
-      navigatorStyle: {} // override the navigator style for the tab screen, see "Styling the navigator" below (optional)
153
+      navigatorStyle: {}, // override the navigator style for the tab screen, see "Styling the navigator" below (optional),
154
+      navigatorButtons: {} // override the nav buttons for the tab screen, see "Adding buttons to the navigator" below (optional)
154 155
     },
155 156
     {
156 157
       label: 'Two',
@@ -187,7 +188,8 @@ Navigation.startSingleScreenApp({
187 188
   screen: {
188 189
     screen: 'example.WelcomeScreen', // unique ID registered with Navigation.registerScreen
189 190
     title: 'Welcome', // title of the screen as appears in the nav bar (optional)
190
-    navigatorStyle: {} // override the navigator style for the screen, see "Styling the navigator" below (optional)
191
+    navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
192
+    navigatorButtons: {} // override the nav buttons for the screen, see "Adding buttons to the navigator" below (optional)
191 193
   },
192 194
   drawer: { // optional, add this if you want a side menu drawer in your app
193 195
     left: { // optional, define if you want a drawer from the left
@@ -212,6 +214,7 @@ Navigation.showModal({
212 214
   title: "Modal", // title of the screen as appears in the nav bar (optional)
213 215
   passProps: {}, // simple serializable object that will pass as props to the modal (optional)
214 216
   navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
217
+  navigatorButtons: {}, // override the nav buttons for the screen, see "Adding buttons to the navigator" below (optional)
215 218
   animationType: 'slide-up' // 'none' / 'slide-up' , appear animation for the modal (optional, default 'slide-up')
216 219
 });
217 220
 ```
@@ -283,7 +286,8 @@ this.props.navigator.push({
283 286
   animated: true, // does the push have transition animation or does it happen immediately (optional)
284 287
   backButtonTitle: undefined, // override the back button title (optional)
285 288
   backButtonHidden: false, // hide the back button altogether (optional)
286
-  navigatorStyle: {} // override the navigator style for the pushed screen (optional)
289
+  navigatorStyle: {}, // override the navigator style for the pushed screen (optional)
290
+  navigatorButtons: {} // override the nav buttons for the pushed screen (optional)
287 291
 });
288 292
 ```
289 293
 
@@ -317,7 +321,8 @@ this.props.navigator.resetTo({
317 321
   title: undefined, // navigation bar title of the pushed screen (optional)
318 322
   passProps: {}, // simple serializable object that will pass as props to the pushed screen (optional)
319 323
   animated: true, // does the push have transition animation or does it happen immediately (optional)
320
-  navigatorStyle: {} // override the navigator style for the pushed screen (optional)
324
+  navigatorStyle: {}, // override the navigator style for the pushed screen (optional)
325
+  navigatorButtons: {} // override the nav buttons for the pushed screen (optional)
321 326
 });
322 327
 ```
323 328
 
@@ -512,7 +517,7 @@ All supported styles are defined [here](https://github.com/wix/react-native-cont
512 517
 
513 518
 ## Adding buttons to the navigator
514 519
 
515
-Nav bar buttons can be defined per-screen by adding `static navigatorButtons = {...};` on the screen component definition. Handle onPress events for the buttons by setting your handler with `navigator.setOnNavigatorEvent(callback)`.
520
+Nav bar buttons can be defined per-screen by adding `static navigatorButtons = {...};` on the screen component definition. This object can also be passed when the screen is originally created; and can be overridden when a screen is pushed. Handle onPress events for the buttons by setting your handler with `navigator.setOnNavigatorEvent(callback)`.
516 521
 
517 522
 ```js
518 523
 class FirstTabScreen extends Component {

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

@@ -150,6 +150,9 @@ function _mergeScreenSpecificSettings(screenID, screenInstanceID, params) {
150 150
 
151 151
   const navigatorEventID = screenInstanceID + '_events';
152 152
   const navigatorButtons = Object.assign({}, screenClass.navigatorButtons);
153
+  if (params.navigatorButtons) {
154
+    Object.assign(navigatorButtons, params.navigatorButtons);
155
+  }
153 156
   if (navigatorButtons.leftButtons) {
154 157
     for (let i = 0 ; i < navigatorButtons.leftButtons.length ; i++) {
155 158
       navigatorButtons.leftButtons[i].onPress = navigatorEventID;