-
-
Save chriseidhof/30ae56ea66d06b0aca418a06219c0198 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(alignment: .firstTextBaseline) { | |
Text(title) | |
.frame(maxWidth: .infinity, alignment: .topTrailing) | |
content() | |
.frame(maxWidth: .infinity, alignment: .leading) | |
} | |
} | |
} | |
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