What is the expectation for slots in components li...
# compose-wear
y
What is the expectation for slots in components like ToggleChip? I didn't notice appIcon, so I put the icon inside the label to start with. Because label is placed inside of a Column, with secondaryColumn, I surrounded it with a row. But it seems like the Column parent is leaking an implementation detail? How do Compose mobile components handle this? Should it be a parent Box? Should it fail if the label @Composable has more than one direct child?
While I'm at it, is there a reason why ToggleChip doesn't have the content lambda (label?) as the last one? Seems like the most essential UI element, so I'd expect to be able to have it last and have a trailing lambda.
j
Taking the 2nd question first - we wanted ToggleChip to be as consistent with Chip as we could for discovery
👍🏻 1
Regarding the first - the description and samples are the way we would look to guide developers - so the toggle chip is opinionated and describes the layout
I don't think we can (or should) try and limit what folks put in slots - the philosophy of slots come from Compose for Mobile and allows developers flexibility - we don't know when 2 or more composables in a slot might make sense
👍🏻 1
y
Is it valid to have two items inside the label @Composable, and then implicitly assume it is a Column? Or a code smell in the client app, but not something we want to actively cause pain over?
a
The layout strategy of a slot is part of a composable's public API contract and composables that have slots should document what that layout contract is. It's not a code smell for apps to rely on it; apps shouldn't have to defensively add their own redundant layout containers in slots
👍🏻 1
y
Thanks for the explanation. Another one of those that I wouldn't have chosen this approach myself, but it follows the Compose guidance which is critical. And this component is nicely documented, it's all in there (i maybe owe @John Nichol an apology for besmirching his good name).
The items are laid out in a row with the optional icon at the start, a column containing the two label slots in the middle and a slot for the toggle icons at the end.
document what that layout contract is
I noticed that almost all Material elements that do this expose BoxScope, RowScope or Column scope. I suspect that ToggleChip should probably have this also. Currently
label: @Composable () -> Unit
@John Nichol @Michail Kulaga Want to reanimate this discussion. What about TimeText? The curved content has
(@Composable CurvedRowScope.() -> Unit)?
but linear just has
(@Composable () -> Unit)? = null
And it looks like you should be able to have multiple items in each slot? Should the behaviour be documented? Should RowScope be made public in the API for linear?