You need call
your function dispatch
in headerRight
and set when your component
is equal mounted
usingthis.props.navigation.setParams
import React from 'react'
import {
StackNavigator
} from 'react-navigation'
import Home from './Home'
import Detail from './Detail'
import MyIcon from './MyIcon'
export default StackNavigator({
Home: {
screen: Home,
navigationOptions: ({ navigation }) => {
title: 'Foo',
headerRight: (<MyIcon
onPress={ () => navigation.state.params.dispatch() } />)
// calling dispatch when headerRight icon is press
}
},
Detail: {
screen: Detail,
navigationOptions: {},
},
})
Define a dispatch
function in your component
...
componentDidMount() {
this.props.navigation.setParams({
dispatch: this.dispatch.bind(this)
});
}
dispatch() {
}
Hope this helps!
source
share