-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
guide on dynamic title, leftButton and rightButton? #3089
Comments
@aksonov - any comment on this? |
Please try to reproduce it with Example project and latest version 4.0.0-beta.40. Feel free to open if the issue still exists |
@compojoom Did you ever determine answers to this? |
I gave up and switched to directly using react navigation, but most probably something similar like this https://reactnavigation.org/docs/en/header-buttons.html#header-interaction-with-its-screen-component |
Interesting, how direct react navigation helped you to implement dynamic buttons? The same static header methods could be used with RNRF as well..
… On 13 Oct 2018, at 06:36, Daniel Dimitrov ***@***.***> wrote:
I gave up and switched to directly using react navigation.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I've been using RNRF for the past year, but up until this day I don't know if what I'm doing is correct or not. I hope that other users who have been through this could share some guidance on how they are managing dynamic properties on the navbar.
In most apps you don't have a static title. The title changes to whatever the user is looking at.
let's imagine the following case.
A list with articles, a click on the title shows you the article (and the navbar shows the title of the article in question).
You would have 2 scenes:
When you do Actions.article() and the user navigates to the article component he would see "Article" for title. We have the Actions.refresh() function and we can call it when we navigate to the Article component. The question is - where do you do this? onEnter? Unfortunately onEnter is static and it doesn't have access to any of the component's params or functions. If we do this in ComponentDidMount, then we manage to change the title, but the user sees "Article" and a second later "Dummy article title"
We could do Actions.article({title: "my title"}) and this would actually change the title in advance, but is this the supposed way to do this? Is the previous component supposed to know what the title of the navbar for the next component in the stack is?
What do we do with the buttons of the navbar? If you have an onRight function that is supposed to call a method of the component?
If you want to display a save button, then you need to provide the rightTitle and onRight properties on the scene. in my case onRight is calling the save method of the component, but when I define the scene I can't access a this.save(), so I do this:
<Scene rightTitle="Save" onRight={() => {}} ... />
when the user navigates to this screen - he would see a save button - if he immediately clicks it - nothing will happen and after few miliseconds/second the onRight would change in response to Actions.refresh({onRight: {} => this.save()})
With this approach however I've run into a lot of
errors... If one is not carefull enough and updates the navbar in componentWillReceive props with Actions.refresh, one often runs in to the maximum update depth problem.
Because of all that I created my own Navbar component and I render it myself in every component. The render function of my fictional Article component would look like:
I don't like the fact that I have to render the Navbar in every scene, but this way it seems that I spare myself a lot of troubles with componentWillUpdate, refreshes etc.
How is everyone else solving this issue? Neither the provided example, not the API reference and docs answer this. Can anyone shed some light on this?
The text was updated successfully, but these errors were encountered: