https://kotlinlang.org logo
m

Matej Drobnič

06/22/2019, 5:09 PM
Follow up question to:
Compose has no specific notion of View IDs.
Without that information, how can compose distinguish between "old item removed, new item inserted" and "old item updated" events to display proper animations (e.g in recycler-view like setting)?
l

louiscad

06/22/2019, 5:10 PM
Compose is not using Views unless you want interop. They use keys internally for optimising stuff, but that's implementation details.
m

Matej Drobnič

06/22/2019, 5:11 PM
I was thinking view as general term, not Android VIews
without keys, how does it know to display proper animation?
or will those animations be handled differently?
l

louis993546

06/22/2019, 6:46 PM
I remember in “ScrollingList” (which doesn’t exist yet), you will be able to give each row an id, and that combine with some smart diffing should be enough to get some basic move/add/remove animations I think they talked about it in the compose episode of android developer backstage
s

sngrekov

06/22/2019, 7:41 PM
This aspect is partly described in this article http://intelligiblebabble.com/compose-from-first-principles/
s

scottmeschke

06/23/2019, 4:31 AM
Basically it's positional/tree based for diffing etc.
l

Leland Richardson [G]

06/23/2019, 3:21 PM
there is a notion of a “key” that groups of emmitted views/nodes have in compose. The source position is part of this key right now but you can add more to the key (like a stable id from your data model) and compose will use that to appropriately move/insert/remove
the way you can add more to the key is by specifying a parameter to your composable function that is annotated as
@Pivotal
(likely to be renamed to
@Key
) which will cause it to be part of the key for that composable. This is an inversion in responsibilities from the react world where
key
is always specified by the consumer of the component, instead of the declaration of the component. That said, we will provide a
key
component or something (currently it is
Key
) which will allow you to wrap a component with a key which puts the control back in the consumer, so both are handled.
2 Views