@independo/capacitor-emoji-picker 1.1.1-dev.2 → 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 (27) hide show
  1. package/README.md +25 -0
  2. package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPicker.java +11 -0
  3. package/android/src/main/java/app/independo/capacitoremojipicker/core/EmojiBackdropOptions.java +48 -0
  4. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DefaultEmojiPickerDialogFactory.java +27 -1
  5. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DispatchingEmojiPickerPresenter.java +3 -1
  6. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerDialogFactory.java +8 -1
  7. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerPresenter.java +2 -0
  8. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/NativeEmojiPickerPresenter.java +19 -4
  9. package/android/src/main/java/app/independo/capacitoremojipicker/presenter/WebFallbackEmojiPickerPresenter.java +18 -5
  10. package/android/src/main/java/app/independo/capacitoremojipicker/service/EmojiPickerService.java +3 -0
  11. package/dist/docs.json +42 -0
  12. package/dist/esm/definitions.d.ts +25 -0
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/dist/esm/platform/web/WebEmojiPickerPresenter.js +34 -9
  15. package/dist/esm/platform/web/WebEmojiPickerPresenter.js.map +1 -1
  16. package/dist/plugin.cjs.js +34 -9
  17. package/dist/plugin.cjs.js.map +1 -1
  18. package/dist/plugin.js +34 -9
  19. package/dist/plugin.js.map +1 -1
  20. package/ios/Sources/EmojiPicker/Bridge/EmojiPicker.swift +14 -0
  21. package/ios/Sources/EmojiPicker/Core/EmojiBackdropColor.swift +27 -0
  22. package/ios/Sources/EmojiPicker/Presenter/DefaultEmojiKeyboardPresentationFactory.swift +69 -3
  23. package/ios/Sources/EmojiPicker/Presenter/EmojiKeyboardPresentationFactory.swift +1 -0
  24. package/ios/Sources/EmojiPicker/Presenter/EmojiPickerPresenter.swift +11 -0
  25. package/ios/Sources/EmojiPicker/Presenter/NativeEmojiPickerPresenter.swift +12 -1
  26. package/ios/Sources/EmojiPicker/Presenter/WebFallbackEmojiPickerPresenter.swift +14 -4
  27. package/package.json +1 -1
@@ -22,6 +22,8 @@ public class EmojiPicker: CAPPlugin, CAPBridgedPlugin {
22
22
  private static let validCloseButtonSizes: Set<String> = ["xSmall", "small", "medium", "large"]
23
23
  private static let validCloseButtonPositions: Set<String> = ["left", "center", "right"]
24
24
  private static let validThemes: Set<String> = ["system", "light", "dark"]
25
+ private static let hexColorPattern = try! NSRegularExpression(pattern: "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$")
26
+ private static let defaultBackdropColor = "#00000066"
25
27
 
26
28
  /// Initializes dependencies after the plugin loads.
27
29
  public override func load() {
@@ -59,6 +61,9 @@ public class EmojiPicker: CAPPlugin, CAPBridgedPlugin {
59
61
  let closeButtonObject = call.getObject("closeButton")
60
62
  let size = closeButtonObject?["size"] as? String ?? "medium"
61
63
  let position = closeButtonObject?["position"] as? String ?? "right"
64
+ let backdropObject = call.getObject("backdrop")
65
+ let backdropColor = backdropObject?["color"] as? String ?? Self.defaultBackdropColor
66
+ let backdropBlur = backdropObject?["blur"] as? Int ?? 0
62
67
  let theme = call.getString("theme") ?? "system"
63
68
  let options = EmojiPickerPresentOptions(
64
69
  presentation: call.getString("presentation") ?? "auto",
@@ -67,6 +72,10 @@ public class EmojiPicker: CAPPlugin, CAPBridgedPlugin {
67
72
  position: Self.validCloseButtonPositions.contains(position) ? position : "right",
68
73
  hidden: closeButtonObject?["hidden"] as? Bool ?? false
69
74
  ),
75
+ backdrop: EmojiBackdropOptions(
76
+ color: Self.isValidHexColor(backdropColor) ? backdropColor : Self.defaultBackdropColor,
77
+ blur: backdropBlur
78
+ ),
70
79
  dismissOnBackdropTap: call.getBool("dismissOnBackdropTap") ?? true,
71
80
  theme: Self.validThemes.contains(theme) ? theme : "system"
72
81
  )
@@ -79,4 +88,9 @@ public class EmojiPicker: CAPPlugin, CAPBridgedPlugin {
79
88
  }
80
89
  }
81
90
  }
91
+
92
+ private static func isValidHexColor(_ value: String) -> Bool {
93
+ let range = NSRange(value.startIndex..<value.endIndex, in: value)
94
+ return hexColorPattern.firstMatch(in: value, range: range) != nil
95
+ }
82
96
  }
@@ -0,0 +1,27 @@
1
+ import UIKit
2
+
3
+ extension UIColor {
4
+ /// Converts a validated `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex string into a `UIColor`. Assumes the
5
+ /// input already matches that shape (validated by the caller, `EmojiPicker.present`) - not
6
+ /// defensive against arbitrary input.
7
+ convenience init(emojiPickerBackdropHex hex: String) {
8
+ var chars = Array(hex)
9
+ if chars.first == "#" {
10
+ chars.removeFirst()
11
+ }
12
+ if chars.count == 3 {
13
+ chars = chars.flatMap { [$0, $0] }
14
+ }
15
+
16
+ func component(_ index: Int) -> CGFloat {
17
+ CGFloat(UInt8(String(chars[index...index + 1]), radix: 16) ?? 0) / 255
18
+ }
19
+
20
+ let red = component(0)
21
+ let green = component(2)
22
+ let blue = component(4)
23
+ let alpha = chars.count == 8 ? component(6) : 1
24
+
25
+ self.init(red: red, green: green, blue: blue, alpha: alpha)
26
+ }
27
+ }
@@ -24,6 +24,7 @@ final class DefaultEmojiKeyboardPresentationFactory: EmojiKeyboardPresentationFa
24
24
  func create(
25
25
  hostViewController: UIViewController,
26
26
  closeButtonOptions: EmojiCloseButtonOptions,
27
+ backdropOptions: EmojiBackdropOptions,
27
28
  dismissOnBackdropTap: Bool,
28
29
  theme: String,
29
30
  listener: EmojiKeyboardPresentationListener
@@ -38,6 +39,7 @@ final class DefaultEmojiKeyboardPresentationFactory: EmojiKeyboardPresentationFa
38
39
  let container = EmojiKeyboardContainerViewController(
39
40
  listener: listener,
40
41
  closeButtonOptions: closeButtonOptions,
42
+ backdropOptions: backdropOptions,
41
43
  dismissOnBackdropTap: dismissOnBackdropTap,
42
44
  theme: theme
43
45
  )
@@ -134,8 +136,19 @@ final class EmojiKeyboardContainerViewController: UIViewController, UITextFieldD
134
136
  private static let closeButtonKeyboardGap: CGFloat = 12
135
137
  private static let closeButtonEdgeInset: CGFloat = 16
136
138
 
139
+ /// Bucket boundaries (px) mapping the continuous `blur` option onto the nearest system
140
+ /// material - there is no continuous-radius blur API on iOS. Values below the first threshold
141
+ /// get no blur view at all.
142
+ private static let blurStyleThresholds: [(maxPx: Int, style: UIBlurEffect.Style)] = [
143
+ (4, .systemUltraThinMaterial),
144
+ (10, .systemThinMaterial),
145
+ (18, .systemMaterial),
146
+ (Int.max, .systemThickMaterial),
147
+ ]
148
+
137
149
  private weak var listener: EmojiKeyboardPresentationListener?
138
150
  private let closeButtonOptions: EmojiCloseButtonOptions
151
+ private let backdropOptions: EmojiBackdropOptions
139
152
  /// `dismissOnBackdropTap` OR'd with `closeButtonOptions.hidden`: a hidden close button must
140
153
  /// never leave the user with zero ways to dismiss the keyboard, so hiding it force-enables
141
154
  /// backdrop-tap-to-dismiss regardless of what was explicitly requested.
@@ -145,6 +158,9 @@ final class EmojiKeyboardContainerViewController: UIViewController, UITextFieldD
145
158
  /// after `viewDidLoad` - mirrors the class-level visibility rationale above.
146
159
  let emojiField = EmojiTextField()
147
160
  private let closeButton: UIButton
161
+ /// Full-bleed dimming/blur view inserted behind `emojiField`/`closeButton`. Internal so tests
162
+ /// can assert its color/blur and its position in the tap-gesture's hit-testing.
163
+ let backdropView = UIView()
148
164
  private var modeChangeObserver: NSObjectProtocol?
149
165
  private var verificationTimeoutWorkItem: DispatchWorkItem?
150
166
  private var hasReportedOutcome = false
@@ -152,11 +168,13 @@ final class EmojiKeyboardContainerViewController: UIViewController, UITextFieldD
152
168
  init(
153
169
  listener: EmojiKeyboardPresentationListener,
154
170
  closeButtonOptions: EmojiCloseButtonOptions,
171
+ backdropOptions: EmojiBackdropOptions,
155
172
  dismissOnBackdropTap: Bool,
156
173
  theme: String
157
174
  ) {
158
175
  self.listener = listener
159
176
  self.closeButtonOptions = closeButtonOptions
177
+ self.backdropOptions = backdropOptions
160
178
  self.effectiveDismissOnBackdropTap = dismissOnBackdropTap || closeButtonOptions.hidden
161
179
  self.theme = theme
162
180
  self.closeButton = Self.makeCloseButton(options: closeButtonOptions)
@@ -172,6 +190,8 @@ final class EmojiKeyboardContainerViewController: UIViewController, UITextFieldD
172
190
  super.viewDidLoad()
173
191
  view.backgroundColor = .clear
174
192
 
193
+ setUpBackdrop()
194
+
175
195
  emojiField.delegate = self
176
196
  emojiField.alpha = 0
177
197
  emojiField.frame = CGRect(x: 0, y: 0, width: 1, height: 1)
@@ -308,6 +328,51 @@ final class EmojiKeyboardContainerViewController: UIViewController, UITextFieldD
308
328
  }
309
329
  }
310
330
 
331
+ /// Inserts the dimming/blur view as the first subview, behind `emojiField`/`closeButton`.
332
+ /// Must run before those are added, since insertion order determines z-order.
333
+ private func setUpBackdrop() {
334
+ backdropView.translatesAutoresizingMaskIntoConstraints = false
335
+ backdropView.backgroundColor = .clear
336
+ view.insertSubview(backdropView, at: 0)
337
+ NSLayoutConstraint.activate([
338
+ backdropView.topAnchor.constraint(equalTo: view.topAnchor),
339
+ backdropView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
340
+ backdropView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
341
+ backdropView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
342
+ ])
343
+
344
+ if let blurStyle = Self.blurStyle(forPx: backdropOptions.blur) {
345
+ let blurView = UIVisualEffectView(effect: UIBlurEffect(style: blurStyle))
346
+ blurView.translatesAutoresizingMaskIntoConstraints = false
347
+ blurView.isUserInteractionEnabled = false
348
+ backdropView.addSubview(blurView)
349
+ NSLayoutConstraint.activate([
350
+ blurView.topAnchor.constraint(equalTo: backdropView.topAnchor),
351
+ blurView.bottomAnchor.constraint(equalTo: backdropView.bottomAnchor),
352
+ blurView.leadingAnchor.constraint(equalTo: backdropView.leadingAnchor),
353
+ blurView.trailingAnchor.constraint(equalTo: backdropView.trailingAnchor),
354
+ ])
355
+ }
356
+
357
+ let tintView = UIView()
358
+ tintView.translatesAutoresizingMaskIntoConstraints = false
359
+ tintView.backgroundColor = UIColor(emojiPickerBackdropHex: backdropOptions.color)
360
+ tintView.isUserInteractionEnabled = false
361
+ backdropView.addSubview(tintView)
362
+ NSLayoutConstraint.activate([
363
+ tintView.topAnchor.constraint(equalTo: backdropView.topAnchor),
364
+ tintView.bottomAnchor.constraint(equalTo: backdropView.bottomAnchor),
365
+ tintView.leadingAnchor.constraint(equalTo: backdropView.leadingAnchor),
366
+ tintView.trailingAnchor.constraint(equalTo: backdropView.trailingAnchor),
367
+ ])
368
+ }
369
+
370
+ /// Maps a px blur radius to the nearest system material, or `nil` for no blur (`blur <= 0`).
371
+ private static func blurStyle(forPx px: Int) -> UIBlurEffect.Style? {
372
+ guard px > 0 else { return nil }
373
+ return blurStyleThresholds.first { px <= $0.maxPx }?.style
374
+ }
375
+
311
376
  /// Adds a tap gesture that dismisses when the user taps the transparent backdrop - anywhere
312
377
  /// in `view` that isn't a subview (the close button, primarily). The system keyboard itself
313
378
  /// lives in a separate window/responder chain, so this can't intercept its touches.
@@ -321,9 +386,10 @@ final class EmojiKeyboardContainerViewController: UIViewController, UITextFieldD
321
386
  // MARK: UIGestureRecognizerDelegate
322
387
 
323
388
  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
324
- // Only recognize taps landing directly on the backdrop view itself, not on subviews
325
- // (the close button handles its own taps via its target/action).
326
- touch.view === view
389
+ // Only recognize taps landing directly on the backdrop (`view` itself, or the dimming/blur
390
+ // view now inserted beneath the other subviews), not on subviews like the close button
391
+ // (which handles its own taps via its target/action).
392
+ touch.view === view || touch.view === backdropView
327
393
  }
328
394
 
329
395
  @objc private func closeTapped() {
@@ -13,6 +13,7 @@ protocol EmojiKeyboardPresentationFactory {
13
13
  func create(
14
14
  hostViewController: UIViewController,
15
15
  closeButtonOptions: EmojiCloseButtonOptions,
16
+ backdropOptions: EmojiBackdropOptions,
16
17
  dismissOnBackdropTap: Bool,
17
18
  theme: String,
18
19
  listener: EmojiKeyboardPresentationListener
@@ -10,12 +10,23 @@ struct EmojiCloseButtonOptions {
10
10
  let hidden: Bool
11
11
  }
12
12
 
13
+ /// Backdrop configuration for a single `present()` call, mirroring Android's
14
+ /// `EmojiBackdropOptions` POJO.
15
+ struct EmojiBackdropOptions {
16
+ /// Validated `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex string.
17
+ let color: String
18
+ /// Blur radius in px; bucketed to the nearest `UIBlurEffect.Style` (there is no continuous
19
+ /// blur-radius API), see `DefaultEmojiKeyboardPresentationFactory`.
20
+ let blur: Int
21
+ }
22
+
13
23
  /// Options for a single `present()` call, forwarded from the JS layer down to whichever
14
24
  /// presenter/factory ends up handling it.
15
25
  struct EmojiPickerPresentOptions {
16
26
  /// `"auto"` or `"web"`.
17
27
  let presentation: String
18
28
  let closeButton: EmojiCloseButtonOptions
29
+ let backdrop: EmojiBackdropOptions
19
30
  /// Only consulted by presenters that render a close affordance; ignored elsewhere.
20
31
  let dismissOnBackdropTap: Bool
21
32
  /// `"system"`, `"light"`, or `"dark"`.
@@ -62,6 +62,7 @@ final class NativeEmojiPickerPresenter: EmojiPickerPresenter {
62
62
  DispatchQueue.main.async { [weak self] in
63
63
  self?.presentOnMainThread(
64
64
  closeButton: options.closeButton,
65
+ backdrop: options.backdrop,
65
66
  dismissOnBackdropTap: options.dismissOnBackdropTap,
66
67
  theme: options.theme,
67
68
  completion: completion
@@ -71,6 +72,7 @@ final class NativeEmojiPickerPresenter: EmojiPickerPresenter {
71
72
 
72
73
  private func presentOnMainThread(
73
74
  closeButton: EmojiCloseButtonOptions,
75
+ backdrop: EmojiBackdropOptions,
74
76
  dismissOnBackdropTap: Bool,
75
77
  theme: String,
76
78
  completion: @escaping (Result<EmojiPickerResult, EmojiPickerError>) -> Void
@@ -91,7 +93,14 @@ final class NativeEmojiPickerPresenter: EmojiPickerPresenter {
91
93
  let presentation = Presentation(completion: completion)
92
94
  current = presentation
93
95
  presentation.owner = self
94
- presentation.start(host: host, closeButton: closeButton, dismissOnBackdropTap: dismissOnBackdropTap, theme: theme, factory: factory)
96
+ presentation.start(
97
+ host: host,
98
+ closeButton: closeButton,
99
+ backdrop: backdrop,
100
+ dismissOnBackdropTap: dismissOnBackdropTap,
101
+ theme: theme,
102
+ factory: factory
103
+ )
95
104
  }
96
105
 
97
106
  /// Owns everything about ONE presentation attempt: its handle, its cleanup, and whether it
@@ -111,6 +120,7 @@ final class NativeEmojiPickerPresenter: EmojiPickerPresenter {
111
120
  func start(
112
121
  host: UIViewController,
113
122
  closeButton: EmojiCloseButtonOptions,
123
+ backdrop: EmojiBackdropOptions,
114
124
  dismissOnBackdropTap: Bool,
115
125
  theme: String,
116
126
  factory: EmojiKeyboardPresentationFactory
@@ -118,6 +128,7 @@ final class NativeEmojiPickerPresenter: EmojiPickerPresenter {
118
128
  let createdHandle = factory.create(
119
129
  hostViewController: host,
120
130
  closeButtonOptions: closeButton,
131
+ backdropOptions: backdrop,
121
132
  dismissOnBackdropTap: dismissOnBackdropTap,
122
133
  theme: theme,
123
134
  listener: self
@@ -68,6 +68,7 @@ final class WebFallbackEmojiPickerPresenter: EmojiPickerPresenter {
68
68
  let json = Self.encodeOptionsJson(
69
69
  dismissOnBackdropTap: options.dismissOnBackdropTap,
70
70
  closeButton: options.closeButton,
71
+ backdrop: options.backdrop,
71
72
  theme: options.theme
72
73
  )
73
74
  // The eval "completion" here only means the script at least started executing (i.e. the
@@ -112,10 +113,19 @@ final class WebFallbackEmojiPickerPresenter: EmojiPickerPresenter {
112
113
  }
113
114
 
114
115
  /// Hand-rolled instead of `JSONSerialization`: `size`/`position`/`theme` are always one of a
115
- /// small fixed set of ASCII enum values validated/defaulted when the plugin call is parsed,
116
- /// never arbitrary user text, so plain string interpolation is safe here.
117
- private static func encodeOptionsJson(dismissOnBackdropTap: Bool, closeButton: EmojiCloseButtonOptions, theme: String) -> String {
118
- "{\"dismissOnBackdropTap\":\(dismissOnBackdropTap),\"closeButton\":{\"size\":\"\(closeButton.size)\",\"position\":\"\(closeButton.position)\",\"hidden\":\(closeButton.hidden)},\"theme\":\"\(theme)\"}"
116
+ /// small fixed set of ASCII enum values, and `backdrop.color` is a hex string matched against
117
+ /// a strict pattern, all validated/defaulted when the plugin call is parsed, never arbitrary
118
+ /// user text, so plain string interpolation is safe here.
119
+ private static func encodeOptionsJson(
120
+ dismissOnBackdropTap: Bool,
121
+ closeButton: EmojiCloseButtonOptions,
122
+ backdrop: EmojiBackdropOptions,
123
+ theme: String
124
+ ) -> String {
125
+ "{\"dismissOnBackdropTap\":\(dismissOnBackdropTap),"
126
+ + "\"closeButton\":{\"size\":\"\(closeButton.size)\",\"position\":\"\(closeButton.position)\",\"hidden\":\(closeButton.hidden)},"
127
+ + "\"backdrop\":{\"color\":\"\(backdrop.color)\",\"blur\":\(backdrop.blur)},"
128
+ + "\"theme\":\"\(theme)\"}"
119
129
  }
120
130
 
121
131
  private struct PendingRequest {
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/independo-gmbh/capacitor-emoji-picker.git"
14
14
  },
15
15
  "description": "Emoji picker plugin for Capacitor 8 with native Android support, iOS system emoji keyboard integration, and a web fallback.",
16
- "version": "1.1.1-dev.2",
16
+ "version": "1.2.0-dev.1",
17
17
  "packageManager": "pnpm@11.8.0",
18
18
  "devDependencies": {
19
19
  "@capacitor/android": "catalog:",