From 8889261b6bf665a41aa605df77f61948a8d4b4d7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 9 Jun 2021 11:01:11 -0400 Subject: [PATCH] Fix compose reply avatar scroll effect not working on iOS 15 --- Tusker/Screens/Compose/ComposeReplyView.swift | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeReplyView.swift b/Tusker/Screens/Compose/ComposeReplyView.swift index 92ac9d70f5..8c984ef524 100644 --- a/Tusker/Screens/Compose/ComposeReplyView.swift +++ b/Tusker/Screens/Compose/ComposeReplyView.swift @@ -23,21 +23,21 @@ struct ComposeReplyView: View { HStack(alignment: .top, spacing: horizSpacing) { GeometryReader(content: self.replyAvatarImage) .frame(width: 50) - + VStack(alignment: .leading, spacing: 0) { HStack { AccountDisplayNameLabel(account: status.account, fontSize: 17) .lineLimit(1) .layoutPriority(1) - + Text(verbatim: "@\(status.account.acct)") .font(.system(size: 17, weight: .light)) .foregroundColor(.secondary) .lineLimit(1) - + Spacer() } - + ComposeReplyContentView(status: status) { (newHeight) in self.contentHeight = newHeight } @@ -52,9 +52,20 @@ struct ComposeReplyView: View { private func replyAvatarImage(geometry: GeometryProxy) -> some View { // using named coordinate spaces produces an incorrect scroll offset on iOS 13, // so simply compare the geometry inside and outside the scroll view in the global coordinate space - var scrollOffset = outerMinY - geometry.frame(in: .global).minY - scrollOffset += stackPadding - let offset = min(max(scrollOffset, 0), geometry.size.height - 50 - stackPadding) + let scrollOffset = outerMinY - geometry.frame(in: .global).minY + + // add stackPadding so that the image is always at least stackPadding away from the top + var offset = scrollOffset + stackPadding + + // offset can never be less than 0 (i.e., above the top of the in-reply-to content) + offset = max(offset, 0) + + // subtract 50, because we care about where the bottom of the view is but the offset is relative to the top of the view + let maxOffset = (contentHeight ?? 0) - 50 + + // once you scroll past the in-reply-to-content, the bottom of the avatar should be pinned to the bottom of the content + offset = min(offset, maxOffset) + return ComposeAvatarImageView(url: status.account.avatar) .frame(width: 50, height: 50) .cornerRadius(preferences.avatarStyle.cornerRadiusFraction * 50)