From a398115d5f8f1c369e23c2d288ef7ce97d61dcf7 Mon Sep 17 00:00:00 2001 From: Matus Klasovity Date: Wed, 31 Jan 2024 07:35:10 +0100 Subject: [PATCH 1/2] fix: Add option to not reload async image --- Sources/GRAsyncImage/GRAsyncImage.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/GRAsyncImage/GRAsyncImage.swift b/Sources/GRAsyncImage/GRAsyncImage.swift index d6fd387..2f7ccdc 100644 --- a/Sources/GRAsyncImage/GRAsyncImage.swift +++ b/Sources/GRAsyncImage/GRAsyncImage.swift @@ -17,6 +17,7 @@ public struct GRAsyncImage: var url: URL? var failurePlaceholder: FailurePlaceholder var loadingPlaceholder: LoadingPlaceholder + var reloadingIsAllowed: Bool var onLoading: VoidClosure? var onSuccess: VoidClosure? var onFailure: VoidClosure? @@ -27,6 +28,7 @@ public struct GRAsyncImage: url: URL?, @ViewBuilder failurePlaceholder: () -> FailurePlaceholder = { Image(systemName: "arrow.clockwise") }, @ViewBuilder loadingPlaceholder: () -> LoadingPlaceholder = { ProgressView().progressViewStyle(.circular) }, + reloadingIsAllowed: Bool = true, onLoading: VoidClosure? = nil, onSuccess: VoidClosure? = nil, onFailure: VoidClosure? = nil @@ -36,6 +38,7 @@ public struct GRAsyncImage: self.url = url self.failurePlaceholder = failurePlaceholder() self.loadingPlaceholder = loadingPlaceholder() + self.reloadingIsAllowed = reloadingIsAllowed self.onLoading = onLoading self.onSuccess = onSuccess self.onFailure = onFailure @@ -58,7 +61,11 @@ public struct GRAsyncImage: } case .failure: - Button(action: { loadImage(url: url) }, label: { failurePlaceholder }) + if let url, reloadingIsAllowed { + Button(action: { loadImage(url: url) }, label: { failurePlaceholder }) + } else { + failurePlaceholder + } case .idle: Color.clear From 10e6e5d6375a41df46d2aac13852be25a70ea99d Mon Sep 17 00:00:00 2001 From: Filip Sasala <31418257+plajdo@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:13:23 +0200 Subject: [PATCH 2/2] Code review - refactor --- Sources/GRAsyncImage/GRAsyncImage.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/GRAsyncImage/GRAsyncImage.swift b/Sources/GRAsyncImage/GRAsyncImage.swift index 2f7ccdc..92bb3a8 100644 --- a/Sources/GRAsyncImage/GRAsyncImage.swift +++ b/Sources/GRAsyncImage/GRAsyncImage.swift @@ -17,7 +17,7 @@ public struct GRAsyncImage: var url: URL? var failurePlaceholder: FailurePlaceholder var loadingPlaceholder: LoadingPlaceholder - var reloadingIsAllowed: Bool + var allowsReloading: Bool var onLoading: VoidClosure? var onSuccess: VoidClosure? var onFailure: VoidClosure? @@ -28,7 +28,7 @@ public struct GRAsyncImage: url: URL?, @ViewBuilder failurePlaceholder: () -> FailurePlaceholder = { Image(systemName: "arrow.clockwise") }, @ViewBuilder loadingPlaceholder: () -> LoadingPlaceholder = { ProgressView().progressViewStyle(.circular) }, - reloadingIsAllowed: Bool = true, + allowsReloading: Bool = true, onLoading: VoidClosure? = nil, onSuccess: VoidClosure? = nil, onFailure: VoidClosure? = nil @@ -38,7 +38,7 @@ public struct GRAsyncImage: self.url = url self.failurePlaceholder = failurePlaceholder() self.loadingPlaceholder = loadingPlaceholder() - self.reloadingIsAllowed = reloadingIsAllowed + self.allowsReloading = allowsReloading self.onLoading = onLoading self.onSuccess = onSuccess self.onFailure = onFailure @@ -61,7 +61,7 @@ public struct GRAsyncImage: } case .failure: - if let url, reloadingIsAllowed { + if let url, allowsReloading { Button(action: { loadImage(url: url) }, label: { failurePlaceholder }) } else { failurePlaceholder