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

Q:Adding button to navbar #2256

Closed
Paul-Todd opened this issue Aug 17, 2017 · 2 comments
Closed

Q:Adding button to navbar #2256

Paul-Todd opened this issue Aug 17, 2017 · 2 comments

Comments

@Paul-Todd
Copy link

I would like to know why the code to add a button to the navbar (in V4) is considered an antipattern?

    componentDidMount() {
        Actions.refresh({
            right: () => <TouchableOpacity onPress={this._add}><Text>{"Add"}</Text></TouchableOpacity>
        });
    }

To me it seems the simplest way to add a button that has a closure to the object into the navbar or am I missing something?

@Paul-Todd Paul-Todd changed the title Adding button to navbar Q:Adding button to navbar Aug 17, 2017
@Stophface
Copy link

Stophface commented Aug 17, 2017

I do it that way and do not get any complaints

<Router>
    <Scene key = "root">
          <Scene 
            key = "index"
            component = {one}
            title = "Whatever"
            navigationBarStyle = {styles.header}
            titleStyle = {styles.text}
            onRight={() => alert("hello")}
            rightTitle = {SomeIconComponent} 
            initial
            />
   </Scene>
</Router>

@aksonov
Copy link
Owner

aksonov commented Aug 17, 2017

@Paul-Todd It is anti-pattern because you are doing unnecessary 'refresh' (i.e. changing of nav state) when it is not needed. You may try new feature of beta.18 - using Actions.refs.SCENE_NAME to refer to component instance (PR about new docs is welcome).

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

No branches or pull requests

3 participants