SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.16k stars 223 forks source link

Try to refactor the ImageManager trigger published value, avoiding the View will refreshing when deallocing #180

Closed dreampiggy closed 1 year ago

dreampiggy commented 3 years ago

This may solve #176

The callstack trace shows that UIHostingView's dealloc method will trigger the View's onDisappear method. And it use the unownded but not weak for the internal storage. If we trigger another body refreshing call from the Publisher (in the #176 is because of the ImageManager.isLoading property), this will cause the crash because the internal storage already been destroyed.

Instead, I try to avoid setting isLoading inside cancel. Tthis property is previouslly used to supports the delayPlaceholder feature.

delayPlaceholder in SDWebImage means:

So, instead I use the error to check whether there are loading failure. This can keep this function as well.

dreampiggy commented 3 years ago

Try using the demo code, function works as expected.

image

codecov[bot] commented 3 years ago

Codecov Report

Merging #180 (d175c0d) into master (cd8625b) will increase coverage by 0.20%. The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   74.81%   75.02%   +0.20%     
==========================================
  Files          11       11              
  Lines         969      965       -4     
==========================================
- Hits          725      724       -1     
+ Misses        244      241       -3     
Flag Coverage Δ
ios 71.11% <50.00%> (+0.20%) :arrow_up:
macos 75.77% <50.00%> (+0.23%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
SDWebImageSwiftUI/Classes/WebImage.swift 87.97% <20.00%> (-1.47%) :arrow_down:
SDWebImageSwiftUI/Classes/ImageManager.swift 84.00% <100.00%> (+8.56%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update cd8625b...d175c0d. Read the comment docs.