@onekeyfe/react-native-native-overlay 6.8.0-4 → 6.8.0-6

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 (68) hide show
  1. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +871 -0
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
  5. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
  6. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
  7. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
  8. package/docs/SPEC.md +120 -9
  9. package/ios/NativeOverlayToastCardView.swift +572 -0
  10. package/ios/NativeOverlayToastSpec.swift +356 -0
  11. package/ios/NativeOverlayToasterView.swift +519 -0
  12. package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
  13. package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
  14. package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
  15. package/lib/module/index.js +2 -0
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/toast/OverlayToastHost.js +42 -0
  18. package/lib/module/toast/OverlayToastHost.js.map +1 -0
  19. package/lib/module/toast/OverlayToastHost.web.js +32 -0
  20. package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
  21. package/lib/module/toast/OverlayToastStore.js +217 -0
  22. package/lib/module/toast/OverlayToastStore.js.map +1 -0
  23. package/lib/module/toast/toastBridge.js +65 -0
  24. package/lib/module/toast/toastBridge.js.map +1 -0
  25. package/lib/module/toast/toastDomContent.web.js +298 -0
  26. package/lib/module/toast/toastDomContent.web.js.map +1 -0
  27. package/lib/module/toast/toastDomRenderer.web.js +629 -0
  28. package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
  29. package/lib/module/toast/toastStyles.web.js +97 -0
  30. package/lib/module/toast/toastStyles.web.js.map +1 -0
  31. package/lib/module/toast/types.js +2 -0
  32. package/lib/module/toast/types.js.map +1 -0
  33. package/lib/module/web/overlayLayers.js +5 -0
  34. package/lib/module/web/overlayLayers.js.map +1 -1
  35. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
  36. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts +4 -0
  38. package/lib/typescript/src/index.d.ts.map +1 -1
  39. package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
  40. package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
  41. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
  42. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
  43. package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
  44. package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
  45. package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
  46. package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
  47. package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
  48. package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
  49. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
  50. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
  51. package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
  52. package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
  53. package/lib/typescript/src/toast/types.d.ts +240 -0
  54. package/lib/typescript/src/toast/types.d.ts.map +1 -0
  55. package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
  56. package/package.json +3 -2
  57. package/react-native.config.js +1 -0
  58. package/src/NativeOverlayToasterNativeComponent.ts +24 -0
  59. package/src/index.ts +23 -0
  60. package/src/toast/OverlayToastHost.tsx +62 -0
  61. package/src/toast/OverlayToastHost.web.tsx +29 -0
  62. package/src/toast/OverlayToastStore.ts +254 -0
  63. package/src/toast/toastBridge.ts +62 -0
  64. package/src/toast/toastDomContent.web.ts +351 -0
  65. package/src/toast/toastDomRenderer.web.ts +748 -0
  66. package/src/toast/toastStyles.web.ts +97 -0
  67. package/src/toast/types.ts +251 -0
  68. package/src/web/overlayLayers.ts +7 -0
@@ -2,6 +2,7 @@ package com.onekey.nativeoverlay
2
2
 
3
3
  import android.app.Activity
4
4
  import android.view.KeyEvent
5
+ import android.view.View
5
6
  import android.view.ViewGroup
6
7
  import android.view.Window
7
8
  import android.widget.FrameLayout
@@ -103,6 +104,32 @@ internal class NativeOverlayHost private constructor(
103
104
  onEntriesChanged()
104
105
  }
105
106
 
107
+ /**
108
+ * Adds the message-toast layer under every entry of the `toast` level: the
109
+ * cards are plain views, drawn by the platform rather than hosted React
110
+ * content, and custom toast entries stay above them.
111
+ */
112
+ fun attachToastLayer(layer: View) {
113
+ val content = activity.findViewById<ViewGroup>(android.R.id.content) ?: return
114
+ if (parent !== content) {
115
+ (parent as? ViewGroup)?.removeView(this)
116
+ content.addView(this, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
117
+ } else if (content.getChildAt(content.childCount - 1) !== this) {
118
+ bringToFront()
119
+ }
120
+ val container = levelContainer(NativeOverlayLevel.TOAST)
121
+ if (layer.parent !== container) {
122
+ (layer.parent as? ViewGroup)?.removeView(layer)
123
+ container.addView(layer, 0, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
124
+ }
125
+ updateAccessibility()
126
+ }
127
+
128
+ fun detachToastLayer(layer: View) {
129
+ (layer.parent as? ViewGroup)?.removeView(layer)
130
+ updateAccessibility()
131
+ }
132
+
106
133
  fun detach(entry: NativeOverlayEntryRootView) {
107
134
  (entry.parent as? ViewGroup)?.removeView(entry)
108
135
  onEntriesChanged()
@@ -128,11 +155,14 @@ internal class NativeOverlayHost private constructor(
128
155
  container
129
156
  }
130
157
 
131
- private fun orderedEntries(): List<NativeOverlayEntryRootView> =
158
+ private fun orderedViews(): List<View> =
132
159
  levelContainers.values.flatMap { container ->
133
- (0 until container.childCount).mapNotNull { container.getChildAt(it) as? NativeOverlayEntryRootView }
160
+ (0 until container.childCount).map { container.getChildAt(it) }
134
161
  }
135
162
 
163
+ private fun orderedEntries(): List<NativeOverlayEntryRootView> =
164
+ orderedViews().filterIsInstance<NativeOverlayEntryRootView>()
165
+
136
166
  /** Global overlays win; otherwise the topmost visible page overlay. */
137
167
  private fun topBackEntry(): NativeOverlayEntryRootView? =
138
168
  orderedEntries().lastOrNull {
@@ -149,11 +179,13 @@ internal class NativeOverlayHost private constructor(
149
179
 
150
180
  /** TalkBack only reads the topmost blocking overlay and what is above it. */
151
181
  private fun updateAccessibility() {
152
- val entries = orderedEntries()
153
- val topIndex = entries.indexOfLast { it.blocking && it.isShownForInput }
182
+ val views = orderedViews()
183
+ val topIndex = views.indexOfLast {
184
+ it is NativeOverlayEntryRootView && it.blocking && it.isShownForInput
185
+ }
154
186
  val content = activity.findViewById<ViewGroup>(android.R.id.content) ?: return
155
187
  if (topIndex >= 0) {
156
- accessibilityIsolation.update(content, this, entries.take(topIndex), this)
188
+ accessibilityIsolation.update(content, this, views.take(topIndex), this)
157
189
  return
158
190
  }
159
191
  val pageEntry = shownPageHosts().flatMap { it.shownEntries() }.lastOrNull { it.blocking }
@@ -8,7 +8,7 @@ import com.facebook.react.uimanager.ViewManager
8
8
  class NativeOverlayPackage : ReactPackage {
9
9
  override fun createViewManagers(
10
10
  reactContext: ReactApplicationContext,
11
- ): List<ViewManager<*, *>> = listOf(NativeOverlayViewManager(), NativeOverlayPageHostViewManager())
11
+ ): List<ViewManager<*, *>> = listOf(NativeOverlayViewManager(), NativeOverlayPageHostViewManager(), NativeOverlayToasterViewManager())
12
12
 
13
13
  override fun createNativeModules(
14
14
  reactContext: ReactApplicationContext,