@onekeyfe/react-native-native-overlay 6.7.0-alpha.466 → 6.8.0-10

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 (104) hide show
  1. package/README.md +119 -21
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +60 -0
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
  5. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPageHostView.kt +14 -3
  6. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +869 -0
  7. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
  8. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
  9. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
  10. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +12 -0
  11. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +8 -0
  12. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
  13. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayMotionTest.kt +42 -0
  14. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayPageHostLayoutTest.kt +58 -0
  15. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
  16. package/docs/SPEC.md +337 -33
  17. package/ios/NativeOverlayContainerView.swift +6 -0
  18. package/ios/NativeOverlayToastCardView.swift +572 -0
  19. package/ios/NativeOverlayToastSpec.swift +356 -0
  20. package/ios/NativeOverlayToasterView.swift +519 -0
  21. package/ios/NativeOverlayWindowManager.swift +244 -7
  22. package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
  23. package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
  24. package/lib/module/NativeOverlayNativeComponent.ts +13 -0
  25. package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
  26. package/lib/module/OverlayView.js +7 -1
  27. package/lib/module/OverlayView.js.map +1 -1
  28. package/lib/module/animation/anchoredOrigin.js +26 -0
  29. package/lib/module/animation/anchoredOrigin.js.map +1 -0
  30. package/lib/module/animation/resolveAnimation.js +26 -4
  31. package/lib/module/animation/resolveAnimation.js.map +1 -1
  32. package/lib/module/index.js +3 -0
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/toast/OverlayToastHost.js +42 -0
  35. package/lib/module/toast/OverlayToastHost.js.map +1 -0
  36. package/lib/module/toast/OverlayToastHost.web.js +32 -0
  37. package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
  38. package/lib/module/toast/OverlayToastStore.js +217 -0
  39. package/lib/module/toast/OverlayToastStore.js.map +1 -0
  40. package/lib/module/toast/toastBridge.js +65 -0
  41. package/lib/module/toast/toastBridge.js.map +1 -0
  42. package/lib/module/toast/toastDomContent.web.js +298 -0
  43. package/lib/module/toast/toastDomContent.web.js.map +1 -0
  44. package/lib/module/toast/toastDomRenderer.web.js +695 -0
  45. package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
  46. package/lib/module/toast/toastStyles.web.js +97 -0
  47. package/lib/module/toast/toastStyles.web.js.map +1 -0
  48. package/lib/module/toast/types.js +2 -0
  49. package/lib/module/toast/types.js.map +1 -0
  50. package/lib/module/web/animateTransition.js +38 -12
  51. package/lib/module/web/animateTransition.js.map +1 -1
  52. package/lib/module/web/overlayLayers.js +5 -0
  53. package/lib/module/web/overlayLayers.js.map +1 -1
  54. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +13 -0
  55. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -1
  56. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
  57. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
  58. package/lib/typescript/src/OverlayView.d.ts.map +1 -1
  59. package/lib/typescript/src/animation/anchoredOrigin.d.ts +7 -0
  60. package/lib/typescript/src/animation/anchoredOrigin.d.ts.map +1 -0
  61. package/lib/typescript/src/animation/resolveAnimation.d.ts +9 -3
  62. package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -1
  63. package/lib/typescript/src/animation/types.d.ts +5 -1
  64. package/lib/typescript/src/animation/types.d.ts.map +1 -1
  65. package/lib/typescript/src/index.d.ts +5 -0
  66. package/lib/typescript/src/index.d.ts.map +1 -1
  67. package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
  68. package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
  69. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
  70. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
  71. package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
  72. package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
  73. package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
  74. package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
  75. package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
  76. package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
  77. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
  78. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
  79. package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
  80. package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
  81. package/lib/typescript/src/toast/types.d.ts +240 -0
  82. package/lib/typescript/src/toast/types.d.ts.map +1 -0
  83. package/lib/typescript/src/web/animateTransition.d.ts +12 -0
  84. package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
  85. package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
  86. package/package.json +3 -2
  87. package/react-native.config.js +1 -0
  88. package/src/NativeOverlayNativeComponent.ts +13 -0
  89. package/src/NativeOverlayToasterNativeComponent.ts +24 -0
  90. package/src/OverlayView.tsx +7 -0
  91. package/src/animation/anchoredOrigin.ts +35 -0
  92. package/src/animation/resolveAnimation.ts +28 -7
  93. package/src/animation/types.ts +5 -1
  94. package/src/index.ts +24 -0
  95. package/src/toast/OverlayToastHost.tsx +62 -0
  96. package/src/toast/OverlayToastHost.web.tsx +29 -0
  97. package/src/toast/OverlayToastStore.ts +254 -0
  98. package/src/toast/toastBridge.ts +62 -0
  99. package/src/toast/toastDomContent.web.ts +351 -0
  100. package/src/toast/toastDomRenderer.web.ts +856 -0
  101. package/src/toast/toastStyles.web.ts +97 -0
  102. package/src/toast/types.ts +251 -0
  103. package/src/web/animateTransition.ts +54 -14
  104. package/src/web/overlayLayers.ts +7 -0
@@ -2,9 +2,17 @@ package com.onekey.nativeoverlay
2
2
 
3
3
  import android.view.View
4
4
  import android.widget.FrameLayout
5
+ import androidx.activity.ComponentActivity
6
+ import com.facebook.react.bridge.BridgeReactContext
7
+ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
8
+ import com.facebook.react.uimanager.ThemedReactContext
9
+ import org.json.JSONObject
5
10
  import org.junit.Assert.assertEquals
11
+ import org.junit.Assert.assertNotNull
12
+ import org.junit.Assert.assertTrue
6
13
  import org.junit.Test
7
14
  import org.junit.runner.RunWith
15
+ import org.robolectric.Robolectric
8
16
  import org.robolectric.RobolectricTestRunner
9
17
  import org.robolectric.RuntimeEnvironment
10
18
  import org.robolectric.annotation.Config
@@ -109,4 +117,168 @@ class NativeOverlayAccessibilityIsolationTest {
109
117
  assertEquals(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO, tree.blocker.importantForAccessibility)
110
118
  assertEquals(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, tree.lower.importantForAccessibility)
111
119
  }
120
+
121
+ @Test
122
+ fun lockBlockerIsolatesMessageToastLayerBothBeforeAndAfterLockOpens() {
123
+ val localAccessor = Class.forName(
124
+ "com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsLocalAccessor"
125
+ ).getDeclaredConstructor().newInstance()
126
+ ReactNativeFeatureFlags::class.java.getDeclaredField("accessor").apply {
127
+ isAccessible = true
128
+ set(null, localAccessor)
129
+ }
130
+ val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().visible().get()
131
+ val reactContext = BridgeReactContext(activity)
132
+ reactContext.onHostResume(activity)
133
+ val themedContext = ThemedReactContext(reactContext, activity, "ToastIsolationTest", 1)
134
+ val host = NativeOverlayHost.of(activity)
135
+ val toastLayer = FrameLayout(activity)
136
+ host.attachToastLayer(toastLayer)
137
+ val modal = NativeOverlayEntryRootView(themedContext).apply {
138
+ blocking = true
139
+ isShownForInput = true
140
+ }
141
+ host.attach(modal, NativeOverlayLevel.MODAL)
142
+ assertEquals(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO, toastLayer.importantForAccessibility)
143
+
144
+ val lock = NativeOverlayEntryRootView(themedContext).apply {
145
+ blocking = true
146
+ isShownForInput = true
147
+ }
148
+ host.attach(lock, NativeOverlayLevel.LOCK)
149
+ assertEquals(
150
+ View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS,
151
+ toastLayer.importantForAccessibility,
152
+ )
153
+
154
+ val secondToastLayer = FrameLayout(activity)
155
+ host.detachToastLayer(toastLayer)
156
+ host.attachToastLayer(secondToastLayer)
157
+ assertEquals(
158
+ View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS,
159
+ secondToastLayer.importantForAccessibility,
160
+ )
161
+
162
+ host.detach(lock)
163
+ assertEquals(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO, secondToastLayer.importantForAccessibility)
164
+ }
165
+
166
+ @Test
167
+ @Config(sdk = [24, 26, 28])
168
+ fun toastFontAndPresenterSupportApi24Through28() {
169
+ assertNotNull(ToastFont.make(context, null, emptyMap(), "400"))
170
+ assertNotNull(ToastFont.make(context, null, emptyMap(), "700"))
171
+ val hostView = View(context)
172
+ val presenter = NativeOverlayToastPresenter(hostView)
173
+ presenter.sync(
174
+ ToastItem.parseList("""[{"spec":{"id":"a","layout":"message","duration":1000},"visible":true,"revision":0,"generation":0}]"""),
175
+ ToasterConfig.parse("{}"),
176
+ )
177
+ presenter.invalidate()
178
+ }
179
+
180
+ @Test
181
+ fun namedIconColorsNormalizeToStrictRgbaAcrossCssFormats() {
182
+ val strictPattern = Regex("""^rgba\(\d{1,3},\d{1,3},\d{1,3},(?:0(?:\.\d+)?|1(?:\.0+)?)\)$""")
183
+ val inputs = listOf(
184
+ "#ff0000" to "rgba(255,0,0,1)",
185
+ "#00ff0080" to "rgba(0,255,0,0.502)",
186
+ "rgb(12, 34, 56)" to "rgba(12,34,56,1)",
187
+ "rgba(255, 0, 128, 0.5)" to "rgba(255,0,128,0.502)",
188
+ "hsl(120, 100%, 50%)" to "rgba(0,255,0,1)",
189
+ "transparent" to "rgba(0,0,0,0)",
190
+ )
191
+ for ((raw, expected) in inputs) {
192
+ val icon = ToastIcon.parse(
193
+ JSONObject().put("kind", "icon").put("name", "DotVerSolid").put("color", raw).put("size", 20),
194
+ ) as ToastIcon.Named
195
+ assertEquals(expected, icon.colorString)
196
+ assertTrue(strictPattern.matches(icon.colorString))
197
+ }
198
+ }
199
+
200
+ @Test
201
+ fun rebuildingOrInvalidatingToastCardCancelsPendingImageLoads() {
202
+ val card = NativeOverlayToastCardView(context)
203
+ val spec = ToastSpec.parse(
204
+ JSONObject()
205
+ .put("id", "img-toast")
206
+ .put("layout", "notification")
207
+ .put("duration", 5000)
208
+ .put("icon", JSONObject().put("kind", "image").put("uri", "http://127.0.0.1:1/slow.png").put("size", 24))
209
+ .put("image", JSONObject().put("uri", "http://127.0.0.1:1/thumb.png").put("size", 40)),
210
+ )
211
+ repeat(10) {
212
+ card.apply(spec, 0xffffffff.toInt())
213
+ }
214
+ card.cancelLoads()
215
+ }
216
+
217
+ @Test
218
+ fun pressableNotificationCardExposesAccessibilityClickActionSeparatelyFromButtons() {
219
+ val card = NativeOverlayToastCardView(context)
220
+ var pressed = 0
221
+ val actions = mutableListOf<String>()
222
+ card.onPress = { pressed += 1 }
223
+ card.onAction = { actions.add(it) }
224
+ val spec = ToastSpec.parse(
225
+ JSONObject()
226
+ .put("id", "press-notif")
227
+ .put("layout", "notification")
228
+ .put("duration", 5000)
229
+ .put("pressable", true)
230
+ .put("badgeSize", 36)
231
+ .put("badgeColor", "#eeeeee")
232
+ .put(
233
+ "title",
234
+ JSONObject()
235
+ .put("color", "#111111")
236
+ .put("fontSize", 14)
237
+ .put("lineHeight", 20)
238
+ .put("fontWeight", "600")
239
+ .put("paragraphs", org.json.JSONArray().put(org.json.JSONArray().put(JSONObject().put("text", "Hello")))),
240
+ )
241
+ .put(
242
+ "actions",
243
+ org.json.JSONArray().put(
244
+ JSONObject()
245
+ .put("id", "view")
246
+ .put("label", "View")
247
+ .put("color", "#ffffff")
248
+ .put("backgroundColor", "#000000")
249
+ .put("fontSize", 14)
250
+ .put("lineHeight", 20)
251
+ .put("fontWeight", "500")
252
+ .put("paddingHorizontal", 10)
253
+ .put("paddingVertical", 4)
254
+ .put("borderRadius", 8),
255
+ ),
256
+ ),
257
+ )
258
+ card.apply(spec, 0xffffffff.toInt())
259
+ val info = android.view.accessibility.AccessibilityNodeInfo.obtain()
260
+ card.onInitializeAccessibilityNodeInfo(info)
261
+ assertTrue(card.isClickable)
262
+ assertTrue(card.isFocusable)
263
+ assertTrue(info.isClickable)
264
+ assertEquals("Hello", info.contentDescription.toString())
265
+ assertTrue(card.performAccessibilityAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK, null))
266
+ assertEquals(1, pressed)
267
+ assertTrue(card.performClick())
268
+ assertEquals(2, pressed)
269
+ assertTrue(
270
+ card.onKeyDown(
271
+ android.view.KeyEvent.KEYCODE_ENTER,
272
+ android.view.KeyEvent(android.view.KeyEvent.ACTION_DOWN, android.view.KeyEvent.KEYCODE_ENTER),
273
+ ),
274
+ )
275
+ assertTrue(
276
+ card.onKeyUp(
277
+ android.view.KeyEvent.KEYCODE_ENTER,
278
+ android.view.KeyEvent(android.view.KeyEvent.ACTION_UP, android.view.KeyEvent.KEYCODE_ENTER),
279
+ ),
280
+ )
281
+ assertEquals(3, pressed)
282
+ assertEquals(emptyList<String>(), actions)
283
+ }
112
284
  }
@@ -114,6 +114,48 @@ class NativeOverlayMotionTest {
114
114
  assertEquals(1, dismissals)
115
115
  }
116
116
 
117
+ @Test
118
+ fun fadeFreeExitSnapsAnInterruptedFadeInToFullOpacity() {
119
+ val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().visible().get()
120
+ val reactContext = BridgeReactContext(activity)
121
+ reactContext.onHostResume(activity)
122
+ val context = ThemedReactContext(reactContext, activity, "OverlayMotionTest", 1)
123
+ val quick = """{"type":"spring","spring":{"mass":0.1,"stiffness":100,"damping":20}}"""
124
+ val overlay = NativeOverlayView(context).apply {
125
+ presentation = "center"
126
+ animationConfig = """
127
+ {"enter":{"type":"scale","scale":0.85,"fade":true,"motion":$quick},
128
+ "exit":{"type":"scale","scale":0.96,"fade":false,"motion":$quick},
129
+ "backdrop":{"motion":$quick}}
130
+ """.trimIndent()
131
+ addReactChild(View(context))
132
+ }
133
+ activity.setContentView(overlay)
134
+ overlay.visible = true
135
+ overlay.commitConfiguration()
136
+
137
+ val entryField = NativeOverlayView::class.java.getDeclaredField("entry").apply { isAccessible = true }
138
+ val entry = entryField.get(overlay) as NativeOverlayEntryRootView
139
+ val animatorField = NativeOverlayView::class.java.getDeclaredField("contentAnimator").apply { isAccessible = true }
140
+ val enterAnimator = animatorField.get(overlay) as ValueAnimator
141
+ // Freeze a frame of the running fade-in: closing now starts the exit from a
142
+ // partly transparent surface.
143
+ enterAnimator.currentPlayTime = enterAnimator.duration / 3
144
+ val interruptedAlpha = entry.animatedView.alpha
145
+ assertTrue(interruptedAlpha > 0f && interruptedAlpha < 1f)
146
+
147
+ overlay.visible = false
148
+ overlay.commitConfiguration()
149
+
150
+ // A fade-free exit must not start from the interrupted alpha: the card stays
151
+ // fully opaque while it scales out so the content behind it cannot show through.
152
+ assertEquals(1f, entry.animatedView.alpha, 0.001f)
153
+ val exitAnimator = animatorField.get(overlay) as ValueAnimator
154
+ assertEquals(292L, exitAnimator.duration)
155
+ exitAnimator.currentPlayTime = exitAnimator.duration / 3
156
+ assertEquals(1f, entry.animatedView.alpha, 0.001f)
157
+ }
158
+
117
159
  @Test
118
160
  fun finishingExitMovesTransitioningContentBackToStagingView() {
119
161
  val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().visible().get()
@@ -0,0 +1,58 @@
1
+ package com.onekey.nativeoverlay
2
+
3
+ import android.graphics.Color
4
+ import android.os.Looper
5
+ import android.view.View
6
+ import androidx.activity.ComponentActivity
7
+ import com.facebook.react.bridge.BridgeReactContext
8
+ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
9
+ import com.facebook.react.uimanager.ThemedReactContext
10
+ import com.facebook.react.views.view.ReactViewGroup
11
+ import org.junit.Assert.assertEquals
12
+ import org.junit.Assert.assertFalse
13
+ import org.junit.Test
14
+ import org.junit.runner.RunWith
15
+ import org.robolectric.Robolectric
16
+ import org.robolectric.RobolectricTestRunner
17
+ import org.robolectric.Shadows
18
+ import org.robolectric.annotation.Config
19
+ import java.time.Duration
20
+
21
+ @RunWith(RobolectricTestRunner::class)
22
+ @Config(sdk = [34])
23
+ class NativeOverlayPageHostLayoutTest {
24
+ @Test
25
+ fun pageSheetTracksHeightChangesAfterAttachInsideFabricParent() {
26
+ ReactNativeFeatureFlagsForTests.setUp()
27
+ val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().visible().get()
28
+ val reactContext = BridgeReactContext(activity)
29
+ val context = ThemedReactContext(reactContext, activity, "PageHostLayoutTest", 1)
30
+ val parent = ReactViewGroup(context)
31
+ val host = NativeOverlayPageHostView(context)
32
+ parent.addView(host)
33
+ activity.setContentView(parent)
34
+ val widthSpec = View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.EXACTLY)
35
+ val heightSpec = View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY)
36
+ host.measure(widthSpec, heightSpec)
37
+ host.layout(0, 0, 400, 1000)
38
+ val entry = NativeOverlayEntryRootView(context)
39
+ entry.configureSheet(200, 24f, Color.WHITE, false, true)
40
+
41
+ host.attach(entry)
42
+ Shadows.shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(100))
43
+ val sheet = entry.sheetView!!
44
+ assertEquals(entry.sheetHeightPx(), sheet.height)
45
+ assertEquals(1000 - entry.sheetHeightPx(), sheet.top)
46
+
47
+ entry.configureSheet(600, 24f, Color.WHITE, false, true)
48
+ Shadows.shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(100))
49
+ assertEquals(entry.sheetHeightPx(), sheet.height)
50
+ assertEquals(1000 - entry.sheetHeightPx(), sheet.top)
51
+ assertFalse(host.isLayoutRequested)
52
+
53
+ entry.configureSheet(320, 24f, Color.WHITE, false, true)
54
+ Shadows.shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(100))
55
+ assertEquals(entry.sheetHeightPx(), sheet.height)
56
+ assertEquals(1000 - entry.sheetHeightPx(), sheet.top)
57
+ }
58
+ }
@@ -0,0 +1,78 @@
1
+ package com.onekey.nativeoverlay
2
+
3
+ import android.graphics.Color
4
+ import android.graphics.drawable.ColorDrawable
5
+ import android.view.Gravity
6
+ import android.widget.FrameLayout
7
+ import androidx.activity.ComponentActivity
8
+ import com.facebook.react.bridge.BridgeReactContext
9
+ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
10
+ import com.facebook.react.uimanager.ThemedReactContext
11
+ import org.junit.Assert.assertEquals
12
+ import org.junit.Assert.assertNull
13
+ import org.junit.Assert.assertTrue
14
+ import org.junit.Test
15
+ import org.junit.runner.RunWith
16
+ import org.robolectric.Robolectric
17
+ import org.robolectric.RobolectricTestRunner
18
+ import org.robolectric.annotation.Config
19
+
20
+ @RunWith(RobolectricTestRunner::class)
21
+ @Config(sdk = [34])
22
+ class NativeOverlaySheetInsetTest {
23
+ private fun newEntry(): NativeOverlayEntryRootView {
24
+ ReactNativeFeatureFlagsForTests.setUp()
25
+ val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().visible().get()
26
+ val reactContext = BridgeReactContext(activity)
27
+ val context = ThemedReactContext(reactContext, activity, "SheetInsetTest", 1)
28
+ return NativeOverlayEntryRootView(context)
29
+ }
30
+
31
+ @Test
32
+ fun paintsTheNavigationBarStripBehindTheContent() {
33
+ val entry = newEntry()
34
+ // Platform-painted sheet: the platform background reaches the inset.
35
+ entry.configureSheet(200, 24f, Color.WHITE, false, true)
36
+ assertNull(entry.sheetBottomInsetPaintView)
37
+ val sheet = entry.sheetView!!
38
+ val content = entry.contentView
39
+
40
+ entry.updateSheetBottomInsetPaint(48, Color.WHITE, 12f)
41
+
42
+ val paint = entry.sheetBottomInsetPaintView!!
43
+ assertTrue(sheet.indexOfChild(paint) < sheet.indexOfChild(content))
44
+ val params = paint.layoutParams as FrameLayout.LayoutParams
45
+ assertEquals(Gravity.BOTTOM, params.gravity)
46
+ assertEquals(12, params.leftMargin)
47
+ assertEquals(12, params.rightMargin)
48
+ // The inset plus a small overlap over the fractional content height.
49
+ assertTrue(params.height >= 48)
50
+ assertEquals(Color.WHITE, (paint.background as ColorDrawable).color)
51
+ }
52
+
53
+ @Test
54
+ fun clearsTheStripWhenThePlatformSheetPaintsTheSurface() {
55
+ val entry = newEntry()
56
+ entry.configureSheet(200, 24f, Color.TRANSPARENT, false, true)
57
+ val sheet = entry.sheetView!!
58
+ entry.updateSheetBottomInsetPaint(48, Color.WHITE, 0f)
59
+ assertTrue(sheet.childCount == 3)
60
+
61
+ entry.updateSheetBottomInsetPaint(48, null, 0f)
62
+
63
+ assertEquals(2, sheet.childCount)
64
+ assertNull(entry.sheetBottomInsetPaintView)
65
+ }
66
+
67
+ @Test
68
+ fun keepsTheStripSquareWhenTheSurfaceIsNarrowerThanTheSheet() {
69
+ val entry = newEntry()
70
+ entry.configureSheet(200, 24f, Color.TRANSPARENT, false, true)
71
+ entry.updateSheetBottomInsetPaint(48, Color.BLACK, 40f)
72
+
73
+ val params = entry.sheetBottomInsetPaintView!!.layoutParams as FrameLayout.LayoutParams
74
+ assertEquals(40, params.leftMargin)
75
+ assertEquals(40, params.rightMargin)
76
+ assertEquals(Gravity.BOTTOM, params.gravity)
77
+ }
78
+ }