added emojicollectionviewcell with labels, swill working on it

This commit is contained in:
neon443 committed 2026-04-26 18:30:56 +01:00
1 parent e820edb75e
commit a28913bca9
6 files changed
+131 -10

No files matched your search

@@ -76,7 +76,8 @@ struct EmojiPackDetailView: View {
EmojiCollectionView(
hoarder: hoarder,
pack: pack,
width: 80
width: 80,
style: .full
)
GeometryReader { geo in
+2 -1
View File
@@ -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")
@@ -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
}
}
@@ -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]
// }
}
}
@@ -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
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.