fix animating removing items from sitckerpack

This commit is contained in:
neon443 committed 2026-04-08 20:38:46 +01:00
1 parent 600d2e3cb6
commit d79b0557a9
4 files changed
+32 -22

No files matched your search

@@ -11,7 +11,12 @@ struct EmojiPack: Identifiable, Codable {
var id: UUID
var name: String
var description: String
var emojiNames: [String]
var items: [EmojiPack.Item]
struct Item: Identifiable, Codable, Equatable {
var id: UUID
var name: String
}
}
extension EmojiPack {
@@ -20,7 +25,7 @@ extension EmojiPack {
id: UUID(),
name: "New Pack",
description: "Created on \(Date().formatted())",
emojiNames: []
items: []
)
}
}
+9 -9
View File
@@ -126,15 +126,15 @@ extension EmojiPack {
id: UUID(),
name: "test pack",
description: "neon443's debug emoji pack",
emojiNames: [
"pf",
"heavysob",
"yay",
"skulk",
"loll",
"bleh",
"uhh",
"communist"
items: [
Item(id: UUID(uuidString: "06b65aee-8831-466a-b003-1feed53695ec")!, name: "pf"),
Item(id: UUID(uuidString: "b93f296b-6fd9-4aeb-8345-159d11f448c4")!, name: "heavysob"),
Item(id: UUID(uuidString: "ce03516a-61cf-429d-85e8-fe439e95b3dd")!, name: "yay"),
Item(id: UUID(uuidString: "c0bd5d04-c71f-40b3-ab8d-f49b07518f74")!, name: "skulk"),
Item(id: UUID(uuidString: "f6c0d4e0-5bf7-4d23-89fb-f415c132519a")!, name: "loll"),
Item(id: UUID(uuidString: "263dc294-6d98-4a85-bf82-f40602855e2b")!, name: "bleh"),
Item(id: UUID(uuidString: "df504b1d-f9bc-4b2c-b092-491b5850e508")!, name: "uhh"),
Item(id: UUID(uuidString: "896efcce-3021-4a3f-9847-e0f8fdd64d9a")!, name: "communist")
]
)
}
@@ -54,7 +54,7 @@ struct EmojiPackDetailView: View {
TextField("", text: $pack.description)
}
if pack.emojiNames.isEmpty {
if pack.items.isEmpty {
VStack(alignment: .center) {
HStack {
Image(systemName: "exclamationmark.triangle.fill")
@@ -63,7 +63,7 @@ struct EmojiPackDetailView: View {
Image(systemName: "exclamationmark.triangle.fill")
}
.foregroundStyle(.yellow)
Text("This pack contians no emojis 😭")
Text("This pack contians no emojis")
.padding(.vertical, 5)
.foregroundStyle(.foreground)
Text("Add emojis to this pack by editing it using the pencil button in the toolbar.")
@@ -80,14 +80,13 @@ struct EmojiPackDetailView: View {
.blur(radius: 5)
.shadow(color: .purple, radius: 5)
}
// .padding(.vertical)
}
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(pack.emojiNames, id: \.self) { name in
let emoji = hoarder.trie.dict[name] ?? .test
ForEach(pack.items) { item in
let emoji = hoarder.trie.dict[item.name] ?? .test
VStack {
StickerPreview(sticker: emoji)
Spacer()
@@ -98,8 +97,8 @@ struct EmojiPackDetailView: View {
.overlay(alignment: .topLeading) {
if edit {
Button(role: .destructive) {
withAnimation {
pack.emojiNames.removeAll { $0 == name }
withAnimation(.spring) {
pack.items.removeAll { $0.id == item.id }
}
} label: {
Image(systemName: "minus.circle.fill")
@@ -129,15 +128,21 @@ struct EmojiPackDetailView: View {
SearchView(hoarder: hoarder, fromPackEditor: true) { selection in
print(selection)
withAnimation {
pack.emojiNames.append(selection)
guard let id = UUID(uuidString: selection.id) else {
fatalError("bruh what happened to ur uuid")
}
pack.items.append(
EmojiPack.Item(id: id, name: selection.name)
)
}
}
}
}
}
.animation(.spring, value: pack.items)
.padding(.vertical)
Text("\(pack.emojiNames.count) Emoji\(pack.emojiNames.count.plural)")
Text("\(pack.items.count) Emoji\(pack.items.count.plural)")
.bold()
.multilineTextAlignment(.center)
}
+2 -2
View File
@@ -18,7 +18,7 @@ struct SearchView: View {
@State var stickerType: StickerType = .slackEmoji
@State var fromPackEditor: Bool = false
@State var callback: ((String) -> Void) = { _ in }
@State var callback: ((Emoji) -> Void) = { _ in }
var minColWidth: CGFloat { 75 }
var spacing: CGFloat { 10 }
var col: GridItem {
@@ -43,7 +43,7 @@ struct SearchView: View {
let emoji = hoarder.trie.dict[name] ?? .test
StickerPreview(sticker: emoji)
.onTapGesture {
callback(emoji.name)
callback(emoji)
dismiss()
}
}
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.