有没有实现react native复选框的简单示例?Facebook没有提供任何例子.我提到的复选框组件可以在这里的文档中找到:http://facebook.github.io/react-native/docs/checkbox.html

推荐答案

目前,复选框组件仅在Android上受支持,如here所述.您应该使用iOS的交换机组件.

对于Android来说,使用非常简单:

<View style={{ flexDirection: 'column'}}>
  <CheckBox />
  <View style={{ flexDirection: 'row' }}>
    <CheckBox
      value={this.state.checked}
      onValueChange={() => this.setState({ checked: !this.state.checked })}
    />
    <Text style={{marginTop: 5}}> this is checkbox</Text>
  </View>
</View>

视图和文本组件是可选的,只是为了显示复选框如何与这些组件一起使用.

Screenshot of the above code

以上代码在iOS设备上的显示方式如下:

enter image description here

React-native相关问答推荐

添加REACT-Native-SVG时出现错误-失败:构建失败并出现异常

在我的 React Native 应用程序中获取数据返回 [object Object] 而不是 renderSectionHeader

React Native 映射未定义不是函数

导出命名空间应首先由 `@babel/plugin-proposal-export-namespace-from` 转换

Error: Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component stack

React native flexbox - 如何做 percentages || columns || responsive || grid etc

如何为我的 React Native Android 应用程序使用 Crashlytics?

如何在 mac 上卸载 react-native-cli?

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

React native base headers for ios not found

如何使用 Typescript 在无状态组件上设置 navigationOptions

react-native fetch 和基本身份验证

使用 expo SDK react-native ios 应用程序的 Info.plist 文件

在 FlatList 上使用 React Native 搜索过滤器

如何在react-native中绘制虚线边框样式

Gradlew bundleRelease 不会在 react-native 中生成发布 apk

react-native:0.41 app.json

如何将 jest 测试移动到 /test 文件夹并让它们运行?

如何从 react-native-fbsdk 获取用户信息(邮箱、姓名等)?

Flatlist getItemLayout 用例