damus

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

commit c6c47e824a3b6b247c698a79c14a272991493f07
parent d19596c17ea59088e6607b023fcf1cfec7564e81
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 27 Mar 2023 10:39:07 -0400

reduce code duplication in nip05 gradients

Diffstat:
Mdamus/Components/NIP05Badge.swift | 43+++++++++++++++++++++++++------------------
Mdamus/Views/ActionBar/EventActionBar.swift | 12+++---------
2 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/damus/Components/NIP05Badge.swift b/damus/Components/NIP05Badge.swift @@ -28,8 +28,8 @@ struct NIP05Badge: View { return use_nip05_color(pubkey: pubkey, contacts: contacts) } - var body: some View { - HStack(spacing: 2) { + var Seal: some View { + Group { if nip05_color { LINEAR_GRADIENT .mask(Image(systemName: "checkmark.seal.fill") @@ -40,26 +40,22 @@ struct NIP05Badge: View { .font(.footnote) .foregroundColor(.gray) } + } + } + + var body: some View { + HStack(spacing: 2) { + Seal if show_domain { if clickable { - if nip05_color { - Text(nip05.host) - .foregroundStyle(LINEAR_GRADIENT) - .onTapGesture { - if let nip5url = nip05.siteUrl { - openURL(nip5url) - } - } - } else { - Text(nip05.host) - .foregroundColor(.gray) - .onTapGesture { - if let nip5url = nip05.siteUrl { - openURL(nip5url) - } + Text(nip05.host) + .nip05_colorized(gradient: nip05_color) + .onTapGesture { + if let nip5url = nip05.siteUrl { + openURL(nip5url) } - } + } } else { Text(nip05.host) .foregroundColor(.gray) @@ -70,6 +66,17 @@ struct NIP05Badge: View { } } +extension View { + func nip05_colorized(gradient: Bool) -> some View { + if gradient { + return AnyView(self.foregroundStyle(LINEAR_GRADIENT)) + } else { + return AnyView(self.foregroundColor(.gray)) + } + + } +} + func use_nip05_color(pubkey: String, contacts: Contacts) -> Bool { return contacts.is_friend_or_self(pubkey) ? true : false } diff --git a/damus/Views/ActionBar/EventActionBar.swift b/damus/Views/ActionBar/EventActionBar.swift @@ -77,16 +77,10 @@ struct EventActionBar: View { send_like() } } - if bar.liked { - Text(verbatim: "\(bar.likes > 0 ? "\(bar.likes)" : "")") - .font(.footnote.weight(.medium)) - .foregroundStyle(LINEAR_GRADIENT) - } else { - Text(verbatim: "\(bar.likes > 0 ? "\(bar.likes)" : "")") - .font(.footnote.weight(.medium)) - .foregroundColor(Color.gray) - } + Text(verbatim: "\(bar.likes > 0 ? "\(bar.likes)" : "")") + .font(.footnote.weight(.medium)) + .nip05_colorized(gradient: bar.liked) } if let lnurl = self.lnurl {