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

Freeze of the app #161

Closed karenxpn closed 3 years ago

karenxpn commented 3 years ago

SDWebImageSwiftUI causes freeze of the app in LazyVStack

this is my code of that part

ScrollView { LazyVStack {

  CommentTextField().environmentObject(self.profileVM)

  ForEach( self.profileVM.comments, id: \.id ) { comment in
      NavigationLink(destination: VisitedProfile(userID: comment.user.id, theme: self.theme)) {
          PostSingleComment(comment: comment, theme: self.theme, toggler: self.$userFullNameColorToggler)
              .environmentObject(self.profileVM)
      }
  }

} }

struct PostSingleComment: View { @EnvironmentObject var profileVM: ProfileViewModel @State private var isExpanded: Bool = false let comment: CommentModel let theme: Theme @Binding var toggler: Bool

var body: some View {

    HStack( alignment: .top ) {
        WebImage(url: URL(string: comment.user.profile_image))
            .resizable()
            .aspectRatio(contentMode: .fill)
            .frame(width: 40, height: 40)

        VStack( alignment: .leading) {
            Text( comment.user.fullName )
                .foregroundColor( toggler ? Color(UIColor(red: 0/255, green: 255/255, blue: 224/255, alpha: 1)) : .white)
                .font(.custom("Avenir", size: 18))
                .fontWeight(.heavy)

            Text( comment.comment )
                .foregroundColor(.gray )
                .font(.custom("Avenir", size: 16))
                .lineLimit( isExpanded ? nil : 2)

            Button(action: {
                isExpanded.toggle()
            }) {
                HStack {
                    Spacer()
                    Text(isExpanded ? "Less" : "More")  // add to localizable
                        .font(.custom("Avenir", size: 16))
                        .foregroundColor(.white)
                        .padding(.leading, 8.0)
                        .padding(.top, 0)
                }
            }

            Text( comment.created_at )
                .foregroundColor(.gray)
                .font(.custom("Avenir", size: 14))
                .padding(.top, 8)
        }.padding(.leading)

    }.padding()
}
dreampiggy commented 3 years ago

Known bug...Move this into #121

SDWebImageSwiftUI current version can not use with LazyStack in iOS 14. I'll investigate this issue soon.

dreampiggy commented 3 years ago

Seems related to the iOS 14's LazyVStack, which will reset the @State or @Binding for any item inside him in some situation. Which cause a recursive call to SDWebImageManager to load image again...


Continue invesgating. Anyone who is expect and know SwiftUI implmentation detail can help with ?

karenxpn commented 3 years ago

as I understood this can be done with changing NavigationLink to isActive: Bool this solves this issue but its not correct solution I think

karenxpn commented 3 years ago

the problem is connected somehow with SDWebImageSiwftUI and navigation

dreampiggy commented 3 years ago

@KALIMI Maybe solved by #162. Reason is in #121

dreampiggy commented 3 years ago

Solved by v2.0.0