Fix Compose reply scroll effect not working on iOS 13

This commit is contained in:
Shadowfacts 2020-09-07 16:54:56 -04:00
parent dd8a196630
commit 9a4ddfea3f
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 13 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import SwiftUI
struct ComposeReplyView: View { struct ComposeReplyView: View {
let status: StatusMO let status: StatusMO
let stackPadding: CGFloat let stackPadding: CGFloat
let outerMinY: CGFloat
@State private var contentHeight: CGFloat? @State private var contentHeight: CGFloat?
@ -48,8 +49,11 @@ struct ComposeReplyView: View {
} }
private func replyAvatarImage(geometry: GeometryProxy) -> some View { private func replyAvatarImage(geometry: GeometryProxy) -> some View {
let scrollOffset = geometry.frame(in: .named("outer")).minY - stackPadding // using named coordinate spaces produces an incorrect scroll offset on iOS 13,
let offset = min(max(-scrollOffset, 0), geometry.size.height - 50 - 8) // 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) return ComposeAvatarImageView(url: status.account.avatar)
.offset(x: 0, y: offset) .offset(x: 0, y: offset)
} }

View File

@ -57,14 +57,15 @@ struct ComposeView: View {
var mostOfTheBody: some View { var mostOfTheBody: some View {
ZStack(alignment: .top) { ZStack(alignment: .top) {
GeometryReader { (outer) in
ScrollView(.vertical) { ScrollView(.vertical) {
mainStack mainStack(outerMinY: outer.frame(in: .global).minY)
}
} }
// can't use SwiftUI.ProgressView because there's no UIProgressView.Style.bar equivalent, see FB8587149 // can't use SwiftUI.ProgressView because there's no UIProgressView.Style.bar equivalent, see FB8587149
WrappedProgressView(value: postProgress, total: postTotalProgress) WrappedProgressView(value: postProgress, total: postTotalProgress)
} }
.coordinateSpace(name: "outer")
.onAppear(perform: self.didAppear) .onAppear(perform: self.didAppear)
.navigationBarTitle("Compose") .navigationBarTitle("Compose")
.actionSheet(isPresented: $uiState.isShowingSaveDraftSheet, content: self.saveAndCloseSheet) .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) { VStack(alignment: .leading, spacing: 8) {
if let id = draft.inReplyToID, if let id = draft.inReplyToID,
let status = mastodonController.persistentContainer.status(for: id) { let status = mastodonController.persistentContainer.status(for: id) {
ComposeReplyView( ComposeReplyView(
status: status, status: status,
stackPadding: stackPadding stackPadding: stackPadding,
outerMinY: outerMinY
) )
} }