sergio250
06/05/2019, 3:42 PMstruct ContentView: View {
var body: some View {
Spacer().padding()
}
}
Is transformed into
▿ _ModifiedContent<Spacer, _PaddingLayout>
▿ content: Spacer
- minLength: Optional<CGFloat>.none
▿ modifier: _PaddingLayout
▿ edges: Set
- rawValue: 15
- insets: Optional<EdgeInsets>.none
Padding
component:
struct Padding<Content>: View where Content : View {
let content: Content
init(content: () -> Content) {
self.content = content()
}
var body: some View {
content.padding()
}
}
struct ContentView: View {
var body: some View {
Padding{
Spacer()
}
}
}
Ruckus
06/05/2019, 4:36 PMsergio250
06/05/2019, 4:42 PMPadding { … }
syntax is any more readable than view.padding()
, it’s more explicit in that what we are doing is changing a view’s properties, not creating any more views. I guess that’s just a matter of taste, thoughRuckus
06/05/2019, 4:50 PMit’s more explicit in that what we are doing is changing a view’s properties, not creating any more viewsThat's only true if padding is a property of every view. If instead you have padding be a separate composable that creates padding around whatever you put in it (as I believe it is done in Compose), it's just the opposite.
sergio250
06/05/2019, 4:53 PMRuckus
06/05/2019, 4:59 PMsergio250
06/05/2019, 5:02 PM