Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/Features/Listing/Gallery.swift10// Description : galerie de photos de la fiche — carrousel et visionneuse11// plein écran avec zoom.12// Module : LouKa13// Repository : https://git.spboucher.ai/lou-ka-ios-v314// Project Website : https://www.lou-ka.com15// Created : 2026-11-2516// Last Modified : 2026-11-2817//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author : Simon-Pierre Boucher23// Position : Professor of Finance24// Institution : Université du Québec en Outaouais (UQO)25// Department : Département des sciences administratives26// Organization : SP Boucher27//28// Website : https://spboucher.ai29// Git : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General : info@spboucher.ai36// Professional : contact@spboucher.ai37// Direct : simon@spboucher.ai38// Research : research@spboucher.ai39// Development : dev@spboucher.ai40// Support : support@spboucher.ai41// Security/Admin : admin@spboucher.ai42// Notifications : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification : Public69// Distribution : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License : None specified (no license file in this repository)83// Maintainer : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI9192struct GalleryCarousel: View {93 let images: [String]94 let title: String95 @Binding var index: Int96 var onOpen: () -> Void9798 var body: some View {99 ZStack(alignment: .bottomTrailing) {100 if images.isEmpty {101 RemoteImage(source: nil)102 } else {103 TabView(selection: $index) {104 ForEach(Array(images.enumerated()), id: \.offset) { i, src in105 RemoteImage(source: src, width: .medium)106 .contentShape(Rectangle())107 .onTapGesture { onOpen() }108 .tag(i)109 }110 }111 .tabViewStyle(.page(indexDisplayMode: .never))112 Text("\(index + 1) / \(images.count)")113 .font(.caption.weight(.semibold)).num().foregroundStyle(.white)114 .padding(.horizontal, 10).padding(.vertical, 6)115 .background(.black.opacity(0.55), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))116 .padding(14)117 .accessibilityHidden(true)118 }119 }120 .accessibilityElement(children: .ignore)121 .accessibilityLabel(images.isEmpty ? "Aucune photo" : "Photos de \(title), \(index + 1) sur \(images.count)")122 .accessibilityAddTraits(images.isEmpty ? [] : .isButton)123 .accessibilityAction { if !images.isEmpty { onOpen() } }124 .accessibilityAdjustableAction { dir in125 switch dir {126 case .increment: index = min(images.count - 1, index + 1)127 case .decrement: index = max(0, index - 1)128 @unknown default: break129 }130 }131 }132}133134/// Visionneuse plein écran : glisser pour changer de photo, pincer ou toucher deux fois pour zoomer.135struct GalleryViewer: View {136 let images: [String]137 @Binding var index: Int138 @Environment(\.dismiss) private var dismiss139140 var body: some View {141 ZStack(alignment: .top) {142 Color.black.ignoresSafeArea()143 TabView(selection: $index) {144 ForEach(Array(images.enumerated()), id: \.offset) { i, src in145 ZoomableImage(source: src).tag(i)146 }147 }148 .tabViewStyle(.page(indexDisplayMode: .never))149 .ignoresSafeArea()150 HStack {151 Text("\(index + 1) / \(images.count)").font(.subheadline.weight(.semibold)).num().foregroundStyle(.white)152 .padding(.horizontal, 12).padding(.vertical, 7).background(.white.opacity(0.14), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))153 Spacer()154 Button { dismiss() } label: {155 Image(systemName: "xmark").font(.system(size: 15, weight: .bold)).foregroundStyle(.white)156 .frame(width: 40, height: 40).background(.white.opacity(0.14), in: Circle())157 }158 .accessibilityLabel("Fermer la galerie")159 }160 .padding(.horizontal, 16).padding(.top, 8)161 }162 .statusBarHidden()163 }164}165166private struct ZoomableImage: View {167 let source: String168 @State private var scale: CGFloat = 1169 @State private var base: CGFloat = 1170 @State private var offset: CGSize = .zero171 @State private var baseOffset: CGSize = .zero172173 var body: some View {174 RemoteImage(source: source, width: .large, contentMode: .fit)175 .background(Color.black)176 .scaleEffect(scale)177 .offset(offset)178 .gesture(179 MagnifyGesture()180 .onChanged { v in scale = min(5, max(1, base * v.magnification)) }181 .onEnded { _ in182 base = scale183 if scale <= 1.02 { withAnimation(.snappy) { reset() } }184 }185 )186 .simultaneousGesture(187 DragGesture(minimumDistance: scale > 1 ? 4 : 10_000)188 .onChanged { v in offset = CGSize(width: baseOffset.width + v.translation.width, height: baseOffset.height + v.translation.height) }189 .onEnded { _ in baseOffset = offset }190 )191 .onTapGesture(count: 2) {192 withAnimation(.snappy) {193 if scale > 1 { reset() } else { scale = 2.4; base = 2.4 }194 }195 }196 }197198 private func reset() {199 scale = 1; base = 1; offset = .zero; baseOffset = .zero200 }201}202