Browse Source

refactor profile pic into view

we'll need this in thread and event details view

Signed-off-by: William Casarin <jb55@jb55.com>
profiles-everywhere
William Casarin 3 years ago
parent
commit
d3d8b56a08
  1. 4
      damus.xcodeproj/project.pbxproj
  2. 3
      damus/ContentView.swift
  3. 14
      damus/Views/EventView.swift
  4. 39
      damus/Views/ProfilePicView.swift

4
damus.xcodeproj/project.pbxproj

@ -30,6 +30,7 @@
4CEE2AEB2805AEA300AB5EEF /* secp256k1 in Frameworks */ = {isa = PBXBuildFile; productRef = 4CEE2AEA2805AEA300AB5EEF /* secp256k1 */; }; 4CEE2AEB2805AEA300AB5EEF /* secp256k1 in Frameworks */ = {isa = PBXBuildFile; productRef = 4CEE2AEA2805AEA300AB5EEF /* secp256k1 */; };
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; }; 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; };
4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEE2805BE2500AB5EEF /* NostrTimeline.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 */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -75,6 +76,7 @@
4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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 */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -111,6 +113,7 @@
4C75EFA327FA577B0006080F /* PostView.swift */, 4C75EFA327FA577B0006080F /* PostView.swift */,
4C75EFAC28049CFB0006080F /* PostButton.swift */, 4C75EFAC28049CFB0006080F /* PostButton.swift */,
4C75EFB82804A2740006080F /* EventView.swift */, 4C75EFB82804A2740006080F /* EventView.swift */,
4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */,
); );
path = Views; path = Views;
sourceTree = "<group>"; sourceTree = "<group>";
@ -350,6 +353,7 @@
4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */, 4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */,
4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */, 4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */,
4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */, 4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */,
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */,
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */, 4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */,
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */, 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */,
4C75EFA427FA577B0006080F /* PostView.swift in Sources */, 4C75EFA427FA577B0006080F /* PostView.swift in Sources */,

3
damus/ContentView.swift

@ -8,9 +8,6 @@
import SwiftUI import SwiftUI
import Starscream import Starscream
let PFP_SIZE: CGFloat? = 64
let CORNER_RADIUS: CGFloat = 32
struct TimestampedProfile { struct TimestampedProfile {
let profile: Profile let profile: Profile
let timestamp: Int64 let timestamp: Int64

14
damus/Views/EventView.swift

@ -16,19 +16,7 @@ struct EventView: View {
var body: some View { var body: some View {
HStack { HStack {
VStack { VStack {
if let pic = profile?.picture.flatMap { URL(string: $0) } { ProfilePicView(picture: profile?.picture, size: 64)
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)
}
Spacer() Spacer()
} }

39
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)
}
}
Loading…
Cancel
Save