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,6 +31,7 @@ function startTabBasedApp(params) {
31 31
       navigatorButtons,
32 32
       navigatorEventID
33 33
     } = _mergeScreenSpecificSettings(tab.screen, screenInstanceID, tab);
34
+    _processNavigatorButtons(navigatorButtons);
34 35
     tab.navigationParams = {
35 36
       screenInstanceID,
36 37
       navigatorStyle,
@@ -138,6 +139,7 @@ function startSingleScreenApp(params) {
138 139
     navigatorButtons,
139 140
     navigatorEventID
140 141
   } = _mergeScreenSpecificSettings(screen.screen, screenInstanceID, screen);
142
+  _processNavigatorButtons(navigatorButtons);
141 143
   params.navigationParams = {
142 144
     screenInstanceID,
143 145
     navigatorStyle,
@@ -236,6 +238,7 @@ function navigatorPush(navigator, params) {
236 238
     navigatorButtons,
237 239
     navigatorEventID
238 240
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
241
+  _processNavigatorButtons(navigatorButtons);
239 242
   const passProps = Object.assign({}, params.passProps);
240 243
   passProps.navigatorID = navigator.navigatorID;
241 244
   passProps.screenInstanceID = screenInstanceID;
@@ -294,6 +297,7 @@ function navigatorResetTo(navigator, params) {
294 297
     navigatorButtons,
295 298
     navigatorEventID
296 299
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
300
+  _processNavigatorButtons(navigatorButtons);
297 301
   const passProps = Object.assign({}, params.passProps);
298 302
   passProps.navigatorID = navigator.navigatorID;
299 303
   passProps.screenInstanceID = screenInstanceID;
@@ -443,6 +447,7 @@ function navigatorSwitchToTab(navigator, params) {
443 447
 }
444 448
 
445 449
 function navigatorSetButtons(navigator, navigatorEventID, params) {
450
+  _processNavigatorButtons(params);
446 451
   if (params.leftButtons) {
447 452
     const buttons = params.leftButtons.slice(); // clone
448 453
     for (let i = 0; i < buttons.length; i++) {
@@ -472,6 +477,7 @@ function showModal(params) {
472 477
     navigatorButtons,
473 478
     navigatorEventID
474 479
   } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
480
+  _processNavigatorButtons(navigatorButtons);
475 481
   const passProps = Object.assign({}, params.passProps);
476 482
   passProps.navigatorID = navigatorID;
477 483
   passProps.screenInstanceID = screenInstanceID;
@@ -640,6 +646,21 @@ async function getCurrentlyVisibleScreenId() {
640 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 664
 export default {
644 665
   startTabBasedApp,
645 666
   startSingleScreenApp,