Writing a custom Layout, in order to be able to re...
# compose
s
Writing a custom Layout, in order to be able to reference it back in the layout block, I am wrapping it in a box with a layoutId
Layout(content = { Box(Modifier.layoutId("id")) { content() }
and then in the block I do
measurables.fastFirstOrNull { it.layoutId == "id }
to find it. This works well to get the item that I want (this layout takes more than 1 slot), but it breaks another assumption, regarding the modifier that is used in the call site for
content
. In particular, I got a modifier that animates the placement offset the item gets, but this is broken because in my custom layout I am now laying out the Box actually, and not the content itself. Is there something clever I can do here to still get the layout ID to my composable, without breaking what I describe above?
I can see how I can change the slot to
content: @Composable (Modifier) -> Unit
instead, and take the modifier there and append the layoutId to it instead, but this makes the API of my custom layout really non-standard, as I need to remember to use the modifier myself on the call-site. It becomes really awkward. Anything else I can do here? 👀