自己写一个 react-native 的 checkbox

广告位招租
扫码页面底部二维码联系

react-native 默认不能支持 未经授权,禁止复制转载。【访问 www.tangshuang.net 获取更多精彩内容】checkbox,内置的 CheckBo【未经授权禁止转载】【访问 www.tangshuang.net 获取更多精彩内容】x 组件只能在安卓下工作。看了一堆第三方【转载请注明来源】【本文受版权保护】组件,都需要借助 Image 或 Ico著作权归作者所有,禁止商业用途转载。原创内容,盗版必究。n 来实现。在 stackoverflo转载请注明出处:www.tangshuang.net本文版权归作者所有,未经授权不得转载。w 看到一个帖子之后,觉得用 View 原创内容,盗版必究。【本文首发于唐霜的博客】来实现最简单,而且不需要加载额外任何资源原创内容,盗版必究。【版权所有,侵权必究】

【版权所有】唐霜 www.tangshuang.net转载请注明出处:www.tangshuang.net
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 就是增加一原创内容,盗版必究。著作权归作者所有,禁止商业用途转载。个 borderRadius,也是非常容【转载请注明来源】【本文首发于唐霜的博客】易。

【作者:唐霜】【关注微信公众号:wwwtangshuangnet】