Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Placeholder image always displayed before cached image on iOS 15 when using an animation modifier #23

Description

@johnrogers

Hello there,

First of all, let me start by saying, thank you for creating such a great package. It has greatly simplified our image loading and caching, something that we wish Apple offered out of the box.

When running the app on an iOS 15 device, we have discovered that even if the image has already been loaded, our placeholder view will always be shown before displaying the cached image. When the view reappears, the placeholder will be shown for a brief moment before the cached image is loaded in. This creates the effect that the image is being loaded again, however I have confirmed that there is no network activity. It appears to be something to do with the fact that the image has an animation added to it.

Example code:

LazyImage(source: url) { state in
    if let image = state.image {
        image
            .aspectRatio(contentMode: .fit)
    } else {
        generic
            .aspectRatio(contentMode: .fit)
    }
}
.frame(height: targetHeight)
.animation(.easeIn)
.clipShape(Circle()))

Putting a breakpoint in the content closure shows that it is initially called with a nil value for state.image, before almost immediately being called again with a non-nil image. This results in the behaviour I described above.

When removing the animation, it works as expected. The above code works fine running on iOS 14, using the same build. We are building using Xcode 12.5.1, and I have also confirmed that this issue is present when building using Xcode 13.

I suspect that this may be something to do with changes to the way SwiftUI handles animations, but I thought I'd point it out here nonetheless in case it is something you need to look into.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions