
Then the last trick for for decomposing the views, is to remember we can pass values when we init a struct. So something like this:
struct ContentView: View {
var body: some View {
VStack{
GreenPaddedText(text: "Hello")
GreenPaddedText(text: "world")
}
}
struct GreenPaddedText: View {
var text: String
var body: some View {
Text(text)
.foregroundColor(.green)
.padding()
}
}
}
This is probably my favourite - because although in this example I’ve created the mini-view struct in the body, if it’s a building block I can use elsewhere in a different view, it’s super portable.