SPB Git

Repository Public

Effects.swift 5.4 KB 129 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Search iOS9// File             : Components/Effects.swift10// Description      : Liquid Glass surface with its fallbacks, and haptics that11//                    respect the app's switch.12// Module           : Components13// Repository       : https://git.spboucher.ai/sp-search-ios14// Project Website  : https://search.spboucher.ai15// Created          : 2026-12-0116// Last Modified    : 2026-12-0117//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 SwiftUI9192/// Liquid Glass where the system has it (iOS 26 and later), a plain material before, and an opaque surface with a93/// visible edge when the reader asked for less transparency. Used sparingly: the search field and the floating controls.94struct GlassSurface: ViewModifier {95    var cornerRadius: CGFloat = 1696    var interactive = false97    var edge: Color = Theme.rule98    @Environment(\.accessibilityReduceTransparency) private var reduceTransparency99100    func body(content: Content) -> some View {101        let shape = RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)102        if reduceTransparency {103            content.background(Theme.raised, in: shape).overlay(shape.stroke(Theme.ruleStrong, lineWidth: 1))104        } else if #available(iOS 26.0, *) {105            content.glassEffect(interactive ? .regular.interactive() : .regular, in: shape)106        } else {107            content.background(.regularMaterial, in: shape).overlay(shape.stroke(edge, lineWidth: 1))108        }109    }110}111112extension View {113    func glassSurface(cornerRadius: CGFloat = 16, interactive: Bool = false) -> some View {114        modifier(GlassSurface(cornerRadius: cornerRadius, interactive: interactive))115    }116117    /// A light tap when `trigger` changes, unless the reader switched haptics off in the app.118    func haptic<T: Equatable>(_ feedback: SensoryFeedback, trigger: T) -> some View { modifier(Haptic(feedback: feedback, trigger: trigger)) }119}120121struct Haptic<T: Equatable>: ViewModifier {122    let feedback: SensoryFeedback123    let trigger: T124    @Environment(AppSettings.self) private var settings125    func body(content: Content) -> some View {126        content.sensoryFeedback(trigger: trigger) { _, _ in settings.haptics ? feedback : nil }127    }128}129
Files main
Menu

Theme