Repository Public
1//2// Auto-Ka iOS v23// File: AutoKa/Features/Vehicle/Gallery.swift4// Description: galerie d'une fiche — carrousel de tête (balayage) et visionneuse plein écran (balayage,5// pincement, double toucher).6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9//1011import SwiftUI1213struct GalleryCarousel: View {14 let images: [String]15 let title: String16 var placeholder: String = "ic-berline"17 @Binding var index: Int18 var onOpen: () -> Void1920 var body: some View {21 ZStack(alignment: .bottomTrailing) {22 if images.isEmpty {23 RemoteImage(source: nil, placeholder: placeholder)24 } else if images.count == 1 {25 // une seule photo (la moitié des annonces) : pas de carrousel26 RemoteImage(source: images[0], width: .large, placeholder: placeholder)27 .contentShape(Rectangle())28 .onTapGesture { onOpen() }29 } else {30 TabView(selection: $index) {31 ForEach(Array(images.enumerated()), id: \.offset) { i, src in32 RemoteImage(source: src, width: i == 0 ? .large : .medium, placeholder: placeholder)33 .contentShape(Rectangle())34 .onTapGesture { onOpen() }35 .tag(i)36 }37 }38 .tabViewStyle(.page(indexDisplayMode: .never))39 Text("\(index + 1) / \(images.count)")40 .font(.caption.weight(.semibold)).num().foregroundStyle(Theme.ink)41 .padding(.horizontal, 8).padding(.vertical, 5)42 .background(Theme.surface.opacity(0.94), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))43 .padding(10)44 .accessibilityHidden(true)45 }46 }47 .accessibilityElement(children: .ignore)48 .accessibilityLabel(images.isEmpty ? "Aucune photo" : "Photos de \(title), \(index + 1) sur \(images.count)")49 .accessibilityAddTraits(images.isEmpty ? [] : .isButton)50 .accessibilityHint(images.isEmpty ? "" : "Ouvre la galerie en plein écran")51 .accessibilityAction { if !images.isEmpty { onOpen() } }52 .accessibilityAdjustableAction { dir in53 switch dir {54 case .increment: index = min(images.count - 1, index + 1)55 case .decrement: index = max(0, index - 1)56 @unknown default: break57 }58 }59 .accessibilityIdentifier("galerie")60 }61}6263/// Visionneuse plein écran : glisser pour changer de photo, pincer ou toucher deux fois pour zoomer.64struct GalleryViewer: View {65 let images: [String]66 @Binding var index: Int67 @Environment(\.dismiss) private var dismiss6869 var body: some View {70 ZStack(alignment: .top) {71 Color.black.ignoresSafeArea()72 TabView(selection: $index) {73 ForEach(Array(images.enumerated()), id: \.offset) { i, src in74 ZoomableImage(source: src).tag(i)75 }76 }77 .tabViewStyle(.page(indexDisplayMode: .never))78 .ignoresSafeArea()79 HStack {80 Text("\(index + 1) / \(images.count)").font(.subheadline.weight(.semibold)).num().foregroundStyle(.white)81 .padding(.horizontal, 12).padding(.vertical, 7)82 .background(Color(white: 0.16), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))83 Spacer()84 Button { dismiss() } label: {85 Image(systemName: "xmark").font(.system(size: 15, weight: .bold)).foregroundStyle(.white)86 .frame(width: 44, height: 44).background(Color(white: 0.16), in: RoundedRectangle(cornerRadius: Theme.radiusControl, style: .continuous))87 }88 .accessibilityLabel("Fermer la galerie")89 }90 .padding(.horizontal, 16).padding(.top, 8)91 }92 .statusBarHidden()93 }94}9596private struct ZoomableImage: View {97 let source: String98 @State private var scale: CGFloat = 199 @State private var base: CGFloat = 1100 @State private var offset: CGSize = .zero101 @State private var baseOffset: CGSize = .zero102103 var body: some View {104 RemoteImage(source: source, width: .large, contentMode: .fit)105 .background(Color.black)106 .scaleEffect(scale)107 .offset(offset)108 .gesture(109 MagnifyGesture()110 .onChanged { v in scale = min(5, max(1, base * v.magnification)) }111 .onEnded { _ in112 base = scale113 if scale <= 1.02 { withAnimation(.snappy) { reset() } }114 }115 )116 .simultaneousGesture(117 DragGesture(minimumDistance: scale > 1 ? 4 : 10_000)118 .onChanged { v in offset = CGSize(width: baseOffset.width + v.translation.width, height: baseOffset.height + v.translation.height) }119 .onEnded { _ in baseOffset = offset }120 )121 .onTapGesture(count: 2) {122 withAnimation(.snappy) {123 if scale > 1 { reset() } else { scale = 2.4; base = 2.4 }124 }125 }126 .accessibilityLabel("Photo")127 }128129 private func reset() {130 scale = 1; base = 1; offset = .zero; baseOffset = .zero131 }132}133