Skip to content

Instantly share code, notes, and snippets.

@sant0will
Created February 12, 2020 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sant0will/8d71158b52f597b21292c7bbc5b702d6 to your computer and use it in GitHub Desktop.
Save sant0will/8d71158b52f597b21292c7bbc5b702d6 to your computer and use it in GitHub Desktop.
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import CheckBox from '@react-native-community/checkbox';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
checkboxes: [
{
id: 1,
title: 'UE/HQB',
checked: false,
},
{
id: 2,
title: 'Exportável',
checked: false,
},
{
id: 3,
title: 'Não exportável',
checked: false,
},
],
};
}
toggleCheckbox(id) {
let array_checkboxes = this.state.checkboxes;
array_checkboxes.map(cb => {
if (cb.id === id) {
cb.checked = !cb.checked;
}
});
this.setState({
checkboxes: array_checkboxes,
});
}
render() {
return (
<View style={styles.container}>
{this.state.checkboxes.map((cb, index) => (
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start' }}>
<CheckBox
value={cb.checked}
onChange={() => this.toggleCheckbox(cb.id)}
/>
<Text>{cb.title}</Text>
</View>
))}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment