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
       icon: require('../img/one.png'), // local image asset for the tab icon unselected state (optional)
150
       icon: require('../img/one.png'), // local image asset for the tab icon unselected state (optional)
151
       selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional)
151
       selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional)
152
       title: 'Screen One', // title of the screen as appears in the nav bar (optional)
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
       label: 'Two',
157
       label: 'Two',
187
   screen: {
188
   screen: {
188
     screen: 'example.WelcomeScreen', // unique ID registered with Navigation.registerScreen
189
     screen: 'example.WelcomeScreen', // unique ID registered with Navigation.registerScreen
189
     title: 'Welcome', // title of the screen as appears in the nav bar (optional)
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
   drawer: { // optional, add this if you want a side menu drawer in your app
194
   drawer: { // optional, add this if you want a side menu drawer in your app
193
     left: { // optional, define if you want a drawer from the left
195
     left: { // optional, define if you want a drawer from the left
212
   title: "Modal", // title of the screen as appears in the nav bar (optional)
214
   title: "Modal", // title of the screen as appears in the nav bar (optional)
213
   passProps: {}, // simple serializable object that will pass as props to the modal (optional)
215
   passProps: {}, // simple serializable object that will pass as props to the modal (optional)
214
   navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
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
   animationType: 'slide-up' // 'none' / 'slide-up' , appear animation for the modal (optional, default 'slide-up')
218
   animationType: 'slide-up' // 'none' / 'slide-up' , appear animation for the modal (optional, default 'slide-up')
216
 });
219
 });
217
 ```
220
 ```
283
   animated: true, // does the push have transition animation or does it happen immediately (optional)
286
   animated: true, // does the push have transition animation or does it happen immediately (optional)
284
   backButtonTitle: undefined, // override the back button title (optional)
287
   backButtonTitle: undefined, // override the back button title (optional)
285
   backButtonHidden: false, // hide the back button altogether (optional)
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
   title: undefined, // navigation bar title of the pushed screen (optional)
321
   title: undefined, // navigation bar title of the pushed screen (optional)
318
   passProps: {}, // simple serializable object that will pass as props to the pushed screen (optional)
322
   passProps: {}, // simple serializable object that will pass as props to the pushed screen (optional)
319
   animated: true, // does the push have transition animation or does it happen immediately (optional)
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
 
517
 
513
 ## Adding buttons to the navigator
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
 ```js
522
 ```js
518
 class FirstTabScreen extends Component {
523
 class FirstTabScreen extends Component {

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

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