Skip to content

Instantly share code, notes, and snippets.

@ralfebert
Last active July 28, 2025 18:58
Show Gist options
  • Save ralfebert/10255eb3a2ac51c8078f71078b43be2b to your computer and use it in GitHub Desktop.
Save ralfebert/10255eb3a2ac51c8078f71078b43be2b to your computer and use it in GitHub Desktop.
import SwiftUI
enum Experiment: String, CaseIterable, Identifiable {
case form
case concentricRect
case uniformConcentricRect
case containerRelative
case containerRelativeWithContainerShape
case containerCornerInsets
var title: String {
self.rawValue
}
var id: String {
self.rawValue
}
}
struct ContentView: View {
@State var experiment : Experiment? = .concentricRect
var body: some View {
NavigationStack {
Form {
Picker("Experiment", selection: $experiment) {
ForEach(Experiment.allCases, id: \.self) { experiment in
Text(experiment.title).tag(experiment)
}
}
.pickerStyle(.inline)
}
}
.sheet(item: $experiment) { experiment in
Group {
switch(experiment) {
case .form:
Form {
Section {
Text("Form + Section")
Text("Form + Section")
}
}
case .concentricRect:
ShapeView {
ConcentricRectangle()
}
case .uniformConcentricRect:
ShapeView {
ConcentricRectangle(corners: .concentric, isUniform: true)
}
case .containerRelative:
ShapeView {
ContainerRelativeShape()
}
case .containerRelativeWithContainerShape:
ShapeView {
ContainerRelativeShape()
}
.containerShape(RoundedRectangle(cornerRadius: 36))
case .containerCornerInsets:
GeometryReader { geometry in
Form {
Text(String(describing: geometry.containerCornerInsets))
}
}
}
}
.presentationDetents([.medium, .large])
}
}
}
struct ShapeView<S : Shape> : View {
@ViewBuilder let content: () -> S
var body: some View {
VStack {
HStack {
content()
.fill(Color.yellow)
.frame(height: 80)
.frame(maxWidth: .infinity)
content()
.fill(Color.orange)
.frame(height: 80)
.frame(maxWidth: .infinity)
}
content()
.fill(Color.green)
.frame(height: 80)
.frame(maxWidth: .infinity)
content()
.fill(Color.blue)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.padding()
.ignoresSafeArea(edges: [.bottom])
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment