SDWebImage / SDWebImageSwiftUI

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

Some images do not appear until scroll #103

Closed Cyclic closed 3 years ago

Cyclic commented 4 years ago

First of all, thank you for the great framework. My app is loading assets from S3, which seem to load most of the time, but often when opening the app, the images are not loaded and do not load until I scroll even just slightly. It appears that something is either blocking the main thread for images loading, not sure what (advice on debugging this as a possible issue is appreciated), or SDWebImageSwiftUI is running into its own threading entanglement issues.

Please let me know, and thank you in advance. Here is the code:

            WebImage(url: listing.imageURLs?.first)
                .renderingMode(.original)
                .resizable()
                .placeholder {
                    Rectangle()
                        .foregroundColor(.gray)
                        .opacity(0.3)
                }
                .indicator(.progress)
                .transition(.fade)
                .frame(width: 155, height: 155)
                .cornerRadius(6)

IMG_0019

walidhossain commented 4 years ago

I'm, also facing the issue

alahdal commented 4 years ago

I have similar problem.

I update an array with list of urls, however, then I run a loop to create image views for each link. The images does not appear unless I scroll or move between views.

ForEach(0..<self.imagesLinks.count) {
                                 WebImage(url: URL(string: self.imagesLinks[$0]))
                                 .resizable()
                                 .placeholder(Image("logo"))
                                 .frame(width: 150, height: 150, alignment: .center)
                             }
dreampiggy commented 4 years ago

Some internal logic changed (using a prefetch from memory cache) from v1.2.1.

@alahdal @walidhossain @Cyclic Can you two have to try with v1.2.0 or earily to see what happended ?

alahdal commented 4 years ago

@dreampiggy, I have installed the latest version using Cocoa, where and how can I install 1.2

I tried pod 'SDWebImageSwiftUI', '~> 1.2', but still I am getting 1.3.3

dreampiggy commented 4 years ago

@dreampiggy, I have installed the latest version using Cocoa, where and how can I install 1.2

I tried pod 'SDWebImageSwiftUI', '~> 1.2', but still I am getting 1.3.3

Use

pod 'SDWebImageSwiftUI', '1.2.0'

~>1.2 means any version from >= 1.2.0 ~ < 2.0.0. Learn more in CocoaPods’s tutorial and semversion standard.

alahdal commented 4 years ago

Still the same problem, I have tried 1.1.0 as well still I can produce the same problem. Either to scroll or I have to move between views (Tab).

dreampiggy commented 4 years ago

I'll have a check for this today and find a workaround. Please have a wait. (busy on daily job yesterday)

dreampiggy commented 4 years ago

The onAppear does not get called when you click button to switch from nil to new url, this cause the issue.

dreampiggy commented 4 years ago

We query the image in onAppear, not when WebImage.init() (Previouslly in v0.9 version do this). This is because of bugs from user reply #76 .

I guess there are un-resolvable conflict for you and #76 's user. I have to choose a proper solution.

dreampiggy commented 4 years ago

Decide to revert changes about performance introduced in #92.

Same root case in #105

dreampiggy commented 4 years ago

@alahdal @walidhossain @Cyclic Please have a try again with v1.3.4

alahdal commented 4 years ago

@dreampiggy sorry for the question, how to add this version to my project. I have downloaded, but could not figure which one to take. From Cocoa, it is not available.

dreampiggy commented 4 years ago

@alahdal You should use pod install --repo-update, or pod update to update the Spec repo. (You can also directlly run pod repo update in any directory)

CocoaPods host a central Spec repo to find which of version available, not using any git tag.

I can ensure this v1.3.4 version is available on Spec repo.

➜  SDWebImageSwiftUI git:(master) pod trunk info SDWebImageSwiftUI

SDWebImageSwiftUI
    - Versions:
      - 0.1.0 (2019-08-09 10:23:37 UTC)
      - 0.10.0 (2019-12-06 14:46:29 UTC)
      - 0.10.1 (2020-01-26 10:23:32 UTC)
      - 0.10.2 (2020-01-26 12:19:12 UTC)
      - 0.10.3 (2020-02-01 10:15:50 UTC)
      - 0.1.1 (2019-09-24 19:14:35 UTC)
      - 0.1.2 (2019-10-01 08:35:16 UTC)
      - 0.2.0 (2019-10-03 10:26:34 UTC)
      - 0.3.0 (2019-10-05 08:53:39 UTC)
      - 0.3.1 (2019-10-05 12:31:36 UTC)
      - 0.3.2 (2019-10-10 10:24:03 UTC)
      - 0.3.3 (2019-10-20 08:26:46 UTC)
      - 0.4.0 (2019-10-21 17:44:28 UTC)
      - 0.4.1 (2019-10-22 15:25:42 UTC)
      - 0.4.2 (2019-10-24 04:50:12 UTC)
      - 0.5.0 (2019-10-25 21:14:54 UTC)
      - 0.5.1 (2019-10-26 11:14:23 UTC)
      - 0.5.2 (2019-10-26 21:12:36 UTC)
      - 0.6.0 (2019-10-27 12:22:13 UTC)
      - 0.6.2 (2019-10-29 07:32:55 UTC)
      - 0.6.3 (2019-10-29 18:16:02 UTC)
      - 0.6.4 (2019-11-01 21:39:56 UTC)
      - 0.6.5 (2019-11-02 04:02:29 UTC)
      - 0.7.0 (2019-11-02 11:21:20 UTC)
      - 0.8.0 (2019-11-09 08:04:25 UTC)
      - 0.8.1 (2019-11-09 09:19:15 UTC)
      - 0.8.2 (2019-11-09 22:40:09 UTC)
      - 0.8.3 (2019-11-10 11:14:46 UTC)
      - 0.8.4 (2019-11-14 14:05:21 UTC)
      - 0.8.5 (2019-11-16 08:02:45 UTC)
      - 0.8.6 (2019-11-23 03:31:20 UTC)
      - 0.9.0 (2019-11-29 18:24:44 UTC)
      - 1.0.0 (2020-03-03 14:02:55 UTC)
      - 1.0.0-beta (2020-01-28 11:30:28 UTC)
      - 1.0.0-beta2 (2020-02-01 16:24:11 UTC)
      - 1.0.0-beta3 (2020-02-25 10:53:12 UTC)
      - 1.1.0 (2020-03-24 12:18:07 UTC)
      - 1.2.0 (2020-03-29 13:37:51 UTC)
      - 1.3.0 (2020-04-05 07:32:02 UTC)
      - 1.3.1 (2020-04-10 15:45:33 UTC)
      - 1.3.2 (2020-04-14 14:41:24 UTC)
      - 1.3.3 (2020-04-15 12:17:19 UTC)
      - 1.3.4 (2020-04-30 08:03:13 UTC)
alahdal commented 4 years ago

My bad, I was using pod install.

I updated, still the same problem.

Cyclic commented 4 years ago

I’m unsure that I can reproduce this issue after updating to 1.3.4. I’m going to keep testing, but so far the images appear immediately.

Update 1: So far, after testing multiple passes, the images appear immediately without any scrolling. I also noticed that they don't load again after app launch, which means that I'm seeing caching that I didn't see before.

dreampiggy commented 4 years ago

I’m unsure that I can reproduce this issue after updating to 1.3.4. I’m going to keep testing, but so far the images appear immediately.

Update 1: So far, after testing multiple passes, the images appear immediately without any scrolling. I also noticed that they don't load again after app launch, which means that I'm seeing caching that I didn't see before.

Isn’t this the designed behavior ?

alahdal commented 4 years ago

@dreampiggy Just to clarify more about my example, the imagesLinks array is updated when the user add photos from his gallery.

I noticed that if I add the if condition before the ForEach, it works only for the first image.

if self.imagesLinks.count > 0 {
                                    ForEach(0..<self.imagesLinks.count) {
                                        WebImage(url: URL(string: self.imagesLinks[$0]))
                                            .resizable()
                                            .placeholder(Image("logo"))
                                            .indicator(.activity)
                                            .frame(width: 150, height: 150, alignment: .center)
                                    }
                                }

Which means the WebImage refreshes when the link is added to the list. Now, I am trying to figure out how I can make the view refreshes with every link added to the list.

Cyclic commented 4 years ago

@alahdal I had the same problem. I ended up storing a list of images on the parent entity. I realized that I was lazy loading the images, but they were not always there. You will need to make the imageLinks type an observable and maybe use didSet or willSet to get the WebImage type to load the newly added items. That's just what I gathered. I opted to keep it simple and store an array of the image links on my list item so I didn't have to worry about the links reloading.

nitinkumardb commented 3 years ago

Does anyone have a solution for this problem?

dreampiggy commented 3 years ago

Should be solved by v2.0.0

dmi3j commented 2 years ago

Appeared again in 2.0.2 for some reason.

HappyIosDeveloper commented 2 years ago

It's happening for me inside the picker.