Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Valo-Plex iOS9// File : ValoPlex/App/Racine.swift10// Description : structure de l'application : cinq onglets, barre d'onglets11// et en-tête dessinés (papier et filets, sans matériau12// translucide du système), gabarit d'écran commun.13// Module : ValoPlex14// Repository : https://git.spboucher.ai/valo-plex-ios15// Project Website : https://www.valo-plex.com16// Created : 2026-12-0117// Last Modified : 2026-12-0118//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author : Simon-Pierre Boucher24// Position : Professor of Finance25// Institution : Université du Québec en Outaouais (UQO)26// Department : Département des sciences administratives27// Organization : SP Boucher28//29// Website : https://spboucher.ai30// Git : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General : info@spboucher.ai37// Professional : contact@spboucher.ai38// Direct : simon@spboucher.ai39// Research : research@spboucher.ai40// Development : dev@spboucher.ai41// Support : support@spboucher.ai42// Security/Admin : admin@spboucher.ai43// Notifications : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification : Public70// Distribution : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License : None specified (no license file in this repository)84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import SwiftUI9293struct Racine: View {94 @Environment(Navigation.self) private var navigation95 @State private var visites: Set<Onglet> = []96 @State private var clavier = false97 @State private var ouverture = true9899 var body: some View {100 ZStack {101 interface102 if ouverture, !navigation.sansOuverture {103 Ouverture(fige: navigation.ouvertureFigee)104 .transition(.opacity)105 .zIndex(1)106 }107 }108 .task {109 // le geste de la marque dure 1,2 s ; l'interface se charge dessous pendant ce temps110 guard navigation.ouvertureFigee == nil else { return }111 try? await Task.sleep(for: .milliseconds(1500))112 withAnimation(.easeOut(duration: 0.24)) { ouverture = false }113 }114 }115116 private var interface: some View {117 VStack(spacing: 0) {118 ZStack {119 // un onglet n'est construit qu'à sa première visite, puis garde son état120 ForEach(Onglet.allCases) { o in121 if visites.contains(o) || navigation.onglet == o {122 Pile(onglet: o)123 .opacity(navigation.onglet == o ? 1 : 0)124 .allowsHitTesting(navigation.onglet == o)125 .accessibilityHidden(navigation.onglet != o)126 }127 }128 }129 if clavier { BarreClavier() } else { BarreOnglets() }130 }131 .background(VX.papier.ignoresSafeArea())132 .onAppear { visites.insert(navigation.onglet) }133 .onChange(of: navigation.onglet) { _, o in visites.insert(o) }134 .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) { _ in clavier = true }135 .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)) { _ in clavier = false }136 }137}138139private struct Pile: View {140 let onglet: Onglet141 @Environment(Navigation.self) private var navigation142143 var body: some View {144 @Bindable var navigation = navigation145 NavigationStack(path: Binding(get: { navigation.chemin(onglet) }, set: { navigation.chemins[onglet] = $0 })) {146 Group {147 switch onglet {148 case .recherche: AccueilVue()149 case .carte: CarteVue()150 case .annonces: AnnoncesVue()151 case .marche: MarcheVue()152 case .calcul: CalculateurEcran(depart: .exemple, racine: true)153 case .methode: MethodeVue()154 }155 }156 .toolbar(.hidden, for: .navigationBar)157 .navigationDestination(for: Route.self) { route in158 Group {159 switch route {160 case .immeuble(let id): FicheVue(id: id)161 case .region(let cle): RegionVue(cle: cle)162 case .calculateur(let depart): CalculateurEcran(depart: depart, racine: false)163 case .cadre(let c): CadreVue(cadre: c)164 }165 }166 .toolbar(.hidden, for: .navigationBar)167 }168 }169 }170}171172/// Ouverture : sur le papier, la marque se bâtit (mur, toit, puis les quatre ouvertures), le nom dessous.173private struct Ouverture: View {174 var fige: Double? = nil175176 var body: some View {177 VStack(spacing: 18) {178 Marque(taille: 96, anime: true, fige: fige)179 Text("Valo-Plex").font(.serif(26, .demiGras, style: .title)).foregroundStyle(VX.encre)180 }181 .frame(maxWidth: .infinity, maxHeight: .infinity)182 .background(VX.papier.ignoresSafeArea())183 .accessibilityElement(children: .ignore)184 .accessibilityLabel("Valo-Plex")185 }186}187188/// Pendant la saisie, la barre d'onglets cède la place à un bouton qui referme le clavier189/// (les pavés numériques n'ont pas de touche de retour).190private struct BarreClavier: View {191 var body: some View {192 VStack(spacing: 0) {193 Filet(couleur: VX.encre)194 HStack {195 Spacer()196 Button {197 UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)198 } label: {199 Etiquette("Terminé", couleur: VX.encre).padding(.horizontal, VX.marge).frame(height: 42).contentShape(Rectangle())200 }201 .buttonStyle(.plain)202 .accessibilityLabel("Terminé")203 .accessibilityIdentifier("clavier-termine")204 }205 }206 .background(VX.papier)207 }208}209210private struct BarreOnglets: View {211 @Environment(Navigation.self) private var navigation212213 var body: some View {214 VStack(spacing: 0) {215 Filet(couleur: VX.encre)216 HStack(spacing: 0) {217 ForEach(Onglet.allCases) { o in218 let actif = navigation.onglet == o219 Button {220 navigation.choisir(o)221 } label: {222 VStack(spacing: 7) {223 Rectangle().fill(actif ? VX.brique : Color.clear).frame(height: 3)224 Text(o.libelle.uppercased())225 .font(.custom("IBMPlexMono-Medium", fixedSize: 10))226 .tracking(0.3)227 .foregroundStyle(actif ? VX.encre : VX.encre2)228 .lineLimit(1)229 .minimumScaleFactor(0.8)230 Spacer(minLength: 0)231 }232 .frame(maxWidth: .infinity)233 .frame(height: 46)234 .contentShape(Rectangle())235 }236 .buttonStyle(.plain)237 .accessibilityLabel(o.libelle)238 .accessibilityAddTraits(actif ? [.isSelected, .isButton] : .isButton)239 .accessibilityIdentifier("onglet-\(o.rawValue)")240 }241 }242 .frame(maxWidth: 700)243 .frame(maxWidth: .infinity)244 }245 .background(VX.papier.ignoresSafeArea(edges: .bottom))246 }247}248249/// Gabarit d'écran : en-tête à filet d'encre (marque à la racine, retour ailleurs), contenu défilant sur papier,250/// largeur de lecture bornée sur iPad.251struct Ecran<Contenu: View, Actions: View>: View {252 var racine = false253 var titre: String? = nil254 var largeur: CGFloat = VX.largeur255 /// Identifiant d'une section vers laquelle défiler une fois le contenu en place.256 var ancre: String? = nil257 @ViewBuilder var actions: () -> Actions258 @ViewBuilder var contenu: () -> Contenu259260 @Environment(\.dismiss) private var fermer261262 var body: some View {263 VStack(spacing: 0) {264 HStack(spacing: 12) {265 if racine {266 Marque(taille: 26)267 Text("Valo-Plex").font(.serif(20, .demiGras, style: .headline)).foregroundStyle(VX.encre)268 } else {269 Button {270 fermer()271 } label: {272 HStack(spacing: 8) {273 Fleche().stroke(VX.encre, lineWidth: 1.5).frame(width: 7, height: 12)274 Etiquette("Retour", couleur: VX.encre)275 }276 .frame(minHeight: 44)277 .contentShape(Rectangle())278 }279 .buttonStyle(.plain)280 .accessibilityLabel("Retour")281 }282 Spacer(minLength: 8)283 if let titre, !racine {284 Text(titre).font(.sans(14, .moyen, style: .subheadline)).foregroundStyle(VX.encre2).lineLimit(1)285 Spacer(minLength: 8)286 }287 actions()288 }289 .padding(.horizontal, VX.marge)290 .frame(height: 52)291 .frame(maxWidth: largeur + 2 * VX.marge)292 .frame(maxWidth: .infinity)293 Filet(couleur: VX.encre)294 ScrollViewReader { lecteur in295 ScrollView {296 VStack(alignment: .leading, spacing: 0) {297 contenu()298 }299 .frame(maxWidth: largeur, alignment: .leading)300 .padding(.horizontal, VX.marge)301 .padding(.bottom, 56)302 .frame(maxWidth: .infinity)303 }304 .scrollDismissesKeyboard(.immediately)305 .task(id: ancre) {306 guard let ancre else { return }307 try? await Task.sleep(for: .milliseconds(700))308 lecteur.scrollTo(ancre, anchor: .top)309 }310 }311 }312 .background(VX.papier.ignoresSafeArea())313 }314}315316extension Ecran where Actions == EmptyView {317 init(racine: Bool = false, titre: String? = nil, largeur: CGFloat = VX.largeur, ancre: String? = nil, @ViewBuilder contenu: @escaping () -> Contenu) {318 self.init(racine: racine, titre: titre, largeur: largeur, ancre: ancre, actions: { EmptyView() }, contenu: contenu)319 }320}321322/// Chevron de retour, tracé au trait.323struct Fleche: Shape {324 func path(in r: CGRect) -> Path {325 var p = Path()326 p.move(to: CGPoint(x: r.maxX, y: r.minY))327 p.addLine(to: CGPoint(x: r.minX, y: r.midY))328 p.addLine(to: CGPoint(x: r.maxX, y: r.maxY))329 return p330 }331}332333/// Grand titre d'écran : étiquette, titre en serif, chapeau.334struct TitreEcran: View {335 let etiquette: String336 let titre: String337 var chapeau: String? = nil338339 var body: some View {340 VStack(alignment: .leading, spacing: 10) {341 Etiquette(etiquette)342 Text(titre)343 .font(.serif(31, style: .largeTitle))344 .foregroundStyle(VX.encre)345 .fixedSize(horizontal: false, vertical: true)346 .accessibilityAddTraits(.isHeader)347 if let chapeau {348 Text(chapeau).font(.sans(17)).foregroundStyle(VX.encre2).fixedSize(horizontal: false, vertical: true).padding(.top, 4)349 }350 }351 .padding(.top, 28)352 }353}354