Created
February 12, 2020 13:42
-
-
Save sant0will/8d71158b52f597b21292c7bbc5b702d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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