Open looneytsci opened 1 year ago
PS this is for SwiftUI project
I can make a snapshot of a Alert using this code below, propably it'll work to sheets @looneytsci
extension Snapshotting where Value: UIViewController, Format == UIImage {
public static func windowedImage(interfaceStyle: UIUserInterfaceStyle = .unspecified,
precision: Float = 0.98,
perceptualPrecision: Float = 1) -> Snapshotting {
return Snapshotting<UIImage, UIImage>.image(
precision: precision,
perceptualPrecision: perceptualPrecision,
scale: nil
).asyncPullback { viewController in
Async<UIImage> { callback in
UIView.setAnimationsEnabled(false)
let window = UIApplication.shared.windows.first!
window.rootViewController = viewController
window.windowScene?.traitOverrides.userInterfaceStyle = interfaceStyle
DispatchQueue.main.async {
let image = UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
}
callback(image)
UIView.setAnimationsEnabled(true)
}
}
}
}
}
Im facing the same issue. The code above doesn't snapshot a sheet.
I'm trying to make a snapshot for a view, which can open bottomSheet via .fullScreenCover and transparent background. Looks like It captures only the view layer without bottomSheet layer. Can I make the snapshot of the full view hierarchy? Or can I implement some custom snapshotting strategy with modal screen capturing?