Skip to content

Instantly share code, notes, and snippets.

@ozgurshn
Created September 22, 2021 14:10
Show Gist options
  • Save ozgurshn/3b8e94baa5fbb1fec91cf8da90594e2c to your computer and use it in GitHub Desktop.
Save ozgurshn/3b8e94baa5fbb1fec91cf8da90594e2c to your computer and use it in GitHub Desktop.
SwiftUI hug content, take parameter to extracted view and put elements inside
import SwiftUI
struct SubscriptionView: View {
var body: some View {
AppBackgroundView{
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
}
struct SubscriptionView_Previews: PreviewProvider {
static var previews: some View {
SubscriptionView()
}
}
struct AppBackgroundView<Content:View>: View
{
let viewBuilder: () -> Content
var body: some View
{
ZStack
{
Color.blue
viewBuilder()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment