From a28913bca9ce76c36c8ee65e7aa6042ffccdca9a Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Sun, 26 Apr 2026 18:30:56 +0100 Subject: [PATCH] added emojicollectionviewcell with labels, swill working on it --- StickerSlack.xcodeproj/project.pbxproj | 12 +++++ .../EmojiPacks/EmojiPackDetailView.swift | 3 +- StickerSlack/SwiftUI/SettingsView.swift | 3 +- .../EmojiCollectionFlowLayout.swift | 15 ++++++ .../CollectionView/EmojiCollectionView.swift | 54 ++++++++++++++++--- .../EmojiCollectionViewCell.swift | 54 +++++++++++++++++++ 6 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift create mode 100644 StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index e8e52ec..2cbf53d 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -51,6 +51,10 @@ 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 */; }; + A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */; }; + A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */; }; + A97BFFC22F9E7F18000441E5 /* EmojiCollectionFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFC12F9E7F10000441E5 /* EmojiCollectionFlowLayout.swift */; }; + A97BFFC32F9E7F18000441E5 /* EmojiCollectionFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFC12F9E7F10000441E5 /* EmojiCollectionFlowLayout.swift */; }; A986A6AE2EB658DF00B6E0FA /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A969D6932EA3E86500399C05 /* Messages.framework */; }; A986A6BA2EB658E100B6E0FA /* StickerSlackiMessageApp.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; A986A6C12EB6595F00B6E0FA /* EmojiHoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F72EA04F2300215164 /* EmojiHoarder.swift */; }; @@ -209,6 +213,8 @@ A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; }; 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 = ""; }; + A97BFFC12F9E7F10000441E5 /* EmojiCollectionFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionFlowLayout.swift; sourceTree = ""; }; A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StickerSlackiMessageApp.appex; sourceTree = BUILT_PRODUCTS_DIR; }; A986A6C62EB659E000B6E0FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; A986A6C72EB659E000B6E0FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -426,8 +432,10 @@ A94F3E642F9E385300FA6995 /* CollectionView */ = { isa = PBXGroup; children = ( + A97BFFC12F9E7F10000441E5 /* EmojiCollectionFlowLayout.swift */, A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */, A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */, + A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */, ); path = CollectionView; sourceTree = ""; @@ -688,6 +696,7 @@ A9A7A4452F68360900BB84C6 /* Pagination.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */, + A97BFFC32F9E7F18000441E5 /* EmojiCollectionFlowLayout.swift in Sources */, A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */, A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */, A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */, @@ -729,6 +738,7 @@ A9A7A4482F68361200BB84C6 /* Meta.swift in Sources */, A995D95C2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, A9BE30FE2F5FA47100A57668 /* Hoarder.swift in Sources */, + A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */, A9C52F792F89BB0800078588 /* EmojiTableViewCell.swift in Sources */, A9C52F722F89A85F00078588 /* ShareSheet.swift in Sources */, ); @@ -807,8 +817,10 @@ A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */, A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */, A9BDEADF2F82BC93002798DF /* NoStickersView.swift in Sources */, + A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */, A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */, A957C1782ECD008E00EA3EE9 /* Bundle.swift in Sources */, + A97BFFC22F9E7F18000441E5 /* EmojiCollectionFlowLayout.swift in Sources */, A921C2E02ED067BB00E57B1A /* WelcomeView.swift in Sources */, A9B9A82E2EB2CCBE004C9245 /* StickerSlackTests.swift in Sources */, A9A7A44F2F68383900BB84C6 /* GiphyImages.swift in Sources */, diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index 1f969a4..9f0a3da 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -76,7 +76,8 @@ struct EmojiPackDetailView: View { EmojiCollectionView( hoarder: hoarder, pack: pack, - width: 80 + width: 80, + style: .full ) GeometryReader { geo in diff --git a/StickerSlack/SwiftUI/SettingsView.swift b/StickerSlack/SwiftUI/SettingsView.swift index 6b24ee1..dec34c5 100644 --- a/StickerSlack/SwiftUI/SettingsView.swift +++ b/StickerSlack/SwiftUI/SettingsView.swift @@ -116,7 +116,8 @@ struct SettingsView: View { EmojiCollectionView( hoarder: hoarder, pack: .test, - width: 50 + width: 50, + style: .plain ) } label: { Label("grid view", systemImage: "square.grid.2x2.fill") diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift new file mode 100644 index 0000000..07265c9 --- /dev/null +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift @@ -0,0 +1,15 @@ +// +// EmojiCollectionFlowLayout.swift +// StickerSlack +// +// Created by neon443 on 26/04/2026. +// + +import Foundation +import UIKit + +class EmojiCollectionFlowLayout: NSObject, UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + let emojiName = pack + } +} diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index b42d7af..9d0eb9b 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -14,11 +14,14 @@ struct EmojiCollectionView: UIViewRepresentable { let pack: EmojiPack let width: CGFloat let spacing: CGFloat = 16 + let style: EmojiCollectionView.Style func makeUIView(context: Context) -> UICollectionView { let collectionView = context.coordinator as UICollectionViewController - collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "cell") + collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plainCell") + collectionView.collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "cell") collectionView.collectionView.dataSource = context.coordinator + collectionView.collectionView.delegate = context.coordinator return collectionView.collectionView } @@ -29,21 +32,41 @@ struct EmojiCollectionView: UIViewRepresentable { } func makeCoordinator() -> Coordinator { - Coordinator(hoarder: hoarder, pack: pack, width: width, spacing: spacing) + Coordinator( + hoarder: hoarder, + pack: pack, + width: width, + spacing: spacing, + style: style + ) } - final class Coordinator: UICollectionViewController { + enum Style { + case plain + case full + } + + final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout { var hoarder: EmojiHoarder var pack: EmojiPack var width: CGFloat var spacing: CGFloat + var style: EmojiCollectionView.Style + var layout = UICollectionViewFlowLayout() - init(hoarder: EmojiHoarder, pack: EmojiPack, width: CGFloat, spacing: CGFloat) { + init( + hoarder: EmojiHoarder, + pack: EmojiPack, + width: CGFloat, + spacing: CGFloat, + style: EmojiCollectionView.Style + ) { self.hoarder = hoarder self.pack = pack self.width = width self.spacing = spacing + self.style = style layout.sectionInset.left = 16 layout.sectionInset.right = 16 @@ -69,17 +92,32 @@ struct EmojiCollectionView: UIViewRepresentable { } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! PlainEmojiCollectionViewCell - + let cell: PlainEmojiCollectionViewCell + switch style { + case .plain: + cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plainCell", for: indexPath) as! PlainEmojiCollectionViewCell + case .full: + cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! EmojiCollectionViewCell + } + guard !hoarder.trie.dict.isEmpty else { return cell } - let emojiName = pack.items[indexPath.item] - guard let emoji = hoarder.trie.dict[emojiName] else { return cell } cell.configure(with: hoarder, emoji: emoji) return cell } + +// func collectionView( +// _ collectionView: UICollectionView, +// layout collectionViewLayout: UICollectionViewLayout, +// sizeForItemAt indexPath: IndexPath +// ) -> CGSize { +// let defaultSize = CGSize(width: width, height: width) +// +// guard !hoarder.trie.dict.isEmpty else { return defaultSize } +// let emojiName = pack.items[indexPath.item] +// } } } diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift new file mode 100644 index 0000000..b907f0b --- /dev/null +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift @@ -0,0 +1,54 @@ +// +// EmojiCollectionViewCell.swift +// StickerSlack +// +// Created by neon443 on 26/04/2026. +// + +import Foundation +import UIKit + +class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { + let label = UILabel() + + override init(frame: CGRect) { + super.init(frame: frame) + + label.font = .preferredFont(forTextStyle: .caption1) + label.textAlignment = .center + contentView.addSubview(label) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func configureSkeleton() { + super.configureSkeleton() + } + + override func configure(with: EmojiHoarder, emoji: Emoji) { + super.configure(with: with, emoji: emoji) + label.text = emoji.UIName + setNeedsLayout() + } + + override func layoutSubviews() { + super.layoutSubviews() + + label.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor) + ]) + +// label.frame = contentView.bounds + contentView.bringSubviewToFront(label) + } + + override func prepareForReuse() { + super.prepareForReuse() + label.text = nil + } +}