@independo/capacitor-emoji-picker 1.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/IndependoCapacitorEmojiPicker.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +223 -0
- package/android/build.gradle +109 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPicker.java +82 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPickerWebBridgeInterface.java +28 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiCloseButtonOptions.java +18 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiPickerCallback.java +11 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiPickerResult.java +16 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/core/ErrorCodes.java +14 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DefaultEmojiPickerDialogFactory.java +35 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DispatchingEmojiPickerPresenter.java +26 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerDialogFactory.java +26 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerPresenter.java +16 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/NativeEmojiPickerPresenter.java +220 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/WebFallbackEmojiPickerPresenter.java +228 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/service/EmojiPickerService.java +46 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +169 -0
- package/dist/esm/core/error-codes.d.ts +9 -0
- package/dist/esm/core/error-codes.js +10 -0
- package/dist/esm/core/error-codes.js.map +1 -0
- package/dist/esm/definitions.d.ts +81 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/platform/web/EmojiPickerWebAdapter.d.ts +10 -0
- package/dist/esm/platform/web/EmojiPickerWebAdapter.js +12 -0
- package/dist/esm/platform/web/EmojiPickerWebAdapter.js.map +1 -0
- package/dist/esm/platform/web/WebEmojiPickerPresenter.d.ts +22 -0
- package/dist/esm/platform/web/WebEmojiPickerPresenter.js +292 -0
- package/dist/esm/platform/web/WebEmojiPickerPresenter.js.map +1 -0
- package/dist/esm/platform/web/emoji-data-source.d.ts +5 -0
- package/dist/esm/platform/web/emoji-data-source.js +16 -0
- package/dist/esm/platform/web/emoji-data-source.js.map +1 -0
- package/dist/esm/platform/web/nativeWebBridge.d.ts +29 -0
- package/dist/esm/platform/web/nativeWebBridge.js +58 -0
- package/dist/esm/platform/web/nativeWebBridge.js.map +1 -0
- package/dist/esm/service/EmojiPickerService.d.ts +16 -0
- package/dist/esm/service/EmojiPickerService.js +23 -0
- package/dist/esm/service/EmojiPickerService.js.map +1 -0
- package/dist/esm/web.d.ts +9 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +3274 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +3277 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/EmojiPicker/Bridge/EmojiPicker.swift +79 -0
- package/ios/Sources/EmojiPicker/Bridge/EmojiPickerScriptMessageHandler.swift +19 -0
- package/ios/Sources/EmojiPicker/Core/EmojiPickerResult.swift +12 -0
- package/ios/Sources/EmojiPicker/Core/ErrorCodes.swift +12 -0
- package/ios/Sources/EmojiPicker/Presenter/DefaultEmojiKeyboardPresentationFactory.swift +370 -0
- package/ios/Sources/EmojiPicker/Presenter/DispatchingEmojiPickerPresenter.swift +19 -0
- package/ios/Sources/EmojiPicker/Presenter/EmojiKeyboardPresentationFactory.swift +36 -0
- package/ios/Sources/EmojiPicker/Presenter/EmojiPickerPresenter.swift +31 -0
- package/ios/Sources/EmojiPicker/Presenter/NativeEmojiPickerPresenter.swift +186 -0
- package/ios/Sources/EmojiPicker/Presenter/WebFallbackEmojiPickerPresenter.swift +122 -0
- package/ios/Sources/EmojiPicker/Service/EmojiPickerService.swift +25 -0
- package/package.json +120 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// Presents the system emoji keyboard via an injected `EmojiKeyboardPresentationFactory`.
|
|
4
|
+
final class NativeEmojiPickerPresenter: EmojiPickerPresenter {
|
|
5
|
+
|
|
6
|
+
/// Supplies the current host view controller to present atop; nil if none is available.
|
|
7
|
+
typealias HostViewControllerProvider = () -> UIViewController?
|
|
8
|
+
|
|
9
|
+
/// Decides whether a host view controller can currently present UI.
|
|
10
|
+
///
|
|
11
|
+
/// Isolated from `present` for symmetry with Android's `ActivityAvailabilityChecker` seam and
|
|
12
|
+
/// to keep the check fakeable in tests. UIKit has no throwing-outside-instrumented-tests trap
|
|
13
|
+
/// the way `Activity#isFinishing()` does under Android's mockable jar, so this isn't
|
|
14
|
+
/// load-bearing for crash-avoidance the way Android's is - it exists for seam consistency.
|
|
15
|
+
typealias HostAvailabilityChecker = (UIViewController?) -> Bool
|
|
16
|
+
|
|
17
|
+
private static let defaultAvailabilityChecker: HostAvailabilityChecker = { host in
|
|
18
|
+
guard let host = host else { return false }
|
|
19
|
+
return host.isViewLoaded && host.view.window != nil
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private let hostViewControllerProvider: HostViewControllerProvider
|
|
23
|
+
private let factory: EmojiKeyboardPresentationFactory
|
|
24
|
+
private let availabilityChecker: HostAvailabilityChecker
|
|
25
|
+
|
|
26
|
+
/// The presentation currently owning the UI/handle, if any. Only the `Presentation` instance
|
|
27
|
+
/// that is still `current` may settle and clear this field; a stale presentation whose async
|
|
28
|
+
/// callback fires after a newer one has taken over must not be able to touch it.
|
|
29
|
+
private var current: Presentation?
|
|
30
|
+
|
|
31
|
+
convenience init(hostViewControllerProvider: @escaping HostViewControllerProvider, factory: EmojiKeyboardPresentationFactory) {
|
|
32
|
+
self.init(
|
|
33
|
+
hostViewControllerProvider: hostViewControllerProvider,
|
|
34
|
+
factory: factory,
|
|
35
|
+
availabilityChecker: Self.defaultAvailabilityChecker
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// Internal: lets tests inject a fake `HostAvailabilityChecker`.
|
|
40
|
+
init(
|
|
41
|
+
hostViewControllerProvider: @escaping HostViewControllerProvider,
|
|
42
|
+
factory: EmojiKeyboardPresentationFactory,
|
|
43
|
+
availabilityChecker: @escaping HostAvailabilityChecker
|
|
44
|
+
) {
|
|
45
|
+
self.hostViewControllerProvider = hostViewControllerProvider
|
|
46
|
+
self.factory = factory
|
|
47
|
+
self.availabilityChecker = availabilityChecker
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func present(options: EmojiPickerPresentOptions, completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void) {
|
|
51
|
+
guard options.presentation == "auto" else {
|
|
52
|
+
// 'web' (and any future non-native presentation) isn't implemented on iOS yet;
|
|
53
|
+
// honestly reject rather than silently showing the native picker instead.
|
|
54
|
+
completion(.failure(EmojiPickerError(code: ErrorCodes.notImplemented)))
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Capacitor iOS plugin calls are not guaranteed to arrive on the main thread, but
|
|
59
|
+
// UIViewController/UITextField/UIWindow are main-thread-only APIs. Unconditionally hop -
|
|
60
|
+
// unlike Android's Activity-based branch, the provider closure here is always safe to call
|
|
61
|
+
// from any thread, so there's no "no UI to touch" case to special-case around.
|
|
62
|
+
DispatchQueue.main.async { [weak self] in
|
|
63
|
+
self?.presentOnMainThread(
|
|
64
|
+
closeButton: options.closeButton,
|
|
65
|
+
dismissOnBackdropTap: options.dismissOnBackdropTap,
|
|
66
|
+
completion: completion
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private func presentOnMainThread(
|
|
72
|
+
closeButton: EmojiCloseButtonOptions,
|
|
73
|
+
dismissOnBackdropTap: Bool,
|
|
74
|
+
completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void
|
|
75
|
+
) {
|
|
76
|
+
let host = hostViewControllerProvider()
|
|
77
|
+
guard availabilityChecker(host), let host = host else {
|
|
78
|
+
completion(.failure(EmojiPickerError(code: ErrorCodes.nativeUnavailable)))
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Dismiss the prior presentation's UI, but do NOT clear `current` here: dismissal may
|
|
83
|
+
// complete asynchronously (e.g. dismiss(animated:) completion, or the emoji-mode
|
|
84
|
+
// verification path still in flight). The old Presentation's own settle() - triggered
|
|
85
|
+
// whenever its callback eventually fires - clears `current` itself, and only if it's
|
|
86
|
+
// still the active one, so it can never clobber the new Presentation created below.
|
|
87
|
+
current?.dismissPresentation()
|
|
88
|
+
|
|
89
|
+
let presentation = Presentation(completion: completion)
|
|
90
|
+
current = presentation
|
|
91
|
+
presentation.owner = self
|
|
92
|
+
presentation.start(host: host, closeButton: closeButton, dismissOnBackdropTap: dismissOnBackdropTap, factory: factory)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/// Owns everything about ONE presentation attempt: its handle, its cleanup, and whether it
|
|
96
|
+
/// has already settled. Identity - not a shared field - determines whether a (possibly
|
|
97
|
+
/// late-arriving, async) callback is allowed to mutate `current`.
|
|
98
|
+
private final class Presentation: EmojiKeyboardPresentationListener {
|
|
99
|
+
private let completion: (Result<EmojiPickerResult, EmojiPickerError>) -> Void
|
|
100
|
+
weak var owner: NativeEmojiPickerPresenter?
|
|
101
|
+
private var handle: EmojiKeyboardPresentationHandle?
|
|
102
|
+
private var settled = false
|
|
103
|
+
private var resignActiveObserver: NSObjectProtocol?
|
|
104
|
+
|
|
105
|
+
init(completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void) {
|
|
106
|
+
self.completion = completion
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
func start(
|
|
110
|
+
host: UIViewController,
|
|
111
|
+
closeButton: EmojiCloseButtonOptions,
|
|
112
|
+
dismissOnBackdropTap: Bool,
|
|
113
|
+
factory: EmojiKeyboardPresentationFactory
|
|
114
|
+
) {
|
|
115
|
+
let createdHandle = factory.create(
|
|
116
|
+
hostViewController: host,
|
|
117
|
+
closeButtonOptions: closeButton,
|
|
118
|
+
dismissOnBackdropTap: dismissOnBackdropTap,
|
|
119
|
+
listener: self
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
if settled {
|
|
123
|
+
// Defensive: if create() somehow synchronously settled us (e.g. immediate
|
|
124
|
+
// onUnavailable/onDismissed), don't leak the handle - dismiss it right away.
|
|
125
|
+
createdHandle.dismiss()
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
handle = createdHandle
|
|
130
|
+
|
|
131
|
+
// Belt-and-suspenders: settle {emoji: nil} if the app backgrounds mid-presentation.
|
|
132
|
+
// There's no exact iOS analog to Android's Lifecycle.ON_DESTROY hook here, but this
|
|
133
|
+
// closes the same class of "never settles" risk if the keyboard/first-responder chain
|
|
134
|
+
// gets torn down by the system while backgrounded.
|
|
135
|
+
resignActiveObserver = NotificationCenter.default.addObserver(
|
|
136
|
+
forName: UIApplication.willResignActiveNotification,
|
|
137
|
+
object: nil,
|
|
138
|
+
queue: .main
|
|
139
|
+
) { [weak self] _ in
|
|
140
|
+
self?.dismissPresentationAndSettleNil()
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Dismisses this presentation's handle, if any. Does not settle synchronously.
|
|
145
|
+
func dismissPresentation() {
|
|
146
|
+
handle?.dismiss()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private func dismissPresentationAndSettleNil() {
|
|
150
|
+
handle?.dismiss()
|
|
151
|
+
settle(.success(EmojiPickerResult(emoji: nil)))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// MARK: EmojiKeyboardPresentationListener
|
|
155
|
+
|
|
156
|
+
func onEmojiSelected(_ emoji: String) {
|
|
157
|
+
settle(.success(EmojiPickerResult(emoji: emoji)))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
func onDismissed() {
|
|
161
|
+
settle(.success(EmojiPickerResult(emoji: nil)))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
func onUnavailable() {
|
|
165
|
+
settle(.failure(EmojiPickerError(code: ErrorCodes.nativeUnavailable)))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private func settle(_ result: Result<EmojiPickerResult, EmojiPickerError>) {
|
|
169
|
+
guard !settled else { return }
|
|
170
|
+
settled = true
|
|
171
|
+
closeOut()
|
|
172
|
+
completion(result)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// Removes the notification observer and, if still current, clears `current`. Never
|
|
176
|
+
/// touches another Presentation instance's state.
|
|
177
|
+
private func closeOut() {
|
|
178
|
+
if let observer = resignActiveObserver {
|
|
179
|
+
NotificationCenter.default.removeObserver(observer)
|
|
180
|
+
}
|
|
181
|
+
if owner?.current === self {
|
|
182
|
+
owner?.current = nil
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// Presents the web bottom sheet inside the app's own Capacitor webview by evaluating JS there
|
|
4
|
+
/// (registered by `registerNativeWebBridge()` in the JS layer), and resolves once that JS
|
|
5
|
+
/// reports back via `handleBridgeMessage`. Kept independent of any real `WKWebView` type so it
|
|
6
|
+
/// stays unit-testable: production wiring in `EmojiPicker.load()` supplies a JS evaluator backed
|
|
7
|
+
/// by `WKWebView.evaluateJavaScript`, tests supply a fake one.
|
|
8
|
+
final class WebFallbackEmojiPickerPresenter: EmojiPickerPresenter {
|
|
9
|
+
/// How long to wait for the JS side to report back before giving up.
|
|
10
|
+
static let timeoutSeconds: TimeInterval = 3
|
|
11
|
+
|
|
12
|
+
/// Evaluates JS in the app's webview. The completion callback fires once the script has at
|
|
13
|
+
/// least started executing (i.e. the bridge/webview is alive) - it is a liveness signal, not
|
|
14
|
+
/// a signal that the picker has settled.
|
|
15
|
+
private let jsEvaluator: (String, @escaping () -> Void) -> Void
|
|
16
|
+
private let scheduler: (TimeInterval, @escaping () -> Void) -> Void
|
|
17
|
+
private var pending: [String: PendingRequest] = [:]
|
|
18
|
+
|
|
19
|
+
convenience init(jsEvaluator: @escaping (String, @escaping () -> Void) -> Void) {
|
|
20
|
+
self.init(jsEvaluator: jsEvaluator) { delay, work in
|
|
21
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: work)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Internal: lets tests inject a fake scheduler instead of waiting real time.
|
|
26
|
+
init(
|
|
27
|
+
jsEvaluator: @escaping (String, @escaping () -> Void) -> Void,
|
|
28
|
+
scheduler: @escaping (TimeInterval, @escaping () -> Void) -> Void
|
|
29
|
+
) {
|
|
30
|
+
self.jsEvaluator = jsEvaluator
|
|
31
|
+
self.scheduler = scheduler
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func present(options: EmojiPickerPresentOptions, completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void) {
|
|
35
|
+
// Capacitor plugin calls arrive on a background "bridge" queue, but `jsEvaluator` ends up
|
|
36
|
+
// calling `WKWebView.evaluateJavaScript`, a main-thread-only UI API (mirrors the
|
|
37
|
+
// unconditional hop `NativeEmojiPickerPresenter` already does for its own UIKit calls).
|
|
38
|
+
DispatchQueue.main.async { [weak self] in
|
|
39
|
+
self?.presentOnMainThread(options: options, completion: completion)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private func presentOnMainThread(options: EmojiPickerPresentOptions, completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void) {
|
|
44
|
+
let requestId = UUID().uuidString
|
|
45
|
+
|
|
46
|
+
// Genuine timeout - i.e. the eval-completion callback below never fired at all (extremely
|
|
47
|
+
// rare: webview torn down mid-call, etc). Defensively tell the JS side to close (in case
|
|
48
|
+
// the bridge partially works) and settle via the same path as a normal dismiss. If the
|
|
49
|
+
// eval completion DID fire by the time this runs, it's a no-op: the request just stays
|
|
50
|
+
// pending for its real result.
|
|
51
|
+
scheduler(Self.timeoutSeconds) { [weak self] in
|
|
52
|
+
self?.handleTimeout(requestId: requestId)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Belt-and-suspenders, mirroring `NativeEmojiPickerPresenter`'s own backgrounding safety
|
|
56
|
+
// net: force-dismiss (and tell the JS sheet to close) if the app backgrounds mid-presentation,
|
|
57
|
+
// since there's no guarantee the JS side's own bridge call ever lands in that case.
|
|
58
|
+
let resignActiveObserver = NotificationCenter.default.addObserver(
|
|
59
|
+
forName: UIApplication.willResignActiveNotification,
|
|
60
|
+
object: nil,
|
|
61
|
+
queue: .main
|
|
62
|
+
) { [weak self] _ in
|
|
63
|
+
self?.dismiss(requestId: requestId)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
pending[requestId] = PendingRequest(completion: completion, resignActiveObserver: resignActiveObserver)
|
|
67
|
+
|
|
68
|
+
let json = Self.encodeOptionsJson(dismissOnBackdropTap: options.dismissOnBackdropTap, closeButton: options.closeButton)
|
|
69
|
+
// The eval "completion" here only means the script at least started executing (i.e. the
|
|
70
|
+
// bridge/webview is alive) - it cancels the timeout WITHOUT settling the request, which
|
|
71
|
+
// stays pending for the real result reported later via handleBridgeMessage.
|
|
72
|
+
jsEvaluator("window.__CapacitorEmojiPickerPresentWeb('\(requestId)', '\(json)')") { [weak self] in
|
|
73
|
+
self?.pending[requestId]?.evalAcknowledged = true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// Called by the `WKScriptMessageHandler` once the JS sheet settles.
|
|
78
|
+
func handleBridgeMessage(requestId: String, emoji: String?, errorCode: String?) {
|
|
79
|
+
settle(requestId: requestId, emoji: emoji, errorCode: errorCode)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Force-dismisses a still-pending presentation (e.g. on app backgrounding).
|
|
83
|
+
func dismiss(requestId: String) {
|
|
84
|
+
jsEvaluator("window.__CapacitorEmojiPickerDismissWeb && window.__CapacitorEmojiPickerDismissWeb('\(requestId)')") {}
|
|
85
|
+
settle(requestId: requestId, emoji: nil, errorCode: nil)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// Handles the timeout firing: a no-op if the eval-completion callback already acknowledged
|
|
89
|
+
/// the bridge is alive (the request stays pending for its real result); otherwise this is a
|
|
90
|
+
/// genuine bridge-liveness failure (the JS side never even started processing the request),
|
|
91
|
+
/// so defensively evaluate the JS dismiss call and settle as an error rather than reusing
|
|
92
|
+
/// `dismiss(requestId:)`'s success/null semantics (that's reserved for genuine user/app
|
|
93
|
+
/// dismissal, e.g. backgrounding).
|
|
94
|
+
private func handleTimeout(requestId: String) {
|
|
95
|
+
guard let request = pending[requestId], !request.evalAcknowledged else { return }
|
|
96
|
+
jsEvaluator("window.__CapacitorEmojiPickerDismissWeb && window.__CapacitorEmojiPickerDismissWeb('\(requestId)')") {}
|
|
97
|
+
settle(requestId: requestId, emoji: nil, errorCode: ErrorCodes.notImplemented)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private func settle(requestId: String, emoji: String?, errorCode: String?) {
|
|
101
|
+
guard let request = pending.removeValue(forKey: requestId) else { return }
|
|
102
|
+
NotificationCenter.default.removeObserver(request.resignActiveObserver)
|
|
103
|
+
if let errorCode = errorCode {
|
|
104
|
+
request.completion(.failure(EmojiPickerError(code: errorCode)))
|
|
105
|
+
} else {
|
|
106
|
+
request.completion(.success(EmojiPickerResult(emoji: emoji)))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// Hand-rolled instead of `JSONSerialization`: `size`/`position` are always one of a small
|
|
111
|
+
/// fixed set of ASCII enum values validated/defaulted when the plugin call is parsed, never
|
|
112
|
+
/// arbitrary user text, so plain string interpolation is safe here.
|
|
113
|
+
private static func encodeOptionsJson(dismissOnBackdropTap: Bool, closeButton: EmojiCloseButtonOptions) -> String {
|
|
114
|
+
"{\"dismissOnBackdropTap\":\(dismissOnBackdropTap),\"closeButton\":{\"size\":\"\(closeButton.size)\",\"position\":\"\(closeButton.position)\",\"hidden\":\(closeButton.hidden)}}"
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private struct PendingRequest {
|
|
118
|
+
let completion: (Result<EmojiPickerResult, EmojiPickerError>) -> Void
|
|
119
|
+
let resignActiveObserver: NSObjectProtocol
|
|
120
|
+
var evalAcknowledged = false
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Orchestrates presenter calls and guards against overlapping presentations.
|
|
4
|
+
final class EmojiPickerService {
|
|
5
|
+
private let presenter: EmojiPickerPresenter
|
|
6
|
+
private var isPresenting = false
|
|
7
|
+
|
|
8
|
+
init(presenter: EmojiPickerPresenter) {
|
|
9
|
+
self.presenter = presenter
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/// Presents the picker, rejecting a second concurrent call instead of overlapping pickers.
|
|
13
|
+
func present(options: EmojiPickerPresentOptions, completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void) {
|
|
14
|
+
if isPresenting {
|
|
15
|
+
completion(.failure(EmojiPickerError(code: ErrorCodes.alreadyPresenting)))
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
isPresenting = true
|
|
20
|
+
presenter.present(options: options) { [weak self] result in
|
|
21
|
+
self?.isPresenting = false
|
|
22
|
+
completion(result)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
{
|
|
2
|
+
"capacitor": {
|
|
3
|
+
"ios": {
|
|
4
|
+
"src": "ios"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"src": "android"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"prettier": "@ionic/prettier-config",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/independo-gmbh/capacitor-emoji-picker.git"
|
|
14
|
+
},
|
|
15
|
+
"description": "Emoji picker plugin for Capacitor 8 with native Android support, iOS system emoji keyboard integration, and a web fallback.",
|
|
16
|
+
"version": "1.0.0-dev.1",
|
|
17
|
+
"packageManager": "pnpm@11.8.0",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@capacitor/android": "catalog:",
|
|
20
|
+
"@capacitor/core": "catalog:",
|
|
21
|
+
"@capacitor/docgen": "catalog:",
|
|
22
|
+
"@capacitor/ios": "catalog:",
|
|
23
|
+
"@eslint/js": "10.0.1",
|
|
24
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
25
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
26
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
28
|
+
"@saithodev/semantic-release-backmerge": "^4.0.1",
|
|
29
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
30
|
+
"@semantic-release/git": "^11.0.1",
|
|
31
|
+
"@types/jest": "^30.0.0",
|
|
32
|
+
"@types/node": "^26.2.0",
|
|
33
|
+
"conventional-changelog-conventionalcommits": "^10.2.1",
|
|
34
|
+
"eslint": "10.8.0",
|
|
35
|
+
"globals": "17.9.0",
|
|
36
|
+
"jest": "^30.4.2",
|
|
37
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
38
|
+
"rollup": "^4.62.4",
|
|
39
|
+
"semantic-release": "^25.0.9",
|
|
40
|
+
"swiftlint": "^2.0.0",
|
|
41
|
+
"ts-jest": "^29.4.12",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"typescript-eslint": "8.66.0"
|
|
44
|
+
},
|
|
45
|
+
"main": "dist/plugin.cjs.js",
|
|
46
|
+
"files": [
|
|
47
|
+
"android/src/main/",
|
|
48
|
+
"android/build.gradle",
|
|
49
|
+
"dist/",
|
|
50
|
+
"IndependoCapacitorEmojiPicker.podspec",
|
|
51
|
+
"ios/Sources",
|
|
52
|
+
"Package.swift"
|
|
53
|
+
],
|
|
54
|
+
"author": "Independo GmbH",
|
|
55
|
+
"types": "dist/esm/index.d.ts",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/independo-gmbh/capacitor-emoji-picker/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://www.independo.app/",
|
|
60
|
+
"scripts": {
|
|
61
|
+
"upgrade": "corepack prepare pnpm@latest --activate && pnpm --recursive update",
|
|
62
|
+
"build": "pnpm run clean && pnpm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
63
|
+
"lint": "pnpm run eslint",
|
|
64
|
+
"prepublishOnly": "pnpm run build",
|
|
65
|
+
"verify": "pnpm run verify:ios && pnpm run verify:android && pnpm run verify:web",
|
|
66
|
+
"verify:android": "node scripts/verify-android.js",
|
|
67
|
+
"verify:ios": "xcodebuild -scheme IndependoCapacitorEmojiPicker -destination generic/platform=iOS",
|
|
68
|
+
"verify:web": "pnpm run build",
|
|
69
|
+
"watch": "tsc --watch",
|
|
70
|
+
"test": "pnpm run test:web && pnpm run test:android && pnpm run test:ios",
|
|
71
|
+
"test:web": "jest",
|
|
72
|
+
"test:web:coverage": "jest --coverage --coverageReporters=lcov --coverageReporters=text-summary",
|
|
73
|
+
"test:android": "node scripts/verify-android.js testDebugUnitTest",
|
|
74
|
+
"test:android:coverage": "node scripts/verify-android.js testDebugUnitTest jacocoTestReport",
|
|
75
|
+
"test:ios": "node scripts/test-ios.js",
|
|
76
|
+
"test:ios:coverage": "node scripts/test-ios.js --coverage --result-bundle-path coverage/ios.xcresult && node scripts/xccov-to-cobertura.js --xcresult coverage/ios.xcresult --output coverage/ios-cobertura.xml",
|
|
77
|
+
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"example/**/*.ts\"",
|
|
78
|
+
"clean": "rm -rf dist",
|
|
79
|
+
"swiftlint": "node-swiftlint",
|
|
80
|
+
"docgen": "docgen --api EmojiPickerPlugin --output-readme README.md --output-json dist/docs.json",
|
|
81
|
+
"fmt": "pnpm run eslint --fix"
|
|
82
|
+
},
|
|
83
|
+
"name": "@independo/capacitor-emoji-picker",
|
|
84
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
85
|
+
"license": "MIT",
|
|
86
|
+
"keywords": [
|
|
87
|
+
"capacitor",
|
|
88
|
+
"capacitor-plugin",
|
|
89
|
+
"plugin",
|
|
90
|
+
"native",
|
|
91
|
+
"emoji",
|
|
92
|
+
"emoji-picker",
|
|
93
|
+
"native-emoji-picker",
|
|
94
|
+
"emoji-keyboard",
|
|
95
|
+
"ionic",
|
|
96
|
+
"unicode",
|
|
97
|
+
"ios",
|
|
98
|
+
"android",
|
|
99
|
+
"web"
|
|
100
|
+
],
|
|
101
|
+
"publishConfig": {
|
|
102
|
+
"provenance": true,
|
|
103
|
+
"access": "public"
|
|
104
|
+
},
|
|
105
|
+
"unpkg": "dist/plugin.js",
|
|
106
|
+
"contributors": [
|
|
107
|
+
{
|
|
108
|
+
"email": "admin@independo.app",
|
|
109
|
+
"name": "Independo GmbH"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"peerDependencies": {
|
|
113
|
+
"@capacitor/core": ">=8.0.0"
|
|
114
|
+
},
|
|
115
|
+
"module": "dist/esm/index.js",
|
|
116
|
+
"dependencies": {
|
|
117
|
+
"emoji-picker-element": "^1.29.1",
|
|
118
|
+
"emoji-picker-element-data": "^1.8.0"
|
|
119
|
+
}
|
|
120
|
+
}
|