@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,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'IndependoCapacitorEmojiPicker'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.9'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Independo GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "IndependoCapacitorEmojiPicker",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "IndependoCapacitorEmojiPicker",
|
|
10
|
+
targets: ["EmojiPicker"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "EmojiPicker",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/EmojiPicker"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "EmojiPickerTests",
|
|
25
|
+
dependencies: ["EmojiPicker"],
|
|
26
|
+
path: "ios/Tests/EmojiPickerTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" alt="CapacitorJS Logo" />
|
|
3
|
+
</p>
|
|
4
|
+
<h3 align="center">Capacitor Emoji Picker for iOS, Android & Web</h3>
|
|
5
|
+
<p align="center"><strong><code>@independo/capacitor-emoji-picker</code></strong></p>
|
|
6
|
+
<p align="center">Emoji picker plugin for Capacitor 8 with native Android support, iOS system emoji keyboard integration, and a web fallback.</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2026" alt="Maintenance Badge: until 2026" />
|
|
10
|
+
<a href="https://www.npmjs.com/package/@independo/capacitor-emoji-picker"><img src="https://img.shields.io/npm/l/@independo/capacitor-emoji-picker" alt="License Badge: MIT" /></a>
|
|
11
|
+
<br>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@independo/capacitor-emoji-picker"><img src="https://img.shields.io/npm/dw/@independo/capacitor-emoji-picker" alt="" role="presentation" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@independo/capacitor-emoji-picker"><img src="https://img.shields.io/npm/v/@independo/capacitor-emoji-picker" alt="" role="presentation" /></a>
|
|
14
|
+
<a href="https://codecov.io/gh/independo-gmbh/capacitor-emoji-picker/branch/main"><img src="https://codecov.io/gh/independo-gmbh/capacitor-emoji-picker/branch/main/graph/badge.svg" alt="Coverage Badge: main" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">Built and maintained by <a href="https://www.independo.app/">Independo</a>.</p>
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
`@independo/capacitor-emoji-picker` is a Capacitor emoji picker plugin that brings a native emoji
|
|
22
|
+
picker to Android, a Capacitor emoji keyboard experience via the iOS system emoji keyboard, and a
|
|
23
|
+
web emoji picker fallback everywhere else — one API for Capacitor 8, Ionic, and any framework built
|
|
24
|
+
on top of it (Angular, React, Vue, or vanilla JS/TS).
|
|
25
|
+
|
|
26
|
+
Call `present()` and it resolves with the emoji the user selected: native/system UI first, with an
|
|
27
|
+
automatic fallback to the web picker when native presentation isn't available.
|
|
28
|
+
|
|
29
|
+
<table>
|
|
30
|
+
<tr>
|
|
31
|
+
<th align="center">iOS</th>
|
|
32
|
+
<th align="center">Android</th>
|
|
33
|
+
<th align="center">Web</th>
|
|
34
|
+
</tr>
|
|
35
|
+
<tr>
|
|
36
|
+
<td align="center"><img src="./docs/media/demo-ios.gif" alt="iOS system emoji keyboard demo" width="220" /></td>
|
|
37
|
+
<td align="center"><img src="./docs/media/demo-android.gif" alt="Android native emoji picker demo" width="220" /></td>
|
|
38
|
+
<td align="center"><img src="./docs/media/demo-web.gif" alt="Web emoji picker demo" width="220" /></td>
|
|
39
|
+
</tr>
|
|
40
|
+
</table>
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
pnpm add @independo/capacitor-emoji-picker
|
|
46
|
+
pnpm exec cap sync
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Requirements
|
|
50
|
+
|
|
51
|
+
- Capacitor 8+
|
|
52
|
+
- iOS 15+
|
|
53
|
+
- Android minSdk 24+; builds require Java 21 (recommended). `pnpm verify:android` requires a Java version supported
|
|
54
|
+
by the bundled Gradle wrapper (currently Java 21–24, with Java 21 recommended).
|
|
55
|
+
|
|
56
|
+
### Compatibility
|
|
57
|
+
|
|
58
|
+
Versioning follows Capacitor versioning. Major versions of the plugin are compatible with major versions of Capacitor.
|
|
59
|
+
|
|
60
|
+
| Plugin Version | Capacitor Version | Status |
|
|
61
|
+
|-----------------|--------------------|--------|
|
|
62
|
+
| 1.* | 8 | Active |
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { EmojiPicker } from '@independo/capacitor-emoji-picker';
|
|
68
|
+
|
|
69
|
+
const { emoji } = await EmojiPicker.present();
|
|
70
|
+
if (emoji !== null) {
|
|
71
|
+
// user selected an emoji, e.g. insert it into a text field
|
|
72
|
+
console.log(emoji);
|
|
73
|
+
} else {
|
|
74
|
+
// user dismissed the picker without selecting one
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Force the web picker instead of native/system UI:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const { emoji } = await EmojiPicker.present({ presentation: 'web' });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Customize the close button (iOS/web only) and backdrop-tap dismissal:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const { emoji } = await EmojiPicker.present({
|
|
88
|
+
closeButton: { size: 'large', position: 'left' },
|
|
89
|
+
dismissOnBackdropTap: false,
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Platform behavior
|
|
94
|
+
|
|
95
|
+
With the default `presentation: 'auto'`:
|
|
96
|
+
|
|
97
|
+
- **Android**: presents the AndroidX native picker (via
|
|
98
|
+
[`androidx.emoji2:emoji2-emojipicker`](https://developer.android.com/jetpack/androidx/releases/emoji2)) first.
|
|
99
|
+
If the native picker is unavailable or fails to present, falls back to the web picker rendered as a bottom sheet
|
|
100
|
+
inside the app's own WebView.
|
|
101
|
+
- **iOS**: attempts a best-effort system emoji keyboard/input mode first. This relies in part on behavior Apple
|
|
102
|
+
does not document or guarantee, so it may fall back to the web picker on some OS versions/configurations. The
|
|
103
|
+
web picker is rendered as a bottom sheet inside the app's own WebView.
|
|
104
|
+
- **Web**: uses the web picker (via [`emoji-picker-element`](https://github.com/nolanlawson/emoji-picker-element))
|
|
105
|
+
directly.
|
|
106
|
+
|
|
107
|
+
Passing `presentation: 'web'` bypasses native presentation entirely and always uses the web picker, on every
|
|
108
|
+
platform including Android and iOS.
|
|
109
|
+
|
|
110
|
+
Native-presentation failures fall back to the web picker automatically. User cancellation (dismissing the picker
|
|
111
|
+
without selecting an emoji) always resolves with `{ emoji: null }` and never triggers a fallback.
|
|
112
|
+
|
|
113
|
+
The web picker self-hosts its emoji dataset as a same-origin `blob:` object URL (rather than
|
|
114
|
+
fetching it from `emoji-picker-element`'s default CDN). Apps with a restrictive Content-Security-Policy
|
|
115
|
+
need to allow `blob:` in `connect-src`/`default-src` for this dataset to load.
|
|
116
|
+
|
|
117
|
+
Behavior that can't be reliably simulated in automated tests (especially the iOS system emoji keyboard) has a
|
|
118
|
+
manual QA checklist: see [`docs/MANUAL_QA.md`](./docs/MANUAL_QA.md).
|
|
119
|
+
|
|
120
|
+
## Troubleshooting
|
|
121
|
+
|
|
122
|
+
### Common error codes
|
|
123
|
+
|
|
124
|
+
The plugin rejects with error codes; check `error.code` (native) or `error.message` (web).
|
|
125
|
+
|
|
126
|
+
| Code | Platform(s) | Typical cause |
|
|
127
|
+
|------------------------|-------------------|--------------------------------------------------------------------------------|
|
|
128
|
+
| `ALREADY_PRESENTING` | iOS, Android, Web | `present()` called while a picker is already active. |
|
|
129
|
+
| `NATIVE_UNAVAILABLE` | iOS, Android | The native picker UI could not be presented (e.g. no active Activity); triggers fallback to the web picker under `presentation: 'auto'`. |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## API
|
|
134
|
+
|
|
135
|
+
<docgen-index>
|
|
136
|
+
|
|
137
|
+
* [`present(...)`](#present)
|
|
138
|
+
* [Interfaces](#interfaces)
|
|
139
|
+
* [Type Aliases](#type-aliases)
|
|
140
|
+
|
|
141
|
+
</docgen-index>
|
|
142
|
+
|
|
143
|
+
<docgen-api>
|
|
144
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
145
|
+
|
|
146
|
+
Interface for the EmojiPicker plugin, which presents a native or web emoji picker and
|
|
147
|
+
resolves with the emoji the user selected.
|
|
148
|
+
|
|
149
|
+
### present(...)
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
present(options?: EmojiPickerOptions | undefined) => Promise<EmojiPickerResult>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Presents the emoji picker.
|
|
156
|
+
|
|
157
|
+
Resolves with `{ emoji: null }` rather than leaving the promise pending when the user
|
|
158
|
+
dismisses the picker without selecting an emoji.
|
|
159
|
+
|
|
160
|
+
Calling this method again while a picker is already active rejects immediately with the
|
|
161
|
+
`ALREADY_PRESENTING` error code rather than presenting a second, overlapping picker.
|
|
162
|
+
|
|
163
|
+
| Param | Type | Description |
|
|
164
|
+
| ------------- | ----------------------------------------------------------------- | --------------------------------- |
|
|
165
|
+
| **`options`** | <code><a href="#emojipickeroptions">EmojiPickerOptions</a></code> | The options for the presentation. |
|
|
166
|
+
|
|
167
|
+
**Returns:** <code>Promise<<a href="#emojipickerresult">EmojiPickerResult</a>></code>
|
|
168
|
+
|
|
169
|
+
--------------------
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
### Interfaces
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
#### EmojiPickerResult
|
|
176
|
+
|
|
177
|
+
Result of presenting the emoji picker.
|
|
178
|
+
|
|
179
|
+
| Prop | Type | Description |
|
|
180
|
+
| ----------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
181
|
+
| **`emoji`** | <code>string \| null</code> | The selected emoji as a complete Unicode string/grapheme (unchanged), or `null` when the picker was dismissed without a selection. |
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
#### EmojiPickerOptions
|
|
185
|
+
|
|
186
|
+
Options for presenting the emoji picker.
|
|
187
|
+
|
|
188
|
+
| Prop | Type | Description | Default |
|
|
189
|
+
| -------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
|
|
190
|
+
| **`presentation`** | <code><a href="#emojipickerpresentation">EmojiPickerPresentation</a></code> | `auto`: prefer native/system UI and fall back to the web picker when native presentation is not available or fails. `web`: always use the web picker, including inside Capacitor native apps. | <code>'auto'</code> |
|
|
191
|
+
| **`closeButton`** | <code><a href="#emojipickerclosebuttonoptions">EmojiPickerCloseButtonOptions</a></code> | Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has no system-provided one). Ignored on Android. | |
|
|
192
|
+
| **`dismissOnBackdropTap`** | <code>boolean</code> | Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS) or the scrim outside the picker sheet (Android and web). On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of the value passed here, so the user always has a way to dismiss the picker. | <code>true</code> |
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
#### EmojiPickerCloseButtonOptions
|
|
196
|
+
|
|
197
|
+
Configures the close button rendered above the iOS native emoji keyboard/the web picker sheet.
|
|
198
|
+
|
|
199
|
+
| Prop | Type | Description | Default |
|
|
200
|
+
| -------------- | ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
|
|
201
|
+
| **`size`** | <code>'xSmall' \| 'small' \| 'medium' \| 'large'</code> | `xSmall`: 24pt, `small`: 32pt, `medium`: 48pt, `large`: 64pt. | <code>'medium'</code> |
|
|
202
|
+
| **`position`** | <code>'left' \| 'center' \| 'right'</code> | Which side of the keyboard the button docks to. | <code>'right'</code> |
|
|
203
|
+
| **`hidden`** | <code>boolean</code> | Hides the built-in close button. See <a href="#emojipickeroptions">`EmojiPickerOptions.dismissOnBackdropTap`</a> for the safety net this triggers. | <code>false</code> |
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
### Type Aliases
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
#### EmojiPickerPresentation
|
|
210
|
+
|
|
211
|
+
How the picker should be presented.
|
|
212
|
+
|
|
213
|
+
<code>'auto' | 'web'</code>
|
|
214
|
+
|
|
215
|
+
</docgen-api>
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
`@independo/capacitor-emoji-picker` is MIT licensed (see [`LICENSE`](./LICENSE)) and maintained by [Independo GmbH](https://www.independo.app/).
|
|
222
|
+
|
|
223
|
+
Its web picker implementation depends on [`emoji-picker-element`](https://github.com/nolanlawson/emoji-picker-element) and [`emoji-picker-element-data`](https://github.com/nolanlawson/emoji-picker-element-data), both MIT licensed.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
+
androidxEmoji2EmojiPickerVersion = project.hasProperty('androidxEmoji2EmojiPickerVersion') ? rootProject.ext.androidxEmoji2EmojiPickerVersion : '1.5.0'
|
|
7
|
+
materialVersion = project.hasProperty('materialVersion') ? rootProject.ext.materialVersion : '1.12.0'
|
|
8
|
+
androidxLifecycleVersion = project.hasProperty('androidxLifecycleVersion') ? rootProject.ext.androidxLifecycleVersion : '2.8.7'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
buildscript {
|
|
12
|
+
repositories {
|
|
13
|
+
google()
|
|
14
|
+
mavenCentral()
|
|
15
|
+
}
|
|
16
|
+
dependencies {
|
|
17
|
+
classpath 'com.android.tools.build:gradle:8.13.2'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: 'com.android.library'
|
|
22
|
+
apply plugin: 'jacoco'
|
|
23
|
+
|
|
24
|
+
android {
|
|
25
|
+
namespace = "app.independo.capacitoremojipicker"
|
|
26
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
27
|
+
defaultConfig {
|
|
28
|
+
minSdk = project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
29
|
+
targetSdk = project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
30
|
+
versionCode = 1
|
|
31
|
+
versionName = "1.0"
|
|
32
|
+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
33
|
+
}
|
|
34
|
+
buildTypes {
|
|
35
|
+
release {
|
|
36
|
+
minifyEnabled = false
|
|
37
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
testOptions {
|
|
41
|
+
unitTests.all {
|
|
42
|
+
jacoco {
|
|
43
|
+
includeNoLocationClasses = true
|
|
44
|
+
excludes = ['jdk.internal.*']
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
lint {
|
|
49
|
+
abortOnError = false
|
|
50
|
+
}
|
|
51
|
+
compileOptions {
|
|
52
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
53
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
jacoco {
|
|
58
|
+
toolVersion = '0.8.11'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
repositories {
|
|
62
|
+
google()
|
|
63
|
+
mavenCentral()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
dependencies {
|
|
68
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
69
|
+
implementation project(':capacitor-android')
|
|
70
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
71
|
+
implementation "androidx.emoji2:emoji2-emojipicker:$androidxEmoji2EmojiPickerVersion"
|
|
72
|
+
implementation "com.google.android.material:material:$materialVersion"
|
|
73
|
+
// Relied on for LifecycleOwner/DefaultLifecycleObserver in NativeEmojiPickerPresenter. Declared
|
|
74
|
+
// explicitly (rather than relying on it being pulled in transitively via appcompat) so a future
|
|
75
|
+
// appcompat version bump can't silently break compilation.
|
|
76
|
+
implementation "androidx.lifecycle:lifecycle-common:$androidxLifecycleVersion"
|
|
77
|
+
testImplementation "junit:junit:$junitVersion"
|
|
78
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
79
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
tasks.register('jacocoTestReport', JacocoReport) {
|
|
83
|
+
dependsOn tasks.named('testDebugUnitTest')
|
|
84
|
+
|
|
85
|
+
def fileFilter = [
|
|
86
|
+
'**/R.class',
|
|
87
|
+
'**/R$*.class',
|
|
88
|
+
'**/BuildConfig.*',
|
|
89
|
+
'**/Manifest*.*',
|
|
90
|
+
'**/*Test*.*',
|
|
91
|
+
'android/**/*.*',
|
|
92
|
+
]
|
|
93
|
+
def javaClasses = fileTree(dir: "$buildDir/intermediates/javac/debug", excludes: fileFilter)
|
|
94
|
+
def kotlinClasses = fileTree(dir: "$buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
|
|
95
|
+
classDirectories.setFrom(files([javaClasses, kotlinClasses]))
|
|
96
|
+
sourceDirectories.setFrom(files(['src/main/java', 'src/main/kotlin']))
|
|
97
|
+
executionData.setFrom(
|
|
98
|
+
fileTree(dir: buildDir, includes: [
|
|
99
|
+
'jacoco/testDebugUnitTest.exec',
|
|
100
|
+
'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec',
|
|
101
|
+
]),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
reports {
|
|
105
|
+
xml.required = true
|
|
106
|
+
html.required = true
|
|
107
|
+
csv.required = false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker;
|
|
2
|
+
|
|
3
|
+
import android.webkit.ValueCallback;
|
|
4
|
+
import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
|
|
5
|
+
import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
|
|
6
|
+
import app.independo.capacitoremojipicker.core.EmojiPickerResult;
|
|
7
|
+
import app.independo.capacitoremojipicker.presenter.DefaultEmojiPickerDialogFactory;
|
|
8
|
+
import app.independo.capacitoremojipicker.presenter.DispatchingEmojiPickerPresenter;
|
|
9
|
+
import app.independo.capacitoremojipicker.presenter.EmojiPickerPresenter;
|
|
10
|
+
import app.independo.capacitoremojipicker.presenter.NativeEmojiPickerPresenter;
|
|
11
|
+
import app.independo.capacitoremojipicker.presenter.WebFallbackEmojiPickerPresenter;
|
|
12
|
+
import app.independo.capacitoremojipicker.service.EmojiPickerService;
|
|
13
|
+
import com.getcapacitor.JSObject;
|
|
14
|
+
import com.getcapacitor.Plugin;
|
|
15
|
+
import com.getcapacitor.PluginCall;
|
|
16
|
+
import com.getcapacitor.PluginMethod;
|
|
17
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
|
+
import java.util.Arrays;
|
|
19
|
+
import java.util.HashSet;
|
|
20
|
+
import java.util.Set;
|
|
21
|
+
|
|
22
|
+
/** Capacitor bridge for the EmojiPicker plugin. */
|
|
23
|
+
@CapacitorPlugin(name = "EmojiPicker")
|
|
24
|
+
public class EmojiPicker extends Plugin {
|
|
25
|
+
|
|
26
|
+
private static final Set<String> VALID_CLOSE_BUTTON_SIZES =
|
|
27
|
+
new HashSet<>(Arrays.asList("xSmall", "small", "medium", "large"));
|
|
28
|
+
private static final Set<String> VALID_CLOSE_BUTTON_POSITIONS =
|
|
29
|
+
new HashSet<>(Arrays.asList("left", "center", "right"));
|
|
30
|
+
|
|
31
|
+
/** Service layer that owns presentation flow and concurrency guarding. */
|
|
32
|
+
private EmojiPickerService service;
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
public void load() {
|
|
36
|
+
super.load();
|
|
37
|
+
EmojiPickerPresenter nativePresenter =
|
|
38
|
+
new NativeEmojiPickerPresenter(this::getActivity, new DefaultEmojiPickerDialogFactory());
|
|
39
|
+
WebFallbackEmojiPickerPresenter webFallbackPresenter = new WebFallbackEmojiPickerPresenter(
|
|
40
|
+
(js, onEvaluated) -> getBridge().eval(js, (ValueCallback<String>) value -> onEvaluated.run()),
|
|
41
|
+
this::getActivity
|
|
42
|
+
);
|
|
43
|
+
getBridge().getWebView().addJavascriptInterface(
|
|
44
|
+
new EmojiPickerWebBridgeInterface(webFallbackPresenter),
|
|
45
|
+
"CapacitorEmojiPickerAndroidBridge"
|
|
46
|
+
);
|
|
47
|
+
service = new EmojiPickerService(new DispatchingEmojiPickerPresenter(nativePresenter, webFallbackPresenter));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Presents the emoji picker. */
|
|
51
|
+
@PluginMethod
|
|
52
|
+
public void present(PluginCall call) {
|
|
53
|
+
String presentation = call.getString("presentation", "auto");
|
|
54
|
+
boolean dismissOnBackdropTap = call.getBoolean("dismissOnBackdropTap", true);
|
|
55
|
+
JSObject closeButtonObject = call.getObject("closeButton");
|
|
56
|
+
String size = closeButtonObject != null ? closeButtonObject.getString("size", "medium") : "medium";
|
|
57
|
+
String position = closeButtonObject != null ? closeButtonObject.getString("position", "right") : "right";
|
|
58
|
+
EmojiCloseButtonOptions closeButton = new EmojiCloseButtonOptions(
|
|
59
|
+
VALID_CLOSE_BUTTON_SIZES.contains(size) ? size : "medium",
|
|
60
|
+
VALID_CLOSE_BUTTON_POSITIONS.contains(position) ? position : "right",
|
|
61
|
+
closeButtonObject != null && closeButtonObject.optBoolean("hidden", false)
|
|
62
|
+
);
|
|
63
|
+
service.present(
|
|
64
|
+
presentation,
|
|
65
|
+
dismissOnBackdropTap,
|
|
66
|
+
closeButton,
|
|
67
|
+
new EmojiPickerCallback() {
|
|
68
|
+
@Override
|
|
69
|
+
public void onResult(EmojiPickerResult result) {
|
|
70
|
+
JSObject ret = new JSObject();
|
|
71
|
+
ret.put("emoji", result.getEmoji());
|
|
72
|
+
call.resolve(ret);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public void onError(String code) {
|
|
77
|
+
call.reject(code, code);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPickerWebBridgeInterface.java
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker;
|
|
2
|
+
|
|
3
|
+
import android.os.Handler;
|
|
4
|
+
import android.os.Looper;
|
|
5
|
+
import android.webkit.JavascriptInterface;
|
|
6
|
+
import app.independo.capacitoremojipicker.presenter.WebFallbackEmojiPickerPresenter;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* JS-callable object registered on the Capacitor webview
|
|
10
|
+
* (`webView.addJavascriptInterface(this, "CapacitorEmojiPickerAndroidBridge")`) so the web
|
|
11
|
+
* bottom sheet can report its outcome back to {@link WebFallbackEmojiPickerPresenter} once it
|
|
12
|
+
* settles. `@JavascriptInterface` methods run on a background thread, so this hops back to the
|
|
13
|
+
* main thread before touching the presenter (which touches `Lifecycle`, a main-thread-only API).
|
|
14
|
+
*/
|
|
15
|
+
public class EmojiPickerWebBridgeInterface {
|
|
16
|
+
|
|
17
|
+
private final WebFallbackEmojiPickerPresenter presenter;
|
|
18
|
+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
19
|
+
|
|
20
|
+
EmojiPickerWebBridgeInterface(WebFallbackEmojiPickerPresenter presenter) {
|
|
21
|
+
this.presenter = presenter;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@JavascriptInterface
|
|
25
|
+
public void onWebResult(String requestId, String emoji, String errorCode) {
|
|
26
|
+
mainHandler.post(() -> presenter.onWebResult(requestId, emoji, errorCode));
|
|
27
|
+
}
|
|
28
|
+
}
|
package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiCloseButtonOptions.java
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker.core;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Close-button configuration for a single {@code present()} call. Only consulted by presenters
|
|
5
|
+
* that render their own close affordance (currently the web-fallback presenter); ignored
|
|
6
|
+
* elsewhere, mirroring the iOS `EmojiCloseButtonOptions` struct.
|
|
7
|
+
*/
|
|
8
|
+
public final class EmojiCloseButtonOptions {
|
|
9
|
+
public final String size;
|
|
10
|
+
public final String position;
|
|
11
|
+
public final boolean hidden;
|
|
12
|
+
|
|
13
|
+
public EmojiCloseButtonOptions(String size, String position, boolean hidden) {
|
|
14
|
+
this.size = size;
|
|
15
|
+
this.position = position;
|
|
16
|
+
this.hidden = hidden;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiPickerCallback.java
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker.core;
|
|
2
|
+
|
|
3
|
+
/** Callback used by the service/presenter layers to report a presentation outcome. */
|
|
4
|
+
public interface EmojiPickerCallback {
|
|
5
|
+
|
|
6
|
+
/** Called with the selected emoji, or a result carrying a {@code null} emoji on dismissal. */
|
|
7
|
+
void onResult(EmojiPickerResult result);
|
|
8
|
+
|
|
9
|
+
/** Called with a canonical error code when the presentation could not complete. */
|
|
10
|
+
void onError(String code);
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker.core;
|
|
2
|
+
|
|
3
|
+
/** Result of presenting the emoji picker. */
|
|
4
|
+
public final class EmojiPickerResult {
|
|
5
|
+
|
|
6
|
+
private final String emoji;
|
|
7
|
+
|
|
8
|
+
public EmojiPickerResult(String emoji) {
|
|
9
|
+
this.emoji = emoji;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The selected emoji, or {@code null} when the picker was dismissed without a selection. */
|
|
13
|
+
public String getEmoji() {
|
|
14
|
+
return emoji;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker.core;
|
|
2
|
+
|
|
3
|
+
/** Canonical error codes surfaced by the EmojiPicker plugin. */
|
|
4
|
+
public final class ErrorCodes {
|
|
5
|
+
|
|
6
|
+
/** A `present()` call was made while a picker was already active. */
|
|
7
|
+
public static final String ALREADY_PRESENTING = "ALREADY_PRESENTING";
|
|
8
|
+
/** The native picker UI could not be presented (e.g. no active Activity); distinct from user cancellation. */
|
|
9
|
+
public static final String NATIVE_UNAVAILABLE = "NATIVE_UNAVAILABLE";
|
|
10
|
+
/** The requested presentation is not implemented on this platform yet. */
|
|
11
|
+
public static final String NOT_IMPLEMENTED = "NOT_IMPLEMENTED";
|
|
12
|
+
|
|
13
|
+
private ErrorCodes() {}
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker.presenter;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.view.ViewGroup;
|
|
5
|
+
import androidx.emoji2.emojipicker.EmojiPickerView;
|
|
6
|
+
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
|
7
|
+
|
|
8
|
+
/** Shows {@link EmojiPickerView} inside a Material bottom sheet dialog. */
|
|
9
|
+
public class DefaultEmojiPickerDialogFactory implements EmojiPickerDialogFactory {
|
|
10
|
+
|
|
11
|
+
@Override
|
|
12
|
+
public EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, Listener listener) {
|
|
13
|
+
BottomSheetDialog dialog = new BottomSheetDialog(
|
|
14
|
+
activity,
|
|
15
|
+
com.google.android.material.R.style.Theme_MaterialComponents_DayNight_BottomSheetDialog
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
EmojiPickerView pickerView = new EmojiPickerView(activity);
|
|
19
|
+
pickerView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
20
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
21
|
+
ViewGroup.LayoutParams.MATCH_PARENT
|
|
22
|
+
));
|
|
23
|
+
pickerView.setOnEmojiPickedListener(emojiViewItem -> {
|
|
24
|
+
listener.onEmojiSelected(emojiViewItem.getEmoji());
|
|
25
|
+
dialog.dismiss();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
dialog.setContentView(pickerView);
|
|
29
|
+
dialog.setCanceledOnTouchOutside(dismissOnBackdropTap);
|
|
30
|
+
dialog.setOnDismissListener(d -> listener.onDismissed());
|
|
31
|
+
dialog.show();
|
|
32
|
+
|
|
33
|
+
return dialog::dismiss;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package app.independo.capacitoremojipicker.presenter;
|
|
2
|
+
|
|
3
|
+
import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
|
|
4
|
+
import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Picks between the native and web-fallback presenters by {@code presentation}, so {@code
|
|
8
|
+
* EmojiPickerService}'s single concurrency guard covers both paths uniformly - from its point of
|
|
9
|
+
* view this is just another {@link EmojiPickerPresenter}.
|
|
10
|
+
*/
|
|
11
|
+
public class DispatchingEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
12
|
+
|
|
13
|
+
private final EmojiPickerPresenter nativePresenter;
|
|
14
|
+
private final EmojiPickerPresenter webFallbackPresenter;
|
|
15
|
+
|
|
16
|
+
public DispatchingEmojiPickerPresenter(EmojiPickerPresenter nativePresenter, EmojiPickerPresenter webFallbackPresenter) {
|
|
17
|
+
this.nativePresenter = nativePresenter;
|
|
18
|
+
this.webFallbackPresenter = webFallbackPresenter;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public void present(String presentation, boolean dismissOnBackdropTap, EmojiCloseButtonOptions closeButton, EmojiPickerCallback callback) {
|
|
23
|
+
EmojiPickerPresenter target = "web".equals(presentation) ? webFallbackPresenter : nativePresenter;
|
|
24
|
+
target.present(presentation, dismissOnBackdropTap, closeButton, callback);
|
|
25
|
+
}
|
|
26
|
+
}
|