Repository Public
1// SP Drive iOS2// File: Components/Transitions.swift3// Description: Visual continuity: a card or a thumbnail zooms into what it opens (folder, full preview) and back. One namespace per4// navigation stack, handed down through the environment. With Reduce Motion on, nothing zooms: the system cross-fades.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SwiftUI910extension EnvironmentValues {11 /// Namespace of the zoom transitions of the enclosing navigation stack.12 @Entry var zoomNamespace: Namespace.ID?13}1415private struct ZoomSource: ViewModifier {16 @Environment(\.zoomNamespace) private var namespace17 @Environment(\.accessibilityReduceMotion) private var reduceMotion18 let id: String19 func body(content: Content) -> some View {20 if let namespace, !reduceMotion { content.matchedTransitionSource(id: id, in: namespace) } else { content }21 }22}2324private struct ZoomDestination: ViewModifier {25 @Environment(\.zoomNamespace) private var namespace26 @Environment(\.accessibilityReduceMotion) private var reduceMotion27 let id: String28 let enabled: Bool29 func body(content: Content) -> some View {30 if enabled, let namespace, !reduceMotion { content.navigationTransition(.zoom(sourceID: id, in: namespace)) } else { content }31 }32}3334extension View {35 /// Marks the view a zoom starts from (a card, a thumbnail).36 func zoomSource(_ id: String) -> some View { modifier(ZoomSource(id: id)) }37 /// Makes the presented or pushed view grow out of its source.38 func zoomDestination(_ id: String, enabled: Bool = true) -> some View { modifier(ZoomDestination(id: id, enabled: enabled)) }3940 /// Animates a state change with the design system's curve, or not at all when Reduce Motion is on.41 func spdAnimation<V: Equatable>(_ animation: Animation = SPDTheme.Motion.reveal, value: V) -> some View { modifier(MotionAware(animation: animation, value: value)) }42}4344private struct MotionAware<V: Equatable>: ViewModifier {45 @Environment(\.accessibilityReduceMotion) private var reduceMotion46 let animation: Animation47 let value: V48 func body(content: Content) -> some View { content.animation(SPDTheme.Motion.resolve(animation, reduceMotion: reduceMotion), value: value) }49}50