Fix the WebImage.transaction should use take effect
This commit is contained in:
parent
02b2579a93
commit
26f75715c7
|
@ -60,6 +60,7 @@ public final class ImageManager : ObservableObject {
|
||||||
weak var currentOperation: SDWebImageOperation? = nil
|
weak var currentOperation: SDWebImageOperation? = nil
|
||||||
|
|
||||||
var currentURL: URL?
|
var currentURL: URL?
|
||||||
|
var transaction = Transaction()
|
||||||
var successBlock: ((PlatformImage, Data?, SDImageCacheType) -> Void)?
|
var successBlock: ((PlatformImage, Data?, SDImageCacheType) -> Void)?
|
||||||
var failureBlock: ((Error) -> Void)?
|
var failureBlock: ((Error) -> Void)?
|
||||||
var progressBlock: ((Int, Int) -> Void)?
|
var progressBlock: ((Int, Int) -> Void)?
|
||||||
|
@ -106,18 +107,20 @@ public final class ImageManager : ObservableObject {
|
||||||
// So previous View struct call `onDisappear` and cancel the currentOperation
|
// So previous View struct call `onDisappear` and cancel the currentOperation
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.image = image
|
withTransaction(transaction) {
|
||||||
self.error = error
|
self.image = image
|
||||||
self.isIncremental = !finished
|
self.error = error
|
||||||
if finished {
|
self.isIncremental = !finished
|
||||||
self.imageData = data
|
if finished {
|
||||||
self.cacheType = cacheType
|
self.imageData = data
|
||||||
self.indicatorStatus.isLoading = false
|
self.cacheType = cacheType
|
||||||
self.indicatorStatus.progress = 1
|
self.indicatorStatus.isLoading = false
|
||||||
if let image = image {
|
self.indicatorStatus.progress = 1
|
||||||
self.successBlock?(image, data, cacheType)
|
if let image = image {
|
||||||
} else {
|
self.successBlock?(image, data, cacheType)
|
||||||
self.failureBlock?(error ?? NSError())
|
} else {
|
||||||
|
self.failureBlock?(error ?? NSError())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,6 @@ final class WebImageConfiguration: ObservableObject {
|
||||||
/// A Image View type to load image from url. Supports static/animated image format.
|
/// A Image View type to load image from url. Supports static/animated image format.
|
||||||
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
|
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
|
||||||
public struct WebImage<Content> : View where Content: View {
|
public struct WebImage<Content> : View where Content: View {
|
||||||
var transaction: Transaction
|
|
||||||
|
|
||||||
var configurations: [(Image) -> Image] = []
|
var configurations: [(Image) -> Image] = []
|
||||||
|
|
||||||
var content: (WebImagePhase) -> Content
|
var content: (WebImagePhase) -> Content
|
||||||
|
@ -146,10 +144,10 @@ public struct WebImage<Content> : View where Content: View {
|
||||||
imageModel.context = context
|
imageModel.context = context
|
||||||
_imageModel = ObservedObject(wrappedValue: imageModel)
|
_imageModel = ObservedObject(wrappedValue: imageModel)
|
||||||
let imageManager = ImageManager()
|
let imageManager = ImageManager()
|
||||||
|
imageManager.transaction = transaction
|
||||||
_imageManager = StateObject(wrappedValue: imageManager)
|
_imageManager = StateObject(wrappedValue: imageManager)
|
||||||
_indicatorStatus = ObservedObject(wrappedValue: imageManager.indicatorStatus)
|
_indicatorStatus = ObservedObject(wrappedValue: imageManager.indicatorStatus)
|
||||||
|
|
||||||
self.transaction = transaction
|
|
||||||
self.content = { phase in
|
self.content = { phase in
|
||||||
content(phase)
|
content(phase)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue