Nat Strangerweather
05/09/2021, 7:13 PMdraggable
modifier, I don't really want the whole layout to be dragged, but only the individual elements of the layout. I have posted this on stackoverflow, if anyone wanted to have a look... https://stackoverflow.com/questions/67457124/how-to-apply-the-layout-modifier-to-each-placeable-individually-in-jetpack-compo . Thanks! šorangy
Arrangement
to position elements, but with a value from 0 to 1 to indicate position on the line from start to end (mind RTL). You will likely need your own system, like Row
has itās MeasurePolicy
implementations (look into source) depending on the arrangement, but with the added animation-in-progress behavior.
Then, you need to have quasi-modifier, that you will put on children in the componentās content block. It would be what you have in your .draggable(ā¦)
call, as an extension function like fun Modifier.animateDraggableArragement(ā¦)
or something more suiting your real scenario. It will have optional ArrangementState
argument (kinda like ScrollState
) and do all the magic to animate the arrangement on that particular child for you.
When you have all these in place, you can really use your custom layout and this quasy-modifier in multiple scenarios. In the trivial one when you have a list of items, a simple foreach would do everything for each child without any duplication of code. You can then easily add more features when you need them āĀ ālock itemsā (do not emit the quasi-modifier), āmove in batchesā, whatever.
PS: I didnāt actually try to implement this and didnāt have similar cases yet. Take it with a grain of salt š§ šNat Strangerweather
05/09/2021, 8:18 PMDoris Liu
05/09/2021, 8:47 PMdraggable
modifier on each child to detect the drag on the children, and subsequently offset the one being dragged from its placement done by the CustomLayout
Nat Strangerweather
05/09/2021, 8:53 PMorangy
orangy
Tile
, what exactly are you trying to build? A ātiledā clone? An inventory system for an RPG with drag-n-drop reordering? šNat Strangerweather
05/09/2021, 9:00 PMDoris Liu
05/09/2021, 9:07 PMorangy
Doris Liu
05/09/2021, 9:32 PMNat Strangerweather
05/09/2021, 9:41 PM