damus

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

RelayNipList.swift (2024B)


      1 //
      2 //  RelayNipList.swift
      3 //  damus
      4 //
      5 //  Created by eric on 4/1/24.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct NIPNumber: View {
     11     let character: String
     12     
     13     var body: some View {
     14         NIPIcon {
     15             Text(verbatim: character)
     16                 .font(.title3.bold())
     17                 .mask(Text(verbatim: character)
     18                     .font(.title3.bold()))
     19         }
     20     }
     21 }
     22 
     23 struct NIPIcon<Content: View>: View {
     24     let content: Content
     25     
     26     init(@ViewBuilder content: () -> Content) {
     27         self.content = content()
     28     }
     29     
     30     var body: some View {
     31         ZStack {
     32             Circle()
     33                 .fill(DamusColors.neutral3)
     34                 .frame(width: 40, height: 40)
     35             
     36             content
     37                 .foregroundStyle(DamusColors.mediumGrey)
     38         }
     39     }
     40 }
     41 
     42 struct RelayNipList: View {
     43     
     44     let nips: [Int]
     45     @Environment(\.openURL) var openURL
     46     
     47     var body: some View {
     48         VStack(alignment: .leading, spacing: 10) {
     49             
     50             Text("Supported NIPs", comment: "Label to display relay's supported NIPs.")
     51                 .font(.callout)
     52                 .fontWeight(.bold)
     53                 .foregroundColor(DamusColors.mediumGrey)
     54             
     55             ScrollView(.horizontal) {
     56                 HStack {
     57                     ForEach(nips, id:\.self) { nip in
     58                         if let link = NIPURLBuilder.url(forNIP: nip) {
     59                             let nipString = NIPURLBuilder.formatNipNumber(nip: nip)
     60                             Button(action: {
     61                                 openURL(link)
     62                             }) {
     63                                 NIPNumber(character: "\(nipString)")
     64                             }
     65                         }
     66                     }
     67                 }
     68             }
     69             .padding(.bottom)
     70             .scrollIndicators(.hidden)
     71         }
     72     }
     73 }
     74 
     75 struct RelayNipList_Previews: PreviewProvider {
     76     static var previews: some View {
     77         RelayNipList(nips: [0, 1, 2, 3, 4, 11, 15, 50])
     78     }
     79 }