the emojipicker works!

added stickerbrowserdatasorce to give msstickerbrowserview stikcers
update messagesviewcontroller to add the msstickerbrowser
added Emoji.sticker to get MSSticker from Emoji
This commit is contained in:
neon443
2025-10-29 22:19:57 +00:00
parent 98df6d776b
commit 495abb99b4
5 changed files with 73 additions and 4 deletions

View File

@@ -25,6 +25,8 @@
A969D6AE2EA3F1AF00399C05 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A969D6A92EA3F1AF00399C05 /* MainInterface.storyboard */; };
A969D6AF2EA3F1AF00399C05 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A969D6AA2EA3F1AF00399C05 /* MessagesViewController.swift */; };
A9773C2F2EA54AF000F3B753 /* EmojiPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */; };
A9B9A81C2EB2BCE4004C9245 /* StickerBrowserDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B9A81B2EB2BCE4004C9245 /* StickerBrowserDataSource.swift */; };
A9B9A81E2EB2BEF1004C9245 /* StickerBroswerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B9A81D2EB2BEF1004C9245 /* StickerBroswerViewController.swift */; };
A9BE06DB2EA656B80033B213 /* EmojiHoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F72EA04F2300215164 /* EmojiHoarder.swift */; };
A9BE06DC2EA657C70033B213 /* ApiEmoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A940FE3C2EA232590016870B /* ApiEmoji.swift */; };
A9BE06DD2EA657CF0033B213 /* SlackResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1FA2EA0518800215164 /* SlackResponse.swift */; };
@@ -75,6 +77,8 @@
A969D6A82EA3F1AF00399C05 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = "<group>"; };
A969D6AA2EA3F1AF00399C05 /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = "<group>"; };
A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPreview.swift; sourceTree = "<group>"; };
A9B9A81B2EB2BCE4004C9245 /* StickerBrowserDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerBrowserDataSource.swift; sourceTree = "<group>"; };
A9B9A81D2EB2BEF1004C9245 /* StickerBroswerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerBroswerViewController.swift; sourceTree = "<group>"; };
A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -176,6 +180,8 @@
A969D6A72EA3F1AF00399C05 /* Info.plist */,
A969D6A92EA3F1AF00399C05 /* MainInterface.storyboard */,
A969D6AA2EA3F1AF00399C05 /* MessagesViewController.swift */,
A9B9A81B2EB2BCE4004C9245 /* StickerBrowserDataSource.swift */,
A9B9A81D2EB2BEF1004C9245 /* StickerBroswerViewController.swift */,
);
path = StickerSlackiMessageExtension;
sourceTree = "<group>";
@@ -307,11 +313,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A9B9A81E2EB2BEF1004C9245 /* StickerBroswerViewController.swift in Sources */,
A924C3722EA9127200F20781 /* Emoji.swift in Sources */,
A9BE06DC2EA657C70033B213 /* ApiEmoji.swift in Sources */,
A9BE06DB2EA656B80033B213 /* EmojiHoarder.swift in Sources */,
A935437C2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */,
A969D6AF2EA3F1AF00399C05 /* MessagesViewController.swift in Sources */,
A9B9A81C2EB2BCE4004C9245 /* StickerBrowserDataSource.swift in Sources */,
A9BE06DD2EA657CF0033B213 /* SlackResponse.swift in Sources */,
A9D15B8A2EB1142C00404792 /* EmojiPack.swift in Sources */,
);

View File

@@ -8,6 +8,7 @@
import Foundation
import UIKit
import SwiftUI
import Messages
import UniformTypeIdentifiers
struct Emoji: Codable, Identifiable, Hashable {
@@ -26,6 +27,13 @@ struct Emoji: Codable, Identifiable, Hashable {
return (try? Data(contentsOf: localImageURL)) != nil
}
var sticker: MSSticker {
guard isLocal else {
fatalError("sticker \(name) isnt local")
}
return try! MSSticker(contentsOfFileURL: localImageURL, localizedDescription: name)
}
var image: UIImage? {
if let data = try? Data(contentsOf: localImageURL),
let img = UIImage(data: data) {

View File

@@ -9,23 +9,30 @@ import UIKit
import Messages
class MessagesViewController: MSMessagesAppViewController {
var hoard: EmojiHoarder = EmojiHoarder()
let dataSource: StickerBrowserDataSource = StickerBrowserDataSource()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// sleep(5)
}
// MARK: - Conversation Handling
override func willBecomeActive(with conversation: MSConversation) {
print(hoard.emojis.count)
let l = UILabel()
l.frame = CGRect(x: 20, y: 20, width: 1000, height: 40)
l.frame = CGRect(x: 20, y: 20, width: 200, height: 40)
l.textColor = .systemOrange
l.text = "\(hoard.emojis.count)"
l.text = "hii!"
view.addSubview(l)
view.bringSubviewToFront(l)
let stickerBrowser = MSStickerBrowserView(frame: .zero, stickerSize: .regular)
stickerBrowser.frame = CGRect(x: 60, y: 20, width: 200, height: 600)
stickerBrowser.dataSource = dataSource
view.addSubview(stickerBrowser)
stickerBrowser.reloadData()
view.bringSubviewToFront(stickerBrowser)
// Called when the extension is about to move from the inactive to active state.
// This will happen when the extension is about to present UI.

View File

@@ -0,0 +1,25 @@
//
// StickerBroswerViewController.swift
// StickerSlackiMessageExtension
//
// Created by neon443 on 29/10/2025.
//
import Foundation
import UIKit
import Messages
class StickerBroswerViewController: MSStickerBrowserViewController {
var hoarder: EmojiHoarder = EmojiHoarder()
var emojis: [Emoji] = []
override func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int {
emojis = hoarder.emojis.filter { $0.isLocal }
return emojis.count
}
override func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView, stickerAt index: Int) -> MSSticker {
return emojis[index].sticker
}
}

View File

@@ -0,0 +1,21 @@
//
// StickerBrowserDataSource.swift
// StickerSlackiMessageExtension
//
// Created by neon443 on 29/10/2025.
//
import Foundation
import Messages
class StickerBrowserDataSource: NSObject, MSStickerBrowserViewDataSource {
var hoarder: EmojiHoarder = EmojiHoarder()
func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int {
return hoarder.emojis.filter { $0.isLocal }.count
}
func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView, stickerAt index: Int) -> MSSticker {
return hoarder.emojis.filter { $0.isLocal }[index].sticker
}
}