Select a Native-Base ListItem

1

I currently use native-base for my application

I have a ListItem that lists the dummy entries and would like to keep the item pressed that the id is saved as true in an array. Someone who can give me a light on how to proceed?

state = {
    selected: [] ,
};

onPressAction = (key = int) => {
    if (this.state.selected.indexOf(key) < 0) {
        tmpSelected = this.state.selected
        tmpSelected.push(key)
        tmpSelected[key] = true;

        this.setState({
            selected: tmpSelected,
        })
        console.log('add '+key);
    }
    else {
        var tmpSelected = this.state.selected.slice()
        tmpSelected.splice(key, 1);

        this.setState({
            selected: tmpSelected
        })
        console.log('remove '+key);
    }
    console.log(tmpSelected);
};

<ListItem
     key={data.id}
     onPress={() => this.onPressAction(data.id)}
     selected={this.state.selected[data.id] ? false : true}
     avatar
>
    <Left>
        <Thumbnail source={{ uri: 'https://en.facebookbrand.com/wp-content/uploads/2016/05/FB-fLogo-Blue-broadcast-2.png' }} />
    </Left>
    <Body>
        <Text>{data.sitename}</Text>
        <Text note>{data.url}</Text>
    </Body>
    <Right>
        <Text note>View</Text>
    </Right>
</ListItem>
    
asked by anonymous 02.02.2018 / 12:28

0 answers