diff --git a/Mlem/Views/Shared/Cached Image.swift b/Mlem/Views/Shared/Cached Image.swift index dd7789cd8..e72f2d1f6 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 { @@ -142,11 +142,13 @@ struct CachedImage: View { } else if state.error != nil { // Indicates an error imageNotFound() - .frame(idealWidth: size.width, maxHeight: size.height) + .frame(idealWidth: size.width) + .frame(height: size.height) .background(errorBackgroundColor) } else { ProgressView() // Acts as a placeholder - .frame(idealWidth: size.width, maxHeight: size.height) + .frame(idealWidth: size.width) + .frame(height: size.height) } } .processors([ @@ -155,7 +157,15 @@ struct CachedImage: View { contentMode: contentMode == .fill ? .aspectFill : .aspectFit ) ]) - .frame(idealWidth: size.width, maxHeight: size.height) + .frame(idealWidth: size.width) + .frame(height: size.height) + .onDisappear { + // if the post disappears and the size still isn't computed, cache the fallback size. This ensures that the view doesn't resize while scrolling back up. + if shouldRecomputeSize { + cacheImageSize() + shouldRecomputeSize = false + } + } } static func imageNotFoundDefault() -> AnyView { diff --git a/Mlem/Views/Shared/Posts/Post Sizes/Large Post.swift b/Mlem/Views/Shared/Posts/Post Sizes/Large Post.swift index d01b07d58..983ed81d2 100644 --- a/Mlem/Views/Shared/Posts/Post Sizes/Large Post.swift +++ b/Mlem/Views/Shared/Posts/Post Sizes/Large Post.swift @@ -92,12 +92,6 @@ struct LargePost: View { } } - // REMOVEME: needed for TF hack - @Environment(\.horizontalSizeClass) var horizontalSizeClass - var screenWidth: CGFloat = UIScreen.main.bounds.width - (AppConstants.postAndCommentSpacing * 2) - var imageWidth: CGFloat { horizontalSizeClass == .regular ? screenWidth * 0.8 : screenWidth } - var imageHeight: CGFloat { horizontalSizeClass == .regular ? 600 : screenWidth } - // initializer--used so we can set showNsfwFilterToggle to false when expanded or true when not init( post: PostModel, @@ -208,20 +202,15 @@ struct LargePost: View { if layoutMode != .minimize { CachedImage( url: url, - // maxHeight: layoutMode.getMaxHeight(limitHeight), - // CHANGEME: hack for TF release - fixedSize: CGSize(width: imageWidth, height: imageHeight), + maxHeight: layoutMode.getMaxHeight(limitHeight), dismissCallback: markPostAsRead, cornerRadius: AppConstants.largeItemCornerRadius ) - // CHANGEME: hack for TF release - .frame(height: imageHeight) - .frame(maxWidth: .infinity, alignment: .center) -// .frame( -// maxWidth: .infinity, -// maxHeight: layoutMode.getMaxHeight(limitHeight), -// alignment: .top -// ) + .frame( + maxWidth: .infinity, + maxHeight: layoutMode.getMaxHeight(limitHeight), + alignment: .top + ) .applyNsfwOverlay(post.post.nsfw || post.community.nsfw, canTapFullImage: isExpanded) .clipped() }