Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable react-native-element's checkbox touchable opacity?

Actually, I am using react-native-element design language. When I used to implement checkbox than it behave like touchable opacity that I dont want.

<CheckBox
  containerStyle={{ backgroundColor: "transparent", borderWidth: 0 }}
  center
  size={14}
  title="vegetarian"
  textStyle={{
    fontSize: theme.FONT_SIZE_X_SMALL,
    fontWeight: theme.FONT_WEIGHT_LIGHT
  }}
  checkedColor="red"
  checked={this.state.checked}
  onPress={() => this.setState({ checked: !this.state.checked })}
/>;

like image 697
Muhammad Sulman Avatar asked Oct 16 '25 19:10

Muhammad Sulman


2 Answers

You can pass a Component prop (which is TouchableOpacity by default), with TouchableWithoutFeedback for instance as value.

<CheckBox
  Component={TouchableWithoutFeedback}
  containerStyle={{ backgroundColor: "transparent", borderWidth: 0 }}
  center
  size={14}
  title="vegetarian"
  textStyle={{
    fontSize: theme.FONT_SIZE_X_SMALL,
    fontWeight: theme.FONT_WEIGHT_LIGHT
  }}
  checkedColor="red"
  checked={this.state.checked}
  onPress={() => this.setState({ checked: !this.state.checked })}
/>;
like image 110
colinux Avatar answered Oct 19 '25 09:10

colinux


we can do it by anotherway activeOpacity={1} as prop like below.

<CheckBox
  activeOpacity={1}
  containerStyle={{ backgroundColor: "transparent", borderWidth: 0 }}
  center
  size={14}
  title="vegetarian"
  textStyle={{
    fontSize: theme.FONT_SIZE_X_SMALL,
    fontWeight: theme.FONT_WEIGHT_LIGHT
  }}
  checkedColor="red"
  checked={this.state.checked}
  onPress={() => this.setState({ checked: !this.state.checked })}
/>
like image 35
Muhammad Sulman Avatar answered Oct 19 '25 10:10

Muhammad Sulman