From 6bcef5c8dda1267c105731b18433e72718ca47d2 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Sat, 11 Apr 2026 00:14:39 +0100 Subject: [PATCH] updated emojitableview to: use a custom tableviewcell supports ios 15 need to fix random order when scrolling fast --- StickerSlack.xcodeproj/project.pbxproj | 6 +++ StickerSlack/UIKit/EmojiCell.swift | 61 +++++++++++++++++++++++++ StickerSlack/UIKit/EmojiTableView.swift | 42 ++++------------- 3 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 StickerSlack/UIKit/EmojiCell.swift diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 50545c6..d17bc34 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -119,6 +119,8 @@ A9C52F752F89A93D00078588 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C52F742F89A93D00078588 /* URL.swift */; }; A9C52F762F89A93D00078588 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C52F742F89A93D00078588 /* URL.swift */; }; A9C52F772F89A9BF00078588 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C52F742F89A93D00078588 /* URL.swift */; }; + A9C52F792F89BB0800078588 /* EmojiCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C52F782F89BB0800078588 /* EmojiCell.swift */; }; + A9C52F7A2F89BB0800078588 /* EmojiCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C52F782F89BB0800078588 /* EmojiCell.swift */; }; A9CD6C352EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */; }; A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */; }; A9CD6C382EDDE37500B7F421 /* EmojiPackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */; }; @@ -229,6 +231,7 @@ A9C52F6E2F89A22000078588 /* Wiggle.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Wiggle.metal; sourceTree = ""; }; A9C52F712F89A85F00078588 /* ShareSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareSheet.swift; sourceTree = ""; }; A9C52F742F89A93D00078588 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; + A9C52F782F89BB0800078588 /* EmojiCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCell.swift; sourceTree = ""; }; A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackDetailView.swift; sourceTree = ""; }; A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackManager.swift; sourceTree = ""; }; A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = ""; }; @@ -341,6 +344,7 @@ children = ( A9EB72382EB93FDB00658CEB /* EmojiTableView.swift */, A9C52F712F89A85F00078588 /* ShareSheet.swift */, + A9C52F782F89BB0800078588 /* EmojiCell.swift */, ); path = UIKit; sourceTree = ""; @@ -694,6 +698,7 @@ A9A7A4482F68361200BB84C6 /* Meta.swift in Sources */, A995D95C2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, A9BE30FE2F5FA47100A57668 /* Hoarder.swift in Sources */, + A9C52F792F89BB0800078588 /* EmojiCell.swift in Sources */, A9C52F722F89A85F00078588 /* ShareSheet.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -763,6 +768,7 @@ A9EC46AD2F6D9E4600E066E6 /* Hoarder.swift in Sources */, A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */, A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */, + A9C52F7A2F89BB0800078588 /* EmojiCell.swift in Sources */, A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */, A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */, diff --git a/StickerSlack/UIKit/EmojiCell.swift b/StickerSlack/UIKit/EmojiCell.swift new file mode 100644 index 0000000..2a52896 --- /dev/null +++ b/StickerSlack/UIKit/EmojiCell.swift @@ -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>? + + 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() + } +} diff --git a/StickerSlack/UIKit/EmojiTableView.swift b/StickerSlack/UIKit/EmojiTableView.swift index fae9540..9212613 100644 --- a/StickerSlack/UIKit/EmojiTableView.swift +++ b/StickerSlack/UIKit/EmojiTableView.swift @@ -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") -// } -//}