2020-08-31 23:28:50 +00:00
|
|
|
//
|
|
|
|
// 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
|
2020-09-07 20:54:56 +00:00
|
|
|
let outerMinY: CGFloat
|
2020-08-31 23:28:50 +00:00
|
|
|
|
2020-09-07 02:47:02 +00:00
|
|
|
@State private var contentHeight: CGFloat?
|
|
|
|
|
2020-10-12 02:14:45 +00:00
|
|
|
@ObservedObject private var preferences = Preferences.shared
|
|
|
|
|
2020-08-31 23:28:50 +00:00
|
|
|
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 {
|
2020-09-07 19:22:06 +00:00
|
|
|
AccountDisplayNameLabel(account: status.account, fontSize: 17)
|
2020-08-31 23:28:50 +00:00
|
|
|
.lineLimit(1)
|
|
|
|
.layoutPriority(1)
|
|
|
|
|
|
|
|
Text(verbatim: "@\(status.account.acct)")
|
|
|
|
.font(.system(size: 17, weight: .light))
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.lineLimit(1)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
|
2020-09-07 02:47:02 +00:00
|
|
|
ComposeReplyContentView(status: status) { (newHeight) in
|
|
|
|
self.contentHeight = newHeight
|
|
|
|
}
|
2020-08-31 23:28:50 +00:00
|
|
|
.offset(x: -4, y: -8)
|
|
|
|
.padding(.bottom, -8)
|
|
|
|
}
|
2020-10-24 15:34:49 +00:00
|
|
|
.frame(height: max(50, contentHeight ?? 0) + 8)
|
2020-08-31 23:28:50 +00:00
|
|
|
}
|
|
|
|
.padding(.bottom, -8)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func replyAvatarImage(geometry: GeometryProxy) -> some View {
|
2020-09-07 20:54:56 +00:00
|
|
|
// 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)
|
2020-08-31 23:28:50 +00:00
|
|
|
return ComposeAvatarImageView(url: status.account.avatar)
|
2020-10-12 02:14:45 +00:00
|
|
|
.frame(width: 50, height: 50)
|
|
|
|
.cornerRadius(preferences.avatarStyle.cornerRadiusFraction * 50)
|
2020-08-31 23:28:50 +00:00
|
|
|
.offset(x: 0, y: offset)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//struct ComposeReplyView_Previews: PreviewProvider {
|
|
|
|
// static var previews: some View {
|
|
|
|
// ComposeReplyView()
|
|
|
|
// }
|
|
|
|
//}
|