ReplyView.swift (4067B)
1 // 2 // ReplyView.swift 3 // damus 4 // 5 // Created by William Casarin on 2022-04-17. 6 // 7 8 import SwiftUI 9 10 struct ReplyView: View { 11 let replying_to: NostrEvent 12 let damus: DamusState 13 14 let original_pubkeys: [Pubkey] 15 @Binding var filtered_pubkeys: Set<Pubkey> 16 @State var participantsShown: Bool = false 17 18 var references: [Pubkey] { 19 original_pubkeys.filter { pk in 20 !filtered_pubkeys.contains(pk) 21 } 22 } 23 24 var ReplyingToSection: some View { 25 HStack { 26 Group { 27 let names = references 28 .map { pubkey in 29 let pk = pubkey 30 let prof = damus.ndb.lookup_profile(pk)?.unsafeUnownedValue?.profile 31 return "@" + Profile.displayName(profile: prof, pubkey: pk).username.truncate(maxLength: 50) 32 } 33 .joined(separator: " ") 34 if names.isEmpty { 35 Text("Replying to \(Text("self", comment: "Part of a larger sentence 'Replying to self' in US English. 'self' indicates that the user is replying to themself and no one else.").foregroundColor(.accentColor).font(.footnote))", comment: "Indicating that the user is replying to the themself and no one else, where the parameter is 'self' in US English.") 36 .foregroundColor(.gray) 37 .font(.footnote) 38 } else { 39 Text("Replying to \(Text(verbatim: names).foregroundColor(.accentColor).font(.footnote))", comment: "Indicating that the user is replying to the following listed people.") 40 .foregroundColor(.gray) 41 .font(.footnote) 42 } 43 } 44 .onTapGesture { 45 participantsShown.toggle() 46 } 47 .sheet(isPresented: $participantsShown) { 48 if #available(iOS 16.0, *) { 49 ParticipantsView(damus_state: damus, 50 original_pubkeys: self.original_pubkeys, 51 filtered_pubkeys: $filtered_pubkeys) 52 .presentationDetents([.medium, .large]) 53 .presentationDragIndicator(.visible) 54 } else { 55 ParticipantsView(damus_state: damus, 56 original_pubkeys: self.original_pubkeys, 57 filtered_pubkeys: $filtered_pubkeys) 58 } 59 } 60 .padding(.leading, 75) 61 Spacer() 62 } 63 } 64 65 func line(height: CGFloat) -> some View { 66 return Rectangle() 67 .fill(Color.gray.opacity(0.25)) 68 .frame(width: 2, height: height) 69 .offset(x: 25, y: 40) 70 .padding(.leading) 71 } 72 73 var body: some View { 74 VStack(alignment: .leading) { 75 EventView(damus: damus, event: replying_to, options: [.no_action_bar]) 76 .padding() 77 .background(GeometryReader { geometry in 78 let eventHeight = geometry.frame(in: .global).height 79 line(height: eventHeight) 80 }) 81 82 ReplyingToSection 83 .background(GeometryReader { geometry in 84 let replyingToHeight = geometry.frame(in: .global).height 85 line(height: replyingToHeight) 86 }) 87 } 88 } 89 } 90 91 struct ReplyView_Previews: PreviewProvider { 92 static var previews: some View { 93 VStack { 94 ReplyView(replying_to: test_note, 95 damus: test_damus_state, 96 original_pubkeys: [], 97 filtered_pubkeys: .constant([])) 98 .frame(height: 300) 99 100 ReplyView(replying_to: test_longform_event.event, 101 damus: test_damus_state, 102 original_pubkeys: [], 103 filtered_pubkeys: .constant([])) 104 .frame(height: 300) 105 } 106 } 107 }