m

    Matej Drobnič

    3 years ago
    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)?
    louiscad

    louiscad

    3 years ago
    Compose is not using Views unless you want interop. They use keys internally for optimising stuff, but that's implementation details.
    m

    Matej Drobnič

    3 years ago
    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

    3 years ago
    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

    3 years ago
    This aspect is partly described in this articlehttp://intelligiblebabble.com/compose-from-first-principles/
    s

    scottmeschke

    3 years ago
    Basically it's positional/tree based for diffing etc.
    l

    Leland Richardson [G]

    3 years ago
    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.