Browse Source

Support passing unserializable props to custom button (#2192)

This commit applies the save props mechanism used when pushing screen
to navigator buttons as well, enabling us to pass unserializable props to buttons.
Guy Carmeli 7 years ago
parent
commit
fcd5c597a9
1 changed files with 21 additions and 0 deletions
  1. 21
    0
      src/deprecated/platformSpecificDeprecated.ios.js

+ 21
- 0
src/deprecated/platformSpecificDeprecated.ios.js View File

31
       navigatorButtons,
31
       navigatorButtons,
32
       navigatorEventID
32
       navigatorEventID
33
     } = _mergeScreenSpecificSettings(tab.screen, screenInstanceID, tab);
33
     } = _mergeScreenSpecificSettings(tab.screen, screenInstanceID, tab);
34
+    _processNavigatorButtons(navigatorButtons);
34
     tab.navigationParams = {
35
     tab.navigationParams = {
35
       screenInstanceID,
36
       screenInstanceID,
36
       navigatorStyle,
37
       navigatorStyle,
138
     navigatorButtons,
139
     navigatorButtons,
139
     navigatorEventID
140
     navigatorEventID
140
   } = _mergeScreenSpecificSettings(screen.screen, screenInstanceID, screen);
141
   } = _mergeScreenSpecificSettings(screen.screen, screenInstanceID, screen);
142
+  _processNavigatorButtons(navigatorButtons);
141
   params.navigationParams = {
143
   params.navigationParams = {
142
     screenInstanceID,
144
     screenInstanceID,
143
     navigatorStyle,
145
     navigatorStyle,
236
     navigatorButtons,
238
     navigatorButtons,
237
     navigatorEventID
239
     navigatorEventID
238
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
240
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
241
+  _processNavigatorButtons(navigatorButtons);
239
   const passProps = Object.assign({}, params.passProps);
242
   const passProps = Object.assign({}, params.passProps);
240
   passProps.navigatorID = navigator.navigatorID;
243
   passProps.navigatorID = navigator.navigatorID;
241
   passProps.screenInstanceID = screenInstanceID;
244
   passProps.screenInstanceID = screenInstanceID;
294
     navigatorButtons,
297
     navigatorButtons,
295
     navigatorEventID
298
     navigatorEventID
296
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
299
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
300
+  _processNavigatorButtons(navigatorButtons);
297
   const passProps = Object.assign({}, params.passProps);
301
   const passProps = Object.assign({}, params.passProps);
298
   passProps.navigatorID = navigator.navigatorID;
302
   passProps.navigatorID = navigator.navigatorID;
299
   passProps.screenInstanceID = screenInstanceID;
303
   passProps.screenInstanceID = screenInstanceID;
443
 }
447
 }
444
 
448
 
445
 function navigatorSetButtons(navigator, navigatorEventID, params) {
449
 function navigatorSetButtons(navigator, navigatorEventID, params) {
450
+  _processNavigatorButtons(params);
446
   if (params.leftButtons) {
451
   if (params.leftButtons) {
447
     const buttons = params.leftButtons.slice(); // clone
452
     const buttons = params.leftButtons.slice(); // clone
448
     for (let i = 0; i < buttons.length; i++) {
453
     for (let i = 0; i < buttons.length; i++) {
472
     navigatorButtons,
477
     navigatorButtons,
473
     navigatorEventID
478
     navigatorEventID
474
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
479
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
480
+  _processNavigatorButtons(navigatorButtons);
475
   const passProps = Object.assign({}, params.passProps);
481
   const passProps = Object.assign({}, params.passProps);
476
   passProps.navigatorID = navigatorID;
482
   passProps.navigatorID = navigatorID;
477
   passProps.screenInstanceID = screenInstanceID;
483
   passProps.screenInstanceID = screenInstanceID;
640
   return await ScreenUtils.getCurrentlyVisibleScreenId();
646
   return await ScreenUtils.getCurrentlyVisibleScreenId();
641
 }
647
 }
642
 
648
 
649
+function _processNavigatorButtons({rightButtons, leftButtons}) {
650
+  _saveNavigatorButtonsPassProps(rightButtons);
651
+  _saveNavigatorButtonsPassProps(leftButtons);
652
+}
653
+
654
+function _saveNavigatorButtonsPassProps(buttons = []) {
655
+  buttons.forEach((button) => {
656
+    if (button.component) {
657
+      const passPropsKey = _.uniqueId('customButtonComponent');
658
+      PropRegistry.save(passPropsKey, button.passProps);
659
+      button.passProps = {passPropsKey};
660
+    }
661
+  })
662
+}
663
+
643
 export default {
664
 export default {
644
   startTabBasedApp,
665
   startTabBasedApp,
645
   startSingleScreenApp,
666
   startSingleScreenApp,