SPB Git

Repository Public

Theme.swift 5.0 KB 113 lines swift

1// SP Music iOS2// File: Components/Theme.swift3// Description: Colours, button styles, navigation routes and small shared views.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai78import SPMusicCore9import SwiftUI1011/// SP Music identity: deep aubergine-black surfaces and one warm "ember" accent — the same family as the web player.12extension Color {13    static let spBackground = Color(red: 0.043, green: 0.039, blue: 0.051)14    static let spSurface = Color(red: 0.082, green: 0.075, blue: 0.102)15    static let spRaised = Color(red: 0.118, green: 0.106, blue: 0.145)16    static let spLine = Color(red: 0.173, green: 0.157, blue: 0.212)17    static let spMuted = Color(red: 0.659, green: 0.635, blue: 0.714)18    static let spEmber = Color(red: 1.0, green: 0.416, blue: 0.239)19    static let spAmber = Color(red: 1.0, green: 0.702, blue: 0.278)20    static let spOnAccent = Color(red: 0.082, green: 0.043, blue: 0.031)21}22extension ShapeStyle where Self == LinearGradient {23    static var spBrand: LinearGradient { LinearGradient(colors: [.spEmber, .spAmber], startPoint: .topLeading, endPoint: .bottomTrailing) }24}2526/// Where a tap on an album, an artist or a list leads. One enum for every navigation stack of the app.27enum Route: Hashable {28    case album(String), artist(String), playlist(String)29    case albums, artists, tracks, playlists, favorites, recentlyPlayed, downloaded30    case storage, account, networkSettings, audioSettings31}3233/// Reload trigger of a screen: the library changed, or the "on this device only" filter did.34struct ReloadKey: Hashable { var version: Int; var downloadedOnly: Bool; var extra: String = "" }35extension AppEnvironment {36    func reloadKey(_ extra: String = "") -> ReloadKey { ReloadKey(version: libraryVersion, downloadedOnly: downloadedOnly, extra: extra) }37}3839struct PrimaryButtonStyle: ButtonStyle {40    func makeBody(configuration: Configuration) -> some View {41        configuration.label.font(.headline).foregroundStyle(Color.spOnAccent)42            .frame(maxWidth: .infinity, minHeight: 50).background(.spBrand, in: .capsule)43            .opacity(configuration.isPressed ? 0.8 : 1).scaleEffect(configuration.isPressed ? 0.98 : 1)44            .animation(.snappy(duration: 0.15), value: configuration.isPressed)45    }46}47struct SecondaryButtonStyle: ButtonStyle {48    func makeBody(configuration: Configuration) -> some View {49        configuration.label.font(.headline).foregroundStyle(.white)50            .frame(maxWidth: .infinity, minHeight: 50).background(Color.spRaised, in: .capsule)51            .overlay(Capsule().strokeBorder(Color.spLine))52            .opacity(configuration.isPressed ? 0.7 : 1)53    }54}5556struct SectionTitle: View {57    let title: String58    var route: Route?59    var body: some View {60        HStack {61            Text(title).font(.title2.bold())62            Spacer()63            if let route { NavigationLink(value: route) { Text("Tout voir").font(.subheadline.weight(.semibold)) } }64        }65        .padding(.horizontal)66    }67}6869/// Small animated bars shown on the track that is playing. Paused → still (no animation running for nothing).70struct PlayingBars: View {71    var animating: Bool72    var body: some View {73        HStack(alignment: .bottom, spacing: 2) {74            ForEach(0..<3, id: \.self) { i in75                Capsule().fill(Color.spEmber).frame(width: 3, height: 14)76                    .scaleEffect(y: animating ? 1 : 0.35, anchor: .bottom)77                    .animation(animating ? .easeInOut(duration: 0.45 + Double(i) * 0.12).repeatForever(autoreverses: true) : .default, value: animating)78            }79        }80        .frame(width: 16, height: 14).accessibilityHidden(true)81    }82}8384struct QualityBadge: View {85    let track: Track86    var body: some View {87        if track.isLossless {88            Text(track.isHiRes ? "Hi-Res" : "Lossless").font(.caption2.weight(.bold))89                .padding(.horizontal, 5).padding(.vertical, 2)90                .foregroundStyle(track.isHiRes ? Color.spAmber : Color.spMuted)91                .overlay(RoundedRectangle(cornerRadius: 4).strokeBorder(track.isHiRes ? Color.spAmber.opacity(0.6) : Color.spLine))92                .accessibilityLabel(track.isHiRes ? "Fichier haute résolution" : "Fichier sans perte")93        }94    }95}9697extension View {98    /// Message shown briefly at the bottom of the screen.99    func toast(_ text: Binding<String?>) -> some View {100        overlay(alignment: .bottom) {101            if let t = text.wrappedValue {102                Text(t).font(.subheadline.weight(.medium)).multilineTextAlignment(.center)103                    .padding(.horizontal, 16).padding(.vertical, 11)104                    .background(.regularMaterial, in: .capsule).padding(.horizontal, 24).padding(.bottom, 110)105                    .transition(.move(edge: .bottom).combined(with: .opacity))106                    .task(id: t) { try? await Task.sleep(for: .seconds(3.2)); withAnimation { text.wrappedValue = nil } }107                    .accessibilityAddTraits(.isStaticText)108            }109        }110        .animation(.snappy, value: text.wrappedValue)111    }112}113
Files main
Menu

Theme