From c2329ded9fa18d566799f11552d2b12590f68425 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Fri, 27 Oct 2023 20:57:00 -0700 Subject: [PATCH] toolbar(visionOS): support hiding toolbar --- .../visionOS/VMToolbarOrnamentModifier.swift | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Platform/visionOS/VMToolbarOrnamentModifier.swift b/Platform/visionOS/VMToolbarOrnamentModifier.swift index 1831e642d..bc058a9de 100644 --- a/Platform/visionOS/VMToolbarOrnamentModifier.swift +++ b/Platform/visionOS/VMToolbarOrnamentModifier.swift @@ -19,9 +19,10 @@ import SwiftUI struct VMToolbarOrnamentModifier: ViewModifier { @Binding var state: VMWindowState @EnvironmentObject private var session: VMSessionState - + @AppStorage("ToolbarIsCollapsed") private var isCollapsed: Bool = false + func body(content: Content) -> some View { - content.ornament(attachmentAnchor: .scene(.top)) { + content.ornament(visibility: isCollapsed ? .hidden : .visible, attachmentAnchor: .scene(.top)) { HStack { Button { if session.vm.state == .started { @@ -71,13 +72,34 @@ struct VMToolbarOrnamentModifier: ViewModifier { Label("Keyboard", systemImage: "keyboard") } .disabled(state.isBusy) + Divider() + Button { + isCollapsed = true + } label: { + Label("Hide Controls", systemImage: "chevron.right") + } } - // the following was suggested by Apple via Feedback to look close to .toolbar() with .bottomOrnament + .modifier(ToolbarOrnamentViewModifier()) + } + .ornament(visibility: isCollapsed ? .visible : .hidden, attachmentAnchor: .scene(.topTrailing)) { + Button { + isCollapsed = false + } label: { + Label("Show Controls", systemImage: "chevron.left") + } + .modifier(ToolbarOrnamentViewModifier()) + } + } +} + +// the following was suggested by Apple via Feedback to look close to .toolbar() with .bottomOrnament +private struct ToolbarOrnamentViewModifier: ViewModifier { + func body(content: Content) -> some View { + content .buttonBorderShape(.capsule) .buttonStyle(.borderless) .labelStyle(.iconOnly) .padding(12) .glassBackgroundEffect() - } } }