Skip to content

Commit 2587161

Browse files
committed
Update the example to show how to use animation control with Binding
1 parent 35190d2 commit 2587161

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Example/SDWebImageSwiftUIDemo/DetailView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct DetailView: View {
1313
let url: String
1414
let animated: Bool
1515
@State var progress: CGFloat = 1
16+
@State var isAnimating: Bool = true
1617

1718
var body: some View {
1819
VStack {
@@ -24,7 +25,7 @@ struct DetailView: View {
2425
Spacer()
2526
HStack {
2627
if animated {
27-
AnimatedImage(url: URL(string:url), options: [.progressiveLoad])
28+
AnimatedImage(url: URL(string:url), options: [.progressiveLoad], isAnimating: $isAnimating)
2829
.onProgress(perform: { (receivedSize, expectedSize) in
2930
// SwiftUI engine itself ensure the main queue dispatch
3031
if (expectedSize >= 0) {
@@ -35,6 +36,9 @@ struct DetailView: View {
3536
})
3637
.resizable()
3738
.scaledToFit()
39+
.navigationBarItems(trailing: Button(isAnimating ? "Stop" : "Start") {
40+
self.isAnimating.toggle()
41+
})
3842
} else {
3943
WebImage(url: URL(string:url), options: [.progressiveLoad])
4044
.onProgress(perform: { (receivedSize, expectedSize) in

0 commit comments

Comments
 (0)