Skip to content

Commit c9dbf76

Browse files
committed
fix: add legacy glass fallback surfaces
Provide a shared pre-iOS 26/macOS 26/tvOS 26 fallback for glass-style buttons and glassEffect surfaces so overlay controls remain readable on older systems. Also update the UIKit end-page close button path to use a matching background treatment, including reduce-transparency fallbacks.
1 parent 8d2832c commit c9dbf76

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed

KMReader/Features/Reader/Views/EndPageCloseButtonStyle.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,27 @@
2020
return .glass()
2121
}
2222
#endif
23-
return .bordered()
23+
var configuration = UIButton.Configuration.bordered()
24+
var background = UIBackgroundConfiguration.clear()
25+
#if os(iOS)
26+
if UIAccessibility.isReduceTransparencyEnabled {
27+
background.backgroundColor = .systemBackground.withAlphaComponent(0.96)
28+
background.strokeColor = UIColor.label.withAlphaComponent(0.12)
29+
} else {
30+
background.visualEffect = UIBlurEffect(style: .systemMaterial)
31+
background.strokeColor = UIColor.white.withAlphaComponent(0.24)
32+
}
33+
#elseif os(tvOS)
34+
background.backgroundColor = UIColor.black.withAlphaComponent(
35+
UIAccessibility.isReduceTransparencyEnabled ? 0.92 : 0.76
36+
)
37+
background.strokeColor = UIColor.white.withAlphaComponent(
38+
UIAccessibility.isReduceTransparencyEnabled ? 0.18 : 0.24
39+
)
40+
#endif
41+
background.strokeWidth = 1
42+
configuration.background = background
43+
return configuration
2444
}
2545

2646
private static var buttonSymbolConfiguration: UIImage.SymbolConfiguration {

KMReader/Shared/Extensions/View+ButtonStyle.swift

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,66 @@ enum GlassEffectType {
1717
case regular
1818
}
1919

20+
private struct LegacyGlassSurfaceModifier<SurfaceShape: Shape>: ViewModifier {
21+
@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
22+
23+
let type: GlassEffectType
24+
let shape: SurfaceShape
25+
26+
func body(content: Content) -> some View {
27+
content
28+
.background(backgroundStyle, in: shape)
29+
.overlay {
30+
shape
31+
.stroke(borderColor, lineWidth: reduceTransparency ? 1 : 0.8)
32+
}
33+
.shadow(
34+
color: reduceTransparency ? .clear : .black.opacity(type == .clear ? 0.08 : 0.14),
35+
radius: type == .clear ? 4 : 8,
36+
x: 0,
37+
y: 2
38+
)
39+
}
40+
41+
private var backgroundStyle: AnyShapeStyle {
42+
if reduceTransparency {
43+
return AnyShapeStyle(reducedTransparencyColor)
44+
}
45+
46+
switch type {
47+
case .clear:
48+
return AnyShapeStyle(.ultraThinMaterial)
49+
case .regular:
50+
return AnyShapeStyle(.regularMaterial)
51+
}
52+
}
53+
54+
private var borderColor: Color {
55+
if reduceTransparency {
56+
return .primary.opacity(0.12)
57+
}
58+
59+
switch type {
60+
case .clear:
61+
return .white.opacity(0.18)
62+
case .regular:
63+
return .white.opacity(0.24)
64+
}
65+
}
66+
67+
private var reducedTransparencyColor: Color {
68+
#if os(iOS)
69+
return type == .clear ? Color(.secondarySystemBackground) : Color(.systemBackground)
70+
#elseif os(tvOS)
71+
return type == .clear ? Color.black.opacity(0.84) : Color.black.opacity(0.92)
72+
#elseif os(macOS)
73+
return type == .clear ? Color(NSColor.windowBackgroundColor) : Color(NSColor.controlBackgroundColor)
74+
#else
75+
return .gray
76+
#endif
77+
}
78+
}
79+
2080
extension View {
2181
@ViewBuilder
2282
func adaptiveButtonStyle(_ style: AdaptiveButtonStyleType) -> some View {
@@ -48,9 +108,13 @@ extension View {
48108
case .borderedProminent:
49109
self.buttonStyle(.borderedProminent)
50110
case .bordered:
51-
self.buttonStyle(.bordered)
111+
self
112+
.buttonStyle(.bordered)
113+
.legacyGlassSurface(.regular, in: ButtonBorderShape.buttonBorder)
52114
case .borderless:
53-
self.buttonStyle(.borderless)
115+
self
116+
.buttonStyle(.borderless)
117+
.legacyGlassSurface(.regular, in: ButtonBorderShape.buttonBorder)
54118
case .plain:
55119
#if os(tvOS)
56120
self.buttonStyle(.card)
@@ -74,7 +138,7 @@ extension View {
74138
case .regular: self.glassEffect(.regular)
75139
}
76140
} else {
77-
self
141+
self.legacyGlassSurface(type, in: RoundedRectangle(cornerRadius: 16, style: .continuous))
78142
}
79143
} else {
80144
self
@@ -92,10 +156,14 @@ extension View {
92156
case .regular: self.glassEffect(.regular, in: shape)
93157
}
94158
} else {
95-
self
159+
self.legacyGlassSurface(type, in: shape)
96160
}
97161
} else {
98162
self
99163
}
100164
}
165+
166+
private func legacyGlassSurface<S: Shape>(_ type: GlassEffectType, in shape: S) -> some View {
167+
modifier(LegacyGlassSurfaceModifier(type: type, shape: shape))
168+
}
101169
}

0 commit comments

Comments
 (0)