diff --git a/Packages/StatusKit/Sources/StatusKit/Editor/Components/AccessoryView.swift b/Packages/StatusKit/Sources/StatusKit/Editor/Components/AccessoryView.swift index 2294cc23..04a40d15 100644 --- a/Packages/StatusKit/Sources/StatusKit/Editor/Components/AccessoryView.swift +++ b/Packages/StatusKit/Sources/StatusKit/Editor/Components/AccessoryView.swift @@ -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]) - } } } diff --git a/Packages/StatusKit/Sources/StatusKit/Editor/Components/CustomEmojisView.swift b/Packages/StatusKit/Sources/StatusKit/Editor/Components/CustomEmojisView.swift new file mode 100644 index 00000000..5619c0b2 --- /dev/null +++ b/Packages/StatusKit/Sources/StatusKit/Editor/Components/CustomEmojisView.swift @@ -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]) + } + } +} diff --git a/Packages/StatusKit/Sources/StatusKit/Editor/ViewModel.swift b/Packages/StatusKit/Sources/StatusKit/Editor/ViewModel.swift index 829d55a4..b48519ec 100644 --- a/Packages/StatusKit/Sources/StatusKit/Editor/ViewModel.swift +++ b/Packages/StatusKit/Sources/StatusKit/Editor/ViewModel.swift @@ -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))