Skip to content

AnimatedImage from data issue on 2.1.0 #228

Closed
@sjidkov

Description

@sjidkov

Hello,

First I want to say thank you for SDWebImageSwiftUI.

I recently upgraded to 2.1.0 and found an issue. When AnimatedImage is initiated from Data it no longer updates on data changes.

I have a view set up like the example below. On 2.0.2 it works as expected. On 2.1.0 the view shows an empty image even though avatarImageData loads correctly.

struct ExampleAnimatedView: View {
		@State var avatarImageData: Data? = nil

		var body: some View {
			AnimatedImage(data: self.avatarImageData ?? Data())
				.onAppear(perform: {
					self.loadAvatarData()
				})
		}

          func loadAvatarData() {
                    ...
                   self.avatarImageData = data
              }
	}

Furthermore in other parts of the app I have AnimatedImage views that are display user selected data. So let's say user has image A loaded in an AnimatedImage. They use an image picker to select image b. AnimatedImage now shows image B. On 2.0.2 this works as expected. On 2.1.0 the AnimatedImage aways displays image A.

The issue seems to be caused by AnimatedImage imageModel_SwiftUI being a @StateObject. Changing imageModel_SwiftUI to @ObservedObject (AnimatedImage.swift l:104) fixed this issue. Other fixes introduced by 2.1.0 seem to remain with this change (tested on iOS 16).

Thank you,

Stanislav Jidkov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions