https://kotlinlang.org logo
#compose
Title
# compose
k

Karthick

09/26/2020, 6:45 PM
How a composable lambda would validate or accept only one composable or a list of composable. In flutter we can decide to accept a single widget or list of widget for children or child parameter
a

Adam Powell

09/26/2020, 6:49 PM
A composable function is not a single widget, it's a part of a composition which might emit 0-N tree nodes. If you want to affect a single layout node, you probably want a modifier.
What kind of abstraction are you looking to create?
y

Yann Badoual

09/26/2020, 6:55 PM
You would probably need to collect the content of your lambda in a layout, and then check that it only has 1 child and if not throw an exception. I'm guessing that's what
Surface
is doing to ensure it only has one child. You can take a look at the
Surface
composable source code to check how they did it.
a

Adam Powell

09/26/2020, 6:56 PM
fwiw that behavior of Surface is a bug on the list to be addressed, not a desirable behavior 🙂
don't emulate it
y

Yann Badoual

09/26/2020, 6:57 PM
Nice to know thanks. I think a lint error with a custom annotation shouldn't be too complicated to code if he wants something static edit: nvm, some control flow may make this more complicated than I thought
k

Karthick

09/26/2020, 7:31 PM
Thanks @Adam Powell just curious on how things working under the hood
2 Views