From 0957e3b4c3991bca8432b73bf0f67f4d791a29f9 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 4 May 2026 19:58:34 +0100 Subject: [PATCH] fixed display etc but like lowk cooked cos massive memory leaks --- StickerSlack/JumboMoji.swift | 33 +++++++++---------- StickerSlack/SwiftUI/JumboMojiTestView.swift | 27 +++++++-------- .../CollectionView/EmojiCollectionView.swift | 10 ++++-- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/StickerSlack/JumboMoji.swift b/StickerSlack/JumboMoji.swift index aedd0af..76feaf5 100644 --- a/StickerSlack/JumboMoji.swift +++ b/StickerSlack/JumboMoji.swift @@ -19,21 +19,6 @@ struct JumboMoji: CustomStringConvertible, Hashable { self.baseName + " " + "\(width)x\(height)" } - init(baseName: String, items: [String]) { - fatalError() - let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) } - var coordinates: [(Int, Int)] = [] - for item in itemsBaseNameRemoved { - let split = item.dropLast(item.split(separator: "-").last?.count ?? 0) - print(split) - } - self.width = 0 - self.height = 0 - self.baseName = baseName - self.type = .grid - self.items = items - } - init?(components: [JumboMoji.Components]) { guard components.allSatisfy({$0.baseName == components.first?.baseName}) else { return nil } self.baseName = components.first!.baseName @@ -45,7 +30,16 @@ struct JumboMoji: CustomStringConvertible, Hashable { self.height = height self.type = .grid - self.items = components.map { "\($0.baseName)-\($0.coordinate)-\($0.id)-" } + + guard width*height == components.count else { return nil } + let sorted = components.sorted { + if $0.y != $1.y { + return $0.y < $1.y + } else { + return $0.x < $1.x + } + } + self.items = sorted.map { $0.name } } enum Style { @@ -123,6 +117,8 @@ struct JumboMoji: CustomStringConvertible, Hashable { struct Components { var baseName: String var coordinate: String + var id: String + var x: Int { let split = coordinate.split(separator: "-").first ?? "0" return Int(split) ?? 0 @@ -131,6 +127,9 @@ struct JumboMoji: CustomStringConvertible, Hashable { let split = coordinate.split(separator: "-").last ?? "0" return Int(split) ?? 0 } - var id: String + + var name: String { + return "\(self.baseName)-\(self.coordinate)-\(self.id)" + } } } diff --git a/StickerSlack/SwiftUI/JumboMojiTestView.swift b/StickerSlack/SwiftUI/JumboMojiTestView.swift index a294c82..b8635ae 100644 --- a/StickerSlack/SwiftUI/JumboMojiTestView.swift +++ b/StickerSlack/SwiftUI/JumboMojiTestView.swift @@ -13,7 +13,7 @@ struct JumboMojiTestView: View { @State var searchResult: [String] = [] var body: some View { - ScrollView { + List { TextField("search", text: $searchTerm) .autocorrectionDisabled() .onChange(of: searchTerm) { _ in @@ -21,18 +21,19 @@ struct JumboMojiTestView: View { } ForEach(JumboMoji.from(names: searchResult), id: \.self) { jumboMoji in VStack { - ForEach(0..(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in @@ -113,7 +112,14 @@ struct EmojiCollectionView: UIViewRepresentable { } collectionView.dataSource = dataSource - collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) + if self.style == .jumboMoji { + self.layout.minimumInteritemSpacing = 0 + self.layout.minimumLineSpacing = 0 + collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + } else { + self.layout.minimumInteritemSpacing = 8 + collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) + } } required init?(coder: NSCoder) {