@@ -600,6 +600,11 @@ extension AnimatedImage {
600
600
// Aspect Ratio
601
601
@available ( iOS 14 . 0 , OSX 11 . 0 , tvOS 14 . 0 , watchOS 7 . 0 , * )
602
602
extension AnimatedImage {
603
+ func setImageLayoutAspectRatio( _ aspectRatio: CGFloat ? , contentMode: ContentMode ) {
604
+ self . imageLayout. aspectRatio = aspectRatio
605
+ self . imageLayout. contentMode = contentMode
606
+ }
607
+
603
608
/// Constrains this view's dimensions to the specified aspect ratio.
604
609
/// - Parameters:
605
610
/// - aspectRatio: The ratio of width to height to use for the resulting
@@ -609,6 +614,7 @@ extension AnimatedImage {
609
614
/// fill the parent context.
610
615
/// - Returns: A view that constrains this view's dimensions to
611
616
/// `aspectRatio`, using `contentMode` as its scaling algorithm.
617
+ @ViewBuilder
612
618
public func aspectRatio( _ aspectRatio: CGFloat ? = nil , contentMode: ContentMode ) -> some View {
613
619
// The `SwifUI.View.aspectRatio(_:contentMode:)` says:
614
620
// If `aspectRatio` is `nil`, the resulting view maintains this view's aspect ratio
@@ -618,9 +624,12 @@ extension AnimatedImage {
618
624
// But 2: there are no way to call a Protocol Extention default implementation in Swift 5.1
619
625
// So, we directly call the implementation detail modifier instead
620
626
// Fired Radar: FB7413534
621
- self . imageLayout. aspectRatio = aspectRatio
622
- self . imageLayout. contentMode = contentMode
623
- return self . modifier ( _AspectRatioLayout ( aspectRatio: aspectRatio, contentMode: contentMode) )
627
+ let _ = self . setImageLayoutAspectRatio ( aspectRatio, contentMode: contentMode)
628
+ if let aspectRatio {
629
+ self . modifier ( _AspectRatioLayout ( aspectRatio: aspectRatio, contentMode: contentMode) )
630
+ } else {
631
+ self
632
+ }
624
633
}
625
634
626
635
/// Constrains this view's dimensions to the aspect ratio of the given size.
0 commit comments