在选择器水龙头上启用/禁用页眉按钮

时间:2018-08-14 05:01:57

标签: react-native

我是本机反应的新手。我在标题中使用了一个按钮,在项目中使用了一个选择器。最初,我已通过按钮禁用了,但是我希望它在点击“选择器”时启用。下面是我的代码。

static navigationOptions = ({ navigation }) => ({
    headerRight: (
      <View 
        <Button
          disabled = {true}
          title="Save"

        />
      </View>
    )
  });

render(){
return(
  <Picker
    selectedValue={this.state.changedVal}
    style={{ height: 50, width: 100 }}
    onValueChange={(itemValue, itemIndex) => this.pickerActivity(itemValue)}>
    <Picker.Item label="Java" value="java" />
    <Picker.Item label="JavaScript" value="js" />
  </Picker>
  )
}

1 个答案:

答案 0 :(得分:1)

您可以在此处使用导航参数,例如标题管理:https://reactnavigation.org/docs/en/headers.html#using-params-in-the-title

static navigationOptions = ({ navigation }) => ({
    headerRight: (
      <View 
        <Button
          disabled = {navigation.getParams('isButtonDisable', true)}
          title="Save"

        />
      </View>
    )
  });

pickerActivity = (itemValue, itemIndex) => {
    if(itemValue === 'js') {
        this.props.navigation.setParams('isButtonDisable', false);
    } else {
        this.props.navigation.setParams('isButtonDisable', true);
    }
}

render(){
return(
  <Picker
    selectedValue={this.state.changedVal}
    style={{ height: 50, width: 100 }}
    onValueChange={this.pickerActivity}>
    <Picker.Item label="Java" value="java" />
    <Picker.Item label="JavaScript" value="js" />
  </Picker>
  )
}