@@ -622,6 +622,11 @@ extension AnimatedImage {
622
622
// Aspect Ratio
623
623
@available ( iOS 13 . 0 , OSX 10 . 15 , tvOS 13 . 0 , watchOS 6 . 0 , * )
624
624
extension AnimatedImage {
625
+ func setImageLayoutAspectRatio( _ aspectRatio: CGFloat ? , contentMode: ContentMode ) {
626
+ self . imageLayout. aspectRatio = aspectRatio
627
+ self . imageLayout. contentMode = contentMode
628
+ }
629
+
625
630
/// Constrains this view's dimensions to the specified aspect ratio.
626
631
/// - Parameters:
627
632
/// - aspectRatio: The ratio of width to height to use for the resulting
@@ -631,6 +636,7 @@ extension AnimatedImage {
631
636
/// fill the parent context.
632
637
/// - Returns: A view that constrains this view's dimensions to
633
638
/// `aspectRatio`, using `contentMode` as its scaling algorithm.
639
+ @ViewBuilder
634
640
public func aspectRatio( _ aspectRatio: CGFloat ? = nil , contentMode: ContentMode ) -> some View {
635
641
// The `SwifUI.View.aspectRatio(_:contentMode:)` says:
636
642
// If `aspectRatio` is `nil`, the resulting view maintains this view's aspect ratio
@@ -640,9 +646,12 @@ extension AnimatedImage {
640
646
// But 2: there are no way to call a Protocol Extention default implementation in Swift 5.1
641
647
// So, we directly call the implementation detail modifier instead
642
648
// Fired Radar: FB7413534
643
- self . imageLayout. aspectRatio = aspectRatio
644
- self . imageLayout. contentMode = contentMode
645
- return self . modifier ( _AspectRatioLayout ( aspectRatio: aspectRatio, contentMode: contentMode) )
649
+ let _ = self . setImageLayoutAspectRatio ( aspectRatio, contentMode: contentMode)
650
+ if let aspectRatio {
651
+ self . modifier ( _AspectRatioLayout ( aspectRatio: aspectRatio, contentMode: contentMode) )
652
+ } else {
653
+ self
654
+ }
646
655
}
647
656
648
657
/// Constrains this view's dimensions to the aspect ratio of the given size.
0 commit comments