Repository navigation
Replies: 8 comments 1 reply
|
I think you can use placeholder modifier as skeleton animation or prefetch mechanism. |
|
What did you do to overcome this? |
|
It looks like the black flash you’re seeing happens because the images are not loaded into memory before they appear in the TabView. Using ImagePrefetcher like TelOkan suggested is a good solution. You can prefetch all URLs ahead of time so that when the user scrolls, the images are already cached and display instantly. Another option is to use a placeholder modifier with a blurred version or skeleton view so the transition feels smoother while the image loads. |
|
You’re running into the common ‘image not preloaded’ problem in SwiftUI with KFImage. One approach is to manually prefetch the images before they appear in the TabView using KingfisherManager.shared.retrieveImage(with:). This way, the images are cached ahead of time, reducing or eliminating that black flash when scrolling. For example, you could loop through your pictures array in onAppear and prefetch them asynchronously. That should help smooth out the TabView experience even if loadImmediately is deprecated. |
|
Got it fixed anyway? I think I am at the same bottleneck. |
|
If you haven’t fixed it yet, try prefetching all image URLs before the TabView appears. Kingfisher’s ImagePrefetcher or KingfisherManager.shared.retrieveImage both work well. Once the cache is warm, the black flash disappears and scrolling becomes smooth. Just call the prefetch logic in onAppear and it should solve the issue. |
|
You’re basically seeing the black flash because the image isn’t in memory yet when the next TabView page becomes visible. Since loadImmediately is gone, prefetching is really the cleanest approach now. You can use ImagePrefetcher in onAppear to warm up the cache before the user starts scrolling: .onAppear { That way, by the time the next tab becomes visible, the image is already cached and won’t render as black first. Another small thing to consider is that TabView(.page) can be sensitive to rendering delays if the GPU is already busy. Even slight decoding or layout work can make the transition feel harsher. When I test rendering-heavy UI scenarios, I sometimes use browser-based shader stress tools like https://volumeshader.com/ just to see how weaker GPUs handle continuous graphical load. On lower-end devices, even small delays in texture upload or decoding become noticeable. So combining prefetching + keeping your image sizes reasonable (using DownsamplingImageProcessor) usually gives the smoothest result. If you’re still seeing flashes after prefetching, I’d also double-check that the frame size matches the downsampling size to avoid runtime resizing cost. |
1. Why
|
Uh oh!
There was an error while loading. Please reload this page.
I'm using version 8.
I read that
loadImmediatelyonFKImageis deprecated "because we use@StateObject", but TBH I don't understand this explanation.I have the following code in SwiftUI
When I start scrolling horizontally the next image is black for a short while, until it has been loaded and then it appears as it's supposed to.
I see no way of force-loading the
KFImage's url so I don't have this black flash when scrolling to an image that's not in the cache already, at least not usingFKImagecapture.mov
All reactions