我根据给出的示例编写了一个自定义右导航按钮
here
onNavigatorEvent()
方法在使用自定义组件时不再被调用。我甚至尝试将onPress事件作为道具传递给我的自定义组件,但这是通过
undefined
. 我有什么遗漏吗?
这是我将onPress道具传递给创建按钮的函数的方式:
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');
}