hereの例に従って、カスタムの右ナビゲーションボタンを作成しました。しかし、カスタムコンポーネントを使用するとonNavigatorEvent()
メソッドがもう呼び出されないようです。私はカスタムコンポーネントに小道具としてonPressイベントを渡そうとしましたが、それはundefined
として届きます。私が紛失しているものはありますか?Wixリアクションネイティブナビゲーション:カスタムコンポーネントボタンのonPress
これは私がボタンを作成しています関数にた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');
}
こんにちは、いくつかのコードを共有することはできますか?登録、 'function'それ自体 – gran33
@ gran33もう一度コードを追加してください。 – pnizzle
@ gran33更新されたコードを更新して見てください。 – pnizzle