expo-android-glass-view 0.1.1 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2 — 2026-09-10
4
+
5
+ - Fix a crash when a glass view sits inside a react-native-screens stack (Expo Router and React
6
+ Navigation native stacks): `IllegalStateException: Recording currently in progress`. While a
7
+ glass view captures its backdrop, its ancestors are still being drawn; the capture no longer
8
+ calls their `draw()` again but draws their background and children itself.
9
+ - New native constant `captureRevision` (2), so JS can tell a fixed binary from an older one.
10
+
3
11
  ## 0.1.0 — 2026-09-10
4
12
 
5
13
  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") { 2 }
17
+
13
18
  View(AndroidGlassView::class) {
14
19
  Name("AndroidGlassView")
15
20
 
@@ -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, and expanded branches are positioned with the framework's own child
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 recording.** A glass view samples while it is being drawn, so the RenderNodes
25
- * of its ancestors can be in the middle of `beginRecording`. Drawing one of them again through
26
- * `drawChild` → `updateDisplayListIfDirty` throws
27
- * `IllegalStateException: Recording currently in progress`.
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 every container that has a skipped glass view somewhere below it (an *expanded* container)
34
- * is drawn with the public [View.draw], which neither touches its RenderNode nor records a
35
- * reference to it. For that call, its children that are skipped glass views or contain one are
36
- * hidden (so `dispatchDraw` skips them); the ones that only contain glass are then drawn one level
37
- * deeper with the same rule. Every other child keeps going through the normal fast path (a
38
- * RenderNode reference). That is safe: nothing inside those subtrees is ever hidden, so a display
39
- * list that happens to be re-recorded here is exactly what the regular frame would record, and it
40
- * cannot reference a skipped glass view. It also keeps the backdrop live for free — when such a
41
- * child re-records its display list or animates its RenderNode properties, the backdrop sees it.
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 (same as upstream): inside an expanded container, glass-containing branches
47
- * are drawn after their siblings, so a sibling that normally paints above such a branch ends up
48
- * below it in the backdrop; elevation shadows of expanded branches are not drawn.
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
- val matrix = child.matrix
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.1",
3
+ "version": "0.1.2",
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",