updated emojitableview to:

use a custom tableviewcell
supports ios 15
need to fix random order when scrolling fast
This commit is contained in:
neon443 committed 2026-04-11 00:14:39 +01:00
1 parent 39c8457c3e
commit 6bcef5c8dd
3 files changed
+76 -33

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
//
// EmojiCell.swift
// StickerSlack
//
// Created by neon443 on 11/04/2026.
//
import Foundation
import UIKit
import SwiftUI
class EmojiCell: 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)
spinner.startAnimating()
spinner.frame = frame
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)
])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
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.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() {
spinner.removeFromSuperview()
super.prepareForReuse()
}
}
+9 -33
View File
@@ -16,7 +16,7 @@ struct EmojiTableView: UIViewRepresentable {
func makeUIView(context: Context) -> UITableView {
let tableView = context.coordinator as UITableViewController
tableView.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.tableView.register(EmojiCell.self, forCellReuseIdentifier: "cell")
tableView.tableView.dataSource = context.coordinator
tableView.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
tableView.tableView.separatorStyle = .none
@@ -52,29 +52,17 @@ struct EmojiTableView: UIViewRepresentable {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard !hoarder.trie.dict.isEmpty else {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let spinner = UIActivityIndicatorView()
spinner.startAnimating()
spinner.style = .large
spinner.frame = cell.frame
spinner.autoresizingMask = .flexibleWidth
cell.addSubview(spinner)
return cell
}
let emojiName = items[indexPath.row]
let emoji = hoarder.trie.dict[emojiName]!
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.selectedBackgroundView = nil
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EmojiCell
cell.selectionStyle = .none
let swiftUIView = StickerRow(hoarder: hoarder, sticker: emoji).id(emoji)
let hostingController = UIHostingController(rootView: swiftUIView)
hostingController.view.frame = cell.frame
hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
cell.addSubview(hostingController.view)
guard !hoarder.trie.dict.isEmpty else {
return cell
}
let emojiName = items[indexPath.row]
let emoji = hoarder.trie.dict[emojiName]!
cell.configure(with: hoarder, emoji: emoji)
return cell
}
@@ -91,15 +79,3 @@ struct EmojiTableView: UIViewRepresentable {
}
}
}
//
//class EmojiCell: UITableViewCell {
// override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
// let l = UILabel()
// l.text = "ifosa"
// self.view = l
// }
//
// required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//}
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.