Skip to content

Commit

Permalink
toolbar(visionOS): support hiding toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Oct 28, 2023
1 parent d74131e commit 9db6076
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Platform/visionOS/VMToolbarOrnamentModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
}

0 comments on commit 9db6076

Please sign in to comment.