Last active
February 20, 2021 17:19
-
-
Save steipete/de5d141640d64983da210cc73036c634 to your computer and use it in GitHub Desktop.
FB9013209: SwiftUI: Preview and actual layout differ in this example. (SwiftUI Bug)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Shared | |
// | |
// Created by Peter Steinberger on 20.02.21. | |
// | |
import SwiftUI | |
struct SettingsGroup<Content: View>: View { | |
let title: String | |
let content: () -> Content | |
init(title: String, content: @escaping () -> Content) { | |
self.title = title | |
self.content = content | |
} | |
var body: some View { | |
HStack { | |
VStack { | |
HStack { | |
Text(title) | |
.background(Color.green) | |
} | |
Spacer() | |
} | |
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing) | |
.background(Color.yellow) | |
VStack { | |
HStack { | |
content() | |
} | |
.background(Color.blue) | |
Spacer() | |
} | |
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) | |
.background(Color.red) | |
} | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Text("Large Content") | |
.frame(minHeight: 100) | |
SettingsGroup(title: "Highlight :") { | |
VStack(alignment: .leading) { | |
Text("Checkbox 111") | |
Text("Checkbox 2") | |
} | |
} | |
SettingsGroup(title: "Highlight :") { | |
VStack(alignment: .leading) { | |
Text("Checkbox 111") | |
Text("Checkbox 2") | |
} | |
} | |
SettingsGroup(title: "Highlight :") { | |
VStack(alignment: .leading) { | |
Text("Checkbox 111") | |
Text("Checkbox 2") | |
} | |
} | |
Text("Large Content") | |
.frame(minHeight: 500) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment