@onekeyfe/react-native-native-overlay 6.7.0-alpha.466 → 6.8.0-2
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/NativeOverlayPageHostView.kt +14 -3
- 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/NativeOverlayMotionTest.kt +42 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayPageHostLayoutTest.kt +58 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
- package/docs/SPEC.md +202 -24
- package/ios/NativeOverlayContainerView.swift +6 -0
- package/ios/NativeOverlayWindowManager.swift +244 -7
- package/lib/module/NativeOverlayNativeComponent.ts +13 -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 +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/web/animateTransition.js +38 -12
- package/lib/module/web/animateTransition.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/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 +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/web/animateTransition.d.ts +12 -0
- package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeOverlayNativeComponent.ts +13 -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 +1 -0
- package/src/web/animateTransition.ts +54 -14
package/README.md
CHANGED
|
@@ -1,35 +1,133 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-native-overlay
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
**Overlay hosts that draw above the app on iOS, Android and Web while keeping the caller's React subtree and hit testing intact.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-native-overlay)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
Owns where an overlay is drawn, which overlay is on top and how it enters and
|
|
17
|
+
exits. Levels are fixed (`modal`, `hardware`, `secure`, `toast`, `lock`,
|
|
18
|
+
`debug`), each entry picks a `global` or `page` scope and a lane strategy, and
|
|
19
|
+
the native host reparents the caller's content so React context, refs and
|
|
20
|
+
`measureInWindow` keep working. Sheet, center, fullscreen, toast and anchored
|
|
21
|
+
presentations are available; the application owns the content and business UI.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Predictable ordering** — every page entry renders below every global entry,
|
|
26
|
+
and inside a scope entries sort by level and then by request order.
|
|
27
|
+
- **Lane strategies** — `stack`, `queue` and `replace` apply per
|
|
28
|
+
(scope, host, level) lane, with `priority`, `replaceKey` and de-duplicated ids.
|
|
29
|
+
- **Preserved React identity** — the overlay view stays where the caller
|
|
30
|
+
rendered it; native code moves its content into the host, so there is no
|
|
31
|
+
portal that drops context.
|
|
32
|
+
- **Page scope that covers chrome** — `OverlayPageHost` as the last child of a
|
|
33
|
+
root route lets page overlays cover native headers and the tab bar.
|
|
34
|
+
- **Native presentation and motion** — sheet drag, back handling, keyboard
|
|
35
|
+
avoidance, status bar styling and configurable enter/exit animations.
|
|
36
|
+
- **Web parity** — the Web implementation portals into z-indexed level layers
|
|
37
|
+
with a focus trap and page isolation.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
yarn add @onekeyfe/react-native-native-overlay
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The native hosts are React Native Fabric codegen components, not Nitro views.
|
|
46
|
+
Install the app's iOS pods and rebuild the native application after adding the
|
|
47
|
+
package. Web additionally needs `react-dom`; it is declared as an optional peer
|
|
48
|
+
dependency.
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
6
51
|
|
|
7
52
|
```tsx
|
|
8
|
-
import {
|
|
53
|
+
import { useState } from 'react';
|
|
54
|
+
import {
|
|
55
|
+
OverlayPageHost,
|
|
56
|
+
OverlayView,
|
|
57
|
+
} from '@onekeyfe/react-native-native-overlay';
|
|
9
58
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
59
|
+
function MainRoute() {
|
|
60
|
+
const [visible, setVisible] = useState(false);
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{screen}
|
|
64
|
+
<OverlayView
|
|
65
|
+
visible={visible}
|
|
66
|
+
presentation="sheet"
|
|
67
|
+
level="modal"
|
|
68
|
+
sheet={{ dismissOnPanDown: true, cornerRadius: 24 }}
|
|
69
|
+
onRequestDismiss={() => setVisible(false)}
|
|
70
|
+
>
|
|
71
|
+
{content}
|
|
72
|
+
</OverlayView>
|
|
73
|
+
{/* Last child of the root route, after its navigator. */}
|
|
74
|
+
<OverlayPageHost hostKey="main" />
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
13
78
|
```
|
|
14
79
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
80
|
+
The application still owns `visible` and the content. `scope="page"` resolves
|
|
81
|
+
`hostKey`/`ownerKey` from the nearest `OverlayPageHostScope` and
|
|
82
|
+
`OverlayPageOwnerScope` providers.
|
|
83
|
+
|
|
84
|
+
## API
|
|
85
|
+
|
|
86
|
+
| Export | Shape | Description | Platforms |
|
|
87
|
+
| --- | --- | --- | :-: |
|
|
88
|
+
| `OverlayView` | component | Declarative overlay: `visible`, `scope`, `level`, `strategy`, `priority`, `replaceKey`, `presentation`, `sheet`, `animation`, `backdrop`, `blocking`, `keepContentMounted`, `statusBarStyle`, `contentSize`, dismiss/present callbacks. | iOS, Android, Web |
|
|
89
|
+
| `OverlayPageHost` | component | Renders the page-scope overlays of one root route from `hostKey`. | iOS, Android, Web |
|
|
90
|
+
| `OverlayPageHostScope`, `OverlayPageOwnerScope` | providers | Supply `hostKey` per root route and `ownerKey` per page. | iOS, Android, Web |
|
|
91
|
+
| `overlayStore` | store | Imperative `request`, `dismiss`, `finalize`, `reopen`, `dismissAll`, `setPageVisible`, `removePage`, `resolveBack`. | iOS, Android, Web |
|
|
92
|
+
| `OverlayRequestError` | error class | Thrown for invalid requests such as a page entry without keys. | iOS, Android, Web |
|
|
93
|
+
| `OVERLAY_LEVELS`, `OVERLAY_LEVEL_ORDER` | constants | The level list and their numeric order. | iOS, Android, Web |
|
|
94
|
+
| `resolveOverlayAnimation`, `OVERLAY_MOTION_PRESETS`, `NATIVE_MOTION_PRESETS`, `WEB_MOTION_PRESETS` | helpers | Resolve animation configs per platform. | iOS, Android, Web |
|
|
95
|
+
|
|
96
|
+
`presentation` accepts `sheet`, `center`, `fullscreen`, `toast` and `anchored`.
|
|
97
|
+
`strategy` accepts `stack`, `queue` and `replace`. See
|
|
98
|
+
[`docs/SPEC.md`](docs/SPEC.md) for the ownership model, platform differences and
|
|
99
|
+
acceptance record.
|
|
100
|
+
|
|
101
|
+
## Platform support
|
|
102
|
+
|
|
103
|
+
| Capability | iOS | Android | Web |
|
|
104
|
+
| --- | :-: | :-: | :-: |
|
|
105
|
+
| Global overlays and level ordering | ✅ | ✅ | ✅ |
|
|
106
|
+
| Page scope via `OverlayPageHost` | ✅ | ✅ | ✅ |
|
|
107
|
+
| Sheet presentation | ✅ | ✅ | ✅ |
|
|
108
|
+
| Keyboard avoidance | ✅ | ✅ | ✅ |
|
|
109
|
+
| `windowOffsetRequest` for modal-relative anchors | ✅ | — | — |
|
|
110
|
+
| `contentSize` for pre-rotation layout | ✅ | ✅ | — |
|
|
111
|
+
| Status bar styling | ✅ | ✅ | — |
|
|
112
|
+
|
|
113
|
+
## Caveats
|
|
20
114
|
|
|
21
|
-
|
|
115
|
+
> [!IMPORTANT]
|
|
116
|
+
> Page-scope entries need both `hostKey` and `ownerKey`. A declarative
|
|
117
|
+
> `OverlayView` waits until the nearest scope providers supply them, but a
|
|
118
|
+
> direct `overlayStore.request` with a missing key throws `OverlayRequestError`.
|
|
22
119
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
120
|
+
> [!NOTE]
|
|
121
|
+
> The `windowOffsetRequest`/`onWindowOffset` and `contentSize` props are
|
|
122
|
+
> native-only layout aids; they do nothing on Web. On Web the overlay portals
|
|
123
|
+
> into a level layer and relies on `react-dom`.
|
|
26
124
|
|
|
27
|
-
##
|
|
125
|
+
## References
|
|
28
126
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
127
|
+
- [Package spec](docs/SPEC.md)
|
|
128
|
+
- [Public exports](src/index.ts)
|
|
129
|
+
- [Changelog](../../CHANGELOG.md)
|
|
32
130
|
|
|
33
131
|
## License
|
|
34
132
|
|
|
35
|
-
MIT
|
|
133
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -103,6 +103,9 @@ internal class NativeOverlayEntryRootView(
|
|
|
103
103
|
private var imeBottom = 0
|
|
104
104
|
private var safeTop = 0
|
|
105
105
|
private var sheetBottomPadding = 0
|
|
106
|
+
/** Paints the platform sheet's navigation-bar inset strip. */
|
|
107
|
+
internal var sheetBottomInsetPaintView: View? = null
|
|
108
|
+
private set
|
|
106
109
|
private var keyboardAnimating = false
|
|
107
110
|
|
|
108
111
|
/** `sheet` presentation: the draggable surface; otherwise null. */
|
|
@@ -156,6 +159,8 @@ internal class NativeOverlayEntryRootView(
|
|
|
156
159
|
backgroundColor: Int,
|
|
157
160
|
showHandle: Boolean,
|
|
158
161
|
draggable: Boolean,
|
|
162
|
+
bottomInsetColor: Int? = null,
|
|
163
|
+
bottomInsetHorizontalPx: Float = 0f,
|
|
159
164
|
) {
|
|
160
165
|
val sheet = sheetView ?: createSheet()
|
|
161
166
|
(sheet.background as? GradientDrawable)?.apply {
|
|
@@ -178,6 +183,60 @@ internal class NativeOverlayEntryRootView(
|
|
|
178
183
|
params.height = targetHeight
|
|
179
184
|
sheet.layoutParams = params
|
|
180
185
|
}
|
|
186
|
+
updateSheetBottomInsetPaint(sheetBottomPadding, bottomInsetColor, bottomInsetHorizontalPx)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* `sheet` presentation: the sheet pads its content by the navigation-bar
|
|
191
|
+
* inset so the content sits above the system bar. When JS draws the surface
|
|
192
|
+
* the platform sheet stays transparent, and the JS safe-area tail cannot
|
|
193
|
+
* paint this strip on Android: it hangs below the React content root, which
|
|
194
|
+
* Android does not composite outside its bounds. Paint the strip natively
|
|
195
|
+
* with the drawn surface color instead. A null color keeps it transparent
|
|
196
|
+
* for platform-painted sheets.
|
|
197
|
+
*/
|
|
198
|
+
internal fun updateSheetBottomInsetPaint(
|
|
199
|
+
insetPx: Int,
|
|
200
|
+
color: Int?,
|
|
201
|
+
horizontalInsetPx: Float,
|
|
202
|
+
) {
|
|
203
|
+
val sheet = sheetView ?: return
|
|
204
|
+
if (color == null || insetPx <= 0) {
|
|
205
|
+
sheetBottomInsetPaintView?.let { paint ->
|
|
206
|
+
sheet.removeView(paint)
|
|
207
|
+
sheetBottomInsetPaintView = null
|
|
208
|
+
}
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
val paint = sheetBottomInsetPaintView ?: View(reactContext).apply {
|
|
212
|
+
isClickable = false
|
|
213
|
+
isFocusable = false
|
|
214
|
+
importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO
|
|
215
|
+
// Index 0 keeps the strip behind the sheet content.
|
|
216
|
+
sheet.addView(
|
|
217
|
+
this,
|
|
218
|
+
0,
|
|
219
|
+
LayoutParams(LayoutParams.MATCH_PARENT, 0).apply { gravity = Gravity.BOTTOM },
|
|
220
|
+
)
|
|
221
|
+
sheetBottomInsetPaintView = this
|
|
222
|
+
}
|
|
223
|
+
paint.setBackgroundColor(color)
|
|
224
|
+
// The content height can be fractional; overlap it by a couple of points so
|
|
225
|
+
// rounding cannot leave an unpainted row above the strip. Both views share
|
|
226
|
+
// the same surface color, so the overlap is invisible.
|
|
227
|
+
val height = insetPx + (2 * resources.displayMetrics.density).toInt()
|
|
228
|
+
val horizontal = horizontalInsetPx.toInt().coerceAtLeast(0)
|
|
229
|
+
val params = paint.layoutParams as LayoutParams
|
|
230
|
+
if (
|
|
231
|
+
params.height != height ||
|
|
232
|
+
params.leftMargin != horizontal ||
|
|
233
|
+
params.rightMargin != horizontal
|
|
234
|
+
) {
|
|
235
|
+
params.height = height
|
|
236
|
+
params.leftMargin = horizontal
|
|
237
|
+
params.rightMargin = horizontal
|
|
238
|
+
paint.layoutParams = params
|
|
239
|
+
}
|
|
181
240
|
}
|
|
182
241
|
|
|
183
242
|
/** The sheet's full height, navigation bar padding included. */
|
|
@@ -242,6 +301,7 @@ internal class NativeOverlayEntryRootView(
|
|
|
242
301
|
sheetAnimationView = coordinator
|
|
243
302
|
sheetBehavior = behavior
|
|
244
303
|
handleView = handle
|
|
304
|
+
sheetBottomInsetPaintView = null
|
|
245
305
|
return sheet
|
|
246
306
|
}
|
|
247
307
|
|
|
@@ -80,7 +80,7 @@ class NativeOverlayPageHostView(context: Context) : ViewGroup(context), ReactPoi
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
private var layoutScheduled = false
|
|
83
|
-
private val layoutRunnable = Runnable {
|
|
83
|
+
private val layoutRunnable: Runnable? = Runnable {
|
|
84
84
|
layoutScheduled = false
|
|
85
85
|
layoutEntries()
|
|
86
86
|
}
|
|
@@ -92,14 +92,25 @@ class NativeOverlayPageHostView(context: Context) : ViewGroup(context), ReactPoi
|
|
|
92
92
|
*/
|
|
93
93
|
override fun requestLayout() {
|
|
94
94
|
super.requestLayout()
|
|
95
|
+
// View construction can request layout before this callback is initialized.
|
|
96
|
+
val runnable = layoutRunnable ?: return
|
|
95
97
|
if (!layoutScheduled) {
|
|
96
98
|
layoutScheduled = true
|
|
97
|
-
post(
|
|
99
|
+
post(runnable)
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
private fun layoutEntries() {
|
|
102
|
-
|
|
104
|
+
if (width <= 0 || height <= 0) return
|
|
105
|
+
// Run the host's layout lifecycle to clear FORCE_LAYOUT, so later child
|
|
106
|
+
// requests can reach this host through a Fabric-managed parent.
|
|
107
|
+
// Force another pass even when attach() reuses an existing child.
|
|
108
|
+
forceLayout()
|
|
109
|
+
measure(
|
|
110
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
111
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY),
|
|
112
|
+
)
|
|
113
|
+
layout(left, top, right, bottom)
|
|
103
114
|
}
|
|
104
115
|
|
|
105
116
|
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
|
@@ -69,6 +69,10 @@ class NativeOverlayView(
|
|
|
69
69
|
var sheetCornerRadius = 24.0
|
|
70
70
|
var showHandle = false
|
|
71
71
|
var sheetBackgroundColor: Int? = null
|
|
72
|
+
/** Paints the platform sheet's bottom inset with the drawn surface color. */
|
|
73
|
+
var sheetBottomInsetColor: Int? = null
|
|
74
|
+
/** Horizontal inset of the drawn surface inside the sheet, in points. */
|
|
75
|
+
var sheetBottomInsetHorizontal = 0.0
|
|
72
76
|
var dismissOnPanDown = true
|
|
73
77
|
var animationConfig: String? = null
|
|
74
78
|
var onPresented: ((Int) -> Unit)? = null
|
|
@@ -235,6 +239,12 @@ class NativeOverlayView(
|
|
|
235
239
|
notifyHostEntriesChanged()
|
|
236
240
|
val transition = config.exit.reduceMotionAdjusted(isReduceMotionEnabled())
|
|
237
241
|
if (transition.kind == "none") return finishDismiss("programmatic")
|
|
242
|
+
// A fade-free exit does not animate alpha. If the fade-in was interrupted,
|
|
243
|
+
// the card would otherwise stay partly transparent and show the content
|
|
244
|
+
// behind it for the whole scale-out (OK-66647).
|
|
245
|
+
if (!transition.hidesOpacity) {
|
|
246
|
+
target.animatedView.alpha = 1f
|
|
247
|
+
}
|
|
238
248
|
animate(target, hiddenState(target, transition), 0f, transition.motion) {
|
|
239
249
|
if (phase == Phase.EXITING) finishDismiss("programmatic")
|
|
240
250
|
}
|
|
@@ -392,6 +402,8 @@ class NativeOverlayView(
|
|
|
392
402
|
backgroundColor = sheetBackgroundColor ?: defaultSheetBackgroundColor(),
|
|
393
403
|
showHandle = showHandle,
|
|
394
404
|
draggable = dismissOnPanDown,
|
|
405
|
+
bottomInsetColor = sheetBottomInsetColor,
|
|
406
|
+
bottomInsetHorizontalPx = (sheetBottomInsetHorizontal * density).toFloat(),
|
|
395
407
|
)
|
|
396
408
|
}
|
|
397
409
|
}
|
|
@@ -145,6 +145,14 @@ class NativeOverlayViewManager :
|
|
|
145
145
|
view.sheetBackgroundColor = value
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
override fun setSheetBottomInsetColor(view: NativeOverlayView, value: Int?) {
|
|
149
|
+
view.sheetBottomInsetColor = value
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
override fun setSheetBottomInsetHorizontal(view: NativeOverlayView, value: Double) {
|
|
153
|
+
view.sheetBottomInsetHorizontal = value
|
|
154
|
+
}
|
|
155
|
+
|
|
148
156
|
override fun setDismissOnPanDown(view: NativeOverlayView, value: Boolean) {
|
|
149
157
|
view.dismissOnPanDown = value
|
|
150
158
|
}
|
|
@@ -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
|
+
}
|