@onekeyfe/react-native-native-overlay 6.7.0-alpha.475 → 6.8.0-11
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/README.md +119 -21
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +60 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +869 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +12 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +8 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayMotionTest.kt +42 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
- package/docs/SPEC.md +324 -33
- package/ios/NativeOverlayContainerView.swift +6 -0
- package/ios/NativeOverlayToastCardView.swift +572 -0
- package/ios/NativeOverlayToastSpec.swift +356 -0
- package/ios/NativeOverlayToasterView.swift +519 -0
- package/ios/NativeOverlayWindowManager.swift +244 -7
- package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
- package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
- package/lib/module/NativeOverlayNativeComponent.ts +13 -0
- package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
- package/lib/module/OverlayView.js +7 -1
- package/lib/module/OverlayView.js.map +1 -1
- package/lib/module/animation/anchoredOrigin.js +26 -0
- package/lib/module/animation/anchoredOrigin.js.map +1 -0
- package/lib/module/animation/resolveAnimation.js +26 -4
- package/lib/module/animation/resolveAnimation.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/toast/OverlayToastHost.js +42 -0
- package/lib/module/toast/OverlayToastHost.js.map +1 -0
- package/lib/module/toast/OverlayToastHost.web.js +32 -0
- package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
- package/lib/module/toast/OverlayToastStore.js +217 -0
- package/lib/module/toast/OverlayToastStore.js.map +1 -0
- package/lib/module/toast/toastBridge.js +65 -0
- package/lib/module/toast/toastBridge.js.map +1 -0
- package/lib/module/toast/toastDomContent.web.js +298 -0
- package/lib/module/toast/toastDomContent.web.js.map +1 -0
- package/lib/module/toast/toastDomRenderer.web.js +695 -0
- package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
- package/lib/module/toast/toastStyles.web.js +97 -0
- package/lib/module/toast/toastStyles.web.js.map +1 -0
- package/lib/module/toast/types.js +2 -0
- package/lib/module/toast/types.js.map +1 -0
- package/lib/module/web/animateTransition.js +38 -12
- package/lib/module/web/animateTransition.js.map +1 -1
- package/lib/module/web/overlayLayers.js +5 -0
- package/lib/module/web/overlayLayers.js.map +1 -1
- package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +13 -0
- package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
- package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/OverlayView.d.ts.map +1 -1
- package/lib/typescript/src/animation/anchoredOrigin.d.ts +7 -0
- package/lib/typescript/src/animation/anchoredOrigin.d.ts.map +1 -0
- package/lib/typescript/src/animation/resolveAnimation.d.ts +9 -3
- package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -1
- package/lib/typescript/src/animation/types.d.ts +5 -1
- package/lib/typescript/src/animation/types.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
- package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
- package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
- package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
- package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
- package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
- package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
- package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
- package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/types.d.ts +240 -0
- package/lib/typescript/src/toast/types.d.ts.map +1 -0
- package/lib/typescript/src/web/animateTransition.d.ts +12 -0
- package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
- package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
- package/package.json +3 -2
- package/react-native.config.js +1 -0
- package/src/NativeOverlayNativeComponent.ts +13 -0
- package/src/NativeOverlayToasterNativeComponent.ts +24 -0
- package/src/OverlayView.tsx +7 -0
- package/src/animation/anchoredOrigin.ts +35 -0
- package/src/animation/resolveAnimation.ts +28 -7
- package/src/animation/types.ts +5 -1
- package/src/index.ts +24 -0
- package/src/toast/OverlayToastHost.tsx +62 -0
- package/src/toast/OverlayToastHost.web.tsx +29 -0
- package/src/toast/OverlayToastStore.ts +254 -0
- package/src/toast/toastBridge.ts +62 -0
- package/src/toast/toastDomContent.web.ts +351 -0
- package/src/toast/toastDomRenderer.web.ts +856 -0
- package/src/toast/toastStyles.web.ts +97 -0
- package/src/toast/types.ts +251 -0
- package/src/web/animateTransition.ts +54 -14
- package/src/web/overlayLayers.ts +7 -0
package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt
CHANGED
|
@@ -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,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
|
+
}
|