damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

ProfileNameView.swift (1765B)


      1 //
      2 //  ProfileNameView.swift
      3 //  damus
      4 //
      5 //  Created by William Casarin on 2023-02-07.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct ProfileNameView: View {
     11     let pubkey: Pubkey
     12     let damus: DamusState
     13     
     14     var spacing: CGFloat { 10.0 }
     15     
     16     var body: some View {
     17         Group {
     18             VStack(alignment: .leading) {
     19                 let profile_txn = self.damus.profiles.lookup(id: pubkey)
     20                 let profile = profile_txn?.unsafeUnownedValue
     21 
     22                 switch Profile.displayName(profile: profile, pubkey: pubkey) {
     23                 case .one:
     24                     HStack(alignment: .center, spacing: spacing) {
     25                         ProfileName(pubkey: pubkey, damus: damus, supporterBadgeStyle: .full)
     26                             .font(.title3.weight(.bold))
     27                     }
     28                 case .both(username: _, displayName: let displayName):
     29                     Text(displayName)
     30                         .font(.title3.weight(.bold))
     31                     
     32                     HStack(alignment: .center, spacing: spacing) {
     33                         ProfileName(pubkey: pubkey, prefix: "@", damus: damus, supporterBadgeStyle: .full)
     34                             .font(.callout)
     35                             .foregroundColor(.gray)
     36                     }
     37                 }
     38                 
     39                 Spacer()
     40                 
     41                 PubkeyView(pubkey: pubkey)
     42                     .pubkey_context_menu(pubkey: pubkey)
     43             }
     44         }
     45     }
     46 }
     47 
     48 struct ProfileNameView_Previews: PreviewProvider {
     49     static var previews: some View {
     50         VStack {
     51             ProfileNameView(pubkey: test_note.pubkey, damus: test_damus_state)
     52 
     53             ProfileNameView(pubkey: test_note.pubkey, damus: test_damus_state)
     54         }
     55     }
     56 }