Better profile header (#526)

* Prevent opening quicklook for missing avatar or header. Fixes #127

* Using theme for missing header background in profile

* fix

---------

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
Thomas Durand 2023-01-30 07:15:18 +01:00 committed by GitHub
parent d9546d92d9
commit c6c066564d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -38,20 +38,20 @@ struct AccountDetailHeaderView: View {
ZStack(alignment: .bottomTrailing) {
if reasons.contains(.placeholder) {
Rectangle()
.foregroundColor(.gray)
.foregroundColor(theme.secondaryBackgroundColor)
.frame(height: bannerHeight)
} else {
LazyImage(url: account.header) { state in
if let image = state.image {
image
.resizingMode(.aspectFill)
.overlay(.black.opacity(0.50))
.overlay(account.haveHeader ? .black.opacity(0.50) : .clear)
} else if state.isLoading {
Color.gray
theme.secondaryBackgroundColor
.frame(height: bannerHeight)
.shimmering()
} else {
Color.gray
theme.secondaryBackgroundColor
.frame(height: bannerHeight)
}
}
@ -68,11 +68,14 @@ struct AccountDetailHeaderView: View {
.padding(8)
}
}
.background(Color.gray)
.background(theme.secondaryBackgroundColor)
.frame(height: bannerHeight)
.offset(y: scrollOffset > 0 ? -scrollOffset : 0)
.contentShape(Rectangle())
.onTapGesture {
guard account.haveHeader else {
return
}
Task {
await quickLook.prepareFor(urls: [account.header], selectedURL: account.header)
}
@ -83,6 +86,9 @@ struct AccountDetailHeaderView: View {
HStack {
AvatarView(url: account.avatar, size: .account)
.onTapGesture {
guard account.haveAvatar else {
return
}
Task {
await quickLook.prepareFor(urls: [account.avatar], selectedURL: account.avatar)
}

View file

@ -43,6 +43,14 @@ public struct Account: Decodable, Identifiable, Equatable, Hashable {
public let bot: Bool
public let discoverable: Bool?
public var haveAvatar: Bool {
return avatar.lastPathComponent != "missing.png"
}
public var haveHeader: Bool {
return header.lastPathComponent != "missing.png"
}
public static func placeholder() -> Account {
.init(id: UUID().uuidString,
username: "Username",