Using the hack on watchOS to fix the issue when aspect fit with nil value, this need SwiftUI to provide public API

This commit is contained in:
DreamPiggy 2019-10-30 03:54:47 +08:00
parent 3017ca7968
commit b5d775f15e
1 changed files with 10 additions and 0 deletions

View File

@ -519,7 +519,17 @@ extension AnimatedImage {
// Fired Radar: FB7413534
imageLayout.aspectRatio = aspectRatio
imageLayout.contentMode = contentMode
#if os(macOS) || os(iOS) || os(tvOS)
return self.modifier(EmptyModifier()).aspectRatio(aspectRatio, contentMode: contentMode)
#else
if let aspectRatio = aspectRatio {
return AnyView(self.modifier(EmptyModifier()).aspectRatio(aspectRatio, contentMode: contentMode))
} else {
// on watchOS, there are no workaround like `AnimatedImageViewWrapper` to override `intrinsicContentSize`, so the aspect ratio is undetermined and cause sizing issues
// To workaround, we do not call default implementation for this case, using original solution instead
return AnyView(self)
}
#endif
}
/// Constrains this view's dimensions to the aspect ratio of the given size.