Leland Richardson [G]
10/14/2019, 8:15 PMFudge
10/14/2019, 11:30 PMLeland Richardson [G]
10/15/2019, 12:04 AM@Composable fun MyButton(padding: Int, ...) {
Button(modifier = padding(padding.dp), ... )
}
is just as valid as
@Composable fun MyButton(modifier: Modifier, ...) {
Button(modifier = modifier, ...)
}
gildor
10/15/2019, 12:30 AMvoddan
10/15/2019, 8:51 AMYour custom component can have whatever parameters it wantsIf my goal as a component library writer is for my custom components to feel "native", than I'll have to follow whatever conventions core components follow. E.i I'll have to propagate the
padding
parameter just to be acceptableFudge
10/15/2019, 11:46 AMWe're trying to direct people into writing components that acceptfunction references if they need to display arbitrary content, and in many cases the caller can add padding around their content they put there if they want it. Some designs might call for padding emitted by the container before calling the provided function, some might not.@Composable() () -> Unit
themishkun
10/15/2019, 12:13 PMGeorge Mount
10/15/2019, 9:32 PMRow
layout doesn't have to know anything about padding
to use it. It is just something that is applied to it. It acts quite a bit like:
Padding {
MyButton(...)
}
In that MyButton
doesn't know anything about a padding
modifier. A developer can add custom modifiers to any component. The modifier developer doesn't have to worry about what happens when multiple children are placed within because a layout modifier only applies to a single layout.MyButton(padding(16.dp))
is equivalent to:
Padding(16.dp) { MyButton() }
in that MyButton
doesn't have to know about padding. That is different from Android Views. In Android Views, if you add layout_padding="16dp"
, your layout must understand how to handle the padding attribute.Modifier
parameter now.layout_padding
was a bad example because android:padding
is on the View itself, but insert your custom layout attribute in there instead.Fudge
10/16/2019, 12:07 AMPadding
component?gildor
10/16/2019, 12:57 AMthemishkun
10/16/2019, 6:14 AMgildor
10/16/2019, 6:15 AMbut use the composabilityIf you split 1 big layout to 10 small layouts you do not decrease amount of required paddings. You will still have 1 view with 1 or 2 padding/margin wrappers