gpt4 book ai didi

javascript - 在 native react 中隐藏按钮

转载 作者:行者123 更新时间:2023-12-03 01:11:47 26 4
gpt4 key购买 nike

我想隐藏“注册”,并且使用了 TouchableOpacitydisable 属性,但它似乎不起作用

 const isInvalid = 
passwordOne !== passwordTwo ||
passwordOne === "" ||
email === "" ||
username === "";

<TouchableOpacity style={styles.button} disabled={isInvalid}>
<Text style={styles.buttonText} onPress={this.handleSignUp}>
Sign up
</Text>
</TouchableOpacity>

但是“注册”按钮并未隐藏

enter image description here

我的代码:

import ....

const INITIAL_STATE = {
...
};

export default class Signup extends Component<{}> {

handleSignUp = () => {
...
};

render() {

const isInvalid =
passwordOne !== passwordTwo ||
passwordOne === "" ||
email === "" ||
username === "";
return (
<View style={styles.container}>

<TextInput .../>
<TextInput .../>
<TextInput ... />
<TextInput ... />

<TouchableOpacity style={styles.button} disabled={isInvalid}>
<Text style={styles.buttonText} onPress={this.handleSignUp}>
Sign up
</Text>
</TouchableOpacity>


</View>
);
}
}

const styles = StyleSheet.create({

});

最佳答案

使用显示“none”,如下所示:

const isInvalid = 
passwordOne !== passwordTwo ||
passwordOne === "" ||
email === "" ||
username === "";

const display = isInvalid ? "none" : "flex";

<TouchableOpacity style={[styles.button, {display}]}> // Put display value here
<Text style={styles.buttonText} onPress={this.handleSignUp}>
Sign up
</Text>
</TouchableOpacity>

关于javascript - 在 native react 中隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52185605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com