Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style React Native <CheckBox> component?

Is it possible to style the React Native CheckBox component?

There is no style property listed here: https://facebook.github.io/react-native/docs/checkbox.html

I put an invalid style property on it, and the RN warning message that popped up told me all the valid CSS properties, but none of them did anything beneficial towards styling.

The component looks decent, but I want to change it from that teal color to a brand color.

Is it possible?

These properties are not working but are listed as valid style props for CheckBox:

{
  height: 50,             // changes the hitspace but not the checkbox itself
  width: 50,
  borderWidth: 1,         // does nothing
  backgroundColor: 'red', // makes the area around and inside the checkbox red
  borderColor: 'green',   // does nothing
  borderStyle: 'dotted'   // does nothing
}

I don't understand why it even exists if everyone just makes their own checkbox. If I did that, I wouldn't really have any use for because all it gives is

value={this.state.rememberMe}
onValueChange={() => this.toggleRememberMe()}

unless there is something magic it does under the hood. It has a decent onChange animation, but that would be deprecated instantly when I make my own and use something like <TouchableHighlight or Opacity> wrapped around an on/off image or <View>.

I can't find any info on Google except hundreds of custom checkboxes. It's actually really hard to search around them.

like image 987
agm1984 Avatar asked Oct 09 '17 02:10

agm1984


People also ask

How do I change the color of a checkbox in React Native?

To customize the color of a checkbox in React Material UI, we can set the style prop to an object with the color we want. We set the style prop of the Checkbox to an object with the color of the checkbox. Next, we set the label color by setting the style prop to an object with the color of the label.

How do you style a component in React Native?

With React Native, you style your application using JavaScript. All of the core components accept a prop named style . The style names and values usually match how CSS works on the web, except names are written using camel casing, e.g. backgroundColor rather than background-color .

How do I manage checkboxes in React Native?

The core react-native package does not have checkbox support and you need to install a package to work with it. The value that can be given to status are checked, unchecked and indeterminate. The value is boolean.It can be used to enable/disable the checkbox.


2 Answers

Transform can be used to change CheckBox size.

<CheckBox
  style={{ transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }] }}
/>

checkbox examples

https://github.com/react-native-checkbox/react-native-checkbox

like image 137
dooffy Avatar answered Sep 30 '22 03:09

dooffy


You can use https://github.com/react-native-community/react-native-checkbox

Android: you can use tintColors.

 import CheckBox from '@react-native-community/checkbox';
 .
 .
 .
 <CheckBox
      value={option.item.selected}  
      onValueChange={() => {}}
      tintColors={{ true: '#F15927', false: 'black' }}
 />
like image 36
Jaichand Khatik Avatar answered Sep 30 '22 02:09

Jaichand Khatik