From 9fa6a835f22c6ea38758573357fff98b6b4d403a Mon Sep 17 00:00:00 2001 From: onevcat Date: Sat, 30 Jan 2021 22:46:36 +0900 Subject: [PATCH] Better code readability --- Sources/SwiftUI/KFImage.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Sources/SwiftUI/KFImage.swift b/Sources/SwiftUI/KFImage.swift index f470d3f0c..033cef0bc 100644 --- a/Sources/SwiftUI/KFImage.swift +++ b/Sources/SwiftUI/KFImage.swift @@ -169,18 +169,14 @@ struct KFImageRenderer: View { return } if !binder.loadingOrSucceeded { - binder.start { - self.loadingResult = $0 - switch $0 { - case .success(let result): + binder.start { result in + self.loadingResult = result + switch result { + case .success(let value): CallbackQueue.mainAsync.execute { - if let duration = fadeTransitionDuration(cacheType: result.cacheType) { - withAnimation(.linear(duration: duration)) { - isLoaded = true - } - } else { - isLoaded = true - } + let animation = fadeTransitionDuration(cacheType: value.cacheType) + .map { duration in Animation.linear(duration: duration) } + withAnimation(animation) { isLoaded = true } } case .failure(_): break