https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

12/07/2019, 3:24 AM
Has anyone attempted to have swipe-to-dismiss items in recycler view + unidirectional data flow? Should the item stay swiped out (but other items still are stationary, i.e. there is a hole) until the next emit of the List? which then diffs it and removed the item? or would this be too slow? (if its all backed by a db)
t

tschuchort

12/09/2019, 7:44 AM
This is how I would do it. Afaik when you're swiping an item you aren't actually swiping the item away. You are swiping a layout inside the item which then triggers an action to eventually remove the item from the list. This is also helpful if you want to implement an undo button in place of the swiped item.
u

ursus

12/09/2019, 8:03 AM
so it waits translated all the way out, then gets removed on new emit? how about drag sort?
t

tschuchort

12/09/2019, 8:43 AM
Probably the same. Although I have never done it myself so I don't know if it will be fast enough. And it irks me that for a moment the view state will be different then viewmodel state.
u

ursus

12/09/2019, 9:27 AM
well, yes that is the issue, I think in this case mutating the list at viewmodel leve would be better, and only then save to db
however in not sure what happens if I mutate and emit the new list while the animation is dragging..idk
t

tschuchort

12/09/2019, 10:19 AM
I’m not sure how dragging is implemented in RecyclerView, but I think the ITEM_MOVED event is only sent to ViewModel after dragging is finished. Then you can update the list in the viewmodel to reflect the moving in the recyclerview.
u

ursus

12/09/2019, 10:36 AM
what item moved event to the viewmodel?
but no, the one from drag helper is called every item swap
4 Views