SPB Git

Repository Public

Gallery.swift 8.9 KB 214 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Immo-Ka iOS9// File             : ImmoKa/Features/Listing/Gallery.swift10// Description      : galerie de photos de la fiche — carrousel et visionneuse11//                    plein écran avec zoom.12// Module           : ImmoKa13// Repository       : https://git.spboucher.ai/immo-ka-ios-v314// Project Website  : https://www.immo-ka.com15// Created          : 2026-11-2516// Last Modified    : 2026-11-2517//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    /// légendes publiées par la source, dans l'ordre des photos (« Façade », « Cuisine »…)138    var captions: [String] = []139    @Binding var index: Int140    @Environment(\.dismiss) private var dismiss141142    var body: some View {143        ZStack(alignment: .top) {144            Color.black.ignoresSafeArea()145            TabView(selection: $index) {146                ForEach(Array(images.enumerated()), id: \.offset) { i, src in147                    ZoomableImage(source: src).tag(i)148                }149            }150            .tabViewStyle(.page(indexDisplayMode: .never))151            .ignoresSafeArea()152            HStack {153                Text("\(index + 1) / \(images.count)").font(.subheadline.weight(.semibold)).num().foregroundStyle(.white)154                    .padding(.horizontal, 12).padding(.vertical, 7).background(.white.opacity(0.14), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))155                Spacer()156                Button { dismiss() } label: {157                    Image(systemName: "xmark").font(.system(size: 15, weight: .bold)).foregroundStyle(.white)158                        .frame(width: 40, height: 40).background(.white.opacity(0.14), in: Circle())159                }160                .accessibilityLabel("Fermer la galerie")161            }162            .padding(.horizontal, 16).padding(.top, 8)163            if index < captions.count, !captions[index].isEmpty {164                Text(captions[index]).font(.subheadline.weight(.medium)).foregroundStyle(.white)165                    .padding(.horizontal, 12).padding(.vertical, 7)166                    .background(.black.opacity(0.55), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))167                    .frame(maxHeight: .infinity, alignment: .bottom).padding(.bottom, 28)168                    .id(index)169                    .transition(.opacity)170                    .accessibilityLabel("Légende : \(captions[index])")171            }172        }173        .animation(.easeOut(duration: 0.2), value: index)174        .statusBarHidden()175    }176}177178private struct ZoomableImage: View {179    let source: String180    @State private var scale: CGFloat = 1181    @State private var base: CGFloat = 1182    @State private var offset: CGSize = .zero183    @State private var baseOffset: CGSize = .zero184185    var body: some View {186        RemoteImage(source: source, width: .large, contentMode: .fit)187            .background(Color.black)188            .scaleEffect(scale)189            .offset(offset)190            .gesture(191                MagnifyGesture()192                    .onChanged { v in scale = min(5, max(1, base * v.magnification)) }193                    .onEnded { _ in194                        base = scale195                        if scale <= 1.02 { withAnimation(.snappy) { reset() } }196                    }197            )198            .simultaneousGesture(199                DragGesture(minimumDistance: scale > 1 ? 4 : 10_000)200                    .onChanged { v in offset = CGSize(width: baseOffset.width + v.translation.width, height: baseOffset.height + v.translation.height) }201                    .onEnded { _ in baseOffset = offset }202            )203            .onTapGesture(count: 2) {204                withAnimation(.snappy) {205                    if scale > 1 { reset() } else { scale = 2.4; base = 2.4 }206                }207            }208    }209210    private func reset() {211        scale = 1; base = 1; offset = .zero; baseOffset = .zero212    }213}214
Files main
Menu

Theme