forked from shadowfacts/Tusker
Shadowfacts
262aadf807
Using a non-scrolling UITextView wrapped in SwiftUI combined with the old hack of fixing its layout by passing the view controller's width down to the wrapped view caused very slow layouts, resulting in significant lag when typing into the main text view of the compose screen.
65 lines
2.0 KiB
Swift
65 lines
2.0 KiB
Swift
//
|
|
// ComposeReplyView.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 8/22/20.
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ComposeReplyView: View {
|
|
let status: StatusMO
|
|
let stackPadding: CGFloat
|
|
|
|
@State private var contentHeight: CGFloat?
|
|
|
|
private let horizSpacing: CGFloat = 8
|
|
|
|
var body: some View {
|
|
HStack(alignment: .top, spacing: horizSpacing) {
|
|
GeometryReader(content: self.replyAvatarImage)
|
|
.frame(width: 50)
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
HStack {
|
|
Text(verbatim: status.account.displayName)
|
|
.font(.system(size: 17, weight: .semibold))
|
|
.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
|
|
}
|
|
.frame(height: contentHeight)
|
|
.offset(x: -4, y: -8)
|
|
.padding(.bottom, -8)
|
|
}
|
|
.frame(minHeight: 50 + 8)
|
|
}
|
|
.padding(.bottom, -8)
|
|
}
|
|
|
|
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)
|
|
return ComposeAvatarImageView(url: status.account.avatar)
|
|
.offset(x: 0, y: offset)
|
|
}
|
|
|
|
}
|
|
|
|
//struct ComposeReplyView_Previews: PreviewProvider {
|
|
// static var previews: some View {
|
|
// ComposeReplyView()
|
|
// }
|
|
//}
|