mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
cleanup: use swiftui in debug emojipack thingy
This commit is contained in:
5 files changed
+172
-127
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||