Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Perform emoji selection on main thread #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sources/ElegantEmojiPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ open class ElegantEmojiPicker: UIViewController {
searchFieldBackground?.contentView.addSubview(clearButton!, anchors: [.trailing(spacing), .top(spacing), .bottom(spacing)])

searchField = UITextField()
searchField!.autocorrectionType = .no
searchField!.placeholder = localization.searchFieldPlaceholder
searchField!.delegate = self
searchField!.addTarget(self, action: #selector(searchFieldChanged), for: .editingChanged)
Expand Down Expand Up @@ -339,8 +340,12 @@ extension ElegantEmojiPicker: UICollectionViewDelegate, UICollectionViewDataSour
}

public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selection = searchResults?[indexPath.row] ?? emojiSections[indexPath.section].emojis[indexPath.row]
didSelectEmoji(selection)
DispatchQueue.main.async { [weak self] in
guard let self else { return }

let selection = self.searchResults?[indexPath.row] ?? self.emojiSections[indexPath.section].emojis[indexPath.row]
self.didSelectEmoji(selection)
}
}

public func scrollViewDidScroll(_ scrollView: UIScrollView) {
Expand Down