Files
stemify/ios/Stemify/UI/Nav.swift
T
rootandClaude Opus 5.5 bc30b43eb1 iOS Duo: system tab bar instead of the rail, lyrics in the deck, stems fit, DEV banner
Split panes live inside each tab so the system's vertical bar is never covered.
Docked Now Playing no longer opens its own queue; the deck's queue scrolls under the stems.
Meters run full colour over a dimmed fill. Folded mixer rows shrink to fit every stem,
preset chips fall back to a menu instead of being cut off. Dev builds show DEV BUILD <n>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 14:11:22 -08:00

130 lines
5.0 KiB
Swift

import SwiftUI
import UIKit
enum Tab: String, CaseIterable, Hashable {
case Library, Songs, Albums, Artists, Genres, Playlists, Search, Downloads, Settings
static let defaultLayout: [Tab] = [.Library, .Playlists, .Search, .Downloads, .Settings]
/// iOS folds anything past five tabs into "More", so the bar holds at most this many.
static let maxVisible = 5
/// Parses the saved comma list; Settings is always kept so the app can't lock itself out.
static func layout(_ raw: String) -> [Tab] {
var out: [Tab] = []
for part in raw.split(separator: ",") {
if let t = Tab(rawValue: String(part)), !out.contains(t) { out.append(t) }
}
if out.isEmpty { return defaultLayout }
if !out.contains(.Settings) { out = Array(out.prefix(maxVisible - 1)) + [.Settings] }
return Array(out.prefix(maxVisible))
}
static func encode(_ tabs: [Tab]) -> String { tabs.map(\.rawValue).joined(separator: ",") }
var icon: String {
switch self {
case .Library: "square.stack.fill"
case .Songs: "music.note"
case .Albums: "square.stack"
case .Artists: "music.mic"
case .Genres: "guitars.fill"
case .Playlists: "music.note.list"
case .Search: "magnifyingglass"
case .Downloads: "arrow.down.circle.fill"
case .Settings: "gearshape.fill"
}
}
}
enum Route: Hashable {
case Artists, Albums, Songs, RecentlyAdded, Playlists, Genres, Downloads, DownloadQueue, TabBar, WebRadio
case Eq, EqFilters(profileId: String), EqFilterPage(profileId: String, filterId: String)
case Servers, ServerList, Server(String), StemServer, Quality, Storage, Appearance, NowPlayingOptions, StemEditor, About
case GenrePage(String), ArtistPage(Artist), AlbumPage(Album), PlaylistPage(Playlist), StemPlaylistPage(String)
}
/// Tabs, their stacks and the Now Playing sheet: the things any screen can ask of the shell.
@MainActor
@Observable
final class Ui {
var tab: Tab = .Library
var paths: [Tab: [Route]] = [:]
var nowPlayingOpen = false {
didSet { overlays.level = nowPlayingOpen ? 1 : 0 }
}
/// True while an unfolded iPhone Duo shows Now Playing docked beside the library.
private(set) var split = false
/// Split only: the side opposite Now Playing shows the stems and queue (true) or the selected tab.
var deck = true
/// Split only: the deck shows the lyrics (karaoke) instead of the stems and queue.
var deckLyrics = false
let overlays: Overlays
init(overlays: Overlays) { self.overlays = overlays }
func path(_ t: Tab) -> Binding<[Route]> {
Binding(get: { self.paths[t] ?? [] }, set: { self.paths[t] = $0 })
}
func push(_ r: Route) { paths[tab, default: []].append(r) }
func pop() { if paths[tab]?.isEmpty == false { paths[tab]?.removeLast() } }
/// Tapping the selected tab again pops it to its root.
func selectTab(_ t: Tab) {
if split && deck { deck = false; tab = t; return }
if t == tab { paths[t] = [] } else { tab = t }
}
/// The tabs currently in the bar, in order.
var tabs: [Tab] { Tab.layout(AppGraph.shared.settings.tabLayout) }
/// Where library pages open: Library if it's in the bar, else the first tab that is.
private var home: Tab { tabs.contains(.Library) ? .Library : (tabs.first ?? .Settings) }
/// Downloads as its own tab, or pushed onto the current one when it's hidden.
func openDownloads() {
if tabs.contains(.Downloads) { selectTab(.Downloads) } else { push(.Downloads) }
}
/// Falls back to the first tab when the selected one was just removed from the bar.
func ensureValidTab() {
if !tabs.contains(tab) { tab = tabs.first ?? .Settings }
}
/// Docked Now Playing is already on screen, so there's nothing to open while split.
func openNowPlaying() { if !split { nowPlayingOpen = true } }
/// Split only: brings the stems and queue (or the lyrics) back beside Now Playing.
func showDeck(lyrics: Bool = false) { deck = true; deckLyrics = lyrics }
func setSplit(_ on: Bool) {
guard on != split else { return }
split = on
if on {
nowPlayingOpen = false
// Only an iPhone Duo ever splits, so from here on folded Now Playing uses its tighter layout.
UserDefaults.standard.set(true, forKey: "duoSeen")
}
// Karaoke left on shows its lyrics in the deck.
deckLyrics = on && AppGraph.shared.playback.karaoke
}
/// Switches to the Library tab and pushes [r] there.
func showInLibrary(_ r: Route) {
nowPlayingOpen = false
deck = false
let t = home
tab = t
paths[t, default: []].append(r)
}
/// Switches to Settings and opens [r] (the Equalizer) there.
func showInSettings(_ r: Route) {
nowPlayingOpen = false
deck = false
tab = .Settings
if paths[.Settings]?.last != r { paths[.Settings, default: []].append(r) }
}
}