Improve reply view

Changelog-Changed: Improved look of reply view
This commit is contained in:
ericholguin
2023-03-29 15:05:33 -06:00
committed by William Casarin
parent 7a55ea13e3
commit 0dd74fde7f
5 changed files with 155 additions and 119 deletions

View File

@@ -7,71 +7,71 @@
import SwiftUI
func all_referenced_pubkeys(_ ev: NostrEvent) -> [ReferencedId] {
var keys = ev.referenced_pubkeys
let ref = ReferencedId(ref_id: ev.pubkey, relay_id: nil, key: "p")
keys.insert(ref, at: 0)
return keys
}
struct ReplyView: View {
let replying_to: NostrEvent
let damus: DamusState
@State var originalReferences: [ReferencedId] = []
@State var references: [ReferencedId] = []
@Binding var originalReferences: [ReferencedId]
@Binding var references: [ReferencedId]
@State var participantsShown: Bool = false
var body: some View {
VStack {
Text("Replying to:", comment: "Indicating that the user is replying to the following listed people.")
HStack(alignment: .top) {
var ReplyingToSection: some View {
HStack {
Group {
let names = references.pRefs
.map { pubkey in
let pk = pubkey.ref_id
let prof = damus.profiles.lookup(id: pk)
return Profile.displayName(profile: prof, pubkey: pk).username
return "@" + Profile.displayName(profile: prof, pubkey: pk).username
}
.joined(separator: ", ")
Text(names)
.joined(separator: " ")
Text("Replying to ", comment: "Indicating that the user is replying to the following listed people.")
.foregroundColor(.gray)
.font(.footnote) +
Text(names.isEmpty ? "self" : names)
.foregroundColor(.accentColor)
.font(.footnote)
}
.onTapGesture {
participantsShown.toggle()
}
.sheet(isPresented: $participantsShown) {
ParticipantsView(damus_state: damus, references: $references, originalReferences: $originalReferences)
}
ScrollViewReader { scroller in
ScrollView {
EventView(damus: damus, event: replying_to, options: [.no_action_bar])
PostView(replying_to: replying_to, references: references, damus_state: damus)
.frame(minHeight: 500, maxHeight: .infinity)
.id("post")
}
.frame(maxHeight: .infinity)
.onAppear {
scroll_to_event(scroller: scroller, id: "post", delay: 1.0, animate: true, anchor: .top)
if #available(iOS 16.0, *) {
ParticipantsView(damus_state: damus, references: $references, originalReferences: $originalReferences)
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
} else {
ParticipantsView(damus_state: damus, references: $references, originalReferences: $originalReferences)
}
}
}
.padding()
.onAppear {
references = gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to)
originalReferences = references
.padding(.leading, 75)
Spacer()
}
}
}
var body: some View {
VStack(alignment: .leading) {
struct ReplyView_Previews: PreviewProvider {
static var previews: some View {
ReplyView(replying_to: NostrEvent(content: "hi", pubkey: "pubkey"), damus: test_damus_state(), references: [])
EventView(damus: damus, event: replying_to, options: [.no_action_bar])
.padding()
.background(GeometryReader { geometry in
let eventHeight = geometry.frame(in: .global).height
Rectangle()
.fill(Color.gray.opacity(0.25))
.frame(width: 2, height: eventHeight + 7)
.offset(x: 25, y: 40)
.padding(.leading)
})
ReplyingToSection
.background(GeometryReader { geometry in
let replyingToHeight = geometry.frame(in: .global).height
Rectangle()
.fill(Color.gray.opacity(0.25))
.frame(width: 2, height: replyingToHeight)
.offset(x: 25, y: 40)
.padding(.leading)
})
}
}
}