Skip to content

Commit

Permalink
added disappear action to cache fallback image size
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Oct 1, 2023
1 parent c9878ac commit 4e24f11
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Mlem/Views/Shared/Cached Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ struct CachedImage: View {
width: screenWidth,
height: min(maxHeight, imageContainer.image.size.height * ratio)
)
shouldRecomputeSize = false
cacheImageSize()
shouldRecomputeSize = false
}
}
if shouldExpand {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4e24f11

Please sign in to comment.