SDWebImage / SDWebImageSwiftUI

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

Images not loading via observable objects (@State in my case) #229

Closed shanezzar closed 1 year ago

shanezzar commented 1 year ago
struct UserListView: View {
  var user: CompactMatch

  @State var imageURL: URL = nil

  var body: some View {
    HStack {
        WebImage(url: imageURL)
            .resizable()
            .placeholder {
                Image("placeholder-blank")
                    .resizable()
            }
            .indicator(.activity)
            .transition(.fade(duration: 0.5))
            .aspectRatio(contentMode: .fill)
            .frame(width: 72, height: 72, alignment: .center)
            .clipped()
            .cornerRadius(24)
    }
    .task { // .onAppear
        switch user {
        case .compact(let user):
            imageURL = user.imageURL
        case .match(let user):
            image = user.imageURL
        }
    }
  }
}

It's after the update 2.1.0. Can you please look into it, .onFailure description prints imageURL is nil whereas it is working with the older releases.

dreampiggy commented 1 year ago

Similiar to #228

The change from @ObservedObject to @StateObject loose the update logic for source-of-truth

dreampiggy commented 1 year ago

@shanezzar See video in : https://github.com/SDWebImage/SDWebImageSwiftUI/issues/232#issuecomment-1253801702

dreampiggy commented 1 year ago

v2.2.0 released