SDWebImageSwiftUI icon indicating copy to clipboard operation
SDWebImageSwiftUI copied to clipboard

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

Open ykaito21 opened this issue 4 years ago • 4 comments

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:

ykaito21 avatar Oct 20 '20 10:10 ykaito21

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

atharvsharma1998 avatar Nov 07 '20 23:11 atharvsharma1998

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.

dreampiggy avatar Nov 09 '20 03:11 dreampiggy

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)

mboiman avatar Jan 10 '21 08:01 mboiman

Any solution for this issue?

nitinkumardb avatar Feb 08 '21 08:02 nitinkumardb

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

Any solution for this yet?

Sagarito avatar Sep 26 '22 05:09 Sagarito

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

dreampiggy avatar Sep 26 '22 06:09 dreampiggy

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

bitcooker avatar Sep 29 '23 23:09 bitcooker