mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
fixed the colelctionview again
This commit is contained in:
3 files changed
+39
-36
No files matched your search
@@ -102,7 +102,10 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
return items.count
|
||||
}
|
||||
|
||||
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
override func collectionView(
|
||||
_ collectionView: UICollectionView,
|
||||
cellForItemAt indexPath: IndexPath
|
||||
) -> UICollectionViewCell {
|
||||
let cell: PlainEmojiCollectionViewCell
|
||||
switch style {
|
||||
case .plain, .plainWithMenu:
|
||||
@@ -136,9 +139,9 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
label.text = emojiName
|
||||
let labelHeight = label.sizeThatFits(CGSize(width: width, height: .infinity)).height
|
||||
|
||||
print(width+labelHeight)
|
||||
print(width+labelHeight+4)
|
||||
|
||||
return CGSize(width: width, height: width+labelHeight)
|
||||
return CGSize(width: width, height: width+labelHeight+4)
|
||||
}
|
||||
|
||||
override func collectionView(
|
||||
|
||||
@@ -18,14 +18,7 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||
label.font = .preferredFont(forTextStyle: .caption1)
|
||||
label.textAlignment = .center
|
||||
label.numberOfLines = 0
|
||||
contentView.addSubview(label)
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||
])
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -39,8 +32,10 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||
override func configure(with: EmojiHoarder, emoji: Emoji) {
|
||||
super.configure(with: with, emoji: emoji)
|
||||
label.text = emoji.UIName
|
||||
stackView.addArrangedSubview(label)
|
||||
// setNeedsLayout()
|
||||
|
||||
if label.superview == nil {
|
||||
stackView.addArrangedSubview(label)
|
||||
}
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
|
||||
@@ -16,18 +16,13 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func configureSkeleton() {
|
||||
spinner.frame = frame
|
||||
spinner.startAnimating()
|
||||
self.contentView.addSubview(stackView)
|
||||
stackView.addArrangedSubview(spinner)
|
||||
stackView.axis = .vertical
|
||||
stackView.alignment = .fill
|
||||
stackView.distribution = .fill
|
||||
stackView.spacing = 4
|
||||
|
||||
contentView.addSubview(stackView)
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
stackView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
||||
@@ -35,13 +30,26 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||
stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||
])
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func configureSkeleton() {
|
||||
spinner.startAnimating()
|
||||
if spinner.superview == nil {
|
||||
stackView.addArrangedSubview(spinner)
|
||||
}
|
||||
}
|
||||
|
||||
func configure(with: EmojiHoarder, emoji: Emoji) {
|
||||
spinner.stopAnimating()
|
||||
spinner.removeFromSuperview()
|
||||
let swiftUIView = StickerPreview(sticker: emoji)
|
||||
|
||||
if let hostingController {
|
||||
if let hostingController,
|
||||
hostingController.view.superview != nil {
|
||||
hostingController.rootView = swiftUIView
|
||||
} else {
|
||||
let hostingController = UIHostingController(rootView: swiftUIView)
|
||||
@@ -49,25 +57,22 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||
self.stackView.addArrangedSubview(hostingController.view)
|
||||
|
||||
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate(
|
||||
[
|
||||
hostingController.view.topAnchor.constraint(equalTo: stackView.topAnchor),
|
||||
hostingController.view.leadingAnchor.constraint(equalTo: stackView.leadingAnchor),
|
||||
hostingController.view.trailingAnchor.constraint(equalTo: stackView.trailingAnchor),
|
||||
hostingController.view.heightAnchor.constraint(equalTo: hostingController.view.widthAnchor)
|
||||
]
|
||||
)
|
||||
NSLayoutConstraint.activate([
|
||||
hostingController.view.heightAnchor.constraint(equalTo: hostingController.view.widthAnchor)
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
|
||||
hostingController?.view.removeFromSuperview()
|
||||
hostingController = nil
|
||||
if spinner.superview == nil {
|
||||
configureSkeleton()
|
||||
stackView.arrangedSubviews.forEach {
|
||||
stackView.removeArrangedSubview($0)
|
||||
$0.removeFromSuperview()
|
||||
}
|
||||
spinner.startAnimating()
|
||||
|
||||
hostingController?.view.removeFromSuperview()
|
||||
|
||||
configureSkeleton()
|
||||
}
|
||||
}
|
||||