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