Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrix/Design/Motion.swift10// Description : mouvement de l'interface — entrées échelonnées, tracé des11// graphiques, sélecteur à indicateur glissant. Tout respecte12// « Réduire les animations » et le réglage Animations de13// l'app.14// Module : VraiPrix15// Repository : https://git.spboucher.ai/vrai-prix-ios-v316// Project Website : https://www.vrai-prix.com17// Created : 2026-11-2618// Last Modified : 2026-11-2619//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : None specified (no license file in this repository)85// Maintainer : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import SwiftUI9394/// Le mouvement est-il permis ? (accessibilité du système et réglage de l'app)95struct MotionAllowed: DynamicProperty {96 @Environment(\.accessibilityReduceMotion) private var reduceMotion97 @Environment(MotionCenter.self) private var motion98 @MainActor var value: Bool { motion.allowed(reduceMotion: reduceMotion) }99}100101/// Entrée échelonnée au premier affichage : les éléments d'une liste se posent l'un après l'autre.102private struct StaggeredAppear: ViewModifier {103 let index: Int104 let allowed = MotionAllowed()105 @State private var shown = false106107 func body(content: Content) -> some View {108 content109 .opacity(shown || !allowed.value ? 1 : 0)110 .offset(y: shown || !allowed.value ? 0 : 8)111 .onAppear {112 guard !shown else { return }113 withAnimation(.timingCurve(0.2, 0.7, 0.2, 1, duration: 0.32).delay(Double(min(index, 7)) * 0.04)) { shown = true }114 }115 }116}117118/// Progression 0 → 1 jouée une fois à l'apparition (graphiques qui se tracent).119private struct DrawOnAppear: ViewModifier {120 @Binding var progress: Double121 var duration: Double122 var delay: Double123 let allowed = MotionAllowed()124125 func body(content: Content) -> some View {126 content.onAppear {127 guard progress < 1 else { return }128 if allowed.value {129 withAnimation(.timingCurve(0.2, 0.8, 0.2, 1, duration: duration).delay(delay)) { progress = 1 }130 } else {131 progress = 1132 }133 }134 }135}136137extension View {138 func staggered(_ index: Int) -> some View { modifier(StaggeredAppear(index: index)) }139 func drawOnAppear(_ progress: Binding<Double>, duration: Double = 0.8, delay: Double = 0.05) -> some View {140 modifier(DrawOnAppear(progress: progress, duration: duration, delay: delay))141 }142}143144/// Sélecteur segmenté : l'indicateur glisse d'une option à l'autre.145struct SlidingSegmented<T: Hashable>: View {146 @Binding var selection: T147 let options: [(value: T, label: String)]148 var label: String149 @Namespace private var ns150 let allowed = MotionAllowed()151152 @Environment(\.dynamicTypeSize) private var typeSize153154 var body: some View {155 // en très grand texte, les options passent sur deux colonnes au lieu d'être tronquées156 let layout = typeSize.isAccessibilitySize && options.count > 2157 ? AnyLayout(TwoColumnLayout(spacing: 2)) : AnyLayout(HStackLayout(spacing: 2))158 layout {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.86) : nil) { selection = o.value }164 } label: {165 Text(o.label)166 .font(.footnote.weight(.semibold))167 .foregroundStyle(active ? Theme.ink : Theme.ink3)168 .lineLimit(1).minimumScaleFactor(0.8)169 .padding(.horizontal, 10)170 .frame(maxWidth: .infinity, minHeight: 36)171 .background {172 if active {173 RoundedRectangle(cornerRadius: 7, style: .continuous).fill(Theme.surface)174 .overlay(RoundedRectangle(cornerRadius: 7, style: .continuous).strokeBorder(Theme.line2, lineWidth: 1))175 .matchedGeometryEffect(id: "indicateur", in: ns)176 }177 }178 .contentShape(Rectangle())179 }180 .buttonStyle(.plain)181 .accessibilityAddTraits(active ? .isSelected : [])182 }183 }184 .padding(3)185 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))186 .accessibilityElement(children: .contain)187 .accessibilityLabel(label)188 }189}190191/// Grille à deux colonnes égales (sélecteur en très grand texte).192struct TwoColumnLayout: Layout {193 var spacing: CGFloat = 2194195 private func rowHeights(_ w: CGFloat, _ subviews: Subviews) -> [CGFloat] {196 let cw = (w - spacing) / 2197 return stride(from: 0, to: subviews.count, by: 2).map { i in198 subviews[i..<min(i + 2, subviews.count)].map { $0.sizeThatFits(ProposedViewSize(width: cw, height: nil)).height }.max() ?? 0199 }200 }201202 func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {203 let w = proposal.width ?? 320204 let h = rowHeights(w, subviews)205 return CGSize(width: w, height: h.reduce(0, +) + spacing * CGFloat(max(0, h.count - 1)))206 }207208 func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {209 let cw = (bounds.width - spacing) / 2210 var y = bounds.minY211 for (r, h) in rowHeights(bounds.width, subviews).enumerated() {212 for c in 0..<2 where r * 2 + c < subviews.count {213 subviews[r * 2 + c].place(at: CGPoint(x: bounds.minX + CGFloat(c) * (cw + spacing), y: y), proposal: ProposedViewSize(width: cw, height: h))214 }215 y += h + spacing216 }217 }218}219