Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed scrolling regression #677

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions 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 @@ -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([
Expand All @@ -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 {
Expand Down
23 changes: 6 additions & 17 deletions Mlem/Views/Shared/Posts/Post Sizes/Large Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down