React-native-router-flux: Q:Adding button to navbar

Created on 17 Aug 2017  路  2Comments  路  Source: aksonov/react-native-router-flux

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?

Most helpful comment

@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).

All 2 comments

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>

@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).

Was this page helpful?
0 / 5 - 0 ratings