Skip to content

Commit

Permalink
Merge pull request #4 from GoodRequest/fix/async-image-reloading
Browse files Browse the repository at this point in the history
fix: Add option to not reload async image
  • Loading branch information
plajdo authored Jul 3, 2024
2 parents 7ce3cd4 + 10e6e5d commit 35e50af
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/GRAsyncImage/GRAsyncImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
var url: URL?
var failurePlaceholder: FailurePlaceholder
var loadingPlaceholder: LoadingPlaceholder
var allowsReloading: Bool
var onLoading: VoidClosure?
var onSuccess: VoidClosure?
var onFailure: VoidClosure?
Expand All @@ -28,6 +29,7 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
url: URL?,
@ViewBuilder failurePlaceholder: () -> FailurePlaceholder = { Image(systemName: "arrow.clockwise") },
@ViewBuilder loadingPlaceholder: () -> LoadingPlaceholder = { ProgressView().progressViewStyle(.circular) },
allowsReloading: Bool = true,
onLoading: VoidClosure? = nil,
onSuccess: VoidClosure? = nil,
onFailure: VoidClosure? = nil
Expand All @@ -37,6 +39,7 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
self.url = url
self.failurePlaceholder = failurePlaceholder()
self.loadingPlaceholder = loadingPlaceholder()
self.allowsReloading = allowsReloading
self.onLoading = onLoading
self.onSuccess = onSuccess
self.onFailure = onFailure
Expand All @@ -59,7 +62,11 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
}

case .failure:
Button(action: { loadImage(url: url) }, label: { failurePlaceholder })
if let url, allowsReloading {
Button(action: { loadImage(url: url) }, label: { failurePlaceholder })
} else {
failurePlaceholder
}

case .idle:
Color.clear
Expand Down

0 comments on commit 35e50af

Please sign in to comment.