workaround ratio
(cherry picked from commit b7e5780adcf1aa03a7847be170d84820a31425a8)
This commit is contained in:
parent
cf0dc791bc
commit
5d6502aba9
|
@ -600,6 +600,11 @@ extension AnimatedImage {
|
||||||
// Aspect Ratio
|
// Aspect Ratio
|
||||||
@available(iOS 14.0, OSX 11.0, tvOS 14.0, watchOS 7.0, *)
|
@available(iOS 14.0, OSX 11.0, tvOS 14.0, watchOS 7.0, *)
|
||||||
extension AnimatedImage {
|
extension AnimatedImage {
|
||||||
|
func setImageLayoutAspectRatio(_ aspectRatio: CGFloat?, contentMode: ContentMode) {
|
||||||
|
self.imageLayout.aspectRatio = aspectRatio
|
||||||
|
self.imageLayout.contentMode = contentMode
|
||||||
|
}
|
||||||
|
|
||||||
/// Constrains this view's dimensions to the specified aspect ratio.
|
/// Constrains this view's dimensions to the specified aspect ratio.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - aspectRatio: The ratio of width to height to use for the resulting
|
/// - aspectRatio: The ratio of width to height to use for the resulting
|
||||||
|
@ -609,6 +614,7 @@ extension AnimatedImage {
|
||||||
/// fill the parent context.
|
/// fill the parent context.
|
||||||
/// - Returns: A view that constrains this view's dimensions to
|
/// - Returns: A view that constrains this view's dimensions to
|
||||||
/// `aspectRatio`, using `contentMode` as its scaling algorithm.
|
/// `aspectRatio`, using `contentMode` as its scaling algorithm.
|
||||||
|
@ViewBuilder
|
||||||
public func aspectRatio(_ aspectRatio: CGFloat? = nil, contentMode: ContentMode) -> some View {
|
public func aspectRatio(_ aspectRatio: CGFloat? = nil, contentMode: ContentMode) -> some View {
|
||||||
// The `SwifUI.View.aspectRatio(_:contentMode:)` says:
|
// The `SwifUI.View.aspectRatio(_:contentMode:)` says:
|
||||||
// If `aspectRatio` is `nil`, the resulting view maintains this view's aspect ratio
|
// If `aspectRatio` is `nil`, the resulting view maintains this view's aspect ratio
|
||||||
|
@ -618,9 +624,12 @@ extension AnimatedImage {
|
||||||
// But 2: there are no way to call a Protocol Extention default implementation in Swift 5.1
|
// But 2: there are no way to call a Protocol Extention default implementation in Swift 5.1
|
||||||
// So, we directly call the implementation detail modifier instead
|
// So, we directly call the implementation detail modifier instead
|
||||||
// Fired Radar: FB7413534
|
// Fired Radar: FB7413534
|
||||||
self.imageLayout.aspectRatio = aspectRatio
|
let _ = self.setImageLayoutAspectRatio(aspectRatio, contentMode: contentMode)
|
||||||
self.imageLayout.contentMode = contentMode
|
if let aspectRatio {
|
||||||
return self.modifier(_AspectRatioLayout(aspectRatio: aspectRatio, contentMode: contentMode))
|
self.modifier(_AspectRatioLayout(aspectRatio: aspectRatio, contentMode: contentMode))
|
||||||
|
} else {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constrains this view's dimensions to the aspect ratio of the given size.
|
/// Constrains this view's dimensions to the aspect ratio of the given size.
|
||||||
|
|
Loading…
Reference in New Issue