semoro
04/11/2020, 4:22 AMstateFor
and provide some key?
https://gist.github.com/semoro/ea7c07cf3bcbd3bc4cbc4729b82b4140#file-composeremovalarea-kt-L64
Actually, if I don’t provide some kind of this id parameter, button click also hides subsequent list element, which is a bit counter-intuitive.
Is it due to that changes of input parameters in RemovalArea’s child doesn’t cause recompose in RemovalArea itself, and previously occupied slot for deleted element became used by next one, without reset of state?
Is there is some way to avoid passing id
parameter?Timo Drick
04/11/2020, 12:32 PMsemoro
04/11/2020, 1:08 PMsemoro
04/11/2020, 1:09 PMZach Klippenstein (he/him) [MOD]
04/11/2020, 2:04 PM@Pivotal
annotation to `RemoveArea`'s id
parameter? That should mean you don't need stateFor
anymore, and should all preserve your other list items' state across list modifications (ie supports "moving" groups around).
I think you need id
for that reason, so compose can handle moves/reorders correctly.semoro
04/11/2020, 2:06 PMsemoro
04/11/2020, 2:08 PMZach Klippenstein (he/him) [MOD]
04/11/2020, 2:15 PM@Pivotal
is for, instead of just treating the removal as the composable parameters changing and reusing the slots/states from the deleted item, compose can see that they were actually removed, and the slots/state for the subsequent item in the list are effectively moved back up to fill the gap, preserving the state.Zach Klippenstein (he/him) [MOD]
04/11/2020, 2:16 PMZach Klippenstein (he/him) [MOD]
04/11/2020, 2:17 PMsemoro
04/11/2020, 2:17 PMid
like parameters in such case?Zach Klippenstein (he/him) [MOD]
04/11/2020, 2:38 PMid
here for the same reason RecyclerView does to correctly handle moves (DiffUtil
distinguishes between content changes and "item identity" changes) - the system needs to have some concept of "which" item an item is for the concept of "move" to even make sense. AdapterList
and the Crossfade
composable make use of something like your id
(they call it a key
).semoro
04/11/2020, 2:44 PMZach Klippenstein (he/him) [MOD]
04/11/2020, 2:49 PMZach Klippenstein (he/him) [MOD]
04/11/2020, 2:51 PMCrossfade
uses the key
function which is just a convenience if you don't already have a custom composable wrapping your children.semoro
04/11/2020, 2:52 PMid
parameter Pivotal
and on removal of first item in list application hangs 😞 (ANR)semoro
04/11/2020, 2:55 PMkey
works althroughZach Klippenstein (he/him) [MOD]
04/11/2020, 2:55 PMZach Klippenstein (he/him) [MOD]
04/11/2020, 2:55 PMkey
too actually but I wouldn't think they'd have different behavior 🤔Zach Klippenstein (he/him) [MOD]
04/11/2020, 3:48 PMsemoro
04/11/2020, 4:18 PM