Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active February 20, 2021 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save steipete/de5d141640d64983da210cc73036c634 to your computer and use it in GitHub Desktop.
Save steipete/de5d141640d64983da210cc73036c634 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 {
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