From 4e24f1179a44dfa96dbc402e761538323b97009e Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sat, 30 Sep 2023 21:14:38 -0400 Subject: [PATCH] added disappear action to cache fallback image size --- Mlem/Views/Shared/Cached Image.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Mlem/Views/Shared/Cached Image.swift b/Mlem/Views/Shared/Cached Image.swift index fdf212017..6be397ec5 100644 --- a/Mlem/Views/Shared/Cached Image.swift +++ b/Mlem/Views/Shared/Cached Image.swift @@ -103,8 +103,8 @@ struct CachedImage: View { width: screenWidth, height: min(maxHeight, imageContainer.image.size.height * ratio) ) - shouldRecomputeSize = false cacheImageSize() + shouldRecomputeSize = false } } if shouldExpand { @@ -159,6 +159,13 @@ struct CachedImage: View { ]) .frame(idealWidth: size.width) .frame(height: size.height) + .onDisappear { + // if the post disappears and the size still isn't computed, just cache it as-is + if shouldRecomputeSize { + cacheImageSize() + shouldRecomputeSize = false + } + } } static func imageNotFoundDefault() -> AnyView {