SPB Git

Repository Public

Motion.swift 8.9 KB 224 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Lou-Ka iOS9// File             : LouKa/Design/Motion.swift10// Description      : mouvement de l'interface — entrées échelonnées, sélecteur11//                    à indicateur glissant, cœur qui rebondit, déploiement des12//                    graphiques. Tout respecte « Réduire les animations » et le13//                    réglage Animations de l'app (« Aucune » coupe aussi ces14//                    mouvements).15// Module           : LouKa16// Repository       : https://git.spboucher.ai/lou-ka-ios-v317// Project Website  : https://www.lou-ka.com18// Created          : 2026-11-2519// Last Modified    : 2026-11-2820//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author           : Simon-Pierre Boucher26// Position         : Professor of Finance27// Institution      : Université du Québec en Outaouais (UQO)28// Department       : Département des sciences administratives29// Organization     : SP Boucher30//31// Website          : https://spboucher.ai32// Git              : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General          : info@spboucher.ai39// Professional     : contact@spboucher.ai40// Direct           : simon@spboucher.ai41// Research         : research@spboucher.ai42// Development      : dev@spboucher.ai43// Support          : support@spboucher.ai44// Security/Admin   : admin@spboucher.ai45// Notifications    : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification   : Public72// Distribution     : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License          : None specified (no license file in this repository)86// Maintainer       : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import SwiftUI9495/// Le mouvement est-il permis ? (accessibilité du système et réglage de l'app)96struct MotionAllowed: DynamicProperty {97    @Environment(\.accessibilityReduceMotion) private var reduceMotion98    @Environment(DoorCenter.self) private var door99    @MainActor var value: Bool {100        if reduceMotion { return false }101        return door.preference != .off102    }103}104105/// Entrée échelonnée au premier affichage : les éléments d'une liste se posent l'un après l'autre.106private struct StaggeredAppear: ViewModifier {107    let index: Int108    let allowed = MotionAllowed()109    @State private var shown = false110111    func body(content: Content) -> some View {112        content113            .opacity(shown || !allowed.value ? 1 : 0)114            .offset(y: shown || !allowed.value ? 0 : 12)115            .onAppear {116                guard !shown else { return }117                // seuls les premiers éléments sont décalés : la suite d'une longue liste arrive sans attente118                withAnimation(.spring(response: 0.42, dampingFraction: 0.86).delay(Double(min(index, 7)) * 0.045)) { shown = true }119            }120    }121}122123/// Progression 0 → 1 jouée une fois à l'apparition (graphiques qui se tracent, radar qui se déploie).124private struct DrawOnAppear: ViewModifier {125    @Binding var progress: Double126    var duration: Double127    var delay: Double128    let allowed = MotionAllowed()129130    func body(content: Content) -> some View {131        content.onAppear {132            guard progress < 1 else { return }133            if allowed.value {134                withAnimation(.timingCurve(0.2, 0.8, 0.2, 1, duration: duration).delay(delay)) { progress = 1 }135            } else {136                progress = 1137            }138        }139    }140}141142extension View {143    func staggered(_ index: Int) -> some View { modifier(StaggeredAppear(index: index)) }144    func drawOnAppear(_ progress: Binding<Double>, duration: Double = 0.7, delay: Double = 0.05) -> some View {145        modifier(DrawOnAppear(progress: progress, duration: duration, delay: delay))146    }147}148149/// Sélecteur segmenté maison : l'indicateur glisse d'une option à l'autre (matchedGeometry).150struct SlidingSegmented<T: Hashable>: View {151    @Binding var selection: T152    let options: [(value: T, label: String)]153    var label: String154    @Namespace private var ns155    let allowed = MotionAllowed()156157    var body: some View {158        HStack(spacing: 2) {159            ForEach(options, id: \.value) { o in160                let active = o.value == selection161                Button {162                    Haptics.select()163                    withAnimation(allowed.value ? .spring(response: 0.3, dampingFraction: 0.82) : nil) { selection = o.value }164                } label: {165                    Text(o.label)166                        .font(.footnote.weight(.semibold))167                        .foregroundStyle(active ? Theme.ink : Theme.ink3)168                        .padding(.horizontal, 12)169                        .frame(minHeight: 32)170                        .background {171                            if active {172                                RoundedRectangle(cornerRadius: 7, style: .continuous).fill(Theme.surface)173                                    .shadow(color: .black.opacity(0.1), radius: 2, y: 1)174                                    .matchedGeometryEffect(id: "indicateur", in: ns)175                            }176                        }177                        .contentShape(Rectangle())178                }179                .buttonStyle(.plain)180                .accessibilityAddTraits(active ? .isSelected : [])181            }182        }183        .padding(3)184        .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))185        .accessibilityElement(children: .contain)186        .accessibilityLabel(label)187    }188}189190/// Cœur des favoris : il rebondit (0,82 → 1,18 → 1 en 420 ms) et un anneau orange se dissipe.191struct HeartBurst: ViewModifier {192    let active: Bool193    let allowed = MotionAllowed()194    @State private var ring = false195196    func body(content: Content) -> some View {197        content198            .keyframeAnimator(initialValue: 1.0, trigger: active) { view, scale in199                view.scaleEffect(allowed.value ? scale : 1)200            } keyframes: { _ in201                KeyframeTrack {202                    CubicKeyframe(0.82, duration: 0.1)203                    CubicKeyframe(1.18, duration: 0.16)204                    CubicKeyframe(1.0, duration: 0.16)205                }206            }207            .background {208                Circle().strokeBorder(Theme.heritageOrange, lineWidth: 2)209                    .scaleEffect(ring ? 1.9 : 0.7)210                    .opacity(ring ? 0 : (active && allowed.value ? 0.9 : 0))211                    .allowsHitTesting(false)212            }213            .onChange(of: active) { _, now in214                guard now, allowed.value else { ring = false; return }215                ring = false216                withAnimation(.easeOut(duration: 0.45)) { ring = true }217            }218    }219}220221extension View {222    func heartBurst(_ active: Bool) -> some View { modifier(HeartBurst(active: active)) }223}224
Files main
Menu

Theme