mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-26 00:50:38 +00:00
Fix custom emojis loading
This commit is contained in:
parent
17387626b8
commit
1be9a7b941
3 changed files with 72 additions and 51 deletions
|
@ -181,9 +181,9 @@ extension StatusEditor {
|
|||
.accessibilityLabel("accessibility.editor.button.custom-emojis")
|
||||
.popover(isPresented: $isCustomEmojisSheetDisplay) {
|
||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||
customEmojisSheet
|
||||
CustomEmojisView(viewModel: focusedSEVM)
|
||||
} else {
|
||||
customEmojisSheet
|
||||
CustomEmojisView(viewModel: focusedSEVM)
|
||||
.frame(width: 400, height: 500)
|
||||
}
|
||||
}
|
||||
|
@ -270,52 +270,6 @@ extension StatusEditor {
|
|||
}
|
||||
}
|
||||
|
||||
private var customEmojisSheet: some View {
|
||||
NavigationStack {
|
||||
ScrollView {
|
||||
ForEach(focusedSEVM.customEmojiContainer) { container in
|
||||
VStack(alignment: .leading) {
|
||||
Text(container.categoryName)
|
||||
.font(.scaledFootnote)
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 40))], spacing: 9) {
|
||||
ForEach(container.emojis) { emoji in
|
||||
LazyImage(url: emoji.url) { state in
|
||||
if let image = state.image {
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: 40, height: 40)
|
||||
.accessibilityLabel(emoji.shortcode.replacingOccurrences(of: "_", with: " "))
|
||||
.accessibilityAddTraits(.isButton)
|
||||
} else if state.isLoading {
|
||||
Rectangle()
|
||||
.fill(Color.gray)
|
||||
.frame(width: 40, height: 40)
|
||||
.accessibility(hidden: true)
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
focusedSEVM.insertStatusText(text: " :\(emoji.shortcode): ")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom)
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button("action.cancel", action: { isCustomEmojisSheetDisplay = false })
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(theme.primaryBackgroundColor)
|
||||
.navigationTitle("status.editor.emojis.navigation-title")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
.presentationDetents([.medium])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
import DesignSystem
|
||||
import Env
|
||||
import SwiftUI
|
||||
import Models
|
||||
import NukeUI
|
||||
|
||||
extension StatusEditor {
|
||||
|
||||
@MainActor
|
||||
struct CustomEmojisView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@Environment(Theme.self) private var theme
|
||||
|
||||
var viewModel: ViewModel
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ScrollView {
|
||||
ForEach(viewModel.customEmojiContainer) { container in
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 40, maximum: 40))], spacing: 9) {
|
||||
Section {
|
||||
ForEach(container.emojis) { emoji in
|
||||
LazyImage(url: emoji.url) { state in
|
||||
if let image = state.image {
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40, height: 40)
|
||||
.accessibilityLabel(emoji.shortcode.replacingOccurrences(of: "_", with: " "))
|
||||
.accessibilityAddTraits(.isButton)
|
||||
} else if state.isLoading {
|
||||
Rectangle()
|
||||
.fill(Color.gray)
|
||||
.frame(width: 40, height: 40)
|
||||
.accessibility(hidden: true)
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
viewModel.insertStatusText(text: " :\(emoji.shortcode): ")
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
HStack {
|
||||
Text(container.categoryName)
|
||||
.font(.scaledFootnote)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 8)
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button("action.cancel", action: { dismiss() })
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(theme.primaryBackgroundColor)
|
||||
.navigationTitle("status.editor.emojis.navigation-title")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
.presentationDetents([.medium, .large])
|
||||
}
|
||||
}
|
||||
}
|
|
@ -872,7 +872,7 @@ extension StatusEditor {
|
|||
|
||||
customEmojis.reduce([String: [Emoji]]()) { currentDict, emoji in
|
||||
var dict = currentDict
|
||||
let category = emoji.category ?? "Uncategorized"
|
||||
let category = emoji.category ?? "Custom"
|
||||
|
||||
if let emojis = dict[category] {
|
||||
dict[category] = emojis + [emoji]
|
||||
|
@ -882,8 +882,8 @@ extension StatusEditor {
|
|||
|
||||
return dict
|
||||
}.sorted(by: { lhs, rhs in
|
||||
if rhs.key == "Uncategorized" { false }
|
||||
else if lhs.key == "Uncategorized" { true }
|
||||
if rhs.key == "Custom" { false }
|
||||
else if lhs.key == "Custom" { true }
|
||||
else { lhs.key < rhs.key }
|
||||
}).forEach { key, value in
|
||||
emojiContainers.append(.init(categoryName: key, emojis: value))
|
||||
|
|
Loading…
Reference in a new issue