@@ -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+
2080extension 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