Skip to content

Instantly share code, notes, and snippets.

@steventroughtonsmith
Created September 21, 2023 19:22
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steventroughtonsmith/a65ac64dfca6855fc8e3fb32c094d8ed to your computer and use it in GitHub Desktop.
Save steventroughtonsmith/a65ac64dfca6855fc8e3fb32c094d8ed to your computer and use it in GitHub Desktop.
Trivial visionOS non-rectangular window content layout example
//
// VisionViewPlaygroundApp.swift
// VisionViewPlayground
//
// Created by Steven Troughton-Smith on 21/09/2023.
//
import SwiftUI
@main
struct VisionViewPlaygroundApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.windowStyle(.plain)
}
}
struct ContentView: View {
@State var isShowingOverview = false
var body: some View {
TabView {
VStack(spacing:0) {
HStack {
Button("One") {
}
Text("Just a view")
Button("Two") {
}
}
.buttonBorderShape(.roundedRectangle(radius: 10))
.padding()
.glassBackgroundEffect(in:RoundedRectangle(cornerRadius: 10))
.padding(.bottom, isShowingOverview ? 20 : 0)
.animation(.interactiveSpring(duration:0.5), value: isShowingOverview)
HStack(spacing:0) {
VStack {
Text("Just a view")
.padding()
}
.frame(width:isShowingOverview ? 300 : 0, height:300)
.glassBackgroundEffect()
.rotation3DEffect(.degrees(isShowingOverview ? 45 : 0), axis:.y, anchor: .trailing)
.opacity(isShowingOverview ? 1.0 : 0.0)
.padding(.horizontal, isShowingOverview ? 20 : 0)
VStack {
HStack {
Toggle("Show Overview", isOn: $isShowingOverview)
.padding()
}
}
.frame(maxWidth:isShowingOverview ? 300 : .greatestFiniteMagnitude, maxHeight: isShowingOverview ? 300 : .greatestFiniteMagnitude)
.glassBackgroundEffect()
VStack {
Text("Just a view")
.padding()
}
.frame(width:isShowingOverview ? 300 : 0, height:300)
.glassBackgroundEffect()
.rotation3DEffect(.degrees(isShowingOverview ? -45 : 0), axis:.y, anchor: .leading)
.opacity(isShowingOverview ? 1.0 : 0.0)
.padding(.horizontal, isShowingOverview ? 20 : 0)
}
.animation(.interactiveSpring(duration:0.5), value: isShowingOverview)
}
.frame(maxWidth:.greatestFiniteMagnitude, maxHeight: .greatestFiniteMagnitude)
.border(.red)
.ornament(attachmentAnchor: .scene(.bottom), ornament: {
HStack {
Button("A") {
}
Button("B") {
}
Text("This is an ornament")
Button("C") {
}
Button("D") {
}
}
.padding()
.glassBackgroundEffect()
})
.tabItem {
Image(systemName: "sparkle")
Text("Playground")
}
Text("Tab 2")
.padding()
.glassBackgroundEffect()
.tabItem {
Image(systemName: "star")
Text("Tab 2")
}
}
}
}
#Preview(windowStyle: .automatic) {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment