From c99bdce4a3ebd5b9a398d2095609d5e4d777b244 Mon Sep 17 00:00:00 2001 From: Nihaal Sharma <69979447+neon443@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:52:58 +0100 Subject: [PATCH] implemented collectionview in downloaded --- StickerSlack.xcodeproj/project.pbxproj | 6 - StickerSlack/SwiftUI/DownloadedView.swift | 108 ++++++++++-------- .../EmojiPacks/EmojiPackDetailView.swift | 1 + StickerSlack/SwiftUI/SettingsView.swift | 5 +- .../CollectionView/EmojiCollectionView.swift | 32 ++++-- ...PlainWithMenuEmojiCollectionViewCell.swift | 13 --- 6 files changed, 82 insertions(+), 83 deletions(-) delete mode 100644 StickerSlack/UIKit/CollectionView/PlainWithMenuEmojiCollectionViewCell.swift diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 28da083..6b5cdac 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -48,8 +48,6 @@ 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 */; }; - A975F9162F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */; }; - A975F9172F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.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 */; }; @@ -211,7 +209,6 @@ A957C1792ECE542D00EA3EE9 /* GifManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifManager.swift; sourceTree = ""; }; A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = ""; }; A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; }; - A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlainWithMenuEmojiCollectionViewCell.swift; sourceTree = ""; }; A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = ""; }; A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = ""; }; A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = ""; }; @@ -435,7 +432,6 @@ A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */, A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */, A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */, - A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */, ); path = CollectionView; sourceTree = ""; @@ -707,7 +703,6 @@ A949B1FB2EA0518800215164 /* SlackResponse.swift in Sources */, A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */, A9C52F6F2F89A22000078588 /* Wiggle.metal in Sources */, - A975F9162F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */, A9BDEADE2F82BC93002798DF /* NoStickersView.swift in Sources */, A955B3F52EC22EE900E1732D /* SearchView.swift in Sources */, A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */, @@ -785,7 +780,6 @@ A9A7A4462F68360900BB84C6 /* Pagination.swift in Sources */, A957C17C2ECE542D00EA3EE9 /* GifManager.swift in Sources */, A9104C7F2EB4022500D160EA /* MSSticker.swift in Sources */, - A975F9172F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */, A9C52F762F89A93D00078588 /* URL.swift in Sources */, A9B9A8302EB2CD0B004C9245 /* Emoji.swift in Sources */, A9C52F702F89A22000078588 /* Wiggle.metal in Sources */, diff --git a/StickerSlack/SwiftUI/DownloadedView.swift b/StickerSlack/SwiftUI/DownloadedView.swift index 4d36025..873c5da 100644 --- a/StickerSlack/SwiftUI/DownloadedView.swift +++ b/StickerSlack/SwiftUI/DownloadedView.swift @@ -39,56 +39,64 @@ struct DownloadedView: View { NoStickersView() .padding() } - GeometryReader { geo in - ScrollView { - 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(emojiHoarder.downloadedStickersArr, id: \.self) { name in - if let emoji = emojiHoarder.trie.dict[name] { - ZStack { - Rectangle() - .foregroundStyle(isDark ? .black : .white) - StickerPreview(sticker: emoji) - RoundedRectangle(cornerRadius: 15) - .stroke(.gray, lineWidth: 1) - } - .aspectRatio(1, contentMode: .fit) - .clipShape(RoundedRectangle(cornerRadius: 15)) - .contextMenu { - Text(emoji.UIName) - Button("Copy Name", systemImage: "doc.on.clipboard") { - UIPasteboard.general.string = emoji.UIName - } - Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") { - UIPasteboard.general.image = emoji.image - } - Divider() - if #available(iOS 16, *) { - ShareLink(item: emoji.remoteImageURL) { - Label("Share", systemImage: "square.and.arrow.up") - } - } else { - Button("Share", systemImage: "square.and.arrow.up") { - showShare.toggle() - } - .sheet(isPresented: $showShare) { - ShareSheet(activityItems: [emoji.remoteImageURL]) - } - } - Divider() - Button("Delete", systemImage: "trash.fill", role: .destructive) { - Task { - await emojiHoarder.delete(emoji: emoji) - } - } - } - } - } - } - .padding(.horizontal, spacing) - } - } + + EmojiCollectionView( + hoarder: emojiHoarder, + items: emojiHoarder.downloadedStickersArr, + pack: nil, + width: 75, + style: .plainWithMenu + ) +// GeometryReader { geo in +// ScrollView { +// 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(emojiHoarder.downloadedStickersArr, id: \.self) { name in +// if let emoji = emojiHoarder.trie.dict[name] { +// ZStack { +// Rectangle() +// .foregroundStyle(isDark ? .black : .white) +// StickerPreview(sticker: emoji) +// RoundedRectangle(cornerRadius: 15) +// .stroke(.gray, lineWidth: 1) +// } +// .aspectRatio(1, contentMode: .fit) +// .clipShape(RoundedRectangle(cornerRadius: 15)) +// .contextMenu { +// Text(emoji.UIName) +// Button("Copy Name", systemImage: "doc.on.clipboard") { +// UIPasteboard.general.string = emoji.UIName +// } +// Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") { +// UIPasteboard.general.image = emoji.image +// } +// Divider() +// if #available(iOS 16, *) { +// ShareLink(item: emoji.remoteImageURL) { +// Label("Share", systemImage: "square.and.arrow.up") +// } +// } else { +// Button("Share", systemImage: "square.and.arrow.up") { +// showShare.toggle() +// } +// .sheet(isPresented: $showShare) { +// ShareSheet(activityItems: [emoji.remoteImageURL]) +// } +// } +// Divider() +// Button("Delete", systemImage: "trash.fill", role: .destructive) { +// Task { +// await emojiHoarder.delete(emoji: emoji) +// } +// } +// } +// } +// } +// } +// .padding(.horizontal, spacing) +// } +// } } } diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index 9f0a3da..b69de78 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -75,6 +75,7 @@ struct EmojiPackDetailView: View { EmojiCollectionView( hoarder: hoarder, + items: pack.items, pack: pack, width: 80, style: .full diff --git a/StickerSlack/SwiftUI/SettingsView.swift b/StickerSlack/SwiftUI/SettingsView.swift index dec34c5..b525e17 100644 --- a/StickerSlack/SwiftUI/SettingsView.swift +++ b/StickerSlack/SwiftUI/SettingsView.swift @@ -115,9 +115,10 @@ struct SettingsView: View { NavigationLink { EmojiCollectionView( hoarder: hoarder, - pack: .test, + items: hoarder.emojis.prefix(1000).map { $0.name }, + pack: nil, width: 50, - style: .plain + style: .plainWithMenu ) } label: { Label("grid view", systemImage: "square.grid.2x2.fill") diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index be9242c..0b0994c 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -11,7 +11,8 @@ import SwiftUI struct EmojiCollectionView: UIViewRepresentable { let hoarder: EmojiHoarder - let pack: EmojiPack + let items: [String] + let pack: EmojiPack? let width: CGFloat let spacing: CGFloat = 16 let style: EmojiCollectionView.Style @@ -28,6 +29,7 @@ struct EmojiCollectionView: UIViewRepresentable { func updateUIView(_ uiView: UICollectionView, context: Context) { context.coordinator.hoarder = hoarder + context.coordinator.items = items context.coordinator.pack = pack uiView.reloadData() } @@ -35,6 +37,7 @@ struct EmojiCollectionView: UIViewRepresentable { func makeCoordinator() -> Coordinator { Coordinator( hoarder: hoarder, + items: items, pack: pack, width: width, spacing: spacing, @@ -50,7 +53,8 @@ struct EmojiCollectionView: UIViewRepresentable { final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout { var hoarder: EmojiHoarder - var pack: EmojiPack + var items: [String] + var pack: EmojiPack? var width: CGFloat var spacing: CGFloat var style: EmojiCollectionView.Style @@ -59,13 +63,18 @@ struct EmojiCollectionView: UIViewRepresentable { init( hoarder: EmojiHoarder, - pack: EmojiPack, + items: [String], + pack: EmojiPack?, width: CGFloat, spacing: CGFloat, style: EmojiCollectionView.Style ) { self.hoarder = hoarder - self.pack = pack + self.items = items + if let pack { + self.pack = pack + self.items = pack.items + } self.width = width self.spacing = spacing self.style = style @@ -90,23 +99,20 @@ struct EmojiCollectionView: UIViewRepresentable { } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return pack.items.count + return items.count } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell: PlainEmojiCollectionViewCell switch style { - case .plain: + case .plain, .plainWithMenu: cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell - case .plainWithMenu: - fatalError() -// cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plainWithMenu", for: <#T##IndexPath#>) case .full: cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell } guard !hoarder.trie.dict.isEmpty else { return cell } - let emojiName = pack.items[indexPath.item] + let emojiName = items[indexPath.item] guard let emoji = hoarder.trie.dict[emojiName] else { return cell } cell.configure(with: hoarder, emoji: emoji) @@ -120,8 +126,9 @@ struct EmojiCollectionView: UIViewRepresentable { ) -> CGSize { let defaultSize = CGSize(width: width, height: width) + guard self.style == .full else { return defaultSize } guard !hoarder.trie.dict.isEmpty else { return defaultSize } - let emojiName = pack.items[indexPath.item] + let emojiName = items[indexPath.item] let label = UILabel() label.font = .preferredFont(forTextStyle: .caption1) @@ -139,10 +146,11 @@ struct EmojiCollectionView: UIViewRepresentable { contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint ) -> UIContextMenuConfiguration? { + guard self.style == .plainWithMenu else { return nil } return UIContextMenuConfiguration( identifier: nil, previewProvider: nil) { suggestedActions in - let emojiName = self.pack.items[indexPath.row] + let emojiName = self.items[indexPath.row] let label = UIAction(title: "idk", image: UIImage(systemName: "plus")) { action in print("idk") } diff --git a/StickerSlack/UIKit/CollectionView/PlainWithMenuEmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/PlainWithMenuEmojiCollectionViewCell.swift deleted file mode 100644 index 582ead1..0000000 --- a/StickerSlack/UIKit/CollectionView/PlainWithMenuEmojiCollectionViewCell.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// PlainWithMenuEmojiCollectionViewCell.swift -// StickerSlack -// -// Created by neon443 on 27/04/2026. -// - -import Foundation -import UIKit - -class PlainWithMenuEmojiCollectionViewCell: PlainEmojiCollectionViewCell { -// override func -}