Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Forked from steipete/ContentView.swift
Created February 20, 2021 17:19
Show Gist options
  • Save chriseidhof/30ae56ea66d06b0aca418a06219c0198 to your computer and use it in GitHub Desktop.
Save chriseidhof/30ae56ea66d06b0aca418a06219c0198 to your computer and use it in GitHub Desktop.
FB9013209: SwiftUI: Preview and actual layout differ in this example. (SwiftUI Bug)
//
// 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