forked from shaps80/SwiftUIBackports
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a bug where
inspect
couldn't find some scrollviews
Fixes a bug where parentController could result in an infinite loop Disabling scrolling now works as expected Introduces preliminary ShareLink API + ActivityView API for showing the sheet Label now correctly drops the text in navigation bar contexts Various demo updates
- Loading branch information
Showing
17 changed files
with
655 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Sources/SwiftUIBackports/Shared/ImageRenderer/ProposedViewSize.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import SwiftUI | ||
|
||
public struct ProposedViewSize: Equatable, Sendable { | ||
public var width: CGFloat? | ||
public var height: CGFloat? | ||
|
||
public static let zero = Self(width: 0, height: 0) | ||
public static let infinity = Self(width: .infinity, height: .infinity) | ||
public static let unspecified = Self(width: nil, height: nil) | ||
|
||
public init(_ size: CGSize) { | ||
self.width = size.width | ||
self.height = size.height | ||
} | ||
|
||
public init(width: CGFloat?, height: CGFloat?) { | ||
self.width = width | ||
self.height = height | ||
} | ||
|
||
public func replacingUnspecifiedDimensions(by size: CGSize) -> CGSize { | ||
.init( | ||
width: width ?? size.width, | ||
height: height ?? size.height | ||
) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Sources/SwiftUIBackports/Shared/ImageRenderer/Renderer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import SwiftUI | ||
|
||
public final class ImageRenderer<Content>: ObservableObject where Content: View { | ||
public var content: Content | ||
public var label: String? | ||
public var proposedSize: ProposedViewSize = .unspecified | ||
public var scale: CGFloat = UIScreen.main.scale | ||
public var isOpaque: Bool = false | ||
public var colorMode: ColorRenderingMode = .nonLinear | ||
|
||
public init(content: Content) { | ||
self.content = content | ||
} | ||
} | ||
|
||
//public extension ImageRenderer { | ||
// func render(rasterizationScale: CGFloat = 1, renderer: (CGSize, (CGContext) -> Void) -> Void) { | ||
// | ||
// } | ||
//} | ||
|
||
public extension ImageRenderer { | ||
var cgImage: CGImage? { | ||
#if os(macOS) | ||
nsImage?.cgImage | ||
#else | ||
uiImage?.cgImage | ||
#endif | ||
} | ||
|
||
#if os(macOS) | ||
|
||
var nsImage: NSImage? { | ||
nil | ||
} | ||
|
||
#else | ||
|
||
var uiImage: UIImage? { | ||
let controller = UIHostingController(rootView: content) | ||
let size = controller.view.intrinsicContentSize | ||
controller.view.bounds = CGRect(origin: .zero, size: size) | ||
controller.view.backgroundColor = .clear | ||
|
||
let format = UIGraphicsImageRendererFormat(for: controller.traitCollection) | ||
format.opaque = isOpaque | ||
format.preferredRange = colorMode.range | ||
format.scale = scale | ||
|
||
let renderer = UIGraphicsImageRenderer(size: size, format: format) | ||
|
||
let image = renderer.image { context in | ||
controller.view.drawHierarchy(in: context.format.bounds, afterScreenUpdates: true) | ||
} | ||
|
||
image.accessibilityLabel = label | ||
objectWillChange.send() | ||
|
||
return image | ||
} | ||
|
||
#endif | ||
} | ||
|
||
#if os(macOS) | ||
#else | ||
extension ColorRenderingMode { | ||
var range: UIGraphicsImageRendererFormat.Range { | ||
switch self { | ||
case .extendedLinear: return .extended | ||
case .linear: return .standard | ||
default: return .automatic | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.