Merge pull request #89 from SDWebImage/animatedimage_update

Animatedimage little patch - UIKit/AppKit animated image now applied for resizingMode
This commit is contained in:
DreamPiggy 2020-03-29 17:19:30 +08:00 committed by GitHub
commit e8dcfc5b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 10 deletions

View File

@ -350,7 +350,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
} }
// Animated Image does not support resizing mode and rendering mode // Animated Image does not support resizing mode and rendering mode
if let image = view.wrapped.image, !image.sd_isAnimated, !image.conforms(to: SDAnimatedImageProtocol.self) { if let image = view.wrapped.image, !image.conforms(to: SDAnimatedImageProtocol.self) {
var image = image var image = image
// ResizingMode // ResizingMode
if let resizingMode = imageLayout.resizingMode, imageLayout.capInsets != EdgeInsets() { if let resizingMode = imageLayout.resizingMode, imageLayout.capInsets != EdgeInsets() {
@ -556,11 +556,11 @@ extension AnimatedImage {
// So, if we don't override this method, SwiftUI ignore the content mode on actual ImageView // So, if we don't override this method, SwiftUI ignore the content mode on actual ImageView
// To workaround, we want to call the default `SwifUI.View.aspectRatio(_:contentMode:)` method // To workaround, we want to call the default `SwifUI.View.aspectRatio(_:contentMode:)` method
// 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 need a hack, that create a empty modifier, they call method on that view instead // So, we directly call the implementation detail modifier instead
// Fired Radar: FB7413534 // Fired Radar: FB7413534
self.imageLayout.aspectRatio = aspectRatio self.imageLayout.aspectRatio = aspectRatio
self.imageLayout.contentMode = contentMode self.imageLayout.contentMode = contentMode
return self.modifier(EmptyModifier()).aspectRatio(aspectRatio, contentMode: contentMode) return self.modifier(_AspectRatioLayout(aspectRatio: aspectRatio, contentMode: contentMode))
} }
/// 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.
@ -572,13 +572,7 @@ extension AnimatedImage {
/// - 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.
public func aspectRatio(_ aspectRatio: CGSize, contentMode: ContentMode) -> some View { public func aspectRatio(_ aspectRatio: CGSize, contentMode: ContentMode) -> some View {
var ratio: CGFloat? return self.aspectRatio(aspectRatio.width / aspectRatio.height, contentMode: contentMode)
if aspectRatio.width > 0 && aspectRatio.height > 0 {
ratio = aspectRatio.width / aspectRatio.height
} else {
NSException(name: .invalidArgumentException, reason: "\(type(of: self)).\(#function) should be called with positive aspectRatio", userInfo: nil).raise()
}
return self.aspectRatio(ratio, contentMode: contentMode)
} }
/// Scales this view to fit its parent. /// Scales this view to fit its parent.