Update the test cases and readme about AnimatedImage

This commit is contained in:
DreamPiggy 2020-04-05 14:22:32 +08:00
parent f2f51de40e
commit 1e1ddccc1a
3 changed files with 10 additions and 0 deletions

View File

@ -180,7 +180,11 @@ var body: some View {
AnimatedImage(name: "animation1", isAnimating: $isAnimating)) // Animation control binding
.maxBufferSize(.max)
.onViewUpdate { view, context in // Advanced native view coordinate
// AppKit tooltip for mouse hover
view.toolTip = "Mouseover Tip"
// UIKit advanced content mode
view.contentMode = .topLeft
// Coordinator, used for Cocoa Binding or Delegate method
let coordinator = context.coordinator
}
}
@ -191,6 +195,8 @@ Note: `AnimatedImage` supports both image url or image data for animated image f
Note: `AnimatedImage` some methods like `.transition`, `.indicator` and `.aspectRatio` have the same naming as `SwiftUI.View` protocol methods. But the args receive the different type. This is because `AnimatedImage` supports to be used with UIKit/AppKit component and animation. If you find ambiguity, use full type declaration instead of the dot expression syntax.
Note: some of methods on `AnimatedImage` will return `some View`, a new Modified Content. You'll lose the type related modifier method. For this case, you can either reorder the method call, or use Native View in `.onViewUpdate` for rescue.
```swift
var body: some View {
AnimatedImage(name: "animation2") // Just for showcase, don't mix them at the same time

View File

@ -163,6 +163,9 @@ class AnimatedImageTests: XCTestCase {
XCTAssertEqual(context.coordinator.userInfo?["foo"] as? String, "bar")
}
.placeholder(PlatformImage())
.placeholder {
Circle()
}
.indicator(SDWebImageActivityIndicator.medium)
// Image
.resizable()

View File

@ -82,6 +82,7 @@ class WebImageTests: XCTestCase {
.onProgress { _, _ in
}
.placeholder(.init(platformImage: PlatformImage()))
.placeholder {
Circle()
}