[英]React-Native - How to create a disabled style for the TouchableOpacity component?
如何為 TouchableOpacity 組件應用禁用樣式?
<TouchableOpacity
style={styles.buttonWrapper }
onPress={this.userLogin.bind(this)}
disabled={ !this.state.username || !this.state.password }
>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
最簡單的方法是使用與禁用道具相同的條件。
這樣的事情應該工作:
style={!this.state.username || !this.state.password ? styles.disabled : styles.buttonWrapper}
在React-Native
或React
為元素設置禁用樣式的最佳方法是這樣的:
style={
(!this.state.username || !this.state.password)
? {...styles.buttonWrapper, ...styles.buttonDisabled}
: styles.buttonWrapper
}
見實戰: codeandbox
用這個例子,你不需要有你只需要定義殘疾風格像按鈕重復的樣式backgroundColor
或color
為禁用的按鈕styles.buttonDisabled
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.