SPB Git

Repository Public

SignatureMotions.swift 4.2 KB 87 lines swift

1// SP Notes iOS2// File: Components/SignatureMotions.swift3// Description: The signature motions of the Note Visual System 2.0 that belong to the shell (SPEC §5): Fluid Navigation (the4//              note zooms out of its row in the list — a matched zoom transition), Living Pages (rows rise and fade in, first 245//              only) and Intelligent Panels (assistant / links / statistics sheets slide and blur in). Under Reduce Motion each6//              one is a plain cross-fade or nothing: the decisions are pure functions, tested for both paths.7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10import SPNotesDesign11import SwiftUI1213enum SignatureMotion {14    /// Fluid Navigation is a zoom from the row only when motion is allowed; otherwise the system's standard push (a cross-fade15    /// with Reduce Motion on).16    static func usesZoom(reduceMotion: Bool) -> Bool { !reduceMotion }17    /// Living Pages: only the first rows are animated (SPEC: capped at 24), none under Reduce Motion beyond the token's fade.18    static func revealIndex(_ index: Int, isSelecting: Bool) -> Int? { isSelecting || index >= NVMotion.staggerCap ? nil : index }19    /// Intelligent Panels: the animation of a panel's content coming in.20    static func panelAnimation(reduceMotion: Bool) -> Animation { NVMotion.animation(.base, reduceMotion: reduceMotion) }21}2223private struct FluidNamespaceKey: EnvironmentKey { static let defaultValue: Namespace.ID? = nil }24extension EnvironmentValues {25    /// The namespace shared by the rows of a navigation stack and the note screens it pushes.26    var fluidNamespace: Namespace.ID? {27        get { self[FluidNamespaceKey.self] }28        set { self[FluidNamespaceKey.self] = newValue }29    }30}3132private struct FluidHost: ViewModifier {33    @Namespace private var namespace34    func body(content: Content) -> some View { content.environment(\.fluidNamespace, namespace) }35}3637private struct FluidSource: ViewModifier {38    let id: String39    @Environment(\.fluidNamespace) private var namespace40    @Environment(\.accessibilityReduceMotion) private var reduceMotion41    func body(content: Content) -> some View {42        if let namespace, SignatureMotion.usesZoom(reduceMotion: reduceMotion) { content.matchedTransitionSource(id: id, in: namespace) } else { content }43    }44}4546private struct FluidDestination: ViewModifier {47    let id: String48    @Environment(\.fluidNamespace) private var namespace49    @Environment(\.accessibilityReduceMotion) private var reduceMotion50    func body(content: Content) -> some View {51        if let namespace, SignatureMotion.usesZoom(reduceMotion: reduceMotion) { content.navigationTransition(.zoom(sourceID: id, in: namespace)) } else { content }52    }53}5455private struct LivingRow: ViewModifier {56    let index: Int?57    func body(content: Content) -> some View {58        if let index { content.nvBlockReveal(index: index) } else { content }59    }60}6162private struct IntelligentPanel: ViewModifier {63    let edge: Edge64    @Environment(\.accessibilityReduceMotion) private var reduceMotion65    @State private var shown = false66    func body(content: Content) -> some View {67        ZStack {68            if shown { content.nvPanelTransition(edge: edge) }69        }70        .frame(maxWidth: .infinity, maxHeight: .infinity)71        .onAppear { withAnimation(SignatureMotion.panelAnimation(reduceMotion: reduceMotion)) { shown = true } }72    }73}7475extension View {76    /// On a navigation stack: its rows and the notes it pushes share one namespace.77    func fluidNavigationHost() -> some View { modifier(FluidHost()) }78    /// On a row that opens the note `id`.79    func fluidSource(id: String) -> some View { modifier(FluidSource(id: id)) }80    /// On the note screen pushed for `id`.81    func fluidDestination(id: String) -> some View { modifier(FluidDestination(id: id)) }82    /// Living Pages on a list row.83    func livingRow(index: Int, isSelecting: Bool = false) -> some View { modifier(LivingRow(index: SignatureMotion.revealIndex(index, isSelecting: isSelecting))) }84    /// Intelligent Panels: the content of an assistant / properties sheet comes in from `edge` with a blur.85    func intelligentPanel(edge: Edge = .bottom) -> some View { modifier(IntelligentPanel(edge: edge)) }86}87
Files main
Menu

Theme