@@ -18,20 +18,8 @@ public enum RenderingError: Error {
1818import Foundation
1919import SwiftUI
2020import UIKit
21- import AccessibilitySnapshotCore
2221import SnapshotSharedModels
2322
24- extension AccessibilityMarker : AccessibilityMark {
25- public var accessibilityShape : MarkerShape {
26- switch shape {
27- case . frame( let frame) :
28- return . frame( frame)
29- case . path( let path) :
30- return . path( path)
31- }
32- }
33- }
34-
3523private var _colorScheme : ColorScheme ? = nil
3624
3725extension View {
@@ -59,6 +47,7 @@ extension View {
5947 controller: ExpandingViewController ,
6048 window: UIWindow ,
6149 async : Bool ,
50+ a11yWrapper: ( ( UIViewController , UIWindow , PreviewLayout ) -> UIView ) ? = nil ,
6251 completion: @escaping ( SnapshotResult ) -> Void )
6352 {
6453 controller. expansionSettled = { [ weak controller, weak window] renderingMode, precision, accessibilityEnabled, appStoreSnapshot, error in
@@ -68,44 +57,26 @@ extension View {
6857
6958 if let error {
7059 DispatchQueue . main. async {
71- completion ( SnapshotResult ( image: . failure( error) , precision: precision, accessibilityEnabled: accessibilityEnabled, accessibilityMarkers : nil , colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
60+ completion ( SnapshotResult ( image: . failure( error) , precision: precision, accessibilityEnabled: accessibilityEnabled, colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
7261 }
7362 return
7463 }
7564
7665 if async {
7766 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
7867 let imageResult = Self . takeSnapshot ( layout: layout, renderingMode: renderingMode, window: window, rootVC: containerVC, targetView: controller. view)
79- completion ( SnapshotResult ( image: imageResult. mapError { $0 } , precision: precision, accessibilityEnabled: accessibilityEnabled, accessibilityMarkers : nil , colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
68+ completion ( SnapshotResult ( image: imageResult. mapError { $0 } , precision: precision, accessibilityEnabled: accessibilityEnabled, colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
8069 }
8170 } else {
8271 DispatchQueue . main. async {
83- if let accessibilityEnabled, accessibilityEnabled {
84- let containedView : UIView
85- switch layout {
86- case . device:
87- containedView = containerVC. view
88- default :
89- containedView = controller. view
90- }
91- let mode = controller. view. bounds. size. requiresCoreAnimationSnapshot ? AccessibilitySnapshotView . ViewRenderingMode. renderLayerInContext : renderingMode? . a11yRenderingMode
92- let a11yView = AccessibilitySnapshotView (
93- containedView: containedView,
94- viewRenderingMode: mode ?? . drawHierarchyInRect,
95- activationPointDisplayMode: . never,
96- showUserInputLabels: true )
97-
98- a11yView. center = window. center
99- window. addSubview ( a11yView)
100-
101- let elements = try ? a11yView. parseAccessibility ( useMonochromeSnapshot: false )
102- a11yView. sizeToFit ( )
72+ if let a11yWrapper, let accessibilityEnabled, accessibilityEnabled {
73+ let a11yView = a11yWrapper ( controller, window, layout)
10374 let result = Self . takeSnapshot ( layout: . sizeThatFits, renderingMode: renderingMode, window: window, rootVC: containerVC, targetView: a11yView)
10475 a11yView. removeFromSuperview ( )
105- completion ( SnapshotResult ( image: result. mapError { $0 } , precision: precision, accessibilityEnabled: accessibilityEnabled, accessibilityMarkers : elements , colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
76+ completion ( SnapshotResult ( image: result. mapError { $0 } , precision: precision, accessibilityEnabled: accessibilityEnabled, colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
10677 } else {
10778 let imageResult = Self . takeSnapshot ( layout: layout, renderingMode: renderingMode, window: window, rootVC: containerVC, targetView: controller. view)
108- completion ( SnapshotResult ( image: imageResult. mapError { $0 } , precision: precision, accessibilityEnabled: accessibilityEnabled, accessibilityMarkers : nil , colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
79+ completion ( SnapshotResult ( image: imageResult. mapError { $0 } , precision: precision, accessibilityEnabled: accessibilityEnabled, colorScheme: _colorScheme, appStoreSnapshot: appStoreSnapshot) )
10980 }
11081 }
11182 }
@@ -223,17 +194,6 @@ extension UIView {
223194 }
224195}
225196
226- extension EmergeRenderingMode {
227- var a11yRenderingMode : AccessibilitySnapshotView . ViewRenderingMode {
228- switch self {
229- case . coreAnimation:
230- return . renderLayerInContext
231- case . window, . uiView:
232- return . drawHierarchyInRect
233- }
234- }
235- }
236-
237197extension CALayer {
238198
239199 var layerForSnapshot : Self {
0 commit comments