Update the Example to make WebImage animatable by default

This commit is contained in:
DreamPiggy 2021-02-19 14:58:03 +08:00
parent 7750264245
commit b3530ac956
2 changed files with 12 additions and 20 deletions

View File

@ -155,7 +155,7 @@ struct ContentView: View {
HStack {
if self.animated {
#if os(macOS) || os(iOS) || os(tvOS)
AnimatedImage(url: URL(string:url))
AnimatedImage(url: URL(string:url), isAnimating: .constant(true))
.onViewUpdate { view, context in
#if os(macOS)
view.toolTip = url
@ -178,7 +178,7 @@ struct ContentView: View {
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
#endif
} else {
WebImage(url: URL(string:url))
WebImage(url: URL(string:url), isAnimating: .constant(true))
.resizable()
/**
.placeholder {

View File

@ -36,7 +36,7 @@ extension Image {
struct DetailView: View {
let url: String
let animated: Bool
@State var animated: Bool = true // You can change between WebImage/AnimatedImage
@State var isAnimating: Bool = true
@State var lastScale: CGFloat = 1.0
@State var scale: CGFloat = 1.0
@ -45,26 +45,18 @@ struct DetailView: View {
var body: some View {
VStack {
#if os(iOS) || os(tvOS)
if animated {
zoomView()
.navigationBarItems(trailing: Button(isAnimating ? "Stop" : "Start") {
self.isAnimating.toggle()
})
} else {
zoomView()
}
#endif
#if os(macOS) || os(watchOS)
if animated {
zoomView()
.contextMenu {
Button(isAnimating ? "Stop" : "Start") {
self.isAnimating.toggle()
}
}
} else {
zoomView()
}
#endif
}
}
@ -116,7 +108,7 @@ struct DetailView: View {
.scaledToFit()
#endif
} else {
WebImage(url: URL(string:url), options: [.progressiveLoad, .delayPlaceholder])
WebImage(url: URL(string:url), options: [.progressiveLoad, .delayPlaceholder], isAnimating: $isAnimating)
.resizable()
.placeholder(.wifiExclamationmark)
.indicator(.progress)