Scrolling optimizations with the new emojis

This commit is contained in:
Thomas Ricouard 2023-01-12 21:12:47 +01:00
parent abca429844
commit 7d053592c9
11 changed files with 48 additions and 28 deletions

View file

@ -108,7 +108,7 @@ struct AccountDetailHeaderView: View {
accountAvatarView accountAvatarView
HStack { HStack {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
EmojiText(account.safeDisplayName, emojis: account.emojis) EmojiTextApp(account.safeDisplayName.asMarkdown, emojis: account.emojis)
.font(.headline) .font(.headline)
Text("@\(account.acct)") Text("@\(account.acct)")
.font(.callout) .font(.callout)
@ -123,7 +123,7 @@ struct AccountDetailHeaderView: View {
} }
} }
} }
EmojiText(account.note, emojis: account.emojis) EmojiTextApp(account.note.asMarkdown, emojis: account.emojis)
.font(.body) .font(.body)
.padding(.top, 8) .padding(.top, 8)
.environment(\.openURL, OpenURLAction { url in .environment(\.openURL, OpenURLAction { url in

View file

@ -216,7 +216,7 @@ public struct AccountDetailView: View {
Image(systemName: "checkmark.seal") Image(systemName: "checkmark.seal")
.foregroundColor(Color.green.opacity(0.80)) .foregroundColor(Color.green.opacity(0.80))
} }
EmojiText(field.value, emojis: viewModel.account?.emojis ?? []) EmojiTextApp(field.value.asMarkdown, emojis: viewModel.account?.emojis ?? [])
.foregroundColor(theme.tintColor) .foregroundColor(theme.tintColor)
} }
.font(.body) .font(.body)
@ -334,7 +334,7 @@ public struct AccountDetailView: View {
if scrollOffset < -200 { if scrollOffset < -200 {
switch viewModel.accountState { switch viewModel.accountState {
case let .data(account): case let .data(account):
EmojiText(account.safeDisplayName, emojis: account.emojis) EmojiTextApp(account.safeDisplayName.asMarkdown, emojis: account.emojis)
.font(.headline) .font(.headline)
default: default:
EmptyView() EmptyView()

View file

@ -33,13 +33,13 @@ public struct AccountsListRow: View {
HStack(alignment: .top) { HStack(alignment: .top) {
AvatarView(url: viewModel.account.avatar, size: .status) AvatarView(url: viewModel.account.avatar, size: .status)
VStack(alignment: .leading, spacing: 2) { VStack(alignment: .leading, spacing: 2) {
EmojiText(viewModel.account.safeDisplayName, emojis: viewModel.account.emojis) EmojiTextApp(viewModel.account.safeDisplayName.asMarkdown, emojis: viewModel.account.emojis)
.font(.subheadline) .font(.subheadline)
.fontWeight(.semibold) .fontWeight(.semibold)
Text("@\(viewModel.account.acct)") Text("@\(viewModel.account.acct)")
.font(.footnote) .font(.footnote)
.foregroundColor(.gray) .foregroundColor(.gray)
EmojiText(viewModel.account.note, emojis: viewModel.account.emojis) EmojiTextApp(viewModel.account.note.asMarkdown, emojis: viewModel.account.emojis)
.font(.footnote) .font(.footnote)
.lineLimit(3) .lineLimit(3)
.environment(\.openURL, OpenURLAction { url in .environment(\.openURL, OpenURLAction { url in

View file

@ -26,7 +26,7 @@ public struct AppAccountView: View {
} }
VStack(alignment: .leading) { VStack(alignment: .leading) {
if let account = viewModel.account { if let account = viewModel.account {
EmojiText(account.safeDisplayName, emojis: account.emojis) EmojiTextApp(account.safeDisplayName.asMarkdown, emojis: account.emojis)
Text("\(account.username)@\(viewModel.appAccount.server)") Text("\(account.username)@\(viewModel.appAccount.server)")
.font(.subheadline) .font(.subheadline)
.foregroundColor(.gray) .foregroundColor(.gray)

View file

@ -2,10 +2,29 @@ import Foundation
import EmojiText import EmojiText
import Models import Models
import HTML2Markdown import HTML2Markdown
import SwiftUI
public extension EmojiText { public struct EmojiTextApp: View {
init(_ string: HTMLString, emojis: [Emoji]) { private let markdown: String
let markdown = string.asMarkdown private let emojis: [any CustomEmoji]
self.init(markdown: markdown, emojis: emojis.map { RemoteEmoji(shortcode: $0.shortcode, url: $0.url) }) private let append: (() -> Text)?
public init(_ markdown: HTMLString, emojis: [Emoji], append: (() -> Text)? = nil) {
self.markdown = markdown
self.emojis = emojis.map { RemoteEmoji(shortcode: $0.shortcode, url: $0.url) }
self.append = append
}
public var body: some View {
if let append {
EmojiText(markdown: markdown, emojis: emojis)
.append {
append()
}
} else if emojis.isEmpty {
Text(markdown.asSafeAttributedString)
} else {
EmojiText(markdown: markdown, emojis: emojis)
} }
}
} }

View file

@ -31,7 +31,8 @@ public struct ListEditView: View {
HStack { HStack {
AvatarView(url: account.avatar, size: .status) AvatarView(url: account.avatar, size: .status)
VStack(alignment: .leading) { VStack(alignment: .leading) {
EmojiText(account.safeDisplayName, emojis: account.emojis) EmojiTextApp(account.safeDisplayName.asMarkdown,
emojis: account.emojis)
Text("@\(account.acct)") Text("@\(account.acct)")
.foregroundColor(.gray) .foregroundColor(.gray)
.font(.footnote) .font(.footnote)

View file

@ -51,8 +51,9 @@ struct NotificationRowView: View {
private func makeMainLabel(type: Models.Notification.NotificationType) -> some View { private func makeMainLabel(type: Models.Notification.NotificationType) -> some View {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 0) { HStack(spacing: 0) {
EmojiText(notification.account.safeDisplayName, emojis: notification.account.emojis) EmojiTextApp(notification.account.safeDisplayName.asMarkdown,
.append { emojis: notification.account.emojis,
append: {
Text(" ") + Text(" ") +
Text(type.label()) Text(type.label())
.font(.subheadline) .font(.subheadline)
@ -65,7 +66,7 @@ struct NotificationRowView: View {
.font(.footnote) .font(.footnote)
.fontWeight(.regular) .fontWeight(.regular)
.foregroundColor(.gray) .foregroundColor(.gray)
} })
.font(.subheadline) .font(.subheadline)
.fontWeight(.semibold) .fontWeight(.semibold)
Spacer() Spacer()
@ -92,7 +93,8 @@ struct NotificationRowView: View {
.foregroundColor(.gray) .foregroundColor(.gray)
if type == .follow { if type == .follow {
EmojiText(notification.account.note, emojis: notification.account.emojis) EmojiTextApp(notification.account.note.asMarkdown,
emojis: notification.account.emojis)
.lineLimit(3) .lineLimit(3)
.font(.callout) .font(.callout)
.foregroundColor(.gray) .foregroundColor(.gray)

View file

@ -32,7 +32,8 @@ struct StatusEditorAutoCompleteView: View {
HStack { HStack {
AvatarView(url: account.avatar, size: .badge) AvatarView(url: account.avatar, size: .badge)
VStack(alignment: .leading) { VStack(alignment: .leading) {
EmojiText(account.safeDisplayName, emojis: account.emojis) EmojiTextApp(account.safeDisplayName.asMarkdown,
emojis: account.emojis)
.font(.footnote) .font(.footnote)
.foregroundColor(theme.labelColor) .foregroundColor(theme.labelColor)
Text("@\(account.acct)") Text("@\(account.acct)")

View file

@ -35,7 +35,7 @@ public struct StatusEmbededView: View {
HStack(alignment: .center) { HStack(alignment: .center) {
AvatarView(url: account.avatar, size: .embed) AvatarView(url: account.avatar, size: .embed)
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
EmojiText(status.account.safeDisplayName, emojis: account.emojis) EmojiTextApp(status.account.safeDisplayName.asMarkdown, emojis: account.emojis)
.font(.footnote) .font(.footnote)
.fontWeight(.semibold) .fontWeight(.semibold)
Group { Group {

View file

@ -98,7 +98,7 @@ public struct StatusRowView: View {
HStack(spacing: 2) { HStack(spacing: 2) {
Image(systemName:"arrow.left.arrow.right.circle.fill") Image(systemName:"arrow.left.arrow.right.circle.fill")
AvatarView(url: viewModel.status.account.avatar, size: .boost) AvatarView(url: viewModel.status.account.avatar, size: .boost)
EmojiText(viewModel.status.account.safeDisplayName, emojis: viewModel.status.account.emojis) EmojiTextApp(viewModel.status.account.safeDisplayName.asMarkdown, emojis: viewModel.status.account.emojis)
Text("boosted") Text("boosted")
} }
.font(.footnote) .font(.footnote)
@ -172,7 +172,7 @@ public struct StatusRowView: View {
private func makeStatusContentView(status: AnyStatus) -> some View { private func makeStatusContentView(status: AnyStatus) -> some View {
Group { Group {
if !status.spoilerText.isEmpty { if !status.spoilerText.isEmpty {
EmojiText(status.spoilerText, emojis: status.emojis) EmojiTextApp(status.spoilerText.asMarkdown, emojis: status.emojis)
.font(.body) .font(.body)
Button { Button {
withAnimation { withAnimation {
@ -185,7 +185,7 @@ public struct StatusRowView: View {
} }
if !viewModel.displaySpoiler { if !viewModel.displaySpoiler {
HStack { HStack {
EmojiText(status.content, emojis: status.emojis) EmojiTextApp(status.content.asMarkdown, emojis: status.emojis)
.font(.body) .font(.body)
.environment(\.openURL, OpenURLAction { url in .environment(\.openURL, OpenURLAction { url in
routeurPath.handleStatus(status: status, url: url) routeurPath.handleStatus(status: status, url: url)
@ -241,7 +241,7 @@ public struct StatusRowView: View {
AvatarView(url: status.account.avatar, size: .status) AvatarView(url: status.account.avatar, size: .status)
} }
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
EmojiText(status.account.safeDisplayName, emojis: status.account.emojis) EmojiTextApp(status.account.safeDisplayName.asMarkdown, emojis: status.account.emojis)
.font(.headline) .font(.headline)
.fontWeight(.semibold) .fontWeight(.semibold)
Group { Group {

View file

@ -21,13 +21,10 @@ For contributors and myself, here is a todo list of features that could be added
- [ ] Editor: Support video types - [ ] Editor: Support video types
- [ ] Editor: Add photos from camera - [ ] Editor: Add photos from camera
- [ ] Editor: Support custom emojis - [ ] Editor: Support custom emojis
- [ ] Edit profile - [ ] Edit filters
- [ ] Handle emoji in status
- [ ] Display & Edit server side features (filter, default visibility, etc...)
- [ ] Edit filters.
- [ ] More context menu everywhere
- [ ] Support IceCubesApp://any mastodon links - [ ] Support IceCubesApp://any mastodon links
- [ ] Translate button - [ ] Translate button / display post language / set post language
- [ ] Widgets
- [ ] Proper iPad support - [ ] Proper iPad support
- [ ] macOS support - [ ] macOS support