damus

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

AboutView.swift (2018B)


      1 //
      2 //  AboutView.swift
      3 //  damus
      4 //
      5 //  Created by William Casarin on 2023-06-18.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct AboutView: View {
     11     let state: DamusState
     12     let about: String
     13     let max_about_length: Int
     14     let text_alignment: NSTextAlignment
     15     @State var show_full_about: Bool = false
     16     @State private var about_string: AttributedString? = nil
     17     
     18     init(state: DamusState, about: String, max_about_length: Int? = nil, text_alignment: NSTextAlignment? = nil) {
     19         self.state = state
     20         self.about = about
     21         self.max_about_length = max_about_length ?? 280
     22         self.text_alignment = text_alignment ?? .natural
     23     }
     24     
     25     var body: some View {
     26         Group {
     27             if let about_string {
     28                 let truncated_about = show_full_about ? about_string : about_string.truncateOrNil(maxLength: max_about_length)
     29                 SelectableText(attributedString: truncated_about ?? about_string, textAlignment: self.text_alignment, size: .subheadline)
     30 
     31                 if truncated_about != nil {
     32                     if show_full_about {
     33                         Button(NSLocalizedString("Show less", comment: "Button to show less of a long profile description.")) {
     34                             show_full_about = false
     35                         }
     36                         .font(.footnote)
     37                     } else {
     38                         Button(NSLocalizedString("Show more", comment: "Button to show more of a long profile description.")) {
     39                             show_full_about = true
     40                         }
     41                         .font(.footnote)
     42                     }
     43                 }
     44             } else {
     45                 Text(verbatim: "")
     46                     .font(.subheadline)
     47             }
     48         }
     49         .onAppear {
     50             let blocks = parse_note_content(content: .content(about, nil))
     51             about_string = render_blocks(blocks: blocks, profiles: state.profiles).content.attributed
     52         }
     53         
     54     }
     55 }
     56 
     57 /*
     58  #Preview {
     59  AboutView()
     60  }
     61  */