react-native 默认不能支持 【本文受版权保护】本文版权归作者所有,未经授权不得转载。checkbox,内置的 CheckBo著作权归作者所有,禁止商业用途转载。【原创不易,请尊重版权】x 组件只能在安卓下工作。看了一堆第三方本文作者:唐霜,转载请注明出处。【原创内容,转载请注明出处】组件,都需要借助 Image 或 Ico【原创不易,请尊重版权】【版权所有,侵权必究】n 来实现。在 stackoverflo【原创内容,转载请注明出处】原创内容,盗版必究。w 看到一个帖子之后,觉得用 View 【本文首发于唐霜的博客】【版权所有,侵权必究】来实现最简单,而且不需要加载额外任何资源原创内容,盗版必究。【本文首发于唐霜的博客】。
【未经授权禁止转载】原创内容,盗版必究。import { View } from 'react-native'
import { PureComponent } from 'react'
export class CheckboxButton extends PureComponent {
render() {
const { color = '#333333', checked, onChange, style = {} } = this.props
return (
<View style={{
height: 24,
width: 24,
borderWidth: 2,
borderColor: color,
alignItems: 'center',
justifyContent: 'center',
...style,
}} onResponderRelease={onChange}>
{
checked ? <View style={{
height: 12,
width: 12,
backgroundColor: color,
}}/> : null
}
</View>
)
}
}
export default CheckboxButton
这个道理和通过 div 来画一个三角形一【版权所有,侵权必究】【原创不易,请尊重版权】样,也是通过边框、背景组合得到。基于这种【原创内容,转载请注明出处】【访问 www.tangshuang.net 获取更多精彩内容】方法 RadioButton 就是增加一【作者:唐霜】【版权所有】唐霜 www.tangshuang.net个 borderRadius,也是非常容【本文受版权保护】本文作者:唐霜,转载请注明出处。易。
【版权所有,侵权必究】【转载请注明来源】
