expo-android-glass-view 0.1.1 → 0.1.3
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/CHANGELOG.md +18 -0
- package/android/src/main/java/expo/modules/androidglassview/ExpoAndroidGlassViewModule.kt +5 -0
- package/android/src/main/java/expo/modules/androidglassview/GlassHostView.kt +22 -0
- package/android/src/main/java/expo/modules/androidglassview/capture/ViewBackdropCapture.kt +95 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.3 — 2026-09-11
|
|
4
|
+
|
|
5
|
+
- Fix a crash when navigating to or from a screen that has a glass view (Expo Router and React
|
|
6
|
+
Navigation on react-native-screens): `IllegalStateException: Cannot locate windowRecomposer … is
|
|
7
|
+
not attached to a window`. React Native measures views that are not attached to the window —
|
|
8
|
+
a pushed screen or a tab opened for the first time, before react-native-screens attaches it, or
|
|
9
|
+
a screen it has detached — and measuring the glass layer there made Compose look for the
|
|
10
|
+
window. The glass layer is now skipped while detached and sized when it attaches.
|
|
11
|
+
- `captureRevision` is now 3.
|
|
12
|
+
|
|
13
|
+
## 0.1.2 — 2026-09-10
|
|
14
|
+
|
|
15
|
+
- Fix a crash when a glass view sits inside a react-native-screens stack (Expo Router and React
|
|
16
|
+
Navigation native stacks): `IllegalStateException: Recording currently in progress`. While a
|
|
17
|
+
glass view captures its backdrop, its ancestors are still being drawn; the capture no longer
|
|
18
|
+
calls their `draw()` again but draws their background and children itself.
|
|
19
|
+
- New native constant `captureRevision` (2), so JS can tell a fixed binary from an older one.
|
|
20
|
+
|
|
3
21
|
## 0.1.0 — 2026-09-10
|
|
4
22
|
|
|
5
23
|
First release.
|
|
@@ -10,6 +10,11 @@ class ExpoAndroidGlassViewModule : Module() {
|
|
|
10
10
|
override fun definition() = ModuleDefinition {
|
|
11
11
|
Name("ExpoAndroidGlassView")
|
|
12
12
|
|
|
13
|
+
// Bumped when the backdrop capture changes in a way JS may need to know about.
|
|
14
|
+
// 2: ancestors of a sampling glass view are never drawn again through their own draw()
|
|
15
|
+
// (0.1.1 crashed inside react-native-screens stacks).
|
|
16
|
+
Constant("captureRevision") { 3 }
|
|
17
|
+
|
|
13
18
|
View(AndroidGlassView::class) {
|
|
14
19
|
Name("AndroidGlassView")
|
|
15
20
|
|
|
@@ -120,6 +120,12 @@ abstract class GlassHostView(context: Context, appContext: AppContext) : ExpoVie
|
|
|
120
120
|
clipToPadding = false
|
|
121
121
|
composeView.clipChildren = false
|
|
122
122
|
super.addView(composeView, 0, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
|
|
123
|
+
// The Compose layer is not sized while it is detached (see onMeasure); size it on attach.
|
|
124
|
+
// Listeners run after the view's own onAttachedToWindow, so it is attached by then.
|
|
125
|
+
composeView.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
126
|
+
override fun onViewAttachedToWindow(v: View) = layoutComposeLayer()
|
|
127
|
+
override fun onViewDetachedFromWindow(v: View) = Unit
|
|
128
|
+
})
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
@Composable
|
|
@@ -199,6 +205,12 @@ abstract class GlassHostView(context: Context, appContext: AppContext) : ExpoVie
|
|
|
199
205
|
val width = MeasureSpec.getSize(widthMeasureSpec)
|
|
200
206
|
val height = MeasureSpec.getSize(heightMeasureSpec)
|
|
201
207
|
setMeasuredDimension(width, height)
|
|
208
|
+
// ComposeView creates its composition on its first measure, and that needs the window's
|
|
209
|
+
// recomposer: measured off-window it throws "Cannot locate windowRecomposer". Fabric does
|
|
210
|
+
// measure off-window views — a screen react-native-screens has not attached yet (a pushed
|
|
211
|
+
// screen, a tab opened for the first time) or has detached — so skip the Compose layer until
|
|
212
|
+
// it is attached. The attach listener in init sizes it then.
|
|
213
|
+
if (!composeView.isAttachedToWindow) return
|
|
202
214
|
composeView.measure(
|
|
203
215
|
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
204
216
|
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
@@ -207,9 +219,19 @@ abstract class GlassHostView(context: Context, appContext: AppContext) : ExpoVie
|
|
|
207
219
|
|
|
208
220
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
209
221
|
// React Native lays out the React children; only the glass layer is ours.
|
|
222
|
+
if (!composeView.isAttachedToWindow) return
|
|
210
223
|
composeView.layout(0, 0, right - left, bottom - top)
|
|
211
224
|
}
|
|
212
225
|
|
|
226
|
+
/** Sizes the Compose layer to this view outside a layout pass (see [onMeasure]). */
|
|
227
|
+
private fun layoutComposeLayer() {
|
|
228
|
+
composeView.measure(
|
|
229
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
230
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
231
|
+
)
|
|
232
|
+
composeView.layout(0, 0, width, height)
|
|
233
|
+
}
|
|
234
|
+
|
|
213
235
|
override fun requestLayout() {
|
|
214
236
|
super.requestLayout()
|
|
215
237
|
// React Native does not run Android layout passes, so honour the Compose layer's
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Changes from upstream: renamed, comments translated, generalised from "skip the one glass
|
|
7
7
|
* that is sampling" to "skip every other glass view", glass ancestors of the sampling view are
|
|
8
|
-
* drawn instead of skipped,
|
|
9
|
-
* transform (left/top, scroll, matrix, alpha) instead of screen deltas
|
|
8
|
+
* drawn instead of skipped, expanded branches are positioned with the framework's own child
|
|
9
|
+
* transform (left/top, scroll, matrix, alpha) instead of screen deltas, and the ancestors of the
|
|
10
|
+
* sampling view are drawn child by child instead of through their own draw().
|
|
10
11
|
*/
|
|
11
12
|
package expo.modules.androidglassview.capture
|
|
12
13
|
|
|
@@ -21,33 +22,44 @@ import androidx.annotation.RequiresApi
|
|
|
21
22
|
*
|
|
22
23
|
* A plain `source.draw(canvas)` is only safe when no glass view lives under `source`:
|
|
23
24
|
*
|
|
24
|
-
* 1. **Re-entrant
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `
|
|
25
|
+
* 1. **Re-entrant drawing.** A glass view samples while it is being drawn, so its ancestors are in
|
|
26
|
+
* the middle of their own draw: their RenderNodes are recording and their `dispatchDraw` is
|
|
27
|
+
* mid-loop. Drawing one of them again re-enters both. The child on the way to the glass goes
|
|
28
|
+
* back through `drawChild` → `updateDisplayListIfDirty` and throws
|
|
29
|
+
* `IllegalStateException: Recording currently in progress` — hiding it doesn't help, a view
|
|
30
|
+
* with a running view Animation (react-native-screens' screen transitions) is drawn even when
|
|
31
|
+
* invisible. Per-view drawing state breaks as well: ViewGroup reuses one pre-sorted child list
|
|
32
|
+
* (children with elevation) that the inner call clears under the outer loop.
|
|
28
33
|
* 2. **Reference cycles.** `drawChild` records a *reference* to a child's RenderNode, not pixels.
|
|
29
34
|
* If that subtree contains the sampling glass, the glass would draw itself (glass → backdrop →
|
|
30
35
|
* ancestor → glass), which recurses forever on the RenderThread. The same happens between two
|
|
31
36
|
* glass views that sample each other.
|
|
32
37
|
*
|
|
33
|
-
* So
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* So the ancestors of the sampling glass are never drawn through their own `draw()`: their
|
|
39
|
+
* background and children are drawn here, in their drawing order ([drawAncestor]) — other glass
|
|
40
|
+
* views left out, containers of glass one level deeper, every other child with its public
|
|
41
|
+
* [View.draw] (its own content is copied, its subtree still goes through RenderNode references).
|
|
42
|
+
*
|
|
43
|
+
* Every other container that has a skipped glass view somewhere below it (an *expanded*
|
|
44
|
+
* container) is not being drawn right now, so it is drawn with the public [View.draw], which
|
|
45
|
+
* neither touches its RenderNode nor records a reference to it. For that call, its children that
|
|
46
|
+
* are skipped glass views or contain one are hidden (so `dispatchDraw` skips them); the ones that
|
|
47
|
+
* only contain glass are then drawn one level deeper with the same rule. Every other child keeps
|
|
48
|
+
* going through the normal fast path (a RenderNode reference). That is safe: nothing inside those
|
|
49
|
+
* subtrees is ever hidden, so a display list that happens to be re-recorded here is exactly what
|
|
50
|
+
* the regular frame would record, and it cannot reference a skipped glass view. It also keeps the
|
|
51
|
+
* backdrop live for free — when such a child re-records its display list or animates its
|
|
52
|
+
* RenderNode properties, the backdrop sees it.
|
|
42
53
|
*
|
|
43
54
|
* Glass views that are *ancestors* of the sampling one are not skipped: glass on top of a glass
|
|
44
55
|
* card sees the card. That cannot form a cycle, because an ancestor never samples its own subtree.
|
|
45
56
|
*
|
|
46
|
-
* Known trade-offs
|
|
47
|
-
*
|
|
48
|
-
*
|
|
57
|
+
* Known trade-offs: the children of ancestors are drawn without their view Animation and
|
|
58
|
+
* elevation shadow; inside an expanded container that is not an ancestor, glass-containing
|
|
59
|
+
* branches are drawn after their siblings, so a sibling that normally paints above such a branch
|
|
60
|
+
* ends up below it in the backdrop.
|
|
49
61
|
*/
|
|
50
|
-
@RequiresApi(Build.VERSION_CODES.Q) // View.setTransitionVisibility
|
|
62
|
+
@RequiresApi(Build.VERSION_CODES.Q) // View.setTransitionVisibility, ViewGroup.getChildDrawingOrder(int)
|
|
51
63
|
internal class ViewBackdropCapture {
|
|
52
64
|
|
|
53
65
|
/** Containers that have at least one skipped glass view somewhere below them. */
|
|
@@ -56,7 +68,7 @@ internal class ViewBackdropCapture {
|
|
|
56
68
|
/** Glass views that are never drawn into this backdrop. */
|
|
57
69
|
private val excluded = HashSet<View>()
|
|
58
70
|
|
|
59
|
-
/** Ancestors of the sampling glass view, up to the source. */
|
|
71
|
+
/** Ancestors of the sampling glass view, up to the source. They are being drawn right now. */
|
|
60
72
|
private val selfPath = HashSet<View>()
|
|
61
73
|
|
|
62
74
|
private val path = ArrayList<View>()
|
|
@@ -114,6 +126,11 @@ internal class ViewBackdropCapture {
|
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
private fun drawLevel(canvas: Canvas, host: View) {
|
|
129
|
+
if (host is ViewGroup && host in selfPath) {
|
|
130
|
+
drawAncestor(canvas, host)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
117
134
|
val group = if (host in expanded) host as? ViewGroup else null
|
|
118
135
|
val firstHidden = hidden.size
|
|
119
136
|
if (group != null) {
|
|
@@ -149,13 +166,7 @@ internal class ViewBackdropCapture {
|
|
|
149
166
|
val childSave = canvas.save()
|
|
150
167
|
// Same transform the parent applies when it draws the child normally.
|
|
151
168
|
canvas.translate((child.left - host.scrollX).toFloat(), (child.top - host.scrollY).toFloat())
|
|
152
|
-
|
|
153
|
-
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
154
|
-
if (clipChildren) canvas.clipRect(0f, 0f, child.width.toFloat(), child.height.toFloat())
|
|
155
|
-
val alpha = child.alpha
|
|
156
|
-
if (alpha < 1f) {
|
|
157
|
-
canvas.saveLayerAlpha(0f, 0f, child.width.toFloat(), child.height.toFloat(), (alpha * 255f).toInt())
|
|
158
|
-
}
|
|
169
|
+
applyChildTransform(canvas, child, clipChildren)
|
|
159
170
|
drawLevel(canvas, child)
|
|
160
171
|
canvas.restoreToCount(childSave)
|
|
161
172
|
}
|
|
@@ -166,6 +177,63 @@ internal class ViewBackdropCapture {
|
|
|
166
177
|
}
|
|
167
178
|
}
|
|
168
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Draws an ancestor of the sampling glass view without calling its draw() (see the class
|
|
182
|
+
* comment): its background, then its children in drawing order.
|
|
183
|
+
*/
|
|
184
|
+
private fun drawAncestor(canvas: Canvas, host: ViewGroup) {
|
|
185
|
+
val save = canvas.save()
|
|
186
|
+
try {
|
|
187
|
+
// View.draw() paints the background at the view's origin, whatever its scroll offset.
|
|
188
|
+
host.background?.draw(canvas)
|
|
189
|
+
canvas.translate(-host.scrollX.toFloat(), -host.scrollY.toFloat())
|
|
190
|
+
val clipChildren = host.clipChildren
|
|
191
|
+
for (child in childrenInDrawingOrder(host)) {
|
|
192
|
+
if (child in excluded) continue
|
|
193
|
+
// Same visibility rule as ViewGroup.dispatchDraw.
|
|
194
|
+
if (child.visibility != View.VISIBLE && child.animation == null) continue
|
|
195
|
+
val childSave = canvas.save()
|
|
196
|
+
canvas.translate(child.left.toFloat(), child.top.toFloat())
|
|
197
|
+
applyChildTransform(canvas, child, clipChildren)
|
|
198
|
+
if (child in expanded) {
|
|
199
|
+
drawLevel(canvas, child)
|
|
200
|
+
} else {
|
|
201
|
+
canvas.translate(-child.scrollX.toFloat(), -child.scrollY.toFloat())
|
|
202
|
+
child.draw(canvas)
|
|
203
|
+
}
|
|
204
|
+
canvas.restoreToCount(childSave)
|
|
205
|
+
}
|
|
206
|
+
} finally {
|
|
207
|
+
canvas.restoreToCount(save)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The child's matrix, clip and alpha, as its parent applies them; the canvas is at its left/top. */
|
|
212
|
+
private fun applyChildTransform(canvas: Canvas, child: View, clipChildren: Boolean) {
|
|
213
|
+
val matrix = child.matrix
|
|
214
|
+
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
215
|
+
if (clipChildren) canvas.clipRect(0f, 0f, child.width.toFloat(), child.height.toFloat())
|
|
216
|
+
val alpha = child.alpha
|
|
217
|
+
if (alpha < 1f) {
|
|
218
|
+
canvas.saveLayerAlpha(0f, 0f, child.width.toFloat(), child.height.toFloat(), (alpha * 255f).toInt())
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The children in the order their parent draws them, like ViewGroup.buildOrderedChildList: the
|
|
224
|
+
* custom drawing order (React Native's zIndex), then elevation, stable.
|
|
225
|
+
*/
|
|
226
|
+
private fun childrenInDrawingOrder(group: ViewGroup): List<View> {
|
|
227
|
+
val count = group.childCount
|
|
228
|
+
val children = ArrayList<View>(count)
|
|
229
|
+
for (i in 0 until count) {
|
|
230
|
+
val index = group.getChildDrawingOrder(i)
|
|
231
|
+
children.add(group.getChildAt(if (index in 0 until count) index else i))
|
|
232
|
+
}
|
|
233
|
+
children.sortBy { it.z }
|
|
234
|
+
return children
|
|
235
|
+
}
|
|
236
|
+
|
|
169
237
|
companion object {
|
|
170
238
|
private var depth = 0
|
|
171
239
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-android-glass-view",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Liquid Glass views, buttons, sliders and toggles for React Native on Android (Jetpack Compose, powered by Kyant0/AndroidLiquidGlass)",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|