IceCubesApp/Packages/Status/Sources/Status/Editor/Components/StatusEditorAutoCompleteView.swift
Thomas Ricouard 4189a59cf6
iOS 17+ only support + migrating to Observation framework (#1571)
* Initial iOS 17 + Observable migration

* More Observation

* More observation

* Checkpoint

* Checkpoint

* Bump version to 1.8.0

* SwiftFormat

* Fix home timeline switch on login

* Fix sidebar routerPath

* Fixes on detail view

* Remove print changes

* Simply detail view

* More opt

* Migrate DisplaySettingsLocalValues

* Better post detail transition

* Status detail animation finally right

* Cleanup
2023-09-18 07:01:23 +02:00

67 lines
1.9 KiB
Swift

import DesignSystem
import EmojiText
import Foundation
import SwiftUI
struct StatusEditorAutoCompleteView: View {
@EnvironmentObject private var theme: Theme
var viewModel: StatusEditorViewModel
var body: some View {
if !viewModel.mentionsSuggestions.isEmpty || !viewModel.tagsSuggestions.isEmpty {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack {
if !viewModel.mentionsSuggestions.isEmpty {
suggestionsMentionsView
} else {
suggestionsTagView
}
}
.padding(.horizontal, .layoutPadding)
}
.frame(height: 40)
.background(.ultraThinMaterial)
}
}
private var suggestionsMentionsView: some View {
ForEach(viewModel.mentionsSuggestions) { account in
Button {
viewModel.selectMentionSuggestion(account: account)
} label: {
HStack {
AvatarView(url: account.avatar, size: .badge)
VStack(alignment: .leading) {
EmojiTextApp(.init(stringValue: account.safeDisplayName),
emojis: account.emojis)
.emojiSize(Font.scaledFootnoteFont.emojiSize)
.emojiBaselineOffset(Font.scaledFootnoteFont.emojiBaselineOffset)
.font(.scaledFootnote)
.foregroundColor(theme.labelColor)
Text("@\(account.acct)")
.font(.scaledCaption)
.foregroundColor(theme.tintColor)
}
}
}
}
}
private var suggestionsTagView: some View {
ForEach(viewModel.tagsSuggestions) { tag in
Button {
viewModel.selectHashtagSuggestion(tag: tag)
} label: {
VStack(alignment: .leading) {
Text("#\(tag.name)")
.font(.scaledFootnote)
.foregroundColor(theme.tintColor)
Text("tag.suggested.mentions-\(tag.totalUses)")
.font(.scaledCaption)
.foregroundColor(.gray)
}
}
}
}
}