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 {
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)
}

View File

@ -57,14 +57,15 @@ struct ComposeView: View {
var mostOfTheBody: some View {
ZStack(alignment: .top) {
GeometryReader { (outer) in
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
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
)
}