One Off the Slack: How Default is a Default?
John O’Reilly asked:
In SwiftUI if you do …[provide] no params to
padding()then default system padding values are used… In Compose it looks like
0dpis used if no parameters are passed. Would be nice I think to use SwiftUI’s approach here..
Bryan Herbst immediately got to the heart of the issue:
What would the default padding be? 4dp? 8dp? I don’t think there’s a particularly valuable default value for a broad enough range of applications. I think the “default” padding will change between different apps with different design systems.
John offered up
16dp as a possible default, based on Material Design:
Doesn’t of course over all cases but material design I think generally recommends 16dp in many cases….might be a reasonable default anyway
Joost Klitsie argued that SwiftUI’s approach does not make sense over in the Compose world, because padding recommendations are based on a design system, and not all design systems are the same:
but compose !=material design
apple is very biased and they want you use their (outdated) design system, so of course they will incorporate it into the language
but compose is in essence a UI framework, opened up to support different design philosophies. They will however help you and deliver a material design library on top of it
but padding is part of the base stuff
so 0 padding is a sane default (I would argue that the argument should be specified at all times)
…material design often has 16dp space, but often there are different values
Kirill Grouchnikov echoed that sentiment:
I wouldn’t want the underlying layer (which should be agnostic to the specific “philosophy” of a particular design system such as Material) to be in the business of providing default metrics of its own
What Compose Material does is set up a set of defaults (e.g.,
ButtonDefaults) for values to apply to its composables (e.g.,
Button()). John asked:
so, is it that
ButtonDefaultsis only applied when using
As Bryan pointed out, in effect, there is no spoon:
ButtonDefaultsis part of
MaterialTheme. In fact, all of
Buttonis! There is no design system-agnostic button implementation in Compose.
So, a design system is responsible for “nudging” you towards defaults for things like padding, including trying to minimize the code needed to use those defaults. Compose’s layered architecture means that a lot of those design system concepts wind up in Compose Material, and we as a community are still learning where Compose UI ends and where Compose Material begins.