Files
StickerSlack/StickerSlack/UIKit/TableView/EmojiTableViewCell.swift
T
neon443 ca3f42b398 working emojicollectionview
added a menu to add to a pack from stickerrow
reorg uikit stuff
2026-04-26 14:37:21 +01:00

75 lines
2.2 KiB
Swift

//
// EmojiCell.swift
// StickerSlack
//
// Created by neon443 on 11/04/2026.
//
import Foundation
import UIKit
import SwiftUI
class EmojiTableViewCell: UITableViewCell {
private var spinner: UIActivityIndicatorView = UIActivityIndicatorView(style: .large)
private var hostingController: UIHostingController<StickerRow<EmojiHoarder>>?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = .systemGroupedBackground
contentView.backgroundColor = .clear
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configureSkeleton() {
spinner.frame = frame
spinner.startAnimating()
contentView.addSubview(spinner)
spinner.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
spinner.topAnchor.constraint(equalTo: contentView.topAnchor),
spinner.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
spinner.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
spinner.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
])
}
func configure(with hoarder: EmojiHoarder, emoji: Emoji) {
let swiftUIView = StickerRow(hoarder: hoarder, sticker: emoji)
spinner.removeFromSuperview()
if let hostingController {
hostingController.rootView = swiftUIView
} else {
let controller = UIHostingController(rootView: swiftUIView)
hostingController = controller
contentView.addSubview(controller.view)
controller.view.backgroundColor = .clear
controller.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
controller.view.topAnchor.constraint(equalTo: contentView.topAnchor),
controller.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
controller.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
controller.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
])
}
}
override func prepareForReuse() {
super.prepareForReuse()
hostingController?.view.removeFromSuperview()
hostingController = nil
if spinner.superview == nil {
configureSkeleton()
}
spinner.startAnimating()
}
}