代码之家  ›  专栏  ›  技术社区  ›  pnizzle

Wix React本机导航:按下自定义组件按钮

  •  2
  • pnizzle  · 技术社区  · 7 年前

    我根据给出的示例编写了一个自定义右导航按钮 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');
    }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   guy.gc    7 年前

    由于版本1.1.282,您可以将不可分割的道具传递给自定义按钮,因此您正在传递的onPress方法应该可以工作。