I have written a custom right navigation button by following the example given here. However, it seems like the onNavigatorEvent()
method does not get called anymore when using a custom component. I even tried passing the onPress event as a prop to my custom component but that comes through as undefined
. Is there something I am missing?
This is how I am passing the onPress prop to the function that's creating the button:
Navigation.registerComponent('DoneButton', () => DoneButton);
const DoneButton = ({text, backgroundColor, textColor, onPressAction}) => {
var containerStyle = [{backgroundColor: backgroundColor, width: 70, height:30, justifyContent:'center', borderRadius:4, shadowColor:'black', shadowOpacity:0.2, shadowRadius:1, shadowOffset:{width:0, height:2}}];
return(
<TouchableOpacity style={containerStyle} onPress={onPressAction}>
<Text style={[{color:textColor, textAlign: 'center', fontSize:16}]}>
{text}
</Text>
</TouchableOpacity>
);
}
_renderDoneButton(){
this.props.navigator.setButtons({
rightButtons: [
{
id: 'Done'
component: 'DoneButton',
passProps: this._DoneButtonProps(),
}],
})
}
_DoneButtonProps(){
return {
text: 'Done',
backgroundColor: 'green',
textColor: 'white',
onPressAction: this._doneAction.bind(this)
}
}
_doneAction(){
alert('Done');
}
Since version 1.1.282 you can pass unserializable props to custom buttons, so the onPress method which you are passing should work.