33// OpenSwiftUICore
44//
55// Audited for 6.5.4
6- // Status: WIP
6+ // Status: Complete
77// ID: 34FFA2034B9AD53E0463E3971529C5A1 (SwiftUICore)
88
99package import OpenCoreGraphicsShims
10- import OpenAttributeGraphShims
10+ package import OpenAttributeGraphShims
1111
1212// MARK: - _OpacityEffect
1313
@@ -55,6 +55,11 @@ public struct _OpacityEffect: RendererEffect, Equatable {
5555 )
5656 )
5757 }
58+ inputs . opacityAccessibilityProvider . makeOpacity (
59+ effect : modifier . value ,
60+ inputs : inputs ,
61+ outputs : & outputs
62+ )
5863 return outputs
5964 }
6065 }
@@ -93,7 +98,7 @@ extension View {
9398 ///
9499 /// 
101+ /// visible.](OpenSwiftUI-View-opacity)
97102 ///
98103 /// - Parameter opacity: A value between 0 (fully transparent) and 1 (fully
99104 /// opaque).
@@ -215,17 +220,141 @@ extension _OpacityEffect: ProtobufMessage {
215220
216221// MARK: - ShapeStyle + _OpacityShapeStyle
217222
218- // TODO: _OpacityShapeStyle
223+ @ available ( OpenSwiftUI_v4_0 , * )
224+ extension ShapeStyle where Self == AnyShapeStyle {
225+ /// Returns a new style based on the current style that multiplies
226+ /// by `opacity` when drawing.
227+ ///
228+ /// In most contexts the current style is the foreground but e.g.
229+ /// when setting the value of the background style, that becomes
230+ /// the current implicit style.
231+ ///
232+ /// For example, a circle filled with the current foreground
233+ /// style at fifty-percent opacity:
234+ ///
235+ /// Circle().fill(.opacity(0.5))
236+ ///
237+ @ _alwaysEmitIntoClient
238+ public static func opacity ( _ opacity : Double ) -> some ShapeStyle {
239+ _OpacityShapeStyle ( style : _ImplicitShapeStyle ( ) , opacity : Float ( opacity ) )
240+ }
241+ }
242+
243+ // MARK: - _OpacityShapeStyle
244+
245+ @ available ( OpenSwiftUI_v3_0 , * )
246+ @ frozen
247+ public struct _OpacityShapeStyle < Style > : ShapeStyle , PrimitiveShapeStyle where Style : ShapeStyle {
248+ public var style : Style
249+
250+ public var opacity : Float
251+
252+ @ inlinable
253+ public init ( style : Style , opacity : Float ) {
254+ self . style = style
255+ self . opacity = opacity
256+ }
257+
258+ public func _apply ( to shape : inout _ShapeStyle_Shape ) {
259+ guard opacity != 1 else {
260+ style . _apply ( to : & shape )
261+ return
262+ }
263+ switch shape . operation {
264+ case . prepareText :
265+ shape . result = . preparedText ( . foregroundKeyColor )
266+ case let . resolveStyle ( name , levels ) :
267+ style . _apply ( to : & shape )
268+ shape . stylePack . modify ( name : name , levels : levels ) { style in
269+ style . applyOpacity ( opacity )
270+ }
271+ case . fallbackColor :
272+ style . _apply ( to : & shape )
273+ if case let . color ( color ) = shape . result {
274+ shape . result = . color ( color . opacity ( Double ( opacity ) ) )
275+ }
276+ case . copyStyle :
277+ style . mapCopiedStyle ( in : & shape ) { style in
278+ _OpacityShapeStyle < AnyShapeStyle > ( style : style , opacity : opacity )
279+ }
280+ case . modifyBackground , . multiLevel :
281+ style . _apply ( to : & shape )
282+ case . primaryStyle :
283+ break
284+ }
285+ }
219286
220- // TODO: _OpacitiesShapeStyle
287+ public static func _apply ( to type : inout _ShapeStyle_ShapeType ) {
288+ Style . _apply ( to : & type )
289+ }
290+ }
291+
292+ // MARK: - _OpacitiesShapeStyle
293+
294+ @ _spi ( Private )
295+ @ available ( OpenSwiftUI_v3_0 , * )
296+ @ frozen
297+ public struct _OpacitiesShapeStyle < Style > : ShapeStyle , PrimitiveShapeStyle where Style : ShapeStyle {
298+ public var style : Style
299+
300+ public var opacities : [ Double ]
301+
302+ @ inlinable
303+ public init ( style : Style , opacities : [ Double ] ) {
304+ self . style = style
305+ self . opacities = opacities
306+ }
307+
308+ public func _apply ( to shape : inout _ShapeStyle_Shape ) {
309+ switch shape . operation {
310+ case . prepareText :
311+ shape . result = . preparedText ( . foregroundKeyColor )
312+ case let . resolveStyle ( name , levels ) :
313+ shape . operation = . resolveStyle ( name : name , levels : 0 ..< 1 )
314+ style . _apply ( to : & shape )
315+ let style = shape . stylePack [ name , 0 ]
316+ for level in levels {
317+ let index = min ( level , opacities . count - 1 )
318+ let opacity = index >= 0 ? opacities [ index ] : 1.0
319+ shape . stylePack [ name , level ] = style . applyingOpacity ( Float ( opacity ) )
320+ }
321+ case let . fallbackColor ( level ) :
322+ shape . operation = . fallbackColor ( level : 0 )
323+ style . _apply ( to : & shape )
324+ if case let . color ( color ) = shape . result {
325+ let index = min ( level , opacities . count - 1 )
326+ let opacity = index >= 0 ? opacities [ index ] : 1.0
327+ shape . result = . color ( color . opacity ( opacity ) )
328+ }
329+ case . copyStyle :
330+ style . mapCopiedStyle ( in : & shape ) { style in
331+ _OpacitiesShapeStyle < AnyShapeStyle > ( style : style , opacities : opacities )
332+ }
333+ case . modifyBackground :
334+ style . _apply ( to : & shape )
335+ case . multiLevel :
336+ shape . result = . bool ( true )
337+ case . primaryStyle :
338+ break
339+ }
340+ }
341+
342+ public static func _apply ( to type : inout _ShapeStyle_ShapeType ) {
343+ Style . _apply ( to : & type )
344+ }
345+ }
221346
222347// MARK: - OpacityTransition
223348
224349/// A transition from transparent to opaque on insertion, and from opaque to
225350/// transparent on removal.
226351@ available ( OpenSwiftUI_v5_0 , * )
352+ @ MainActor
353+ @ preconcurrency
227354public struct OpacityTransition : Transition {
228- public init ( ) { }
355+ public init ( ) {
356+ _openSwiftUIEmptyStub ( )
357+ }
229358
230359 public func body (
231360 content : OpacityTransition . Content ,
@@ -276,7 +405,7 @@ struct OpacityResponderFilter: StatefulRule {
276405
277406// MARK: - OpacityAccessibilityProvider
278407
279- protocol OpacityAccessibilityProvider {
408+ package protocol OpacityAccessibilityProvider {
280409 static func makeOpacity (
281410 effect : @autoclosure ( ) -> Attribute < _OpacityEffect > ,
282411 inputs : _ViewInputs ,
@@ -300,17 +429,17 @@ struct EmptyOpacityAccessibilityProvider: OpacityAccessibilityProvider {
300429
301430extension _GraphInputs {
302431 private struct OpacityAccessibilityProviderKey : GraphInput {
303- static let defaultValue : OpacityAccessibilityProvider . Type = EmptyOpacityAccessibilityProvider . self
432+ static let defaultValue : ( any OpacityAccessibilityProvider . Type ) = EmptyOpacityAccessibilityProvider . self
304433 }
305434
306- var opacityAccessibilityProvider : OpacityAccessibilityProvider . Type {
435+ package var opacityAccessibilityProvider : ( any OpacityAccessibilityProvider . Type ) {
307436 get { self [ OpacityAccessibilityProviderKey . self ] }
308437 set { self [ OpacityAccessibilityProviderKey . self ] = newValue }
309438 }
310439}
311440
312441extension _ViewInputs {
313- var opacityAccessibilityProvider : OpacityAccessibilityProvider . Type {
442+ package var opacityAccessibilityProvider : ( any OpacityAccessibilityProvider . Type ) {
314443 get { base . opacityAccessibilityProvider }
315444 set { base . opacityAccessibilityProvider = newValue }
316445 }
0 commit comments