react-native-swipeable icon indicating copy to clipboard operation
react-native-swipeable copied to clipboard

How to close currentSwiper when onPress button

Open phuongdevapp opened this issue 8 years ago • 4 comments

hi all I want to close curent swiper when i onPress button on Item FlatList

phuongdevapp avatar Dec 08 '17 10:12 phuongdevapp

i want to close all open swiper when new swiper is open

ShaileshPrajapati-BTC avatar Dec 15 '17 13:12 ShaileshPrajapati-BTC

`Solution for you both (phuongdevapp & Shailesh), Please follow this; Step 1. .... constructor(props) { super(props); this.state = { currentlyOpenSwipeable: null, } } ... Step 2. ... const rightButtons = [ <TouchableHighlight onPress={() => this.state.currentlyOpenSwipeable.recenter()}><Text>Close</Text> </TouchableHighlight>, <TouchableHighlight onPress={() => yourCustomMethod()}><Text>Another Button</Text></TouchableHighlight> ];

Step 3. ... <Swipeable onRef = {ref => this.swipe = ref} onRightButtonsOpenRelease = { (event, gestureState, swipe) => { if (this.state.currentlyOpenSwipeable && this.state.currentlyOpenSwipeable !== swipe) { this.state.currentlyOpenSwipeable.recenter(); } this.setState({ currentlyOpenSwipeable: swipe }); } } onRightButtonsCloseRelease = {() => this.setState({ currentlyOpenSwipeable: null }) } rightButtons={rightButtons}> [ADD YOUR LIST HERE] </Swipeable> ....`

kapsona avatar Dec 23 '17 09:12 kapsona

@kapsona it's too slow...

ShaileshPrajapati-BTC avatar Jan 02 '18 10:01 ShaileshPrajapati-BTC

@kapsona don't use currentlyOpenSwipeable as state it slow down the performance instead use as this.currentlyOpenSwipeable = null in constructor

ShaileshPrajapati-BTC avatar Jan 03 '18 06:01 ShaileshPrajapati-BTC