diff --git a/Sources/GRAsyncImage/GRAsyncImage.swift b/Sources/GRAsyncImage/GRAsyncImage.swift index 6a9b2f5..09c80c0 100644 --- a/Sources/GRAsyncImage/GRAsyncImage.swift +++ b/Sources/GRAsyncImage/GRAsyncImage.swift @@ -18,6 +18,7 @@ public struct GRAsyncImage: var url: URL? var failurePlaceholder: FailurePlaceholder var loadingPlaceholder: LoadingPlaceholder + var allowsReloading: Bool var onLoading: VoidClosure? var onSuccess: VoidClosure? var onFailure: VoidClosure? @@ -28,6 +29,7 @@ public struct GRAsyncImage: 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 @@ -37,6 +39,7 @@ public struct GRAsyncImage: self.url = url self.failurePlaceholder = failurePlaceholder() self.loadingPlaceholder = loadingPlaceholder() + self.allowsReloading = allowsReloading self.onLoading = onLoading self.onSuccess = onSuccess self.onFailure = onFailure @@ -59,7 +62,11 @@ public struct GRAsyncImage: } 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