damus

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

EmojiListItemView.swift (2095B)


      1 //
      2 //  EmojiListItemView.swift
      3 //  damus
      4 //
      5 //  Created by Suhail Saqan on 7/16/23.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct EmojiListItemView: View {
     11     @ObservedObject var settings: UserSettingsStore
     12 
     13     let emoji: String
     14     let recommended: Bool
     15     
     16     @Binding var showActionButtons: Bool
     17     
     18     var body: some View {
     19         Group {
     20             HStack {
     21                 if showActionButtons {
     22                     if recommended {
     23                         AddButton()
     24                     } else {
     25                         RemoveButton()
     26                     }
     27                 }
     28                 
     29                 Text(emoji)
     30             }
     31         }
     32         .swipeActions {
     33             if !recommended {
     34                 RemoveButton()
     35                     .tint(.red)
     36             } else {
     37                 AddButton()
     38                     .tint(.green)
     39             }
     40         }
     41         .contextMenu {
     42             if !showActionButtons {
     43                 CopyAction(emoji: emoji)
     44             }
     45         }
     46     }
     47     
     48     func CopyAction(emoji: String) -> some View {
     49         Button {
     50             UIPasteboard.general.setValue(emoji, forPasteboardType: "public.plain-text")
     51         } label: {
     52             Label(NSLocalizedString("Copy", comment: "Button to copy an emoji reaction"), image: "copy2")
     53         }
     54     }
     55         
     56     func RemoveButton() -> some View {
     57         Button(action: {
     58             if let index = settings.emoji_reactions.firstIndex(of: emoji) {
     59                 settings.emoji_reactions.remove(at: index)
     60             }
     61         }) {
     62             Image(systemName: "minus.circle")
     63                 .resizable()
     64                 .frame(width: 20, height: 20)
     65                 .foregroundColor(.red)
     66                 .padding(.leading, -5)
     67         }
     68     }
     69     
     70     func AddButton() -> some View {
     71         Button(action: {
     72             settings.emoji_reactions.append(emoji)
     73         }) {
     74             Image(systemName: "plus.circle")
     75                 .resizable()
     76                 .frame(width: 20, height: 20)
     77                 .foregroundColor(.green)
     78                 .padding(.leading, -5)
     79         }
     80     }
     81 }