jeudi 24 septembre 2020

React native elements checkbox selecting multiple items

So I am working on a project where I am using react native elements checkbox and I finally got it working where it does not select all of the fetched items at one. It only selects one time at a time, and if I try to select another item it will unselect the first item and select the second. But now it will not allow me to select multiple items at once. I have searched google, on this platform, and also reddit and I can not find any solutions.

Here is my code

constructor(props) {
        super(props);
        this.state = {
            dataSource: [],
            checked: null,
        }
    }

    render() {

        const  { navigation } = this.props;
        const cust = navigation.getParam('food', 'No-User');
        const other_param = navigation.getParam('otherParam', 'No-User');
        const cust1 = JSON.parse(cust);
    
        const data = cust1;
        console.log(data);

        return (
            <View style={styles.container}>
                <BackButtonMGMT navigation={this.props.navigation} />

                <FlatList
                    data={data}
                    extraData={this.state}
                    keyExtractor={(item, index) => index.toString()}
                    renderItem={({ item, index }) => (
                        <CheckBox
                        center 
                        titleProps=
                        title={item}
                        iconRight
                        checked={this.state.checked == item}
                        size={30}
                        onPress={() => this.setState({checked: item})}
                        containerStyle={styles.checkBox}
                        />
                        
                    )}
                />

            </View>
        )
    }

I have tried to change the checked line within the CheckBox. I have tried to checked={!!item.checked} and it does not work. I have tried checked={!this.state.checked} and this does not work either. Has anyone came across this problem, and if so how did you solve this?




Aucun commentaire:

Enregistrer un commentaire