React-native-navigation: TopBar buttons not rendered when waitForRender is set to true on iOS

Created on 29 Mar 2020  路  18Comments  路  Source: wix/react-native-navigation

Issue Description

Seems like mergeOptions does not work well with waitForRender: true.

Without showModal: { waitForRender: true }

image

With showModal: { waitForRender: true }

image

Steps to Reproduce / Code Snippets / Screenshots

  1. Set default options:
Navigation.setDefaultOptions({
    animations: {
      push: {
        waitForRender: true,
      },
    },
  });
  1. Open any modal page with top bar buttons added by mergeOptions.

Environment

  • React Native Navigation version: 6.3.2
  • React Native version: 0.61.5
  • Platform(s) (iOS, Android, or both?): iOS
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator, 13.2.2
iOS acceptebug

All 18 comments

Seems like wrapping Navigation.mergeOptions into requestAnimationFrame can be used as a workaround.

requestAnimationFrame(() => {
  requestAnimationFrame(() => {
    Navigation.mergeOptions({ ... })
  });
});

_Edit:_

It helps, but not always. Sometimes it needs more delay 馃槩

i have the same issue and it seems i should wait before doing mergeOptions

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

Not stale.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

The issue has been closed for inactivity.

@rosskhanas Where are you calling mergeOptions from? Could you please provide some more code on how to reproduce this with the playground app?

@danilobuerger thank you for looking at this.

So I have a function which opens the modal:

modalOpen({
    name: "suite.ModalOrganizationInformationUpdate",
    options: {
      topBar: {
        leftButtons: [
          {
            id: NAVBAR_BUTTON_INFORMATION_MAIN_UPDATE_CANCEL,
            text: "Cancel",
          },
        ],
        rightButtons: [
          {
            enabled: false,
            id: NAVBAR_BUTTON_INFORMATION_MAIN_UPDATE_SAVE,
            text: "Save",
          },
        ],
        title: {
          text: "Edit Information",
        },
      },
    },
    passProps: {
      pageClose: modalClose,
      topBarButtonLeftIconAndroid,
      topBarButtonLeftTextClose,
      topBarButtonRightIconSaveAndroid,
      topBarButtonRightTextSave,
      ...args,
    },
  });

Then in the ModalOrganizationInformationUpdate I have a componentDidMount method implemented:

componentDidMount() {
    Navigation.events().bindComponent(this);
    BackHandler.addEventListener("hardwareBackPress", this.onHardwareBackPress);
    const { componentId } = this.props;
    Navigation.mergeOptions(componentId, {
      topBar: {
        rightButtons: [
          {
            enabled: true,
            id: NAVBAR_BUTTON_INFORMATION_MAIN_UPDATE_SAVE,
            text: "Save",
          },
        ],
      },
    });
  }

So I just open the page with a Save button disabled, then I set the enabled: true but it is still disabled.

Is there a reason you are doing this via Navigation.mergeOptions instead of static options?

I just simplified the existing code to provide a simpler example. In a full implementation, there is extra validation(like if the user has permission to edit the page or if all required fields are filled) that is stored in a local state. I guess it is not possible to use state values in static options... Am I right?

Afaik only props are passed.

@rosskhanas You can execute whatever logic you want in static options, there's an example in the docs.

But regardless this should be fixed. Thanks for looking into this @danilobuerger 馃檱

@rosskhanas could you please try with #6702 . Does that solve all your issues?

@rosskhanas could you please try with #6702 . Does that solve all your issues?

Could be I messed up and failed to apply changes correctly, but I got a build error:

image

Doesn't really say much... don't forget to run pod install after applying the patch and optionally to clean the build dir with xcode.

image

@danilobuerger is this helpful?

It looks like you applied the patch onto an older version? The patch will probably only work on the current master.

@danilobuerger I tried again, seems like your PR fixes the bug! 馃コ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kiroukou picture kiroukou  路  3Comments

yedidyak picture yedidyak  路  3Comments

henrikra picture henrikra  路  3Comments

nbolender picture nbolender  路  3Comments

tmaly1980 picture tmaly1980  路  3Comments