2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Add avatar to InlinePostPreview

Contributes to #399 [BUG] Multiple interactions do not collapse into a single notification
This commit is contained in:
shannon 2025-02-05 12:55:38 -05:00
parent 6155899a00
commit d8c4886f51
2 changed files with 45 additions and 24 deletions

View File

@ -14,28 +14,7 @@ struct InlinePostPreview: View {
var body: some View {
VStack(alignment: .leading) {
HStack(spacing: 4) {
if viewModel.needsUserAttribution {
RoundedRectangle(cornerRadius: 4)
.frame(width: 16, height: 16)
Text(viewModel.accountDisplayName ?? "")
.bold()
Text(viewModel.accountFullName ?? "")
.foregroundStyle(.secondary)
Spacer(minLength: 0)
} else if viewModel.isPinned {
// This *should* be a Label but it acts funky when this is in a List (i.e. in UserList)
Group {
Image(systemName: "pin.fill")
Text("Pinned")
}
.bold()
.foregroundStyle(.secondary)
.imageScale(.small)
}
}
.lineLimit(1)
.font(.subheadline)
header()
if let content = viewModel.content {
Text(content)
.lineLimit(3)
@ -43,12 +22,53 @@ struct InlinePostPreview: View {
}
.padding(8)
.frame(maxWidth: .infinity)
.overlay {
.background() {
RoundedRectangle(cornerRadius: 8)
.fill(.clear)
.stroke(.separator)
}
}
private let tinyAvatarSize: CGFloat = 16
private let avatarShape = RoundedRectangle(cornerRadius: 4)
@ViewBuilder func header() -> some View {
HStack(spacing: 4) {
if viewModel.needsUserAttribution {
if let url = viewModel.accountAvatarUrl {
AsyncImage(
url: url,
content: { image in
image.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(avatarShape)
},
placeholder: {
avatarShape
.foregroundStyle(Color(UIColor.secondarySystemFill))
}
)
.frame(width: tinyAvatarSize, height: tinyAvatarSize)
}
Text(viewModel.accountDisplayName ?? "")
.bold()
Text(viewModel.accountFullName ?? "")
.foregroundStyle(.secondary)
Spacer(minLength: 0)
} else if viewModel.isPinned {
// This *should* be a Label but it acts funky when this is in a List (i.e. in UserList)
Group {
Image(systemName: "pin.fill")
Text("Pinned")
}
.bold()
.foregroundStyle(.secondary)
.imageScale(.small)
}
}
.lineLimit(1)
.font(.subheadline)
}
}

View File

@ -1093,6 +1093,7 @@ public extension Mastodon.Entity.Status {
public let isPinned: Bool
public let accountDisplayName: String?
public let accountFullName: String?
public let accountAvatarUrl: URL?
public var needsUserAttribution: Bool {
return accountDisplayName != nil || accountFullName != nil
}
@ -1105,6 +1106,6 @@ public extension Mastodon.Entity.Status {
} else {
displayableContent = AttributedString()
}
return ViewModel(content: displayableContent, isPinned: false, accountDisplayName: account.displayName, accountFullName: account.acctWithDomain)
return ViewModel(content: displayableContent, isPinned: false, accountDisplayName: account.displayName, accountFullName: account.acctWithDomain, accountAvatarUrl: account.avatarImageURL())
}
}