Skip to content

Instantly share code, notes, and snippets.

@lucianomlima
Created April 21, 2017 04:12
Show Gist options
  • Save lucianomlima/6eb3f195bc8ebe64fcdaa7d171b76700 to your computer and use it in GitHub Desktop.
Save lucianomlima/6eb3f195bc8ebe64fcdaa7d171b76700 to your computer and use it in GitHub Desktop.
export default class MainScreen extends React.Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.id !== r2.id});
this.state = {
list: [],
dataSource: this.ds.cloneWithRows([]),
check: {},
checkAll: false,
};
}
static navigationOptions = {
title: 'Main',
headerVisible: false
};
_checkAll = () => {
const { checkAll, list, check } = this.state;
const callback = () => {
console.log("checkAll", checkAll);
console.log("students", list);
list.map(student => {
check[student.name] = !check[student.name];
this.setState({check});
});
}
this.setState({checkAll: !this.state.checkAll}, callback);
}
_checkStudent = (student) => {
const { check } = this.state;
check[check.name].check = !check[check.name].check;
this.setState({check});
}
render() {
// const { navigate } = this.props.navigation;
const { check, checkAll, dataSource } = this.state;
return (
<Image source={require('./../images/background_no_logo.png')} style={styles.container}>
<CheckBox
style={{padding: 10}}
onClick={() => this.checkAll()}
isChecked={checkAll}
rightText={this.text.checkText}
/>
<ListView
style={styles.listView}
dataSource={dataSource}
enableEmptySections={true}
renderRow={(student) => {
return (
<View style={styles.row}>
<CheckBox
style={{paddingLeft: 10, paddingRight:10}}
onClick={() => this._checkStudent(check[student.name])}
isChecked={check[student.name].checked}
/>
<Text style={{color:'#336463', fontSize:20, flex: 1}}>
{`${student.name}`}
</Text>
</View>
)
}}
/>
</Image>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment