Colton Idle
01/18/2021, 2:31 PMcontent()
and not just content
🙃
Does this seem fairly idiomatic?
@Composable
fun MyCustomContainer(header: String = "", content: @Composable () -> Unit) {
Column() {
if (header.isNotBlank()) {
Text(text = header)
}
content()
}
}
Adam Powell
01/18/2021, 3:24 PMmodifier
parameter that defaults to the empty Modifier
and pass it to the root Column
then consider propagating the ColumnScope
receiver to content
Colton Idle
01/18/2021, 5:36 PMconsider propagating theYou lost me there.receiver toColumnScope
content
Adam Powell
01/18/2021, 5:37 PM@Composable fun MyCustomContainer(
modifier: Modifier = Modifier,
header: String = "",
content: @Composable ColumnScope.() -> Unit
) = Column(modifier) {
if (header.isNotBlank()) {
Text(header)
}
content()
}
Adam Powell
01/18/2021, 5:37 PMColumnScope
receiver will let callers use any of the usual ColumnScope
child modifiersColton Idle
01/18/2021, 5:38 PMcontent: @Composable ColumnScope.() -> Unit
?Colton Idle
01/18/2021, 5:39 PMcontent: @Composable RowScope.() -> Unit
and I wasn't sure what it was doing, so I just left it as () -> Unit.Adam Powell
01/18/2021, 5:44 PMColton Idle
01/18/2021, 5:44 PM//Key points
//1. Modifier goes first as per convention and we pass it down to internal column so those modifiers are propagated to that layout
//2. This uses a "slot api" in order to pass in content for the container
//3. Marking "content" as a Type of ColumnScope allows us to any ColumnScope child modifiers (not sure what this means yet)
@Composable
fun Container(modifier: Modifier = Modifier, header: String = "", content: @Composable ColumnScope.() -> Unit) {
Column(modifier) {
if (header.isNotBlank()) {
Text(text = header)
}
content()
}
}
Colton Idle
01/18/2021, 9:48 PMAdam Powell
01/18/2021, 10:33 PMModifier.weight
into scopeColton Idle
01/18/2021, 10:39 PMAdam Powell
01/18/2021, 10:45 PMColton Idle
01/18/2021, 10:47 PM