I’m working on a project in react native using expo. I have a 2×2 style grid (4 cards in total are shown) where each card swipes left (no) or right (yes) of the screen. I need the next item of the flatlist to automatically appear in the space where the last swiped away item had been, but I’m struggling to figure out how to accomplish this. Here is an expo snack of what I currently have: Expo Snack. Does anyone know how to do this or if this is possible to do in a flatlist? I would really appreciate any help or advice. Thank you!
Question posted in React native
The official React Native documentation can be found here.
The official React Native documentation can be found here.
2
Answers
I am thinking you can use
useState
hook for this. What you’ll see below is my initial attempt (just two new lines of code) and you can use it to build on your swiping logic thereafter.Lastly, update the
data
props of yourFlatList
to{data}
from{dataFiltered}
.Here is the complete and tested example. Please check it.
What I have done is just delete the card by id using the filter function and with the useState hook. cheers!