From 9a4ddfea3f968bef67a744c3f7bea0924839d910 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 7 Sep 2020 16:54:56 -0400 Subject: [PATCH] Fix Compose reply scroll effect not working on iOS 13 --- Tusker/Screens/Compose/ComposeReplyView.swift | 8 ++++++-- Tusker/Screens/Compose/ComposeView.swift | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeReplyView.swift b/Tusker/Screens/Compose/ComposeReplyView.swift index 6c5d6193f0..0be41d9372 100644 --- a/Tusker/Screens/Compose/ComposeReplyView.swift +++ b/Tusker/Screens/Compose/ComposeReplyView.swift @@ -11,6 +11,7 @@ import SwiftUI struct ComposeReplyView: View { let status: StatusMO let stackPadding: CGFloat + let outerMinY: CGFloat @State private var contentHeight: CGFloat? @@ -48,8 +49,11 @@ struct ComposeReplyView: View { } private func replyAvatarImage(geometry: GeometryProxy) -> some View { - let scrollOffset = geometry.frame(in: .named("outer")).minY - stackPadding - let offset = min(max(-scrollOffset, 0), geometry.size.height - 50 - 8) + // 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) return ComposeAvatarImageView(url: status.account.avatar) .offset(x: 0, y: offset) } diff --git a/Tusker/Screens/Compose/ComposeView.swift b/Tusker/Screens/Compose/ComposeView.swift index 6f35a1fee3..fc23aff9ec 100644 --- a/Tusker/Screens/Compose/ComposeView.swift +++ b/Tusker/Screens/Compose/ComposeView.swift @@ -57,14 +57,15 @@ struct ComposeView: View { var mostOfTheBody: some View { ZStack(alignment: .top) { - ScrollView(.vertical) { - mainStack + GeometryReader { (outer) in + ScrollView(.vertical) { + mainStack(outerMinY: outer.frame(in: .global).minY) + } } // can't use SwiftUI.ProgressView because there's no UIProgressView.Style.bar equivalent, see FB8587149 WrappedProgressView(value: postProgress, total: postTotalProgress) } - .coordinateSpace(name: "outer") .onAppear(perform: self.didAppear) .navigationBarTitle("Compose") .actionSheet(isPresented: $uiState.isShowingSaveDraftSheet, content: self.saveAndCloseSheet) @@ -77,13 +78,14 @@ struct ComposeView: View { } } - var mainStack: some View { + func mainStack(outerMinY: CGFloat) -> some View { VStack(alignment: .leading, spacing: 8) { if let id = draft.inReplyToID, let status = mastodonController.persistentContainer.status(for: id) { ComposeReplyView( status: status, - stackPadding: stackPadding + stackPadding: stackPadding, + outerMinY: outerMinY ) }