refactor profile pic into view

we'll need this in thread and event details view

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-16 09:33:33 -07:00
parent 698ddb31cc
commit d3d8b56a08
4 changed files with 44 additions and 16 deletions

View File

@@ -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

View File

@@ -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()
}

View File

@@ -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)
}
}