Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using "startLoadingBeforeViewAppear()" leads to the image always loading the next run loop #2040

Open
BobbyRohweder opened this issue Feb 28, 2023 · 1 comment

Comments

@BobbyRohweder
Copy link

BobbyRohweder commented Feb 28, 2023

Issue Description

What

When a SwiftUI KFImage is used with "startLoadingBeforeViewAppear()", the image will always load the next run loop, which causes the placeholder to show and the UI to flash.

This was likely caused by the "loading" state in #2036
combined with the async dispatch to main, DispatchQueue.main.async { binder.start(context: context) }

Reproduce

Have the asset already in memory, switch to a view with the image, and the blue still shows.

Remove ".startLoadingBeforeViewAppear()" and the blue does not show, since it can display is synchronously when the view is created and displayed.

KFImage(someImageURL)
    .startLoadingBeforeViewAppear()
    .placeholder { Rectangle().fill(Color.blue) }

Other Comment

Kingfisher version: 7.6.2
iOS version: 16.X

@onevcat
Copy link
Owner

onevcat commented Mar 1, 2023

That flag was created to fix a multiple start(context:) invocation. With the original issue #1988 existing, I guess it might be the best thing we can do now (We do not have the choice to hook up to the SwiftUI's view appear, but also have to not modify the @Published value in view's body).

The good news is, I heard that Xcode 14.3 and iOS 16.4 SDK finally fixed the original issue, and the startLoadingBeforeViewAppear will be not necessary when deploying to the later iOS versions. I do not yet have a chance to try the latest iOS version, but I will do that soon and see what to do with this and the ugly startLoadingBeforeViewAppear workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants