damus

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

commit d3d8b56a0836229da7498574cb5abe82cde7e285
parent 698ddb31cceecfaf36e4fe3e2f619e377c8291ca
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 16 Apr 2022 09:33:33 -0700

refactor profile pic into view

we'll need this in thread and event details view

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Mdamus/ContentView.swift | 3---
Mdamus/Views/EventView.swift | 14+-------------
Adamus/Views/ProfilePicView.swift | 39+++++++++++++++++++++++++++++++++++++++
4 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 4CEE2AEB2805AEA300AB5EEF /* secp256k1 in Frameworks */ = {isa = PBXBuildFile; productRef = 4CEE2AEA2805AEA300AB5EEF /* secp256k1 */; }; 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; }; 4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEE2805BE2500AB5EEF /* NostrTimeline.swift */; }; + 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -75,6 +76,7 @@ 4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = "<group>"; }; 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = "<group>"; }; 4CEE2AEE2805BE2500AB5EEF /* NostrTimeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrTimeline.swift; sourceTree = "<group>"; }; + 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePicView.swift; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -111,6 +113,7 @@ 4C75EFA327FA577B0006080F /* PostView.swift */, 4C75EFAC28049CFB0006080F /* PostButton.swift */, 4C75EFB82804A2740006080F /* EventView.swift */, + 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */, ); path = Views; sourceTree = "<group>"; @@ -350,6 +353,7 @@ 4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */, 4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */, 4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */, + 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */, 4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */, 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */, 4C75EFA427FA577B0006080F /* PostView.swift in Sources */, diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -8,9 +8,6 @@ import SwiftUI import Starscream -let PFP_SIZE: CGFloat? = 64 -let CORNER_RADIUS: CGFloat = 32 - struct TimestampedProfile { let profile: Profile let timestamp: Int64 diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -16,19 +16,7 @@ struct EventView: View { var body: some View { HStack { VStack { - if let pic = profile?.picture.flatMap { URL(string: $0) } { - CachedAsyncImage(url: pic) { img in - img.resizable() - } placeholder: { - Color.purple.opacity(0.1) - } - .frame(width: PFP_SIZE, height: PFP_SIZE) - .cornerRadius(CORNER_RADIUS) - } else { - Color.purple.opacity(0.1) - .frame(width: PFP_SIZE, height: PFP_SIZE) - .cornerRadius(CORNER_RADIUS) - } + ProfilePicView(picture: profile?.picture, size: 64) Spacer() } diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift @@ -0,0 +1,39 @@ +// +// ProfilePicView.swift +// damus +// +// Created by William Casarin on 2022-04-16. +// + +import SwiftUI +import CachedAsyncImage + +let PFP_SIZE: CGFloat? = 64 +let CORNER_RADIUS: CGFloat = 32 + +struct ProfilePicView: View { + let picture: String? + let size: CGFloat + + var body: some View { + if let pic = picture.flatMap({ URL(string: $0) }) { + CachedAsyncImage(url: pic) { img in + img.resizable() + } placeholder: { + Color.purple.opacity(0.1) + } + .frame(width: PFP_SIZE, height: PFP_SIZE) + .cornerRadius(CORNER_RADIUS) + } else { + Color.purple.opacity(0.1) + .frame(width: PFP_SIZE, height: PFP_SIZE) + .cornerRadius(CORNER_RADIUS) + } + } +} + +struct ProfilePicView_Previews: PreviewProvider { + static var previews: some View { + ProfilePicView(picture: "http://cdn.jb55.com/img/red-me.jpg", size: 64) + } +}