From b8708aa3877ad7eb59f7d1da50d0626452184c7b Mon Sep 17 00:00:00 2001 From: Ceylo Date: Sun, 3 Nov 2024 19:10:16 +0100 Subject: [PATCH] Fix preview crash due to negative width --- FurAffinity/User/UserGalleryLikeView.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/FurAffinity/User/UserGalleryLikeView.swift b/FurAffinity/User/UserGalleryLikeView.swift index 1265a97..af1074e 100644 --- a/FurAffinity/User/UserGalleryLikeView.swift +++ b/FurAffinity/User/UserGalleryLikeView.swift @@ -68,10 +68,7 @@ struct UserGalleryLikeView: View { } .listStyle(.plain) .onChange(of: gallery.previews, initial: true) { - let thumbnailsWidth = geometry.size.width - 28.333 - let previews = gallery.previews - prefetchThumbnails(for: previews, availableWidth: thumbnailsWidth) - prefetchAvatars(for: previews) + prefetch(with: geometry) } } } @@ -79,6 +76,17 @@ struct UserGalleryLikeView: View { .navigationBarTitleDisplayMode(.inline) .navigationTitle("\(gallery.displayAuthor)'s \(galleryType)") } + + func prefetch(with geometry: GeometryProxy) { + let thumbnailsWidth = geometry.size.width - 28.333 + guard thumbnailsWidth > 0 else { + logger.error("Skipping prefetch due to too small geometry: \(String(describing: geometry.size))") + return + } + let previews = gallery.previews + prefetchThumbnails(for: previews, availableWidth: thumbnailsWidth) + prefetchAvatars(for: previews) + } } // MARK: -