diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index 8ae6b44..3320cc2 100644 --- 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 = ""; }; 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = ""; }; 4CEE2AEE2805BE2500AB5EEF /* NostrTimeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrTimeline.swift; sourceTree = ""; }; + 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePicView.swift; sourceTree = ""; }; /* 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 = ""; @@ -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 index 165f40d..ccbbcc3 100644 --- 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 index b639677..06b9f11 100644 --- 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 new file mode 100644 index 0000000..5b74a6f --- /dev/null +++ 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) + } +}