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:
@@ -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()
|
||||
}
|
||||
|
||||
39
damus/Views/ProfilePicView.swift
Normal file
39
damus/Views/ProfilePicView.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user