import React , {Component} from 'react' import { Text, View, ListView, StyleSheet, TouchableOpacity, Image, } from 'react-native' import CheckBox from 'react-native-checkbox' var Folder = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) var folder = '' ////// all the new folder var check_folder = [] ////// all the check box conditions class ApproveContent extends Component { ///////// all the upper thing that are global variable for this script is has same value as that of the state the only reason we are using this because of the layout update ////////// state={ folder:[], data:[], check:[]/////// this need to do just to upadte the layout of the check box } render(){ return( <View style = {{flex:1,backgroundColor:'white',alignItems:'center'}}> <ListView dataSource={Folder.cloneWithRows(this.state.folder)} renderRow={(rowData,rowID,sectionID) => <View style = {{ alignItems: 'center',margin:5}}> <TouchableOpacity style = {{width:Dimension.ScreenWidth/1.2,height:Dimension.ScreenHeight/6,flexDirection: 'row',alignItems:'center'}} onPress={() => {}}> <CheckBox label='' labelBefore={false} checked={this.state.check[sectionID]} checkboxStyle = {{marginLeft: 20}} onChange={(checked) => { this.setState({ check:!this.state.check }) if(check_folder[sectionID] == false){ check_folder[sectionID] = true this.setState({ check:check_folder// has to do this because we cant change the single element in the array }) }else{ check_folder[sectionID] = false this.setState({ check:check_folder// has to do this because we cant change the single element in the array }) } console.log(check_folder)a }} /> </TouchableOpacity> </View> } /> </View> )} } export default ApproveContent const style = StyleSheet.create({ TextStyle:{ fontFamily: 'Roboto-Bold', fontSize:15, }, approveButton: { bottom:0, left:0, alignItems: 'center', } })
source share