From 44dc6251dfed0356bce0052f9b40af730eafdc6c Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sat, 30 Sep 2023 11:15:07 -0400 Subject: [PATCH 1/3] fixed scrolling regression --- Mlem/Views/Shared/Cached Image.swift | 9 +++++--- .../Shared/Posts/Post Sizes/Large Post.swift | 23 +++++-------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Mlem/Views/Shared/Cached Image.swift b/Mlem/Views/Shared/Cached Image.swift index dd7789cd8..fdf212017 100644 --- a/Mlem/Views/Shared/Cached Image.swift +++ b/Mlem/Views/Shared/Cached Image.swift @@ -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,8 @@ struct CachedImage: View { contentMode: contentMode == .fill ? .aspectFill : .aspectFit ) ]) - .frame(idealWidth: size.width, maxHeight: size.height) + .frame(idealWidth: size.width) + .frame(height: size.height) } 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() } From 32441067bf9bfef2cfb9ab61a195b81735c2cddf Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sat, 30 Sep 2023 21:14:38 -0400 Subject: [PATCH 2/3] 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 { From 84919ae18e360d87e8945f080c2bfe38440d9803 Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sat, 30 Sep 2023 21:16:20 -0400 Subject: [PATCH 3/3] rebased --- Mlem/Views/Shared/Cached Image.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mlem/Views/Shared/Cached Image.swift b/Mlem/Views/Shared/Cached Image.swift index 6be397ec5..e72f2d1f6 100644 --- a/Mlem/Views/Shared/Cached Image.swift +++ b/Mlem/Views/Shared/Cached Image.swift @@ -160,7 +160,7 @@ 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 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