@independo/capacitor-emoji-picker 1.1.1-dev.1 → 1.2.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.
Files changed (28) hide show
  1. package/README.md +25 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPicker.java +11 -0
  4. package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiBackdropOptions.java +48 -0
  5. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DefaultEmojiPickerDialogFactory.java +27 -1
  6. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DispatchingEmojiPickerPresenter.java +3 -1
  7. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerDialogFactory.java +8 -1
  8. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerPresenter.java +2 -0
  9. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/NativeEmojiPickerPresenter.java +19 -4
  10. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/WebFallbackEmojiPickerPresenter.java +18 -5
  11. package/android/src/main/java/app/independo/capacitoremojipicker/service/EmojiPickerService.java +3 -0
  12. package/dist/docs.json +42 -0
  13. package/dist/esm/definitions.d.ts +25 -0
  14. package/dist/esm/definitions.js.map +1 -1
  15. package/dist/esm/platform/web/WebEmojiPickerPresenter.js +34 -9
  16. package/dist/esm/platform/web/WebEmojiPickerPresenter.js.map +1 -1
  17. package/dist/plugin.cjs.js +34 -9
  18. package/dist/plugin.cjs.js.map +1 -1
  19. package/dist/plugin.js +34 -9
  20. package/dist/plugin.js.map +1 -1
  21. package/ios/Sources/EmojiPicker/Bridge/EmojiPicker.swift +14 -0
  22. package/ios/Sources/EmojiPicker/Core/EmojiBackdropColor.swift +27 -0
  23. package/ios/Sources/EmojiPicker/Presenter/DefaultEmojiKeyboardPresentationFactory.swift +69 -3
  24. package/ios/Sources/EmojiPicker/Presenter/EmojiKeyboardPresentationFactory.swift +1 -0
  25. package/ios/Sources/EmojiPicker/Presenter/EmojiPickerPresenter.swift +11 -0
  26. package/ios/Sources/EmojiPicker/Presenter/NativeEmojiPickerPresenter.swift +12 -1
  27. package/ios/Sources/EmojiPicker/Presenter/WebFallbackEmojiPickerPresenter.swift +14 -4
  28. package/package.json +2 -2
package/README.md CHANGED
@@ -90,6 +90,20 @@ const { emoji } = await EmojiPicker.present({
90
90
  });
91
91
  ```
92
92
 
93
+ Customize the backdrop shown behind the picker:
94
+
95
+ ```typescript
96
+ const { emoji } = await EmojiPicker.present({
97
+ backdrop: { color: '#000000cc', blur: 8 },
98
+ });
99
+ ```
100
+
101
+ `color` is a CSS hex string; the alpha channel controls darkness and applies consistently across
102
+ web, Android, and iOS. `blur` (px) mirrors CSS `backdrop-filter: blur()` on web and is approximated
103
+ on iOS by mapping to the nearest system blur material (there's no continuous-radius blur API); it
104
+ has no visual effect on Android, which has no API to blur what's behind a dialog window - the value
105
+ is still accepted there for cross-platform option compatibility.
106
+
93
107
  ## Platform behavior
94
108
 
95
109
  With the default `presentation: 'auto'`:
@@ -189,6 +203,7 @@ Options for presenting the emoji picker.
189
203
  | -------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
190
204
  | **`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
205
  | **`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. | |
206
+ | **`backdrop`** | <code><a href="#emojipickerbackdropoptions">EmojiPickerBackdropOptions</a></code> | Configures the dimming/blur shown behind the picker. | |
192
207
  | **`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
208
  | **`theme`** | <code><a href="#emojipickertheme">EmojiPickerTheme</a></code> | `system`: follows the OS/app appearance setting. `light` / `dark`: forces the picker's appearance regardless of the system setting. On iOS native presentation, this also sets `keyboardAppearance` on the underlying text input, which is the mechanism the system emoji keyboard itself honors (separate from the app's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close button). | <code>'system'</code> |
194
209
 
@@ -204,6 +219,16 @@ Configures the close button rendered above the iOS native emoji keyboard/the web
204
219
  | **`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> |
205
220
 
206
221
 
222
+ #### EmojiPickerBackdropOptions
223
+
224
+ Configures the dimming/blur shown behind the picker.
225
+
226
+ | Prop | Type | Description | Default |
227
+ | ----------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
228
+ | **`color`** | <code>string</code> | CSS hex color for the backdrop; the alpha channel controls darkness (e.g. `'#000000cc'` is 80% black, `'#00000000'` is no darkening). Supports `#RGB`, `#RRGGBB`, and `#RRGGBBAA`. Falls back to the default on an invalid value. | <code>'#00000066'</code> |
229
+ | **`blur`** | <code>number</code> | Backdrop blur radius in px, analogous to CSS `backdrop-filter: blur()`. Web applies this directly. iOS approximates it by mapping the value to the nearest system blur material (there is no continuous-radius blur API). Android has no API to blur content behind a dialog window, so this option is accepted but has no visual effect there. | <code>0</code> |
230
+
231
+
207
232
  ### Type Aliases
208
233
 
209
234
 
@@ -14,7 +14,7 @@ buildscript {
14
14
  mavenCentral()
15
15
  }
16
16
  dependencies {
17
- classpath 'com.android.tools.build:gradle:8.13.2'
17
+ classpath 'com.android.tools.build:gradle:9.3.1'
18
18
  }
19
19
  }
20
20
 
@@ -34,7 +34,7 @@ android {
34
34
  buildTypes {
35
35
  release {
36
36
  minifyEnabled = false
37
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
37
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
38
38
  }
39
39
  }
40
40
  testOptions {
@@ -1,6 +1,7 @@
1
1
  package app.independo.capacitoremojipicker;
2
2
 
3
3
  import android.webkit.ValueCallback;
4
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
4
5
  import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
5
6
  import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
6
7
  import app.independo.capacitoremojipicker.core.EmojiPickerResult;
@@ -18,6 +19,7 @@ import com.getcapacitor.annotation.CapacitorPlugin;
18
19
  import java.util.Arrays;
19
20
  import java.util.HashSet;
20
21
  import java.util.Set;
22
+ import java.util.regex.Pattern;
21
23
 
22
24
  /** Capacitor bridge for the EmojiPicker plugin. */
23
25
  @CapacitorPlugin(name = "EmojiPicker")
@@ -28,6 +30,8 @@ public class EmojiPicker extends Plugin {
28
30
  private static final Set<String> VALID_CLOSE_BUTTON_POSITIONS =
29
31
  new HashSet<>(Arrays.asList("left", "center", "right"));
30
32
  private static final Set<String> VALID_THEMES = new HashSet<>(Arrays.asList("system", "light", "dark"));
33
+ private static final Pattern HEX_COLOR_PATTERN = Pattern.compile("^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$");
34
+ private static final String DEFAULT_BACKDROP_COLOR = "#00000066";
31
35
 
32
36
  /** Service layer that owns presentation flow and concurrency guarding. */
33
37
  private EmojiPickerService service;
@@ -61,11 +65,18 @@ public class EmojiPicker extends Plugin {
61
65
  VALID_CLOSE_BUTTON_POSITIONS.contains(position) ? position : "right",
62
66
  closeButtonObject != null && closeButtonObject.optBoolean("hidden", false)
63
67
  );
68
+ JSObject backdropObject = call.getObject("backdrop");
69
+ String backdropColor = backdropObject != null ? backdropObject.getString("color", DEFAULT_BACKDROP_COLOR) : DEFAULT_BACKDROP_COLOR;
70
+ EmojiBackdropOptions backdrop = new EmojiBackdropOptions(
71
+ backdropColor != null && HEX_COLOR_PATTERN.matcher(backdropColor).matches() ? backdropColor : DEFAULT_BACKDROP_COLOR,
72
+ backdropObject != null ? backdropObject.optInt("blur", 0) : 0
73
+ );
64
74
  String theme = call.getString("theme", "system");
65
75
  service.present(
66
76
  presentation,
67
77
  dismissOnBackdropTap,
68
78
  closeButton,
79
+ backdrop,
69
80
  VALID_THEMES.contains(theme) ? theme : "system",
70
81
  new EmojiPickerCallback() {
71
82
  @Override
@@ -0,0 +1,48 @@
1
+ package app.independo.capacitoremojipicker.core;
2
+
3
+ /**
4
+ * Backdrop configuration for a single {@code present()} call, mirroring the iOS
5
+ * `EmojiBackdropOptions` struct. {@code color} is a validated `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex
6
+ * string; {@code blur} is accepted for plumbing parity with web/iOS but has no visual effect on
7
+ * Android (see `DefaultEmojiPickerDialogFactory`).
8
+ */
9
+ public final class EmojiBackdropOptions {
10
+ public final String color;
11
+ public final int blur;
12
+
13
+ public EmojiBackdropOptions(String color, int blur) {
14
+ this.color = color;
15
+ this.blur = blur;
16
+ }
17
+
18
+ /**
19
+ * Converts a validated `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex string into an ARGB color int.
20
+ * Assumes the input already matches that shape (validated by the caller,
21
+ * {@code EmojiPicker#present}) - not defensive against arbitrary input.
22
+ *
23
+ * Parses the hex digits directly with {@link Long#parseLong} rather than
24
+ * {@code android.graphics.Color#parseColor} so this class stays plain Java, testable with a
25
+ * bare JUnit runner instead of needing Robolectric/instrumentation for a stubbed android.jar.
26
+ */
27
+ public static int toColorInt(String hex) {
28
+ // Leading '#' is guaranteed by the regex validating this string before it reaches here
29
+ // (see EmojiPicker#present), so this is a plain substring, not a defensive check.
30
+ String h = hex.substring(1);
31
+ if (h.length() == 3) {
32
+ StringBuilder expanded = new StringBuilder();
33
+ for (int i = 0; i < 3; i++) {
34
+ char c = h.charAt(i);
35
+ expanded.append(c).append(c);
36
+ }
37
+ h = expanded.toString();
38
+ }
39
+ if (h.length() == 6) {
40
+ // Opaque: no alpha channel supplied.
41
+ h = "FF" + h;
42
+ } else {
43
+ // #RRGGBBAA -> Android's #AARRGGBB. The regex guarantees h.length() is 6 or 8 here.
44
+ h = h.substring(6, 8) + h.substring(0, 6);
45
+ }
46
+ return (int) Long.parseLong(h, 16);
47
+ }
48
+ }
@@ -1,15 +1,23 @@
1
1
  package app.independo.capacitoremojipicker.presenter;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.view.View;
4
5
  import android.view.ViewGroup;
5
6
  import androidx.emoji2.emojipicker.EmojiPickerView;
7
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
6
8
  import com.google.android.material.bottomsheet.BottomSheetDialog;
7
9
 
8
10
  /** Shows {@link EmojiPickerView} inside a Material bottom sheet dialog. */
9
11
  public class DefaultEmojiPickerDialogFactory implements EmojiPickerDialogFactory {
10
12
 
11
13
  @Override
12
- public EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, String theme, Listener listener) {
14
+ public EmojiPickerDialogHandle create(
15
+ Activity activity,
16
+ boolean dismissOnBackdropTap,
17
+ EmojiBackdropOptions backdrop,
18
+ String theme,
19
+ Listener listener
20
+ ) {
13
21
  BottomSheetDialog dialog = new BottomSheetDialog(activity, resolveThemeResId(theme));
14
22
 
15
23
  // Built from the dialog's own themed context (not `activity`) so it resolves colors
@@ -28,6 +36,24 @@ public class DefaultEmojiPickerDialogFactory implements EmojiPickerDialogFactory
28
36
  dialog.setContentView(pickerView);
29
37
  dialog.setCanceledOnTouchOutside(dismissOnBackdropTap);
30
38
  dialog.setOnDismissListener(d -> listener.onDismissed());
39
+
40
+ // Replace the theme's default black-only dim with an arbitrary-color scrim view: `Window`
41
+ // only exposes `setDimAmount` (alpha over black), with no color hook. `backdrop.blur` is
42
+ // accepted for plumbing parity with web/iOS but not applied here - `RenderEffect` blurs a
43
+ // view's own subtree, not the separate host-Activity window beneath this dialog's window,
44
+ // so there's no API to blur what's behind it.
45
+ dialog.getWindow().setDimAmount(0f);
46
+ ViewGroup content = dialog.findViewById(android.R.id.content);
47
+ if (content != null) {
48
+ View scrim = new View(dialog.getContext());
49
+ scrim.setLayoutParams(new ViewGroup.LayoutParams(
50
+ ViewGroup.LayoutParams.MATCH_PARENT,
51
+ ViewGroup.LayoutParams.MATCH_PARENT
52
+ ));
53
+ scrim.setBackgroundColor(EmojiBackdropOptions.toColorInt(backdrop.color));
54
+ content.addView(scrim, 0);
55
+ }
56
+
31
57
  dialog.show();
32
58
 
33
59
  return dialog::dismiss;
@@ -1,5 +1,6 @@
1
1
  package app.independo.capacitoremojipicker.presenter;
2
2
 
3
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
3
4
  import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
4
5
  import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
5
6
 
@@ -23,10 +24,11 @@ public class DispatchingEmojiPickerPresenter implements EmojiPickerPresenter {
23
24
  String presentation,
24
25
  boolean dismissOnBackdropTap,
25
26
  EmojiCloseButtonOptions closeButton,
27
+ EmojiBackdropOptions backdrop,
26
28
  String theme,
27
29
  EmojiPickerCallback callback
28
30
  ) {
29
31
  EmojiPickerPresenter target = "web".equals(presentation) ? webFallbackPresenter : nativePresenter;
30
- target.present(presentation, dismissOnBackdropTap, closeButton, theme, callback);
32
+ target.present(presentation, dismissOnBackdropTap, closeButton, backdrop, theme, callback);
31
33
  }
32
34
  }
@@ -1,6 +1,7 @@
1
1
  package app.independo.capacitoremojipicker.presenter;
2
2
 
3
3
  import android.app.Activity;
4
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
4
5
 
5
6
  /**
6
7
  * Builds the native picker UI.
@@ -11,7 +12,13 @@ import android.app.Activity;
11
12
  public interface EmojiPickerDialogFactory {
12
13
 
13
14
  /** Creates and shows the dialog for the given activity, reporting outcomes via {@code listener}. */
14
- EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, String theme, Listener listener);
15
+ EmojiPickerDialogHandle create(
16
+ Activity activity,
17
+ boolean dismissOnBackdropTap,
18
+ EmojiBackdropOptions backdrop,
19
+ String theme,
20
+ Listener listener
21
+ );
15
22
 
16
23
  /** Callback used by the factory's dialog implementation to report selection/dismissal. */
17
24
  interface Listener {
@@ -1,5 +1,6 @@
1
1
  package app.independo.capacitoremojipicker.presenter;
2
2
 
3
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
3
4
  import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
4
5
  import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
5
6
 
@@ -16,6 +17,7 @@ public interface EmojiPickerPresenter {
16
17
  String presentation,
17
18
  boolean dismissOnBackdropTap,
18
19
  EmojiCloseButtonOptions closeButton,
20
+ EmojiBackdropOptions backdrop,
19
21
  String theme,
20
22
  EmojiPickerCallback callback
21
23
  );
@@ -3,6 +3,7 @@ package app.independo.capacitoremojipicker.presenter;
3
3
  import android.app.Activity;
4
4
  import androidx.lifecycle.DefaultLifecycleObserver;
5
5
  import androidx.lifecycle.LifecycleOwner;
6
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
6
7
  import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
7
8
  import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
8
9
  import app.independo.capacitoremojipicker.core.EmojiPickerResult;
@@ -63,6 +64,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
63
64
  String presentation,
64
65
  boolean dismissOnBackdropTap,
65
66
  EmojiCloseButtonOptions closeButton,
67
+ EmojiBackdropOptions backdrop,
66
68
  String theme,
67
69
  EmojiPickerCallback callback
68
70
  ) {
@@ -74,7 +76,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
74
76
  }
75
77
 
76
78
  Activity activity = activityProvider.get();
77
- Runnable work = () -> presentOnUiThread(activity, dismissOnBackdropTap, theme, callback);
79
+ Runnable work = () -> presentOnUiThread(activity, dismissOnBackdropTap, backdrop, theme, callback);
78
80
  // Capacitor invokes @PluginMethod handlers on a background "CapacitorPlugins" thread, but
79
81
  // BottomSheetDialog#show() and Lifecycle#addObserver() are UI-thread-only APIs. Hop onto the
80
82
  // UI thread whenever we have a real Activity to hop through; a null Activity means there's no
@@ -86,7 +88,13 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
86
88
  }
87
89
  }
88
90
 
89
- private void presentOnUiThread(Activity activity, boolean dismissOnBackdropTap, String theme, EmojiPickerCallback callback) {
91
+ private void presentOnUiThread(
92
+ Activity activity,
93
+ boolean dismissOnBackdropTap,
94
+ EmojiBackdropOptions backdrop,
95
+ String theme,
96
+ EmojiPickerCallback callback
97
+ ) {
90
98
  if (!availabilityChecker.isAvailable(activity)) {
91
99
  callback.onError(ErrorCodes.NATIVE_UNAVAILABLE);
92
100
  return;
@@ -104,7 +112,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
104
112
  Presentation presentation = new Presentation(callback);
105
113
  LifecycleOwner lifecycleOwner = (activity instanceof LifecycleOwner) ? (LifecycleOwner) activity : null;
106
114
  current = presentation;
107
- presentation.start(activity, dismissOnBackdropTap, theme, lifecycleOwner);
115
+ presentation.start(activity, dismissOnBackdropTap, backdrop, theme, lifecycleOwner);
108
116
  }
109
117
 
110
118
  /**
@@ -124,7 +132,13 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
124
132
  this.callback = callback;
125
133
  }
126
134
 
127
- void start(Activity activity, boolean dismissOnBackdropTap, String theme, LifecycleOwner lifecycleOwner) {
135
+ void start(
136
+ Activity activity,
137
+ boolean dismissOnBackdropTap,
138
+ EmojiBackdropOptions backdrop,
139
+ String theme,
140
+ LifecycleOwner lifecycleOwner
141
+ ) {
128
142
  this.lifecycleOwner = lifecycleOwner;
129
143
 
130
144
  EmojiPickerDialogFactory.EmojiPickerDialogHandle createdHandle;
@@ -132,6 +146,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
132
146
  createdHandle = dialogFactory.create(
133
147
  activity,
134
148
  dismissOnBackdropTap,
149
+ backdrop,
135
150
  theme,
136
151
  new EmojiPickerDialogFactory.Listener() {
137
152
  @Override
@@ -5,6 +5,7 @@ import android.os.Handler;
5
5
  import android.os.Looper;
6
6
  import androidx.lifecycle.DefaultLifecycleObserver;
7
7
  import androidx.lifecycle.LifecycleOwner;
8
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
8
9
  import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
9
10
  import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
10
11
  import app.independo.capacitoremojipicker.core.EmojiPickerResult;
@@ -114,13 +115,14 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
114
115
  String presentation,
115
116
  boolean dismissOnBackdropTap,
116
117
  EmojiCloseButtonOptions closeButton,
118
+ EmojiBackdropOptions backdrop,
117
119
  String theme,
118
120
  EmojiPickerCallback callback
119
121
  ) {
120
122
  Activity activity = activityProvider.get();
121
123
  uiThreadDispatcher.runOnUiThread(
122
124
  activity,
123
- () -> presentOnUiThread(activity, dismissOnBackdropTap, closeButton, theme, callback)
125
+ () -> presentOnUiThread(activity, dismissOnBackdropTap, closeButton, backdrop, theme, callback)
124
126
  );
125
127
  }
126
128
 
@@ -128,6 +130,7 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
128
130
  Activity activity,
129
131
  boolean dismissOnBackdropTap,
130
132
  EmojiCloseButtonOptions closeButton,
133
+ EmojiBackdropOptions backdrop,
131
134
  String theme,
132
135
  EmojiPickerCallback callback
133
136
  ) {
@@ -169,7 +172,7 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
169
172
  // stays pending for the real result reported later via onWebResult.
170
173
  jsEvaluator.eval(
171
174
  "window.__CapacitorEmojiPickerPresentWeb('" + requestId + "', '"
172
- + encodeOptionsBase64Free(dismissOnBackdropTap, closeButton, theme) + "')",
175
+ + encodeOptionsBase64Free(dismissOnBackdropTap, closeButton, backdrop, theme) + "')",
173
176
  () -> scheduler.cancel(timeoutRunnable)
174
177
  );
175
178
  }
@@ -203,12 +206,18 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
203
206
 
204
207
  /**
205
208
  * Hand-rolled instead of a JSON library: `size`/`position`/`theme` are always one of a small
206
- * fixed set of ASCII enum values validated/defaulted in {@code EmojiPicker#present}, never
207
- * arbitrary user text, so plain string interpolation is safe here. This also sidesteps
209
+ * fixed set of ASCII enum values, and `backdrop.color` is a hex string matched against a
210
+ * strict pattern, all validated/defaulted in {@code EmojiPicker#present}, never arbitrary
211
+ * user text, so plain string interpolation is safe here. This also sidesteps
208
212
  * `org.json`/`android.util.Base64` throwing under the mockable `android.jar` in plain JUnit
209
213
  * unit tests (see the plan's Global Constraints).
210
214
  */
211
- private static String encodeOptionsBase64Free(boolean dismissOnBackdropTap, EmojiCloseButtonOptions closeButton, String theme) {
215
+ private static String encodeOptionsBase64Free(
216
+ boolean dismissOnBackdropTap,
217
+ EmojiCloseButtonOptions closeButton,
218
+ EmojiBackdropOptions backdrop,
219
+ String theme
220
+ ) {
212
221
  return "{"
213
222
  + "\"dismissOnBackdropTap\":" + dismissOnBackdropTap + ","
214
223
  + "\"closeButton\":{"
@@ -216,6 +225,10 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
216
225
  + "\"position\":\"" + closeButton.position + "\","
217
226
  + "\"hidden\":" + closeButton.hidden
218
227
  + "},"
228
+ + "\"backdrop\":{"
229
+ + "\"color\":\"" + backdrop.color + "\","
230
+ + "\"blur\":" + backdrop.blur
231
+ + "},"
219
232
  + "\"theme\":\"" + theme + "\""
220
233
  + "}";
221
234
  }
@@ -1,5 +1,6 @@
1
1
  package app.independo.capacitoremojipicker.service;
2
2
 
3
+ import app.independo.capacitoremojipicker.core.EmojiBackdropOptions;
3
4
  import app.independo.capacitoremojipicker.core.EmojiCloseButtonOptions;
4
5
  import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
5
6
  import app.independo.capacitoremojipicker.core.EmojiPickerResult;
@@ -21,6 +22,7 @@ public class EmojiPickerService {
21
22
  String presentation,
22
23
  boolean dismissOnBackdropTap,
23
24
  EmojiCloseButtonOptions closeButton,
25
+ EmojiBackdropOptions backdrop,
24
26
  String theme,
25
27
  EmojiPickerCallback callback
26
28
  ) {
@@ -34,6 +36,7 @@ public class EmojiPickerService {
34
36
  presentation,
35
37
  dismissOnBackdropTap,
36
38
  closeButton,
39
+ backdrop,
37
40
  theme,
38
41
  new EmojiPickerCallback() {
39
42
  @Override
package/dist/docs.json CHANGED
@@ -87,6 +87,15 @@
87
87
  ],
88
88
  "type": "EmojiPickerCloseButtonOptions"
89
89
  },
90
+ {
91
+ "name": "backdrop",
92
+ "tags": [],
93
+ "docs": "Configures the dimming/blur shown behind the picker.",
94
+ "complexTypes": [
95
+ "EmojiPickerBackdropOptions"
96
+ ],
97
+ "type": "EmojiPickerBackdropOptions"
98
+ },
90
99
  {
91
100
  "name": "dismissOnBackdropTap",
92
101
  "tags": [
@@ -159,6 +168,39 @@
159
168
  "type": "boolean | undefined"
160
169
  }
161
170
  ]
171
+ },
172
+ {
173
+ "name": "EmojiPickerBackdropOptions",
174
+ "slug": "emojipickerbackdropoptions",
175
+ "docs": "Configures the dimming/blur shown behind the picker.",
176
+ "tags": [],
177
+ "methods": [],
178
+ "properties": [
179
+ {
180
+ "name": "color",
181
+ "tags": [
182
+ {
183
+ "text": "'#00000066'",
184
+ "name": "default"
185
+ }
186
+ ],
187
+ "docs": "CSS hex color for the backdrop; the alpha channel controls darkness (e.g. `'#000000cc'` is\n80% black, `'#00000000'` is no darkening). Supports `#RGB`, `#RRGGBB`, and `#RRGGBBAA`.\nFalls back to the default on an invalid value.",
188
+ "complexTypes": [],
189
+ "type": "string | undefined"
190
+ },
191
+ {
192
+ "name": "blur",
193
+ "tags": [
194
+ {
195
+ "text": "0",
196
+ "name": "default"
197
+ }
198
+ ],
199
+ "docs": "Backdrop blur radius in px, analogous to CSS `backdrop-filter: blur()`.\n\nWeb applies this directly. iOS approximates it by mapping the value to the nearest system\nblur material (there is no continuous-radius blur API). Android has no API to blur content\nbehind a dialog window, so this option is accepted but has no visual effect there.",
200
+ "complexTypes": [],
201
+ "type": "number | undefined"
202
+ }
203
+ ]
162
204
  }
163
205
  ],
164
206
  "enums": [],
@@ -22,6 +22,10 @@ export interface EmojiPickerOptions {
22
22
  * no system-provided one). Ignored on Android.
23
23
  */
24
24
  closeButton?: EmojiPickerCloseButtonOptions;
25
+ /**
26
+ * Configures the dimming/blur shown behind the picker.
27
+ */
28
+ backdrop?: EmojiPickerBackdropOptions;
25
29
  /**
26
30
  * Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS)
27
31
  * or the scrim outside the picker sheet (Android and web).
@@ -64,6 +68,27 @@ export interface EmojiPickerCloseButtonOptions {
64
68
  */
65
69
  hidden?: boolean;
66
70
  }
71
+ /**
72
+ * Configures the dimming/blur shown behind the picker.
73
+ */
74
+ export interface EmojiPickerBackdropOptions {
75
+ /**
76
+ * CSS hex color for the backdrop; the alpha channel controls darkness (e.g. `'#000000cc'` is
77
+ * 80% black, `'#00000000'` is no darkening). Supports `#RGB`, `#RRGGBB`, and `#RRGGBBAA`.
78
+ * Falls back to the default on an invalid value.
79
+ * @default '#00000066'
80
+ */
81
+ color?: string;
82
+ /**
83
+ * Backdrop blur radius in px, analogous to CSS `backdrop-filter: blur()`.
84
+ *
85
+ * Web applies this directly. iOS approximates it by mapping the value to the nearest system
86
+ * blur material (there is no continuous-radius blur API). Android has no API to blur content
87
+ * behind a dialog window, so this option is accepted but has no visual effect there.
88
+ * @default 0
89
+ */
90
+ blur?: number;
91
+ }
67
92
  /**
68
93
  * Result of presenting the emoji picker.
69
94
  */
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * How the picker should be presented.\n */\nexport type EmojiPickerPresentation = 'auto' | 'web';\n\n/**\n * The picker's appearance.\n */\nexport type EmojiPickerTheme = 'system' | 'light' | 'dark';\n\n/**\n * Options for presenting the emoji picker.\n */\nexport interface EmojiPickerOptions {\n /**\n * `auto`: prefer native/system UI and fall back to the web picker when native presentation\n * is not available or fails.\n * `web`: always use the web picker, including inside Capacitor native apps.\n * @default 'auto'\n */\n presentation?: EmojiPickerPresentation;\n /**\n * Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has\n * no system-provided one). Ignored on Android.\n */\n closeButton?: EmojiPickerCloseButtonOptions;\n /**\n * Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS)\n * or the scrim outside the picker sheet (Android and web).\n *\n * On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of\n * the value passed here, so the user always has a way to dismiss the picker.\n * @default true\n */\n dismissOnBackdropTap?: boolean;\n /**\n * `system`: follows the OS/app appearance setting.\n * `light` / `dark`: forces the picker's appearance regardless of the system setting.\n *\n * On iOS native presentation, this also sets `keyboardAppearance` on the underlying text\n * input, which is the mechanism the system emoji keyboard itself honors (separate from the\n * app's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close\n * button).\n * @default 'system'\n */\n theme?: EmojiPickerTheme;\n}\n\n/**\n * Configures the close button rendered above the iOS native emoji keyboard/the web picker sheet.\n */\nexport interface EmojiPickerCloseButtonOptions {\n /**\n * `xSmall`: 24pt, `small`: 32pt, `medium`: 48pt, `large`: 64pt.\n * @default 'medium'\n */\n size?: 'xSmall' | 'small' | 'medium' | 'large';\n /**\n * Which side of the keyboard the button docks to.\n * @default 'right'\n */\n position?: 'left' | 'center' | 'right';\n /**\n * Hides the built-in close button. See `EmojiPickerOptions.dismissOnBackdropTap` for the\n * safety net this triggers.\n * @default false\n */\n hidden?: boolean;\n}\n\n/**\n * Result of presenting the emoji picker.\n */\nexport interface EmojiPickerResult {\n /**\n * The selected emoji as a complete Unicode string/grapheme (unchanged), or `null` when the\n * picker was dismissed without a selection.\n */\n emoji: string | null;\n}\n\n/**\n * Interface for the EmojiPicker plugin, which presents a native or web emoji picker and\n * resolves with the emoji the user selected.\n */\nexport interface EmojiPickerPlugin {\n /**\n * Presents the emoji picker.\n *\n * Resolves with `{ emoji: null }` rather than leaving the promise pending when the user\n * dismisses the picker without selecting an emoji.\n *\n * Calling this method again while a picker is already active rejects immediately with the\n * `ALREADY_PRESENTING` error code rather than presenting a second, overlapping picker.\n *\n * @param options The options for the presentation.\n * @returns A promise that resolves to an EmojiPickerResult.\n * @throws Error with code `ALREADY_PRESENTING` if a picker is already active.\n */\n present(options?: EmojiPickerOptions): Promise<EmojiPickerResult>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * How the picker should be presented.\n */\nexport type EmojiPickerPresentation = 'auto' | 'web';\n\n/**\n * The picker's appearance.\n */\nexport type EmojiPickerTheme = 'system' | 'light' | 'dark';\n\n/**\n * Options for presenting the emoji picker.\n */\nexport interface EmojiPickerOptions {\n /**\n * `auto`: prefer native/system UI and fall back to the web picker when native presentation\n * is not available or fails.\n * `web`: always use the web picker, including inside Capacitor native apps.\n * @default 'auto'\n */\n presentation?: EmojiPickerPresentation;\n /**\n * Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has\n * no system-provided one). Ignored on Android.\n */\n closeButton?: EmojiPickerCloseButtonOptions;\n /**\n * Configures the dimming/blur shown behind the picker.\n */\n backdrop?: EmojiPickerBackdropOptions;\n /**\n * Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS)\n * or the scrim outside the picker sheet (Android and web).\n *\n * On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of\n * the value passed here, so the user always has a way to dismiss the picker.\n * @default true\n */\n dismissOnBackdropTap?: boolean;\n /**\n * `system`: follows the OS/app appearance setting.\n * `light` / `dark`: forces the picker's appearance regardless of the system setting.\n *\n * On iOS native presentation, this also sets `keyboardAppearance` on the underlying text\n * input, which is the mechanism the system emoji keyboard itself honors (separate from the\n * app's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close\n * button).\n * @default 'system'\n */\n theme?: EmojiPickerTheme;\n}\n\n/**\n * Configures the close button rendered above the iOS native emoji keyboard/the web picker sheet.\n */\nexport interface EmojiPickerCloseButtonOptions {\n /**\n * `xSmall`: 24pt, `small`: 32pt, `medium`: 48pt, `large`: 64pt.\n * @default 'medium'\n */\n size?: 'xSmall' | 'small' | 'medium' | 'large';\n /**\n * Which side of the keyboard the button docks to.\n * @default 'right'\n */\n position?: 'left' | 'center' | 'right';\n /**\n * Hides the built-in close button. See `EmojiPickerOptions.dismissOnBackdropTap` for the\n * safety net this triggers.\n * @default false\n */\n hidden?: boolean;\n}\n\n/**\n * Configures the dimming/blur shown behind the picker.\n */\nexport interface EmojiPickerBackdropOptions {\n /**\n * CSS hex color for the backdrop; the alpha channel controls darkness (e.g. `'#000000cc'` is\n * 80% black, `'#00000000'` is no darkening). Supports `#RGB`, `#RRGGBB`, and `#RRGGBBAA`.\n * Falls back to the default on an invalid value.\n * @default '#00000066'\n */\n color?: string;\n /**\n * Backdrop blur radius in px, analogous to CSS `backdrop-filter: blur()`.\n *\n * Web applies this directly. iOS approximates it by mapping the value to the nearest system\n * blur material (there is no continuous-radius blur API). Android has no API to blur content\n * behind a dialog window, so this option is accepted but has no visual effect there.\n * @default 0\n */\n blur?: number;\n}\n\n/**\n * Result of presenting the emoji picker.\n */\nexport interface EmojiPickerResult {\n /**\n * The selected emoji as a complete Unicode string/grapheme (unchanged), or `null` when the\n * picker was dismissed without a selection.\n */\n emoji: string | null;\n}\n\n/**\n * Interface for the EmojiPicker plugin, which presents a native or web emoji picker and\n * resolves with the emoji the user selected.\n */\nexport interface EmojiPickerPlugin {\n /**\n * Presents the emoji picker.\n *\n * Resolves with `{ emoji: null }` rather than leaving the promise pending when the user\n * dismisses the picker without selecting an emoji.\n *\n * Calling this method again while a picker is already active rejects immediately with the\n * `ALREADY_PRESENTING` error code rather than presenting a second, overlapping picker.\n *\n * @param options The options for the presentation.\n * @returns A promise that resolves to an EmojiPickerResult.\n * @throws Error with code `ALREADY_PRESENTING` if a picker is already active.\n */\n present(options?: EmojiPickerOptions): Promise<EmojiPickerResult>;\n}\n"]}
@@ -69,12 +69,6 @@ function ensureSheetStylesInjected() {
69
69
  background-color: #222;
70
70
  color: #e8e8e8;
71
71
  }
72
- dialog.emoji-picker-sheet::backdrop {
73
- background: rgba(0, 0, 0, 0.4);
74
- }
75
- dialog.emoji-picker-sheet--dark::backdrop {
76
- background: rgba(0, 0, 0, 0.6);
77
- }
78
72
  dialog.emoji-picker-sheet[data-state='open'] {
79
73
  transform: translateY(0);
80
74
  }
@@ -105,6 +99,35 @@ function ensureSheetStylesInjected() {
105
99
  `;
106
100
  document.head.appendChild(style);
107
101
  }
102
+ const DEFAULT_BACKDROP_COLOR = '#00000066';
103
+ const HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
104
+ let backdropStyleCounter = 0;
105
+ /** Validates a `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex color, falling back to the default on any other input. */
106
+ function resolveBackdropColor(color) {
107
+ if (color !== undefined && HEX_COLOR_PATTERN.test(color)) {
108
+ return color;
109
+ }
110
+ return DEFAULT_BACKDROP_COLOR;
111
+ }
112
+ /** Injects a one-off `::backdrop` rule scoped to a unique class, since inline styles can't target it. */
113
+ function injectBackdropStyle(options) {
114
+ var _a;
115
+ const className = `emoji-picker-backdrop-${++backdropStyleCounter}`;
116
+ const color = resolveBackdropColor(options.color);
117
+ const blur = (_a = options.blur) !== null && _a !== void 0 ? _a : 0;
118
+ const style = document.createElement('style');
119
+ // `backdrop-filter` is always set explicitly, never omitted: some browsers (e.g. Safari/WKWebView)
120
+ // apply their own default blur to a <dialog>'s ::backdrop in their UA stylesheet, which would
121
+ // otherwise leak through unopposed whenever the caller doesn't request blur.
122
+ style.textContent = `
123
+ dialog.${className}::backdrop {
124
+ background: ${color};
125
+ backdrop-filter: ${blur > 0 ? `blur(${blur}px)` : 'none'};
126
+ }
127
+ `;
128
+ document.head.appendChild(style);
129
+ return { className, remove: () => style.remove() };
130
+ }
108
131
  function prefersReducedMotion() {
109
132
  return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
110
133
  }
@@ -190,7 +213,7 @@ export class WebEmojiPickerPresenter {
190
213
  this.createPickerElement = (_a = options.createPickerElement) !== null && _a !== void 0 ? _a : defaultCreatePickerElement;
191
214
  }
192
215
  async present(options = {}, presentOptions = {}) {
193
- var _a, _b, _c;
216
+ var _a, _b, _c, _d;
194
217
  const { signal } = presentOptions;
195
218
  const closeButtonOptions = (_a = options.closeButton) !== null && _a !== void 0 ? _a : {};
196
219
  // A hidden close button must never leave the user with zero ways to dismiss the picker,
@@ -207,7 +230,7 @@ export class WebEmojiPickerPresenter {
207
230
  picker.dataSource = getBundledEmojiDataSourceUrl();
208
231
  picker.classList.add(resolvedTheme);
209
232
  }
210
- catch (_d) {
233
+ catch (_e) {
211
234
  throw new Error(ErrorCodes.NOT_IMPLEMENTED);
212
235
  }
213
236
  ensureSheetStylesInjected();
@@ -220,8 +243,9 @@ export class WebEmojiPickerPresenter {
220
243
  // border makes it read as full width, part of the sheet rather than nested inside it.
221
244
  picker.style.setProperty('--background', SHEET_BACKGROUND_COLOR[resolvedTheme]);
222
245
  picker.style.setProperty('--border-size', '0');
246
+ const backdropStyle = injectBackdropStyle((_d = options.backdrop) !== null && _d !== void 0 ? _d : {});
223
247
  const dialog = document.createElement('dialog');
224
- dialog.className = `emoji-picker-sheet emoji-picker-sheet--${resolvedTheme}`;
248
+ dialog.className = `emoji-picker-sheet emoji-picker-sheet--${resolvedTheme} ${backdropStyle.className}`;
225
249
  dialog.setAttribute('role', 'dialog');
226
250
  dialog.setAttribute('aria-modal', 'true');
227
251
  dialog.setAttribute('aria-label', 'Emoji picker');
@@ -248,6 +272,7 @@ export class WebEmojiPickerPresenter {
248
272
  document.body.style.overflow = previousBodyOverflow;
249
273
  dialog.close();
250
274
  dialog.remove();
275
+ backdropStyle.remove();
251
276
  if (previouslyFocusedElement instanceof HTMLElement && document.contains(previouslyFocusedElement)) {
252
277
  (_a = previouslyFocusedElement.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocusedElement);
253
278
  }