Minor fixes

This commit is contained in:
Shaps Benkau 2023-02-06 09:33:23 +00:00
parent d619ce3a08
commit 1877ddf7e4
2 changed files with 17 additions and 18 deletions

View File

@ -96,8 +96,7 @@ private struct DynamicTypeRangeModifier: ViewModifier {
@Environment(\.backportDynamicTypeSize) private var size @Environment(\.backportDynamicTypeSize) private var size
private var resolvedSize: Backport<Any>.DynamicTypeSize { private var resolvedSize: Backport<Any>.DynamicTypeSize {
print(range) range.contains(size)
return range.contains(size)
? size ? size
: max(range.lowerBound, min(range.upperBound, size)) : max(range.lowerBound, min(range.upperBound, size))
} }

View File

@ -18,44 +18,44 @@ public extension Backport<Any> {
public extension Backport<Any>.ImageRenderer { public extension Backport<Any>.ImageRenderer {
var cgImage: CGImage? { var cgImage: CGImage? {
#if os(macOS) #if os(macOS)
nsImage?.cgImage(forProposedRect: nil, context: .current, hints: nil) nsImage?.cgImage(forProposedRect: nil, context: .current, hints: nil)
#else #else
uiImage?.cgImage uiImage?.cgImage
#endif #endif
} }
#if os(macOS) #if os(macOS)
var nsImage: NSImage? { var nsImage: NSImage? {
NSHostingController(rootView: content).view.snapshot NSHostingController(rootView: content).view.snapshot
} }
#else #else
var uiImage: UIImage? { var uiImage: UIImage? {
let controller = UIHostingController(rootView: content) let controller = UIHostingController(rootView: content)
let size = controller.view.intrinsicContentSize let size = controller.view.intrinsicContentSize
controller.view.bounds = CGRect(origin: .zero, size: size) controller.view.bounds = CGRect(origin: .zero, size: size)
controller.view.backgroundColor = .clear controller.view.backgroundColor = .clear
let format = UIGraphicsImageRendererFormat(for: controller.traitCollection) let format = UIGraphicsImageRendererFormat(for: controller.traitCollection)
format.opaque = isOpaque format.opaque = isOpaque
format.scale = scale format.scale = scale
let renderer = UIGraphicsImageRenderer(size: size, format: format) let renderer = UIGraphicsImageRenderer(size: size, format: format)
let image = renderer.image { context in let image = renderer.image { context in
controller.view.drawHierarchy(in: context.format.bounds, afterScreenUpdates: true) controller.view.drawHierarchy(in: context.format.bounds, afterScreenUpdates: true)
} }
image.accessibilityLabel = label image.accessibilityLabel = label
objectWillChange.send() objectWillChange.send()
return image return image
} }
#endif #endif
} }
#if os(iOS) #if os(iOS)