I’m currently using Swipeable
to create a list of items, each of which the user can swipe to delete. It’s working fine but if I swipe a row and open one and then swipe another, the previously-opened row is still swiped open but I’d like it to be closed.
I’ve searched for solutions and made a little progress myself using refs but I’ve not been able to get it working perfectly. I’ve also come across quite a few people asking for the same thing and it seems like pretty standard behaviour. It’d be great if you could add some documentation with examples covering this.
Thank you.
any update?😭
@AmanSharma2609 The idea is using
ref
andclose()
. Hope it helpsi use array of ref to fixed this issue, i think this issue cause by single ref, when we iterate over array the ref became the last ref of item in list so i did give all the list of item a ref based on index or item.id and called the ref based on index or id
first
then in swipeable collect the ref by passing index or your custom id
then to close one item do this in your method
this.refsArray[index].close(); // or this.refsArray[item.id].close(); if you are using custom id
@anniewey It worked thank you!!
This solution works for me. I’m using react-native-gesture-handler v1.4.1 and we have the method onSwipeableWillOpen(). Try to use this instead onSwipeableOpen().
It can help you!
@Lsleiman Sorry for the slow response.
Here’s a sample: https://gist.github.com/calendee/ba37861b237b57ee49b7949766c9a0da
This seems to be working for me. Sharing just in case
Thank you @calendee . Your solution worked for me. I had three tabs and also had to close all swipeables when switching tabs. Using react-navigation as the navigation solution. Here is a gist in case someone needs it https://gist.github.com/barunprasad/a738d944fa9abf4e6993f719b13827ad