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

WebImage doesn't always resize to its frame with ForEach inside List #138

Closed ykaito21 closed 1 year ago

ykaito21 commented 3 years ago

I use WebImage with ForEach inside List, but it doesn't always work well. First case works with ios 13, but not with ios 14; other cases don't work with ios 13 but work with ios 14.

Is there any possible solution?, or is there any problem with my implementation?

First Case:

var body: some View {
        return List {
            ForEach(0..<10, id: \.self) { message in
                WebImage(url: URL(string: "https://i.pinimg.com/736x/50/df/34/50df34b9e93f30269853b96b09c37e3b.jpg"))
                    .resizable()
                    .placeholder {
                        Rectangle().foregroundColor(.lightGray)
                    }
                    .indicator(.activity)
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 260)
                    .background(Color.red)
                    .frame(width: 260)
            }
        }
    }

Second Case:

   var body: some View {
        let messageList = some my own list
        return List {
            ForEach(0..<messageList.count, id: \.self) { message in
                WebImage(url: URL(string: "https://i.pinimg.com/736x/50/df/34/50df34b9e93f30269853b96b09c37e3b.jpg"))
                    .resizable()
                    .placeholder {
                        Rectangle().foregroundColor(.lightGray)
                    }
                    .indicator(.activity)
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 260)
                    .background(Color.red)
                    .frame(width: 260)
            }
        }
    }

Third Case:

   var body: some View {
        let messageList = some my own list
        return List {
            ForEach(messageList) { message in
                WebImage(url: URL(string: "https://i.pinimg.com/736x/50/df/34/50df34b9e93f30269853b96b09c37e3b.jpg"))
                    .resizable()
                    .placeholder {
                        Rectangle().foregroundColor(.lightGray)
                    }
                    .indicator(.activity)
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 260)
                    .background(Color.red)
                    .frame(width: 260)
            }
        }
    }

ios 13 Result:

ios 14 Result:

atharvsharma1998 commented 3 years ago

im also facing this issue. images do not resize to the frame defined inside forEach.

dreampiggy commented 3 years ago

Sorry for delay. SwiftUI integration has some inconsistent behavior because of Apple's SwiftUI internal changes. This is a pain for both developer and community.

Maintain different code path for iOS 13/iOS 14, as well as watchOS 6/7, apply patch for Apple, will make this library too complicated.

I'll decide to remove iOS 13 support in next big version, which only considerate the iOS 14's behavior. Also, fix this issue.

mboiman commented 3 years ago

I I think I have the same problem, when I fill the picture in a ForEach. The Picture looks good, but the non seen part of the pictures goes over the Frame and blocks the possibility to click buttons from another picture

Bildschirmfoto 2021-01-10 um 09 07 31

u See the picture in the middle (the frame is over the buttons up)

nitinkumardb commented 3 years ago

Any solution for this issue?

Sagarito commented 1 year ago

Facing the same problem. Also doesn't resize with ForEach inside TabView.

Any solution for this yet?

dreampiggy commented 1 year ago

Is this still not works on v2.2.1 ?

I test the both 3 cases on iOS 16, seems it works now. So I jsut close this issue ?

image

And maybe you should check whether your model passed to ForEach conforms to Identifier protocol, never return the same ID from different model.

Learn more in https://developer.apple.com/videos/play/wwdc2021/10022

bitcooker commented 11 months ago

Is this issue solved? https://github.com/SDWebImage/SDWebImageSwiftUI/issues/138#issuecomment-757436415