aksonov / react-native-router-flux

The first declarative React Native router
MIT License
8.98k stars 2.11k forks source link

Action.refresh no longer works starting on v4.0.0-beta.40 #3376

Open hugoh59 opened 5 years ago

hugoh59 commented 5 years ago

Version

Any react-native-router-flux version including and higher than 4.0.0-beta.40

Expected behaviour

componentWillMount() { Actions.refresh({onRight: () => this.onButtonPress(), rightTitle: I18n.t("profile.save")}) } refreshes the onRight title and action

Actual behaviour

Instead, it does not do anything when it used to work in previous versions.

Steps to reproduce

  1. Create a project with the latest version
  2. Add onRight action in Router component
  3. Update the action with the onRefresh event and see that it does not work
Q8hma commented 5 years ago

any help here please ??

I used last v4.0.6 and same refresh not work

thnx

Mifayo commented 5 years ago

any updates ??

raffij commented 5 years ago

Looks like it applies the refresh props to the current scene, rather than the new scene.

hugoh59 commented 5 years ago

@aksonov do you know if this is linked to RNRF or to updates in newer version or React Nativation?

aksonov commented 5 years ago

@hugoh59 You have to wrap refresh with setTimeout. Yes, it is connected - react navigation 2.x changed a lot

strindhaug commented 5 years ago

Just how long timeout is needed for it to work? I've tried this with no success

      <Scene
        key="manualSteps"
        component={relayRenderer(ManualSteps)}
        queries={viewerQueries}
        title="Change steps (Initial)"
        hideTabBar
        clone
        backButtonImage={quitButton}
        //renderRightButton={renderDummySaveButton}
        direction="vertical"
      />

I've tried with or without an initial rightbutton dummy, it makes no difference.

In ManualSteps:

  componentDidMount() {
    setTimeout(() => {
      Actions.refresh({
        title: 'Change steps (Mounted)',
        onBack: this.onCancelPress,
        renderRightButton: this.renderRightNavBarButton,
      });
    }, 1000);
  }

The title actually does change after 1 second but the rightButton is unchanged. It seems like refresh simply ignores all props that contain style or components. But I can't see anything that appears to filter it out in the source code...

strindhaug commented 5 years ago

Ahh, it seems that:

because of these:

https://github.com/aksonov/react-native-router-flux/blob/20050c4c2ef0abf4d507c200e5a6a66bf2c62541/src/navigationStore.js#L209-L214

Presumably some of the values earlier in these OR-chains is always non-falsy causing it to ignore the params from refresh().

So for instance to change the navigationBarStyle using refresh you should refresh with the undocumented prop headerStyle as well (I would set both in case this bug is fixed later). I've only tried navigationBarStyle so far but I assume this would work for some of the others.

hugoh59 commented 5 years ago

I managed to fix this issue simply by upgrading to the latest version of React Native, which was a tedious process by the way but quite worth it.

C0dekid commented 5 years ago

Still not working for me!

When using this

Actions.refresh({ title: "New title" });

The title should change, but it does nothing!

"react-native": "0.58.6" "react-native-router-flux": "^4.0.6"

Also it ignores the swipeEnabled property, the transition/animation also being ignored.

KaoPengHsiang commented 5 years ago

@C0dekid Maybe you can try this?


refreshTitle= () => {
    Actions.refresh({ title: "New title", key: Math.random() }); //sometimes refresh didn't work, add a random seems be better
  };
<Scene
    key="page"
    component={page}
    title="New page"               
    back={true}  //must have
    onBack={this.refreshTitle}
 />
jhonattansolartearanda commented 3 years ago

Just how long timeout is needed for it to work? I've tried this with no success

      <Scene
        key="manualSteps"
        component={relayRenderer(ManualSteps)}
        queries={viewerQueries}
        title="Change steps (Initial)"
        hideTabBar
        clone
        backButtonImage={quitButton}
        //renderRightButton={renderDummySaveButton}
        direction="vertical"
      />

I've tried with or without an initial rightbutton dummy, it makes no difference.

In ManualSteps:

  componentDidMount() {
    setTimeout(() => {
      Actions.refresh({
        title: 'Change steps (Mounted)',
        onBack: this.onCancelPress,
        renderRightButton: this.renderRightNavBarButton,
      });
    }, 1000);
  }

The title actually does change after 1 second but the rightButton is unchanged. It seems like refresh simply ignores all props that contain style or components. But I can't see anything that appears to filter it out in the source code...

could you solve it?