SPB Git

Repository Public MIT

Motion.swift 7.0 KB 151 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Astra9// File             : Packages/AstraDesign/Sources/Motion.swift10// Module           : Packages11// Repository       : https://git.spboucher.ai/orix-astra12// Created          : 2026-11-2113// Last Modified    : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI8990/// The motion system. Every animation in the app comes from here so durations, springs and the Reduce Motion fallback stay coherent.91/// All springs are interruptible: a new target retargets the running animation instead of queueing.92public enum AstraMotion {93    /// Taps, toggles, selection feedback.94    public static let quick = Animation.snappy(duration: 0.18, extraBounce: 0)95    /// Standard state changes: expand/collapse, composer growth, card reveal.96    public static let standard = Animation.spring(response: 0.34, dampingFraction: 0.86)97    /// Hero transitions between model selection and chat, sheet-like moves.98    public static let hero = Animation.spring(response: 0.46, dampingFraction: 0.82)99    /// Gentle appearance of content (messages, toasts).100    public static let gentle = Animation.easeOut(duration: 0.24)101    /// Fallback used when Reduce Motion is on: a short cross-fade, no movement.102    public static let reduced = Animation.easeInOut(duration: 0.15)103104    public static func resolve(_ animation: Animation, reduceMotion: Bool) -> Animation { reduceMotion ? reduced : animation }105}106107public extension View {108    /// Animates `value` with a motion token, falling back to a cross-fade when Reduce Motion is on.109    func astraAnimation<V: Equatable>(_ animation: Animation, value: V) -> some View { modifier(MotionModifier(animation: animation, value: value)) }110111    /// Insertion that moves when motion is allowed and only fades otherwise.112    func astraAppear(edge: Edge = .bottom) -> some View { modifier(AppearTransition(edge: edge)) }113}114115private struct MotionModifier<V: Equatable>: ViewModifier {116    @Environment(\.accessibilityReduceMotion) private var reduceMotion117    let animation: Animation; let value: V118    func body(content: Content) -> some View { content.animation(AstraMotion.resolve(animation, reduceMotion: reduceMotion), value: value) }119}120121private struct AppearTransition: ViewModifier {122    @Environment(\.accessibilityReduceMotion) private var reduceMotion123    let edge: Edge124    func body(content: Content) -> some View {125        content.transition(reduceMotion ? .opacity : .asymmetric(insertion: .opacity.combined(with: .offset(y: edge == .bottom ? 10 : -10)), removal: .opacity))126    }127}128129/// Runs a state change with a motion token outside of a view body.130@MainActor public func withAstraMotion(_ animation: Animation = AstraMotion.standard, reduceMotion: Bool, _ body: () -> Void) {131    withAnimation(AstraMotion.resolve(animation, reduceMotion: reduceMotion), body)132}133134#if canImport(UIKit)135import UIKit136/// Haptics, named by intent. Generators are created on use; the system already drops them when haptics are disabled.137@MainActor public enum AstraHaptics {138    public static func selection() { UISelectionFeedbackGenerator().selectionChanged() }139    public static func send() { UIImpactFeedbackGenerator(style: .soft).impactOccurred(intensity: 0.8) }140    public static func tap() { UIImpactFeedbackGenerator(style: .light).impactOccurred() }141    public static func success() { UINotificationFeedbackGenerator().notificationOccurred(.success) }142    public static func warning() { UINotificationFeedbackGenerator().notificationOccurred(.warning) }143    public static func error() { UINotificationFeedbackGenerator().notificationOccurred(.error) }144}145#else146@MainActor public enum AstraHaptics {147    public static func selection() {}; public static func send() {}; public static func tap() {}148    public static func success() {}; public static func warning() {}; public static func error() {}149}150#endif151
Files main
Menu

Theme