如何实现react-native中的复选框,它支持Flatlist中的ios和android

问题描述 投票:1回答:2

官方网站上的复选框(https://facebook.github.io/react-native/docs/checkbox)仅支持Android。

我们如何在react-native中实现复选框,这可以在iOS和Android中得到支持?

react-native react-native-android react-native-ios react-native-flatlist
2个回答
0
投票

您可以尝试使用NativeBase(<CheckBox />)的https://docs.nativebase.io/Components.html#checkbox-headref组件,它应该可以在两个平台上运行。

例:

 <CheckBox 
    checked={this.state.checked}
    onPress={()=>this.setState({ checked: !this.state.checked})}
  />

-1
投票

如果您正在寻找一种纯粹在React Native中呈现布尔值的方法,您可以尝试使用switch,如下所示:

<Switch value={item.selected} onValueChange={selected => this.setState({selected })/>

一个开关呈现如下:enter image description here

否则,如果您正在寻找一个复选框,您可以尝试使用React Native Elements库。像这样:

import { CheckBox } from 'react-native-elements'

<CheckBox
  title='Click Here'
  checked={this.state.checked}
/>
© www.soinside.com 2019 - 2024. All rights reserved.