如何为TouchableOpacity组件应用禁用样式?

<TouchableOpacity 
  style={styles.buttonWrapper } 
  onPress={this.userLogin.bind(this)}
  disabled={ !this.state.username || !this.state.password }
>
  <Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>

推荐答案

最简单的方法是使用与禁用props 相同的条件.

像这样的方法应该有用:

style={!this.state.username || !this.state.password ? styles.disabled : styles.buttonWrapper}

React-native相关问答推荐

如何在堆栈的任何屏幕的后退按钮按下时始终导航到堆栈的初始路径?

React-native 重置数据库

如何在react-native 中处理不同的屏幕尺寸?

Firebase JavaScript SDK 和 react-native-firebase 有什么区别

React-Native:显示加载屏幕直到加载 webview

Undefined 不是判断 this.state.* 的对象

react-native 从右到左

react native如何访问文件系统?

react-native fetch 和基本身份验证

如何在 React Native 上获取设备的 ip?

React Native require(image) 返回数字

如何在 Text 中围绕 Text 包裹 TouchableOpacity?

无法识别的 WebSocket 连接选项 `agent`、`perMessageDeflate`、`pfx`、`key`、`passphrase`... 你的意思是把这些放在 `headers` 下吗?

React Native 无法运行堆栈跟踪

React Native 得到这个错误'Unrecognized operator abs'

在 webview 中检测touch 是 Apple Pencil 还是手指(react-native)

您将如何在 Alert 中模拟onPress?

如何在react-native中显示toast消息

在 React-native 上加载图像时出错:Unexpected character

react-native构建错误:package android.support.annotation does not exist