SPB Git

Repository Public MIT

GlassAccessibilityOverrides.swift 3.7 KB 93 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Sources/SPGlassCore/GlassAccessibilityOverrides.swift8// Module           : SPGlassCore9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI4243/// Simulated accessibility settings for previews and the Studio.44///45/// These values never change the device configuration. A `nil` field means "follow the system". Components46/// read the effective value through ``GlassAccessibility``, which combines the simulation with the real setting.47public struct GlassAccessibilityOverrides: Equatable, Sendable {48    public var reduceTransparency: Bool?49    public var reduceMotion: Bool?5051    public init(reduceTransparency: Bool? = nil, reduceMotion: Bool? = nil) {52        self.reduceTransparency = reduceTransparency53        self.reduceMotion = reduceMotion54    }5556    public static let none = GlassAccessibilityOverrides()57}5859extension EnvironmentValues {60    /// Simulated accessibility settings applied to a subtree. Defaults to no simulation.61    @Entry public var glassAccessibilityOverrides: GlassAccessibilityOverrides = .none62}6364/// Effective accessibility settings: the simulated value when one is set, otherwise the system value.65@MainActor66@propertyWrapper67public struct GlassAccessibility: DynamicProperty {68    @Environment(\.accessibilityReduceTransparency) private var systemReduceTransparency69    @Environment(\.accessibilityReduceMotion) private var systemReduceMotion70    @Environment(\.glassAccessibilityOverrides) private var overrides7172    public init() {}7374    public var wrappedValue: Values {75        Values(76            reduceTransparency: overrides.reduceTransparency ?? systemReduceTransparency,77            reduceMotion: overrides.reduceMotion ?? systemReduceMotion78        )79    }8081    public struct Values: Equatable, Sendable {82        public let reduceTransparency: Bool83        public let reduceMotion: Bool84    }85}8687extension View {88    /// Simulates accessibility settings for this subtree without touching the system configuration.89    public func glassSimulatedAccessibility(reduceTransparency: Bool? = nil, reduceMotion: Bool? = nil) -> some View {90        environment(\.glassAccessibilityOverrides, GlassAccessibilityOverrides(reduceTransparency: reduceTransparency, reduceMotion: reduceMotion))91    }92}93
Files main
Menu

Theme