Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions.refresh renderRightButton has no effect #3218

Closed
jamesholcomb opened this issue Aug 27, 2018 · 6 comments
Closed

Actions.refresh renderRightButton has no effect #3218

jamesholcomb opened this issue Aug 27, 2018 · 6 comments
Assignees
Labels

Comments

@jamesholcomb
Copy link

jamesholcomb commented Aug 27, 2018

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.1 (v3 is not supported)
  • react-native v0.56.0

Expected behaviour

The navbar refreshes with the new right button component

Actual behaviour

No effect

Steps to reproduce

For non-obvious bugs, please fork this component, modify Example project to reproduce your issue and include link here.

  static onEnter = () => {
    const { wrappedInstance } = Actions.refs.profile

    // this works
    Actions.refresh({
      rightTitle: "Logout",
      onRight: wrappedInstance.onLogout
    })

   // this has no effect
   Actions.refresh({
      renderRightButton: () => <MoreButton onPress={() => alert('hi')} />
   })
  }
@jamesholcomb
Copy link
Author

Here is how I worked around it

        <Scene
          back
          key={routes.PROFILE}
          component={ProfileScene}
          renderRightButton={
            <MoreButton
              onPress={() => Actions.refs.profile.wrappedInstance.onMorePress()}
            />
          }
          title="Profile"
        />

@daviscabral
Copy link
Collaborator

Thank you for the update about the workaround. This seems to be sort of a duplicate of #3188. I'll keep it marked as bug and work on both in the same PR.

@aksonov
Copy link
Owner

aksonov commented Sep 5, 2018

@jamesholcomb It looks like a hack and probably just not supported by React Navigation 2.x (its SET_PARAMS action). Instead you should define one renderRightButton that changes its content depending from navigation state. Actions.refresh should be used just to update navigational state (i.e. pass values not functions)

@aksonov aksonov closed this as completed Sep 5, 2018
@jamesholcomb
Copy link
Author

Actions.refresh should be used just to update navigational state (i.e. pass values not functions)

I am attempting to upgrade a 3.X project to 4.0. Actions.refresh is used throughout the app to wire up navbar buttons to their scene handlers based on data/conditions that are determined within the scene.

The example does not seem to demonstrate how to go about this and the migration guide does not mention it.

Can you elaborate or point to an example?

@avivajohnson
Copy link

Actions.refresh is used throughout the app to wire up navbar buttons to their scene handlers based on data/conditions that are determined within the scene.

I would also be interested in seeing an example of how to accomplish this with 4.0.

@waqas19921
Copy link

waqas19921 commented Dec 26, 2019

For react-navigation version 3.X use following example May be it also works with 4.x

class Companies extends Component {

    componentDidMount(){
        Actions.refresh({
          right: () => (
              <MaterialIcons
                name={'mail'}
                size={48}
                color={'black'} />
          )
        })
     } 

    render(){
      ...
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants