激活和停用文本输入

activate and deactivate textInput

Whosebug 我正在尝试创建一个按钮来将布尔值从 true 更改为 false,反之亦然,以便更改 textInput 中的可编辑值。 这是我到现在为止的进展:

  const [change, setChange] = useState(true);
  const [text, setText] = useState("");

  const textEdit = () => {
    change === true ? setChange(false) : setChange(true);

  };

出于某种原因,在达到 TouchableOpacity 以下后,它不会更改状态,或者我的代码中一定存在问题,阻止反应更改以下文本输入中的“更改”状态


        <TextInput
          style={{ width: "100%", height: 100, backgroundColor: "gray" }}
          placeholder={"write something"}
          onChangeText={(text) => setText(text)}
          editable={change}
        >
          <Text>adderess</Text>
        </TextInput>


        <TouchableOpacity
          onPress={() => {
            textEdit;
          }}
        >
          <Text style={{ color: "blue" }}>Change</Text>
        </TouchableOpacity>

因为您不会在按下时调用函数 textEdit。像这样更新:

onPress={() => {
  textEdit();
}}

或清洁工:

onPress={textEdit}