I am using ISEmojiView unbounded to the TextField, it is solely to select an emoji. In the parent UI, I am showing the recent emojis to offer a quick single click option. This is being done in SwiftUI, so I am wrap the recent emojis as a published array from an observableobject.
Great work on ISEmojiView, it saved me a bunch of time.
public class Emoji: ObservableObject, EmojiViewDelegate {
public static let shared = Emoji()
private var tapAwayView: UIView?
private var emojiView: EmojiView?
private var callback: ((String) -> Void)?
private let defaultEmojis: [String] = ["❤", "🙌", "👀", "😍"]
@Published public var popular: [String] = []
private init() {
updatePopular()
}
private func updatePopular() {
var emojis = RecentEmojisManager.sharedInstance
.recentEmojis()
.prefix(4)
.map(\.emoji)
emojis.append(contentsOf: defaultEmojis)
popular = Array(emojis.prefix(upTo: 4))
}
public func pick(callback: @escaping (String) -> Void) {
let keyboardSettings = KeyboardSettings(bottomType: .categories)
keyboardSettings.countOfRecentsEmojis = 0
keyboardSettings.needToShowDeleteButton = false
let emojiView = EmojiView(keyboardSettings: keyboardSettings)
emojiView.translatesAutoresizingMaskIntoConstraints = false
emojiView.delegate = self
let tapAwayView = UIView()
tapAwayView.addTapGesture { [weak self] _ in
self?.dismiss()
}
if let viewController = UIApplication.topViewController() {
self.callback = callback
self.emojiView = emojiView
self.tapAwayView = tapAwayView
viewController.view?.addSubview(tapAwayView)
viewController.view?.addSubview(emojiView)
tapAwayView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
emojiView.snp.makeConstraints {
$0.bottom.equalToSuperview()
$0.horizontal.equalToSuperview()
$0.height.equalTo(320)
}
}
}
public func emojiViewDidSelectEmoji(_ emoji: String, emojiView: EmojiView) {
callback?(emoji)
updatePopular()
dismiss()
}
public func emojiViewDidPressDeleteBackwardButton(_ emojiView: EmojiView) {
dismiss()
}
public func emojiViewDidPressDismissKeyboardButton(_ emojiView: EmojiView) {
dismiss()
}
private func dismiss() {
callback = nil
tapAwayView?.removeFromSuperview()
tapAwayView = nil
emojiView?.removeFromSuperview()
emojiView = nil
}
I am using ISEmojiView unbounded to the TextField, it is solely to select an emoji. In the parent UI, I am showing the recent emojis to offer a quick single click option. This is being done in SwiftUI, so I am wrap the recent emojis as a published array from an observableobject.
Great work on ISEmojiView, it saved me a bunch of time.