Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
209 lines
8.3 KiB
Swift
Executable File
209 lines
8.3 KiB
Swift
Executable File
// ShellHeaderControls — the shell's per-tab header affordances.
|
||
//
|
||
// Flutter's RwShell collapsed its appBarActions (Everything Else, Devices)
|
||
// into one overflow menu and drew the signed-in avatar as the Profile
|
||
// destination's icon. Here they are three SEPARATE items pinned to the
|
||
// trailing edge of every tab root's page header: two real buttons plus a
|
||
// decorative avatar (NOT a button — tapping the Profile TAB is how you reach
|
||
// the profile).
|
||
//
|
||
// Why a header row and not a floating overlay / toolbar item: the tab roots
|
||
// draw their own page headers and no system navigation bar, so a toolbar
|
||
// item has nothing to land in and an overlay floats out of alignment with
|
||
// the title it sits beside.
|
||
//
|
||
// iOS only: the Mac shell reaches these through its sidebar and Everything
|
||
// Else, and its headers already carry the refresh affordance.
|
||
|
||
import CrossSoundKit
|
||
import Inject
|
||
import RedWhiteUI
|
||
import SwiftUI
|
||
|
||
@MainActor
|
||
|
||
struct HeaderOverFlowMenu: View {
|
||
@Environment(\.appPush) private var push
|
||
@Environment(AppServices.self) private var services
|
||
var body: some View {
|
||
RwMenu (items) {
|
||
Image(systemName: "ellipsis")
|
||
.font (.system(size: 13, weight: .semibold))
|
||
}
|
||
}
|
||
|
||
private var items: [RwMenuItem] {
|
||
var items: [RwMenuItem] = []
|
||
if let push {
|
||
items.append(contentsOf: [
|
||
RwMenuItem("Everything Else", systemImage: "square.stack") { push(.services) },
|
||
RwMenuItem("Devices", systemImage: "laptopcomputer.and.iphone") { push(.devices) },
|
||
RwMenuItem("Notifications", systemImage: "bell") { push(.notifications) },
|
||
])
|
||
if services.queue.station != nil {
|
||
items.append(RwMenuItem("Radio", systemImage: "radio") {push(.radio)})
|
||
}
|
||
}
|
||
return items
|
||
}
|
||
}
|
||
|
||
public struct ShellHeaderControls: View {
|
||
@Environment(AppServices.self) private var services
|
||
@Environment(\.rw) private var p
|
||
/// Optional on purpose: views hosted outside the shell (the now-playing
|
||
/// sheet's stack) have no navigator, and a non-optional @Environment read
|
||
/// of a missing @Observable traps at runtime.
|
||
@Environment(ShellNavigator.self) private var nav: ShellNavigator?
|
||
@Environment(\.isPushedPage) private var isPushedPage
|
||
@Environment(\.inPushBar) private var inPushBar
|
||
|
||
private let onRefresh: (@MainActor () async -> Void)?
|
||
private let overFlowMenu: (@MainActor () async -> Void)?
|
||
|
||
public init(
|
||
onReferesh: (@MainActor () async -> Void)? = nil,
|
||
overFlowMenu: (@MainActor () async -> Void)? = nil
|
||
) {
|
||
self.onRefresh = onReferesh
|
||
self.overFlowMenu = overFlowMenu
|
||
}
|
||
|
||
@ObserveInjection var inject
|
||
|
||
private var showsHere: Bool {
|
||
#if os(macOS)
|
||
inPushBar
|
||
#else
|
||
!isPushedPage || inPushBar
|
||
#endif
|
||
}
|
||
|
||
public var body: some View {
|
||
Group {
|
||
// On a pushed page the bar at the top carries these, and on a Mac
|
||
// the title bar always does (PushChrome.swift); the page's own
|
||
// copy steps aside so they never show twice and the title gets
|
||
// the whole row.
|
||
if showsHere {
|
||
HStack(spacing: RwSizes.gap) {
|
||
// The shell's hamburger: opens the RwShell drawer on phones, and
|
||
// collapses/expands the sidebar on the Mac. It lives here because the
|
||
// shell runs with showAppBar: false — every root draws this header
|
||
// instead, so this is the bar the button belongs in.
|
||
RwShellMenuButton()
|
||
AppLink(value: AppDestination.discover) {
|
||
LitPalette { p in
|
||
Image(systemName: "house.fill")
|
||
.font(.system(size:15, weight: .semibold))
|
||
.foregroundStyle(p.red)
|
||
.frame(width:32, height:32)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
.buttonStyle(.bareRow())
|
||
.accessibilityLabel("Home - Discover")
|
||
|
||
AppLink(value: AppDestination.search){
|
||
LitPalette { p in
|
||
Image(systemName: "magnifyingglass")
|
||
.font(.system(size:15, weight: .semibold))
|
||
.foregroundStyle(p.red)
|
||
.frame(width:32, height:32)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
.buttonStyle(.bareRow())
|
||
.accessibilityLabel("Search")
|
||
|
||
AppLink(value: AppDestination.playlists){
|
||
LitPalette { p in
|
||
Image(systemName: "music.note.list")
|
||
.font(.system(size:15, weight: .semibold))
|
||
.foregroundStyle(p.red)
|
||
.frame(width:32, height:32)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
.buttonStyle(.bareRow())
|
||
.accessibilityLabel("Playlists")
|
||
|
||
#if os (macOS)
|
||
AppLink(value: AppDestination.services) {
|
||
LitPalette { p in
|
||
Image(systemName: "gearshape")
|
||
.font(.system(size: 15, weight: .semibold))
|
||
.foregroundStyle(p.red)
|
||
.frame(width: 32, height: 32)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
.buttonStyle(.bareRow())
|
||
.accessibilityLabel("Everything Else")
|
||
|
||
AppLink(value: AppDestination.devices) {
|
||
LitPalette { p in
|
||
Image(systemName: "laptopcomputer.and.iphone")
|
||
.font(.system(size: 15, weight: .semibold))
|
||
.foregroundStyle(p.red)
|
||
.frame(width: 32, height: 32)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
.buttonStyle(.bareRow())
|
||
.accessibilityLabel("Devices – Remote")
|
||
PlayingStationButton()
|
||
NotificationBell()
|
||
#endif
|
||
#if os (iOS)
|
||
if let overFlowMenu {
|
||
HeaderOverFlowMenu()
|
||
}
|
||
#endif
|
||
avatar
|
||
}
|
||
}
|
||
}
|
||
.enableInjection()
|
||
}
|
||
|
||
|
||
|
||
|
||
/// Tapping it selects the Profile TAB (see ShellNavigator — Profile is a
|
||
/// shell destination, not a pushable AppDestination). Still borderless.
|
||
/// Where there is no navigator it stays decorative rather than dead.
|
||
@ViewBuilder private var avatar: some View {
|
||
if let nav {
|
||
Button { nav.selectProfile() } label: { avatarImage }
|
||
.buttonStyle(.plain)
|
||
.accessibilityLabel("Profile")
|
||
} else {
|
||
avatarImage.accessibilityHidden(true)
|
||
}
|
||
}
|
||
/// Electron swaps the ring to --secondary on hover/open; SwiftUI only has
|
||
/// hover on the Mac, so iOS just keeps the rest colour.
|
||
@State private var hovering = false
|
||
|
||
@ViewBuilder private var avatarImage: some View {
|
||
AsyncImage(url: services.currentUser?.avatarUrl.flatMap(URL.init(string:))) { image in
|
||
image.resizable().scaledToFill()
|
||
} placeholder: {
|
||
// An icon, not secondary text: textMuted reads gray/off-brand on chrome.
|
||
Image(systemName: "person.crop.circle.fill")
|
||
.resizable()
|
||
.foregroundStyle(p.iconInactive)
|
||
}
|
||
.frame(width: 30, height: 30)
|
||
.clipShape(Circle())
|
||
.padding(1)
|
||
// `box-shadow: 0 0 0 2px var(--ink)` from the web build: a ring OUTSIDE
|
||
// the image, in the main red, so it follows the accent and stays
|
||
// customisable. --secondary (redHover) on hover, same as #user-info:hover.
|
||
.overlay(Circle().stroke(hovering ? p.redHover : p.red, lineWidth: 2))
|
||
.contentShape(Circle())
|
||
.onHover { hovering = $0 }
|
||
}
|
||
}
|