expo-android-glass-view 0.1.0

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 (140) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +55 -0
  3. package/README.md +260 -0
  4. package/THIRD_PARTY_NOTICES.md +44 -0
  5. package/android/build.gradle +39 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/expo/modules/androidglassview/AndroidGlassBottomTabs.kt +162 -0
  8. package/android/src/main/java/expo/modules/androidglassview/AndroidGlassButton.kt +45 -0
  9. package/android/src/main/java/expo/modules/androidglassview/AndroidGlassSlider.kt +84 -0
  10. package/android/src/main/java/expo/modules/androidglassview/AndroidGlassToggle.kt +59 -0
  11. package/android/src/main/java/expo/modules/androidglassview/AndroidGlassView.kt +21 -0
  12. package/android/src/main/java/expo/modules/androidglassview/ControlledProp.kt +30 -0
  13. package/android/src/main/java/expo/modules/androidglassview/ExpoAndroidGlassViewModule.kt +210 -0
  14. package/android/src/main/java/expo/modules/androidglassview/GlassHostView.kt +346 -0
  15. package/android/src/main/java/expo/modules/androidglassview/GlassRegistry.kt +31 -0
  16. package/android/src/main/java/expo/modules/androidglassview/GlassSurface.kt +96 -0
  17. package/android/src/main/java/expo/modules/androidglassview/ViewBackdrop.kt +151 -0
  18. package/android/src/main/java/expo/modules/androidglassview/backdrop/Backdrop.kt +25 -0
  19. package/android/src/main/java/expo/modules/androidglassview/backdrop/BackdropEffectScope.kt +82 -0
  20. package/android/src/main/java/expo/modules/androidglassview/backdrop/DrawBackdropModifier.kt +397 -0
  21. package/android/src/main/java/expo/modules/androidglassview/backdrop/Platform.kt +18 -0
  22. package/android/src/main/java/expo/modules/androidglassview/backdrop/RuntimeShader.kt +94 -0
  23. package/android/src/main/java/expo/modules/androidglassview/backdrop/RuntimeShaderCache.kt +28 -0
  24. package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/Backdrop.kt +45 -0
  25. package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/CanvasBackdrop.kt +43 -0
  26. package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/CombinedBackdrop.kt +107 -0
  27. package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/EmptyBackdrop.kt +33 -0
  28. package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/LayerBackdrop.kt +82 -0
  29. package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/LayerBackdropModifier.kt +77 -0
  30. package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/Blur.kt +37 -0
  31. package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/ColorFilter.kt +83 -0
  32. package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/Lens.kt +117 -0
  33. package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/RenderEffect.kt +41 -0
  34. package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/Highlight.kt +36 -0
  35. package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/HighlightModifier.kt +174 -0
  36. package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/HighlightStyle.kt +146 -0
  37. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/InverseLayerScope.kt +138 -0
  38. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/LayerRecorder.kt +34 -0
  39. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/Outline.kt +26 -0
  40. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/Paint.kt +24 -0
  41. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/RenderEffect.kt +58 -0
  42. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/Shaders.kt +206 -0
  43. package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/ShapeProvider.kt +52 -0
  44. package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/InnerShadow.kt +49 -0
  45. package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/InnerShadowModifier.kt +166 -0
  46. package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/Shadow.kt +35 -0
  47. package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/ShadowModifier.kt +145 -0
  48. package/android/src/main/java/expo/modules/androidglassview/capture/ViewBackdropCapture.kt +176 -0
  49. package/android/src/main/java/expo/modules/androidglassview/components/CapsuleShape.kt +10 -0
  50. package/android/src/main/java/expo/modules/androidglassview/components/DampedDragAnimation.kt +152 -0
  51. package/android/src/main/java/expo/modules/androidglassview/components/DragGestureInspector.kt +91 -0
  52. package/android/src/main/java/expo/modules/androidglassview/components/InteractiveHighlight.kt +127 -0
  53. package/android/src/main/java/expo/modules/androidglassview/components/LiquidBottomTabs.kt +471 -0
  54. package/android/src/main/java/expo/modules/androidglassview/components/LiquidButton.kt +111 -0
  55. package/android/src/main/java/expo/modules/androidglassview/components/LiquidSlider.kt +227 -0
  56. package/android/src/main/java/expo/modules/androidglassview/components/LiquidToggle.kt +220 -0
  57. package/android/src/main/java/expo/modules/androidglassview/components/TabsFrame.kt +18 -0
  58. package/build/AndroidGlassBottomTabs.android.d.ts +4 -0
  59. package/build/AndroidGlassBottomTabs.android.d.ts.map +1 -0
  60. package/build/AndroidGlassBottomTabs.android.js +42 -0
  61. package/build/AndroidGlassBottomTabs.android.js.map +1 -0
  62. package/build/AndroidGlassBottomTabs.d.ts +5 -0
  63. package/build/AndroidGlassBottomTabs.d.ts.map +1 -0
  64. package/build/AndroidGlassBottomTabs.js +34 -0
  65. package/build/AndroidGlassBottomTabs.js.map +1 -0
  66. package/build/AndroidGlassButton.android.d.ts +4 -0
  67. package/build/AndroidGlassButton.android.d.ts.map +1 -0
  68. package/build/AndroidGlassButton.android.js +32 -0
  69. package/build/AndroidGlassButton.android.js.map +1 -0
  70. package/build/AndroidGlassButton.d.ts +5 -0
  71. package/build/AndroidGlassButton.d.ts.map +1 -0
  72. package/build/AndroidGlassButton.js +38 -0
  73. package/build/AndroidGlassButton.js.map +1 -0
  74. package/build/AndroidGlassComponents.types.d.ts +71 -0
  75. package/build/AndroidGlassComponents.types.d.ts.map +1 -0
  76. package/build/AndroidGlassComponents.types.js +2 -0
  77. package/build/AndroidGlassComponents.types.js.map +1 -0
  78. package/build/AndroidGlassSlider.android.d.ts +4 -0
  79. package/build/AndroidGlassSlider.android.d.ts.map +1 -0
  80. package/build/AndroidGlassSlider.android.js +27 -0
  81. package/build/AndroidGlassSlider.android.js.map +1 -0
  82. package/build/AndroidGlassSlider.d.ts +5 -0
  83. package/build/AndroidGlassSlider.d.ts.map +1 -0
  84. package/build/AndroidGlassSlider.js +47 -0
  85. package/build/AndroidGlassSlider.js.map +1 -0
  86. package/build/AndroidGlassTab.d.ts +9 -0
  87. package/build/AndroidGlassTab.d.ts.map +1 -0
  88. package/build/AndroidGlassTab.js +22 -0
  89. package/build/AndroidGlassTab.js.map +1 -0
  90. package/build/AndroidGlassToggle.android.d.ts +4 -0
  91. package/build/AndroidGlassToggle.android.d.ts.map +1 -0
  92. package/build/AndroidGlassToggle.android.js +27 -0
  93. package/build/AndroidGlassToggle.android.js.map +1 -0
  94. package/build/AndroidGlassToggle.d.ts +5 -0
  95. package/build/AndroidGlassToggle.d.ts.map +1 -0
  96. package/build/AndroidGlassToggle.js +7 -0
  97. package/build/AndroidGlassToggle.js.map +1 -0
  98. package/build/AndroidGlassView.android.d.ts +4 -0
  99. package/build/AndroidGlassView.android.d.ts.map +1 -0
  100. package/build/AndroidGlassView.android.js +10 -0
  101. package/build/AndroidGlassView.android.js.map +1 -0
  102. package/build/AndroidGlassView.d.ts +8 -0
  103. package/build/AndroidGlassView.d.ts.map +1 -0
  104. package/build/AndroidGlassView.js +18 -0
  105. package/build/AndroidGlassView.js.map +1 -0
  106. package/build/AndroidGlassView.types.d.ts +34 -0
  107. package/build/AndroidGlassView.types.d.ts.map +1 -0
  108. package/build/AndroidGlassView.types.js +2 -0
  109. package/build/AndroidGlassView.types.js.map +1 -0
  110. package/build/index.d.ts +10 -0
  111. package/build/index.d.ts.map +1 -0
  112. package/build/index.js +12 -0
  113. package/build/index.js.map +1 -0
  114. package/build/useMinimizeOnScroll.d.ts +17 -0
  115. package/build/useMinimizeOnScroll.d.ts.map +1 -0
  116. package/build/useMinimizeOnScroll.js +39 -0
  117. package/build/useMinimizeOnScroll.js.map +1 -0
  118. package/build/utils.d.ts +5 -0
  119. package/build/utils.d.ts.map +1 -0
  120. package/build/utils.js +9 -0
  121. package/build/utils.js.map +1 -0
  122. package/expo-module.config.json +6 -0
  123. package/package.json +58 -0
  124. package/src/AndroidGlassBottomTabs.android.tsx +93 -0
  125. package/src/AndroidGlassBottomTabs.tsx +59 -0
  126. package/src/AndroidGlassButton.android.tsx +70 -0
  127. package/src/AndroidGlassButton.tsx +70 -0
  128. package/src/AndroidGlassComponents.types.ts +76 -0
  129. package/src/AndroidGlassSlider.android.tsx +70 -0
  130. package/src/AndroidGlassSlider.tsx +78 -0
  131. package/src/AndroidGlassTab.tsx +29 -0
  132. package/src/AndroidGlassToggle.android.tsx +64 -0
  133. package/src/AndroidGlassToggle.tsx +22 -0
  134. package/src/AndroidGlassView.android.tsx +41 -0
  135. package/src/AndroidGlassView.tsx +41 -0
  136. package/src/AndroidGlassView.types.ts +34 -0
  137. package/src/index.ts +11 -0
  138. package/src/useMinimizeOnScroll.ts +53 -0
  139. package/src/utils.ts +10 -0
  140. package/tsconfig.json +28 -0
@@ -0,0 +1,176 @@
1
+ /*
2
+ * Adapted from BackdropCapture.kt in QWEA0/Liquid-Glass-Android
3
+ * (https://github.com/QWEA0/Liquid-Glass-Android), Copyright (c) 2025-2026 pandadog,
4
+ * released under the MIT License. See THIRD_PARTY_NOTICES.md.
5
+ *
6
+ * Changes from upstream: renamed, comments translated, generalised from "skip the one glass
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.
10
+ */
11
+ package expo.modules.androidglassview.capture
12
+
13
+ import android.graphics.Canvas
14
+ import android.os.Build
15
+ import android.view.View
16
+ import android.view.ViewGroup
17
+ import androidx.annotation.RequiresApi
18
+
19
+ /**
20
+ * Draws a source view's content into a canvas while leaving glass views out of it.
21
+ *
22
+ * A plain `source.draw(canvas)` is only safe when no glass view lives under `source`:
23
+ *
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`.
28
+ * 2. **Reference cycles.** `drawChild` records a *reference* to a child's RenderNode, not pixels.
29
+ * If that subtree contains the sampling glass, the glass would draw itself (glass → backdrop →
30
+ * ancestor → glass), which recurses forever on the RenderThread. The same happens between two
31
+ * glass views that sample each other.
32
+ *
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.
42
+ *
43
+ * Glass views that are *ancestors* of the sampling one are not skipped: glass on top of a glass
44
+ * card sees the card. That cannot form a cycle, because an ancestor never samples its own subtree.
45
+ *
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.
49
+ */
50
+ @RequiresApi(Build.VERSION_CODES.Q) // View.setTransitionVisibility
51
+ internal class ViewBackdropCapture {
52
+
53
+ /** Containers that have at least one skipped glass view somewhere below them. */
54
+ private val expanded = HashSet<View>()
55
+
56
+ /** Glass views that are never drawn into this backdrop. */
57
+ private val excluded = HashSet<View>()
58
+
59
+ /** Ancestors of the sampling glass view, up to the source. */
60
+ private val selfPath = HashSet<View>()
61
+
62
+ private val path = ArrayList<View>()
63
+
64
+ /** Children hidden for the current `View.draw` calls, stacked per level. */
65
+ private val hidden = ArrayList<View>()
66
+
67
+ /**
68
+ * @param canvas a hardware canvas whose origin is aligned with [source]'s top-left corner.
69
+ * @param self the glass view that is sampling.
70
+ * @param glassViews every glass view; the ones outside [source] are ignored.
71
+ */
72
+ fun draw(canvas: Canvas, source: View, self: View, glassViews: Collection<View>) {
73
+ expanded.clear()
74
+ excluded.clear()
75
+ selfPath.clear()
76
+
77
+ var ancestor = self.parent
78
+ while (ancestor is View) {
79
+ selfPath.add(ancestor)
80
+ if (ancestor === source) break
81
+ ancestor = ancestor.parent
82
+ }
83
+
84
+ for (glass in glassViews) {
85
+ if (glass === source || glass in selfPath) continue
86
+ path.clear()
87
+ var parent = glass.parent
88
+ var reachedSource = false
89
+ while (parent is View) {
90
+ path.add(parent)
91
+ if (parent === source) {
92
+ reachedSource = true
93
+ break
94
+ }
95
+ parent = parent.parent
96
+ }
97
+ if (reachedSource) {
98
+ excluded.add(glass)
99
+ expanded.addAll(path)
100
+ }
101
+ }
102
+ path.clear()
103
+
104
+ depth++
105
+ val save = canvas.save()
106
+ try {
107
+ canvas.clipRect(0f, 0f, source.width.toFloat(), source.height.toFloat())
108
+ drawLevel(canvas, source)
109
+ } finally {
110
+ canvas.restoreToCount(save)
111
+ hidden.clear()
112
+ depth--
113
+ }
114
+ }
115
+
116
+ private fun drawLevel(canvas: Canvas, host: View) {
117
+ val group = if (host in expanded) host as? ViewGroup else null
118
+ val firstHidden = hidden.size
119
+ if (group != null) {
120
+ for (i in 0 until group.childCount) {
121
+ val child = group.getChildAt(i)
122
+ if (child.visibility == View.VISIBLE && (child in excluded || child in expanded)) {
123
+ // Only flips the visibility flag; does not invalidate anything.
124
+ child.setTransitionVisibility(View.INVISIBLE)
125
+ hidden.add(child)
126
+ }
127
+ }
128
+ }
129
+ val lastHidden = hidden.size
130
+
131
+ val save = canvas.save()
132
+ try {
133
+ // The public View.draw() does not apply the view's own scroll offset (the framework does
134
+ // that in updateDisplayListIfDirty), so apply it here.
135
+ canvas.translate(-host.scrollX.toFloat(), -host.scrollY.toFloat())
136
+ host.draw(canvas)
137
+ } finally {
138
+ canvas.restoreToCount(save)
139
+ for (i in firstHidden until lastHidden) {
140
+ hidden[i].setTransitionVisibility(View.VISIBLE)
141
+ }
142
+ }
143
+
144
+ if (group != null) {
145
+ val clipChildren = group.clipChildren
146
+ for (i in firstHidden until lastHidden) {
147
+ val child = hidden[i]
148
+ if (child in excluded) continue
149
+ val childSave = canvas.save()
150
+ // Same transform the parent applies when it draws the child normally.
151
+ 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
+ }
159
+ drawLevel(canvas, child)
160
+ canvas.restoreToCount(childSave)
161
+ }
162
+ }
163
+
164
+ while (hidden.size > firstHidden) {
165
+ hidden.removeAt(hidden.size - 1)
166
+ }
167
+ }
168
+
169
+ companion object {
170
+ private var depth = 0
171
+
172
+ /** True while any glass view is sampling (main thread only). */
173
+ val isCapturing: Boolean
174
+ get() = depth > 0
175
+ }
176
+ }
@@ -0,0 +1,10 @@
1
+ package expo.modules.androidglassview.components
2
+
3
+ import androidx.compose.foundation.shape.RoundedCornerShape
4
+ import androidx.compose.ui.graphics.Shape
5
+
6
+ /**
7
+ * Stand-in for Kyant's `Capsule()` from io.github.kyant0:shapes (not bundled). A circular-corner
8
+ * capsule instead of a continuous-curvature one; the lens effect supports any CornerBasedShape.
9
+ */
10
+ internal val CapsuleShape: Shape = RoundedCornerShape(percent = 50)
@@ -0,0 +1,152 @@
1
+ /*
2
+ * Copyright 2025 Kyant (https://github.com/Kyant0/AndroidLiquidGlass)
3
+ * Licensed under the Apache License, Version 2.0. See THIRD_PARTY_NOTICES.md.
4
+ *
5
+ * From the Backdrop Catalog sample app. Changes from upstream: package relocated, made internal,
6
+ * onDragStopped reports whether the drag was cancelled, kotlin.time.Clock replaced by
7
+ * SystemClock (Kotlin 2.1 compatible), moveToValue added.
8
+ */
9
+ package expo.modules.androidglassview.components
10
+
11
+ import android.os.SystemClock
12
+ import androidx.compose.animation.core.Animatable
13
+ import androidx.compose.animation.core.spring
14
+ import androidx.compose.foundation.MutatorMutex
15
+ import androidx.compose.runtime.snapshotFlow
16
+ import androidx.compose.ui.Modifier
17
+ import androidx.compose.ui.geometry.Offset
18
+ import androidx.compose.ui.input.pointer.pointerInput
19
+ import androidx.compose.ui.input.pointer.util.VelocityTracker
20
+ import androidx.compose.ui.unit.IntSize
21
+ import kotlinx.coroutines.CoroutineScope
22
+ import kotlinx.coroutines.android.awaitFrame
23
+ import kotlinx.coroutines.flow.filter
24
+ import kotlinx.coroutines.flow.first
25
+ import kotlinx.coroutines.launch
26
+ import kotlin.math.abs
27
+
28
+ internal class DampedDragAnimation(
29
+ private val animationScope: CoroutineScope,
30
+ val initialValue: Float,
31
+ val valueRange: ClosedRange<Float>,
32
+ val visibilityThreshold: Float,
33
+ val initialScale: Float,
34
+ val pressedScale: Float,
35
+ val onDragStarted: DampedDragAnimation.(position: Offset) -> Unit,
36
+ val onDragStopped: DampedDragAnimation.(cancelled: Boolean) -> Unit,
37
+ val onDrag: DampedDragAnimation.(size: IntSize, dragAmount: Offset) -> Unit,
38
+ ) {
39
+
40
+ private val valueAnimationSpec =
41
+ spring(1f, 1000f, visibilityThreshold)
42
+ private val velocityAnimationSpec =
43
+ spring(0.5f, 300f, visibilityThreshold * 10f)
44
+ private val pressProgressAnimationSpec =
45
+ spring(1f, 1000f, 0.001f)
46
+ private val scaleXAnimationSpec =
47
+ spring(0.6f, 250f, 0.001f)
48
+ private val scaleYAnimationSpec =
49
+ spring(0.7f, 250f, 0.001f)
50
+
51
+ private val valueAnimation =
52
+ Animatable(initialValue, visibilityThreshold)
53
+ private val velocityAnimation =
54
+ Animatable(0f, 5f)
55
+ private val pressProgressAnimation =
56
+ Animatable(0f, 0.001f)
57
+ private val scaleXAnimation =
58
+ Animatable(initialScale, 0.001f)
59
+ private val scaleYAnimation =
60
+ Animatable(initialScale, 0.001f)
61
+
62
+ private val mutatorMutex = MutatorMutex()
63
+
64
+ private val velocityTracker = VelocityTracker()
65
+
66
+ val value: Float get() = valueAnimation.value
67
+ val progress: Float get() = (value - valueRange.start) / (valueRange.endInclusive - valueRange.start)
68
+ val targetValue: Float get() = valueAnimation.targetValue
69
+ val pressProgress: Float get() = pressProgressAnimation.value
70
+ val scaleX: Float get() = scaleXAnimation.value
71
+ val scaleY: Float get() = scaleYAnimation.value
72
+ val velocity: Float get() = velocityAnimation.value
73
+
74
+ val modifier: Modifier = Modifier.pointerInput(Unit) {
75
+ inspectDragGestures(
76
+ onDragStart = { down ->
77
+ onDragStarted(down.position)
78
+ press()
79
+ },
80
+ onDragEnd = {
81
+ onDragStopped(false)
82
+ release()
83
+ },
84
+ onDragCancel = {
85
+ onDragStopped(true)
86
+ release()
87
+ }
88
+ ) { _, dragAmount ->
89
+ onDrag(size, dragAmount)
90
+ }
91
+ }
92
+
93
+ fun press() {
94
+ velocityTracker.resetTracking()
95
+ animationScope.launch {
96
+ launch { pressProgressAnimation.animateTo(1f, pressProgressAnimationSpec) }
97
+ launch { scaleXAnimation.animateTo(pressedScale, scaleXAnimationSpec) }
98
+ launch { scaleYAnimation.animateTo(pressedScale, scaleYAnimationSpec) }
99
+ }
100
+ }
101
+
102
+ fun release() {
103
+ animationScope.launch {
104
+ awaitFrame()
105
+ if (value != targetValue) {
106
+ val threshold = (valueRange.endInclusive - valueRange.start) * 0.025f
107
+ snapshotFlow { valueAnimation.value }
108
+ .filter { abs(it - valueAnimation.targetValue) < threshold }
109
+ .first()
110
+ }
111
+ launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }
112
+ launch { scaleXAnimation.animateTo(initialScale, scaleXAnimationSpec) }
113
+ launch { scaleYAnimation.animateTo(initialScale, scaleYAnimationSpec) }
114
+ }
115
+ }
116
+
117
+ fun updateValue(value: Float) {
118
+ val targetValue = value.coerceIn(valueRange)
119
+ animationScope.launch {
120
+ launch { valueAnimation.animateTo(targetValue, valueAnimationSpec) { updateVelocity() } }
121
+ }
122
+ }
123
+
124
+ /** Like [updateValue] but without feeding the velocity, so a jump does not stretch the glass. */
125
+ fun moveToValue(value: Float) {
126
+ val targetValue = value.coerceIn(valueRange)
127
+ animationScope.launch { valueAnimation.animateTo(targetValue, valueAnimationSpec) }
128
+ }
129
+
130
+ fun animateToValue(value: Float) {
131
+ animationScope.launch {
132
+ mutatorMutex.mutate {
133
+ press()
134
+ val targetValue = value.coerceIn(valueRange)
135
+ launch { valueAnimation.animateTo(targetValue, valueAnimationSpec) }
136
+ if (velocity != 0f) {
137
+ launch { velocityAnimation.animateTo(0f, velocityAnimationSpec) }
138
+ }
139
+ release()
140
+ }
141
+ }
142
+ }
143
+
144
+ private fun updateVelocity() {
145
+ velocityTracker.addPosition(
146
+ SystemClock.uptimeMillis(),
147
+ Offset(value, 0f)
148
+ )
149
+ val targetVelocity = velocityTracker.calculateVelocity().x / (valueRange.endInclusive - valueRange.start)
150
+ animationScope.launch { velocityAnimation.animateTo(targetVelocity, velocityAnimationSpec) }
151
+ }
152
+ }
@@ -0,0 +1,91 @@
1
+ /*
2
+ * Copyright 2025 Kyant (https://github.com/Kyant0/AndroidLiquidGlass)
3
+ * Licensed under the Apache License, Version 2.0. See THIRD_PARTY_NOTICES.md.
4
+ *
5
+ * From the Backdrop Catalog sample app. Changes from upstream: package relocated, made internal.
6
+ */
7
+ package expo.modules.androidglassview.components
8
+
9
+ import androidx.compose.foundation.gestures.awaitEachGesture
10
+ import androidx.compose.foundation.gestures.awaitFirstDown
11
+ import androidx.compose.ui.geometry.Offset
12
+ import androidx.compose.ui.input.pointer.AwaitPointerEventScope
13
+ import androidx.compose.ui.input.pointer.PointerEventPass
14
+ import androidx.compose.ui.input.pointer.PointerId
15
+ import androidx.compose.ui.input.pointer.PointerInputChange
16
+ import androidx.compose.ui.input.pointer.PointerInputScope
17
+ import androidx.compose.ui.input.pointer.changedToUpIgnoreConsumed
18
+ import androidx.compose.ui.input.pointer.positionChange
19
+ import androidx.compose.ui.util.fastFirstOrNull
20
+
21
+ internal suspend fun PointerInputScope.inspectDragGestures(
22
+ onDragStart: (down: PointerInputChange) -> Unit = {},
23
+ onDragEnd: (change: PointerInputChange) -> Unit = {},
24
+ onDragCancel: () -> Unit = {},
25
+ onDrag: (change: PointerInputChange, dragAmount: Offset) -> Unit
26
+ ) {
27
+ awaitEachGesture {
28
+ val initialDown = awaitFirstDown(false, PointerEventPass.Initial)
29
+
30
+ val down = awaitFirstDown(false)
31
+ val drag = initialDown
32
+
33
+ onDragStart(down)
34
+ onDrag(drag, Offset.Zero)
35
+ val upEvent =
36
+ drag(
37
+ pointerId = drag.id,
38
+ onDrag = { onDrag(it, it.positionChange()) }
39
+ )
40
+ if (upEvent == null) {
41
+ onDragCancel()
42
+ } else {
43
+ onDragEnd(upEvent)
44
+ }
45
+ }
46
+ }
47
+
48
+ private suspend inline fun AwaitPointerEventScope.drag(
49
+ pointerId: PointerId,
50
+ onDrag: (PointerInputChange) -> Unit
51
+ ): PointerInputChange? {
52
+ val isPointerUp = currentEvent.changes.fastFirstOrNull { it.id == pointerId }?.pressed != true
53
+ if (isPointerUp) {
54
+ return null
55
+ }
56
+ var pointer = pointerId
57
+ while (true) {
58
+ val change = awaitDragOrUp(pointer) ?: return null
59
+ if (change.isConsumed) {
60
+ return null
61
+ }
62
+ if (change.changedToUpIgnoreConsumed()) {
63
+ return change
64
+ }
65
+ onDrag(change)
66
+ pointer = change.id
67
+ }
68
+ }
69
+
70
+ private suspend inline fun AwaitPointerEventScope.awaitDragOrUp(
71
+ pointerId: PointerId
72
+ ): PointerInputChange? {
73
+ var pointer = pointerId
74
+ while (true) {
75
+ val event = awaitPointerEvent()
76
+ val dragEvent = event.changes.fastFirstOrNull { it.id == pointer } ?: return null
77
+ if (dragEvent.changedToUpIgnoreConsumed()) {
78
+ val otherDown = event.changes.fastFirstOrNull { it.pressed }
79
+ if (otherDown == null) {
80
+ return dragEvent
81
+ } else {
82
+ pointer = otherDown.id
83
+ }
84
+ } else {
85
+ val hasDragged = dragEvent.previousPosition != dragEvent.position
86
+ if (hasDragged) {
87
+ return dragEvent
88
+ }
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,127 @@
1
+ /*
2
+ * Copyright 2025 Kyant (https://github.com/Kyant0/AndroidLiquidGlass)
3
+ * Licensed under the Apache License, Version 2.0. See THIRD_PARTY_NOTICES.md.
4
+ *
5
+ * From the Backdrop Catalog sample app. Changes from upstream: package relocated, made internal.
6
+ */
7
+ package expo.modules.androidglassview.components
8
+
9
+ import androidx.compose.animation.core.Animatable
10
+ import androidx.compose.animation.core.VectorConverter
11
+ import androidx.compose.animation.core.VisibilityThreshold
12
+ import androidx.compose.animation.core.spring
13
+ import androidx.compose.ui.Modifier
14
+ import androidx.compose.ui.draw.drawWithContent
15
+ import androidx.compose.ui.geometry.Offset
16
+ import androidx.compose.ui.geometry.Size
17
+ import androidx.compose.ui.graphics.BlendMode
18
+ import androidx.compose.ui.graphics.Color
19
+ import androidx.compose.ui.graphics.ShaderBrush
20
+ import androidx.compose.ui.input.pointer.pointerInput
21
+ import androidx.compose.ui.util.fastCoerceIn
22
+ import expo.modules.androidglassview.backdrop.RuntimeShader
23
+ import expo.modules.androidglassview.backdrop.asComposeShader
24
+ import expo.modules.androidglassview.backdrop.isRuntimeShaderSupported
25
+ import kotlinx.coroutines.CoroutineScope
26
+ import kotlinx.coroutines.launch
27
+
28
+ internal class InteractiveHighlight(
29
+ val animationScope: CoroutineScope,
30
+ val position: (size: Size, offset: Offset) -> Offset = { _, offset -> offset }
31
+ ) {
32
+
33
+ private val pressProgressAnimationSpec =
34
+ spring(0.5f, 300f, 0.001f)
35
+ private val positionAnimationSpec =
36
+ spring(0.5f, 300f, Offset.VisibilityThreshold)
37
+
38
+ private val pressProgressAnimation =
39
+ Animatable(0f, 0.001f)
40
+ private val positionAnimation =
41
+ Animatable(Offset.Zero, Offset.VectorConverter, Offset.VisibilityThreshold)
42
+
43
+ private var startPosition = Offset.Zero
44
+ val pressProgress: Float get() = pressProgressAnimation.value
45
+ val offset: Offset get() = positionAnimation.value - startPosition
46
+
47
+ private val shader =
48
+ if (isRuntimeShaderSupported()) {
49
+ RuntimeShader(
50
+ """
51
+ uniform float2 size;
52
+ layout(color) uniform half4 color;
53
+ uniform float radius;
54
+ uniform float2 position;
55
+
56
+ half4 main(float2 coord) {
57
+ float dist = distance(coord, position);
58
+ float intensity = smoothstep(radius, radius * 0.5, dist);
59
+ return color * intensity;
60
+ }"""
61
+ )
62
+ } else {
63
+ null
64
+ }
65
+
66
+ val modifier: Modifier =
67
+ Modifier.drawWithContent {
68
+ val progress = pressProgressAnimation.value
69
+ if (progress > 0f) {
70
+ if (shader != null) {
71
+ drawRect(
72
+ Color.White.copy(0.08f * progress),
73
+ blendMode = BlendMode.Plus
74
+ )
75
+ shader.apply {
76
+ val position = position(size, positionAnimation.value)
77
+ setFloatUniform("size", size.width, size.height)
78
+ setColorUniform("color", Color.White.copy(0.15f * progress))
79
+ setFloatUniform("radius", size.minDimension * 1.5f)
80
+ setFloatUniform(
81
+ "position",
82
+ position.x.fastCoerceIn(0f, size.width),
83
+ position.y.fastCoerceIn(0f, size.height)
84
+ )
85
+ }
86
+ drawRect(
87
+ ShaderBrush(shader.asComposeShader()),
88
+ blendMode = BlendMode.Plus
89
+ )
90
+ } else {
91
+ drawRect(
92
+ Color.White.copy(0.25f * progress),
93
+ blendMode = BlendMode.Plus
94
+ )
95
+ }
96
+ }
97
+
98
+ drawContent()
99
+ }
100
+
101
+ val gestureModifier: Modifier =
102
+ Modifier.pointerInput(animationScope) {
103
+ inspectDragGestures(
104
+ onDragStart = { down ->
105
+ startPosition = down.position
106
+ animationScope.launch {
107
+ launch { pressProgressAnimation.animateTo(1f, pressProgressAnimationSpec) }
108
+ launch { positionAnimation.snapTo(startPosition) }
109
+ }
110
+ },
111
+ onDragEnd = {
112
+ animationScope.launch {
113
+ launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }
114
+ launch { positionAnimation.animateTo(startPosition, positionAnimationSpec) }
115
+ }
116
+ },
117
+ onDragCancel = {
118
+ animationScope.launch {
119
+ launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }
120
+ launch { positionAnimation.animateTo(startPosition, positionAnimationSpec) }
121
+ }
122
+ }
123
+ ) { change, _ ->
124
+ animationScope.launch { positionAnimation.snapTo(change.position) }
125
+ }
126
+ }
127
+ }