mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
more stuff for emoji pack editor:
edit mode has red - buttons to remove it also has a plus button to add more but it currently doesnt add modified searchview to add a variant for the pack editor
This commit is contained in:
7 files changed
+120
-43
No files matched your search
@@ -11,10 +11,10 @@ struct EmojiPackManager: View {
|
||||
@ObservedObject var hoarder: EmojiHoarder
|
||||
|
||||
var body: some View {
|
||||
ForEach(hoarder.emojiPacks) { pack in
|
||||
EmojiPackDetailView(hoarder: hoarder, pack: pack)
|
||||
ForEach($hoarder.emojiPacks) { $pack in
|
||||
EmojiPackDetailView(hoarder: hoarder, pack: $pack)
|
||||
}
|
||||
EmojiPackDetailView(hoarder: hoarder, pack: .test)
|
||||
EmojiPackDetailView(hoarder: hoarder, pack: .constant(.test))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ struct BrowseView: View {
|
||||
Group {
|
||||
switch browseWhat {
|
||||
case .slackEmoji:
|
||||
EmojiCollectionView(
|
||||
EmojiTableView(
|
||||
hoarder: emojiHoarder,
|
||||
items: emojiHoarder.emojis.map { $0.name }
|
||||
)
|
||||
|
||||
@@ -9,8 +9,11 @@ import SwiftUI
|
||||
|
||||
struct EmojiPackDetailView: View {
|
||||
@ObservedObject var hoarder: EmojiHoarder
|
||||
@State var pack: EmojiPack
|
||||
@Binding var pack: EmojiPack
|
||||
@State var edit: Bool = true
|
||||
@State var editName: Bool = false
|
||||
@State var editDescription: Bool = false
|
||||
@State var showAdder: Bool = true
|
||||
|
||||
var minColWidth: CGFloat { 75 }
|
||||
var spacing: CGFloat { 10 }
|
||||
@@ -21,28 +24,35 @@ struct EmojiPackDetailView: View {
|
||||
alignment: .center
|
||||
)
|
||||
}
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
GeometryReader { geo in
|
||||
VStack {
|
||||
if #unavailable(iOS 19) {
|
||||
Button() {
|
||||
|
||||
} label: {
|
||||
Text(pack.name)
|
||||
.bold()
|
||||
.foregroundStyle(edit ? .blue : .primary)
|
||||
.font(.title)
|
||||
}
|
||||
.disabled(!edit)
|
||||
}
|
||||
Button() {
|
||||
|
||||
editName.toggle()
|
||||
} label: {
|
||||
Text(pack.name)
|
||||
.bold()
|
||||
.foregroundStyle(edit ? .blue : .primary)
|
||||
.font(.title)
|
||||
}
|
||||
.disabled(!edit)
|
||||
.alert("Edit Name", isPresented: $editName) {
|
||||
TextField("", text: $pack.name)
|
||||
}
|
||||
|
||||
Button() {
|
||||
editDescription.toggle()
|
||||
} label: {
|
||||
Text(pack.description)
|
||||
.foregroundStyle(edit ? .blue : .primary)
|
||||
}
|
||||
.disabled(!edit)
|
||||
.alert("Edit Description", isPresented: $editDescription) {
|
||||
TextField("", text: $pack.description)
|
||||
}
|
||||
|
||||
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
||||
let layout = Array(repeating: col, count: columns)
|
||||
@@ -55,6 +65,40 @@ struct EmojiPackDetailView: View {
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
}
|
||||
.overlay(alignment: .topLeading) {
|
||||
if edit {
|
||||
Button(role: .destructive) {
|
||||
withAnimation {
|
||||
pack.emojiNames.removeAll { $0 == name }
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "minus.circle.fill")
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
.frame(maxWidth: 25)
|
||||
.padding(-10)
|
||||
}
|
||||
}
|
||||
}
|
||||
if edit {
|
||||
Button() {
|
||||
showAdder.toggle()
|
||||
} label: {
|
||||
VStack {
|
||||
Image(systemName: "plus.square.dashed")
|
||||
.resizable().scaledToFit()
|
||||
.foregroundStyle(.green.opacity(0.5))
|
||||
Text("Add")
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.green.opacity(0.5))
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showAdder) {
|
||||
SearchView(hoarder: hoarder, fromPackEditor: true) {
|
||||
print($0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical)
|
||||
@@ -64,7 +108,7 @@ struct EmojiPackDetailView: View {
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
.padding()
|
||||
.navigationTitle(edit ? "Editing" : pack.name)
|
||||
.navigationTitle(edit ? "Editing" : "Pack Details")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem() {
|
||||
@@ -91,9 +135,11 @@ struct EmojiPackDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable @State var pack: EmojiPack = .test
|
||||
EmojiPackDetailView(
|
||||
hoarder: EmojiHoarder(localOnly: true, skipIndex: true),
|
||||
pack: .test
|
||||
hoarder: EmojiHoarder(localOnly: true, skipIndex: false),
|
||||
pack: $pack
|
||||
)
|
||||
}
|
||||
@@ -17,21 +17,49 @@ struct SearchView: View {
|
||||
|
||||
@State var stickerType: StickerType = .slackEmoji
|
||||
|
||||
@State var fromPackEditor: Bool = false
|
||||
@State var callback: ((String) -> Void) = { _ in }
|
||||
var minColWidth: CGFloat { 75 }
|
||||
var spacing: CGFloat { 10 }
|
||||
var col: GridItem {
|
||||
GridItem(
|
||||
.flexible(minimum: minColWidth, maximum: 100),
|
||||
spacing: spacing,
|
||||
alignment: .center
|
||||
)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Picker("", selection: $stickerType) {
|
||||
ForEach(StickerType.allCases) { type in
|
||||
Text(type.description).tag(type)
|
||||
if fromPackEditor {
|
||||
GeometryReader { geo in
|
||||
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
||||
let layout = Array(repeating: col, count: columns)
|
||||
LazyVGrid(columns: layout, spacing: spacing) {
|
||||
ForEach(searchResult, id: \.self) { name in
|
||||
let emoji = hoarder.trie.dict[name] ?? .test
|
||||
StickerPreview(sticker: emoji)
|
||||
.onTapGesture {
|
||||
callback(emoji.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Picker("", selection: $stickerType) {
|
||||
ForEach(StickerType.allCases) { type in
|
||||
Text(type.description).tag(type)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
switch stickerType {
|
||||
case .slackEmoji:
|
||||
EmojiTableView(hoarder: hoarder, items: searchResult)
|
||||
.id(searchResult)
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
case .giphyGifs:
|
||||
Text("uhh")
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
switch stickerType {
|
||||
case .slackEmoji:
|
||||
EmojiCollectionView(hoarder: hoarder, items: searchResult)
|
||||
.id(searchResult)
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
case .giphyGifs:
|
||||
Text("uhh")
|
||||
}
|
||||
}
|
||||
.searchable(text: $searchTerm)
|
||||
@@ -50,7 +78,7 @@ struct SearchView: View {
|
||||
previousResult: Set(searchResult)
|
||||
)
|
||||
await MainActor.run {
|
||||
withAnimation(.interactiveSpring) {
|
||||
withAnimation(.snappy) {
|
||||
searchResult = result
|
||||
previousSearches.append(searchTerm)
|
||||
}
|
||||
@@ -61,5 +89,8 @@ struct SearchView: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SearchView(hoarder: EmojiHoarder(localOnly: true))
|
||||
SearchView(
|
||||
hoarder: EmojiHoarder(localOnly: true),
|
||||
fromPackEditor: true
|
||||
)
|
||||
}
|
||||
@@ -116,7 +116,7 @@ struct TrieTestingView: View {
|
||||
}
|
||||
|
||||
if uikit {
|
||||
EmojiCollectionView(hoarder: hoarder, items: searchResults)
|
||||
EmojiTableView(hoarder: hoarder, items: searchResults)
|
||||
.animation(.snappy, value: searchResults)
|
||||
} else {
|
||||
List(searchResults, id: \.self) { item in
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// EmojiCollectionView.swift
|
||||
// EmojiTableView.swift
|
||||
// StickerSlack
|
||||
//
|
||||
// Created by neon443 on 03/11/2025.
|
||||
@@ -10,7 +10,7 @@ import UIKit
|
||||
import SwiftUI
|
||||
import Haptics
|
||||
|
||||
struct EmojiCollectionView: UIViewRepresentable {
|
||||
struct EmojiTableView: UIViewRepresentable {
|
||||
let hoarder: EmojiHoarder
|
||||
let items: [String]
|
||||
|
||||