cleanup: use swiftui in debug emojipack thingy

This commit is contained in:
Nihaal Sharma committed 2026-04-30 14:23:47 +01:00
1 parent 24f12926a1
commit 358bdd714b
5 files changed
+171 -126

No files matched your search

+6
View File
@@ -48,6 +48,8 @@
A957C17E2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; };
A975F91A2FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; };
A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */; };
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
@@ -209,6 +211,7 @@
A957C1792ECE542D00EA3EE9 /* GifManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifManager.swift; sourceTree = "<group>"; };
A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; };
A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; };
A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackGridView.swift; sourceTree = "<group>"; };
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = "<group>"; };
A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = "<group>"; };
@@ -332,6 +335,7 @@
A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */,
A9C52F6E2F89A22000078588 /* Wiggle.metal */,
A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */,
A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */,
);
path = EmojiPacks;
sourceTree = "<group>";
@@ -694,6 +698,7 @@
A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */,
A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */,
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */,
A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */,
A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */,
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */,
A957C1742ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
@@ -823,6 +828,7 @@
A9A7A44C2F6837A800BB84C6 /* GiphyUser.swift in Sources */,
A9B9A8312EB2CD14004C9245 /* FilterCategory.swift in Sources */,
A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */,
A975F91A2FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */,
A917BAD22F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift in Sources */,
A9EB72502EB94FAD00658CEB /* StickerPreview.swift in Sources */,
A9A7A4432F68360200BB84C6 /* GifObject.swift in Sources */,
@@ -14,14 +14,10 @@ struct EmojiPackDetailView: View {
@State var edit: Bool = false
@State var editName: Bool = false
@State var editDescription: Bool = false
@State var initDate: Date = .now
@State var showAdder: Bool = false
@State var searchTerm: String = ""
@State var showShare: Bool = false
@State var showNotFoundAlert: Bool = false
@State var useSwiftUIGrid: Bool = false
var allDownloaded: Bool {
let date = Date.now
@@ -30,17 +26,6 @@ struct EmojiPackDetailView: View {
return result
}
var minColWidth: CGFloat { 75 }
var spacing: CGFloat { 10 }
var col: GridItem {
GridItem(
.flexible(minimum: minColWidth, maximum: 100),
spacing: spacing,
alignment: .center
)
}
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationView2 {
VStack {
@@ -72,114 +57,22 @@ struct EmojiPackDetailView: View {
EmptyEmojiPackView()
}
EmojiCollectionView(
hoarder: hoarder,
items: pack.items,
pack: pack,
width: 75,
style: .full,
edit: edit,
onRemoveSUI: { pack.remove($0) }
)
GeometryReader { geo in
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
let layout = Array(repeating: col, count: columns)
ScrollView {
LazyVGrid(columns: layout, spacing: spacing) {
ForEach(pack.items, id: \.self) { name in
TimelineView(.animation) { tl in
Group {
VStack {
if let emoji = hoarder.trie.dict[name] {
StickerPreview(sticker: emoji)
Text(emoji.UIName)
.multilineTextAlignment(.center)
.font(.caption)
} else {
Image(systemName: "questionmark.circle.dashed")
.resizable().scaledToFit()
.foregroundStyle(.gray.opacity(0.5))
.overlay(alignment: .topTrailing) {
Button {
showNotFoundAlert.toggle()
} label: {
Image(systemName: "info")
.font(.title3.bold())
}
}
Text(name)
.multilineTextAlignment(.center)
.font(.caption)
}
Spacer()
}
.alert("This emoji was not found", isPresented: $showNotFoundAlert) {
Button("OK") {
showNotFoundAlert.toggle()
}
} message: {
Text("Try reopening the app with an Internet connection to refresh the emoji database.")
}
}
.overlay(alignment: .topLeading) {
if edit {
Button(role: .destructive) {
withAnimation(.spring) {
pack.remove(name)
}
} label: {
Image(systemName: "minus.circle.fill")
.resizable().scaledToFit()
}
.frame(maxWidth: 25)
.padding(-10)
}
}
.rotationEffect(
.degrees(
edit ? sin(initDate.timeIntervalSinceNow*20)*4 : 0
)
)
}
}
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))
Spacer()
}
}
.sheet(isPresented: $showAdder) {
NavigationView2 {
SearchView(hoarder: hoarder, fromPackEditor: true) { selection in
withAnimation(.spring) {
pack.add(selection.name)
}
}
.navigationTitle("Search Emojis")
.navigationBarTitleDisplayMode(.inline)
.modifier(presentationHalfAndFullIfAv())
.toolbar {
Button("", systemImage: "xmark") {
showAdder.toggle()
}
}
}
}
}
}
.animation(.spring, value: pack.items)
.padding()
}
if useSwiftUIGrid {
EmojiPackGridView(
hoarder: hoarder,
pack: $pack,
edit: $edit
)
} else {
EmojiCollectionView(
hoarder: hoarder,
items: pack.items,
pack: pack,
width: 75,
style: .full,
edit: edit,
onRemoveSUI: { pack.remove($0) }
)
}
Text("\(pack.items.count) Emoji\(pack.items.count.plural)")
@@ -0,0 +1,142 @@
//
// EmojiPackGridView.swift
// StickerSlack
//
// Created by neon443 on 30/04/2026.
//
import SwiftUI
struct EmojiPackGridView: View {
@ObservedObject var hoarder: EmojiHoarder
@Binding var pack: EmojiPack
@Binding var edit: Bool
@State var initDate: Date = .now
@State var showAdder: Bool = false
@State var searchTerm: String = ""
@State var showNotFoundAlert: Bool = false
var minColWidth: CGFloat { 75 }
var spacing: CGFloat { 10 }
var col: GridItem {
GridItem(
.flexible(minimum: minColWidth, maximum: 100),
spacing: spacing,
alignment: .center
)
}
@Environment(\.dismiss) var dismiss
var body: some View {
GeometryReader { geo in
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
let layout = Array(repeating: col, count: columns)
ScrollView {
LazyVGrid(columns: layout, spacing: spacing) {
ForEach(pack.items, id: \.self) { name in
TimelineView(.animation) { tl in
Group {
VStack {
if let emoji = hoarder.trie.dict[name] {
StickerPreview(sticker: emoji)
Text(emoji.UIName)
.multilineTextAlignment(.center)
.font(.caption)
} else {
Image(systemName: "questionmark.circle.dashed")
.resizable().scaledToFit()
.foregroundStyle(.gray.opacity(0.5))
.overlay(alignment: .topTrailing) {
Button {
showNotFoundAlert.toggle()
} label: {
Image(systemName: "info")
.font(.title3.bold())
}
}
Text(name)
.multilineTextAlignment(.center)
.font(.caption)
}
Spacer()
}
.alert("This emoji was not found", isPresented: $showNotFoundAlert) {
Button("OK") {
showNotFoundAlert.toggle()
}
} message: {
Text("Try reopening the app with an Internet connection to refresh the emoji database.")
}
}
.overlay(alignment: .topLeading) {
if edit {
Button(role: .destructive) {
withAnimation(.spring) {
pack.remove(name)
}
} label: {
Image(systemName: "minus.circle.fill")
.resizable().scaledToFit()
}
.frame(maxWidth: 25)
.padding(-10)
}
}
.rotationEffect(
.degrees(
edit ? sin(initDate.timeIntervalSinceNow*20)*4 : 0
)
)
}
}
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))
Spacer()
}
}
.sheet(isPresented: $showAdder) {
NavigationView2 {
SearchView(hoarder: hoarder, fromPackEditor: true) { selection in
withAnimation(.spring) {
pack.add(selection.name)
}
}
.navigationTitle("Search Emojis")
.navigationBarTitleDisplayMode(.inline)
.modifier(presentationHalfAndFullIfAv())
.toolbar {
Button("", systemImage: "xmark") {
showAdder.toggle()
}
}
}
}
}
}
.animation(.spring, value: pack.items)
.padding()
}
}
}
}
#Preview {
EmojiPackGridView(
hoarder: EmojiHoarder(),
pack: .constant(.test),
edit: .constant(Bool.random())
)
}
@@ -9,6 +9,7 @@ import SwiftUI
struct EmojiPackManager: View {
@ObservedObject var hoarder: EmojiHoarder
@State var useSwiftUIGrid: Bool = false
var body: some View {
NavigationView2 {
@@ -22,7 +23,7 @@ struct EmojiPackManager: View {
}
ForEach($hoarder.emojiPacks) { $pack in
NavigationLink {
EmojiPackDetailView(hoarder: hoarder, pack: $pack)
EmojiPackDetailView(hoarder: hoarder, pack: $pack, useSwiftUIGrid: useSwiftUIGrid)
} label: {
Text(pack.name)
}
+4 -1
View File
@@ -135,7 +135,10 @@ struct SettingsView: View {
}
NavigationLink {
EmojiPackManager(hoarder: hoarder)
Text("<SwiftUI Grids>")
.foregroundStyle(.red)
.font(.title)
EmojiPackManager(hoarder: hoarder, useSwiftUIGrid: true)
} label: {
Label("packs wip", systemImage: "square.stack")
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.