Colorize friend icons

No reason why nip05 badges should have all the fun

Changelog-Added: Colorize friend icons
This commit is contained in:
William Casarin
2023-04-20 14:30:27 -07:00
parent ac82f1bc09
commit 191950a5aa
5 changed files with 63 additions and 22 deletions

View File

@@ -35,10 +35,10 @@ struct NIP05Badge: View {
.mask(Image(systemName: "checkmark.seal.fill")
.resizable()
).frame(width: 14, height: 14)
} else {
} else if show_domain {
Image(systemName: "checkmark.seal.fill")
.font(.footnote)
.foregroundColor(.gray)
.nip05_colorized(gradient: nip05_color)
}
}
}

View File

@@ -39,8 +39,8 @@ struct EventProfileName: View {
self.size = size
}
var friend_icon: String? {
return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: show_friend_confirmed)
var friend_type: FriendType? {
return get_friend_type(contacts: damus_state.contacts, pubkey: self.pubkey)
}
var current_nip05: NIP05? {
@@ -71,10 +71,8 @@ struct EventProfileName: View {
NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: false, clickable: false)
}
if let frend = friend_icon, current_nip05 == nil {
Label("", systemImage: frend)
.foregroundColor(.gray)
.font(.footnote)
if current_nip05 == nil, let frend = friend_type {
FriendIcon(friend: frend)
}
}
.onReceive(handle_notify(.profile_updated)) { notif in

View File

@@ -0,0 +1,39 @@
//
// FriendIcon.swift
// damus
//
// Created by William Casarin on 2023-04-20.
//
import SwiftUI
struct FriendIcon: View {
let friend: FriendType
var body: some View {
Group {
switch friend {
case .friend:
LINEAR_GRADIENT
.mask(Image(systemName: "person.fill.checkmark")
.resizable()
).frame(width: 20, height: 14)
case .fof:
Image(systemName: "person.fill.and.arrow.left.and.arrow.right")
.resizable()
.frame(width: 21, height: 14)
.foregroundColor(.gray)
}
}
}
}
struct FriendIcon_Previews: PreviewProvider {
static var previews: some View {
VStack {
FriendIcon(friend: .friend)
FriendIcon(friend: .fof)
}
}
}

View File

@@ -7,17 +7,18 @@
import SwiftUI
func get_friend_icon(contacts: Contacts, pubkey: String, show_confirmed: Bool) -> String? {
if !show_confirmed {
return nil
}
enum FriendType {
case friend
case fof
}
func get_friend_type(contacts: Contacts, pubkey: String) -> FriendType? {
if contacts.is_friend_or_self(pubkey) {
return "person.fill.checkmark"
return .friend
}
if contacts.is_friend_of_friend(pubkey) {
return "person.fill.and.arrow.left.and.arrow.right"
return .fof
}
return nil
@@ -53,8 +54,8 @@ struct ProfileName: View {
self.show_nip5_domain = show_nip5_domain
}
var friend_icon: String? {
return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: show_friend_confirmed)
var friend_type: FriendType? {
return get_friend_type(contacts: damus_state.contacts, pubkey: self.pubkey)
}
var current_nip05: NIP05? {
@@ -77,9 +78,8 @@ struct ProfileName: View {
if let nip05 = current_nip05 {
NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: show_nip5_domain, clickable: true)
}
if let friend = friend_icon, current_nip05 == nil {
Image(systemName: friend)
.foregroundColor(.gray)
if let friend = friend_type, current_nip05 == nil {
FriendIcon(friend: friend)
}
}
.onReceive(handle_notify(.profile_updated)) { notif in