From 8c214f183740cb744401ccf228ace29edcd67520 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 27 Apr 2026 10:38:13 +0100 Subject: [PATCH] proper labels --- StickerSlack.xcodeproj/project.pbxproj | 6 ---- .../EmojiCollectionFlowLayout.swift | 15 --------- .../CollectionView/EmojiCollectionView.swift | 30 ++++++++++++------ .../EmojiCollectionViewCell.swift | 31 ++++++++++--------- .../PlainEmojiCollectionViewCell.swift | 15 +++++---- 5 files changed, 46 insertions(+), 51 deletions(-) delete mode 100644 StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 2cbf53d..6b5cdac 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -53,8 +53,6 @@ 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 */; }; @@ -214,7 +212,6 @@ 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 = ""; }; @@ -432,7 +429,6 @@ A94F3E642F9E385300FA6995 /* CollectionView */ = { isa = PBXGroup; children = ( - A97BFFC12F9E7F10000441E5 /* EmojiCollectionFlowLayout.swift */, A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */, A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */, A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */, @@ -696,7 +692,6 @@ 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 */, @@ -820,7 +815,6 @@ 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/UIKit/CollectionView/EmojiCollectionFlowLayout.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift deleted file mode 100644 index 07265c9..0000000 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionFlowLayout.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// 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 9d0eb9b..bb925f0 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -108,16 +108,26 @@ struct EmojiCollectionView: UIViewRepresentable { 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] -// } + 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] + + let label = UILabel() + label.font = .preferredFont(forTextStyle: .caption1) + label.numberOfLines = 0 + label.text = emojiName + let labelHeight = label.sizeThatFits(CGSize(width: width, height: .infinity)).height + + print(width+labelHeight) + + return CGSize(width: width, height: width+labelHeight) + } } } diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift index b907f0b..6f6d10c 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift @@ -10,13 +10,30 @@ import UIKit class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { let label = UILabel() + let spacer = UIView() override init(frame: CGRect) { super.init(frame: frame) + contentView.addSubview(spacer) + spacer.translatesAutoresizingMaskIntoConstraints = false + label.font = .preferredFont(forTextStyle: .caption1) label.textAlignment = .center + label.numberOfLines = 0 contentView.addSubview(label) + label.translatesAutoresizingMaskIntoConstraints = false + + NSLayoutConstraint.activate([ + spacer.topAnchor.constraint(equalTo: topAnchor), + spacer.bottomAnchor.constraint(equalTo: label.topAnchor), + spacer.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + spacer.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + + label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor) + ]) } required init?(coder: NSCoder) { @@ -33,20 +50,6 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { 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 diff --git a/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift index ee096fa..db79c57 100644 --- a/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift @@ -47,12 +47,15 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell { self.contentView.addSubview(hostingController.view) hostingController.view.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([ - hostingController.view.topAnchor.constraint(equalTo: contentView.topAnchor), - hostingController.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), - hostingController.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor) - ]) + NSLayoutConstraint.activate( + [ + hostingController.view.topAnchor.constraint(equalTo: contentView.topAnchor), +// hostingController.view.bottomAnchor.constraint(equalTo: contentView.topAnchor, ), + hostingController.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + hostingController.view.heightAnchor.constraint(equalTo: hostingController.view.widthAnchor) + ] + ) } }