Skip to content

Instantly share code, notes, and snippets.

@tallenh
Created October 28, 2017 20:12
Show Gist options
  • Save tallenh/dfebf73859cca956bf8d6f31ccc4bf7c to your computer and use it in GitHub Desktop.
Save tallenh/dfebf73859cca956bf8d6f31ccc4bf7c to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {CheckBox, FlatList, StyleSheet, Text, View} from 'react-native';
import Swipeable from 'react-native-gesture-handler/Swipeable'
import {RectButton} from "react-native-gesture-handler";
const initialItems = [
{id: 1, name:'item1'},
{id: 2, name:'item2'},
{id: 3, name:'item3'},
{id: 4, name:'item4'},
{id: 5, name:'item5'},
];
export default class App extends Component {
state = {items: initialItems};
_remove = (id) => {
let index = this.state.items.findIndex((item) => item.id === id);
let items = [...this.state.items.slice(0,index), ...this.state.items.slice(index + 1)];
this.setState({items})
};
_renderLeftActions = () => {
return (
<RectButton style={styles.leftAction} />
);
};
_renderItem = ({ item }) => (
<Swipeable leftThreshold={50}
renderLeftActions={this._renderLeftActions}
onSwipeableLeftOpen={() => this._remove(item.id)}>
<View style={{backgroundColor: 'white', flexDirection: 'row', alignItems: 'stretch'}}>
<CheckBox onChange={() => this._remove(item.id)}/>
<Text style={{flex: 1}}>{item.name}</Text>
</View>
</Swipeable>
);
_keyExtractor = (item) => item.id;
render() {
return (
<View style={{flex: 1, flexDirection:'column'}}>
<FlatList data={this.state.items}
renderItem={this._renderItem}
keyExtractor={this._keyExtractor}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
leftAction: {
flex: 1,
backgroundColor: '#388e3c',
justifyContent: 'center',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment