expo-android-glass-view 0.1.8 → 0.1.9
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 +3 -29
- package/README.md +6 -6
- package/android/build.gradle +2 -5
- package/android/src/main/java/expo/modules/androidglassview/ExpoAndroidGlassViewModule.kt +1 -1
- package/android/src/main/java/expo/modules/androidglassview/GlassHostView.kt +17 -11
- package/android/src/main/java/expo/modules/androidglassview/ViewBackdrop.kt +0 -8
- package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/HighlightModifier.kt +24 -46
- package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/InnerShadowModifier.kt +12 -33
- package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/ShadowModifier.kt +16 -42
- package/android/src/main/java/expo/modules/androidglassview/capture/ViewBackdropCapture.kt +9 -227
- package/build/AndroidGlassComponents.types.d.ts +1 -1
- package/build/AndroidGlassComponents.types.js.map +1 -1
- package/package.json +2 -2
- package/src/AndroidGlassComponents.types.ts +1 -1
- package/tsconfig.json +6 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,35 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.
|
|
3
|
+
## 0.1.9 — 2026-09-14
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
screens. Manually applied transforms and alpha are tracked too, including drawer movement.
|
|
8
|
-
All glass components share this fix; referenced lists still scroll without re-capturing.
|
|
9
|
-
- `captureRevision` is now 4. Consumer apps need a native rebuild to receive this fix.
|
|
10
|
-
|
|
11
|
-
## 0.1.6 — 2026-09-12
|
|
12
|
-
|
|
13
|
-
- Fix: 0.1.4 and 0.1.5 were published without their compiled JavaScript (`build/`), so Metro
|
|
14
|
-
failed with `Unable to resolve "expo-android-glass-view"`. The native code is the same as in
|
|
15
|
-
0.1.5: an app whose native build already has 0.1.5 only needs the new JavaScript, no rebuild.
|
|
16
|
-
- `prepare` now fails when TypeScript emits nothing, so a package without its JavaScript can't be
|
|
17
|
-
published again.
|
|
18
|
-
|
|
19
|
-
## 0.1.5 — 2026-09-12
|
|
20
|
-
|
|
21
|
-
- Performance: a glass view's capture leaves out everything that cannot reach it. Before, an
|
|
22
|
-
animation anywhere on screen made every glass view re-render its blur and refraction on every
|
|
23
|
-
frame; now only the glass views it can be seen through do. On a screen with 17 glass views over
|
|
24
|
-
an animated backdrop (Helio G99, release build) this took the frame rate from about 20 to about
|
|
25
|
-
70 fps. A left-out view that moves, resizes or scrolls triggers a new capture.
|
|
26
|
-
|
|
27
|
-
- Performance: scrolling no longer re-captures every glass view in the window. A glass view
|
|
28
|
-
captures again only when a container whose scroll offset its capture baked in has scrolled;
|
|
29
|
-
lists it merely references (e.g. a screen's list under a tab bar) scroll live for free.
|
|
30
|
-
- Performance: the drop shadow, inner shadow and rim highlight are only re-recorded when their
|
|
31
|
-
shape or parameters change (not when they fade, and not on every redraw), and are skipped at
|
|
32
|
-
zero alpha.
|
|
5
|
+
- Republish the 0.1.3 implementation with the updated README and npm-compatible demo image URLs.
|
|
6
|
+
- No runtime changes from 0.1.3; supersedes the 0.1.4–0.1.8 publications.
|
|
33
7
|
|
|
34
8
|
## 0.1.3 — 2026-09-11
|
|
35
9
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src=".github/assets/hero.png" alt="Liquid Glass — expo-android-glass-view" width="1040" />
|
|
2
|
+
<img src="https://raw.githubusercontent.com/kagantemizkan/expo-android-glass-view/5a563ac/.github/assets/hero.png" alt="Liquid Glass — expo-android-glass-view" width="1040" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
#
|
|
@@ -67,7 +67,7 @@ A container: children render on top of the glass and stay fully interactive.
|
|
|
67
67
|
</AndroidGlassView>
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
<img src=".github/assets/glasses.gif" alt="AndroidGlassView with different props: default, frosted, lens, prism, tint, no shadow" width="480" />
|
|
70
|
+
<img src="https://raw.githubusercontent.com/kagantemizkan/expo-android-glass-view/5a563ac/.github/assets/glasses.gif" alt="AndroidGlassView with different props: default, frosted, lens, prism, tint, no shadow" width="480" />
|
|
71
71
|
|
|
72
72
|
Accepts every `View` prop plus:
|
|
73
73
|
|
|
@@ -94,7 +94,7 @@ or `surfaceColor` instead.
|
|
|
94
94
|
Kyant's liquid button: while pressed, the glass swells, stretches towards the finger and a
|
|
95
95
|
highlight follows it.
|
|
96
96
|
|
|
97
|
-
<img src=".github/assets/buttons.gif" alt="AndroidGlassButton" width="480" />
|
|
97
|
+
<img src="https://raw.githubusercontent.com/kagantemizkan/expo-android-glass-view/5a563ac/.github/assets/buttons.gif" alt="AndroidGlassButton" width="480" />
|
|
98
98
|
|
|
99
99
|
```tsx
|
|
100
100
|
<AndroidGlassButton title="Save" onPress={save} />
|
|
@@ -120,7 +120,7 @@ don't put interactive elements in a button.
|
|
|
120
120
|
|
|
121
121
|
## `AndroidGlassToggle`
|
|
122
122
|
|
|
123
|
-
<img src=".github/assets/toggles.gif" alt="AndroidGlassToggle" width="480" />
|
|
123
|
+
<img src="https://raw.githubusercontent.com/kagantemizkan/expo-android-glass-view/5a563ac/.github/assets/toggles.gif" alt="AndroidGlassToggle" width="480" />
|
|
124
124
|
|
|
125
125
|
```tsx
|
|
126
126
|
<AndroidGlassToggle value={enabled} onValueChange={setEnabled} />
|
|
@@ -141,7 +141,7 @@ new value, the switch returns to `value`.
|
|
|
141
141
|
|
|
142
142
|
## `AndroidGlassSlider`
|
|
143
143
|
|
|
144
|
-
<img src=".github/assets/sliders.gif" alt="AndroidGlassSlider" width="480" />
|
|
144
|
+
<img src="https://raw.githubusercontent.com/kagantemizkan/expo-android-glass-view/5a563ac/.github/assets/sliders.gif" alt="AndroidGlassSlider" width="480" />
|
|
145
145
|
|
|
146
146
|
```tsx
|
|
147
147
|
<AndroidGlassSlider value={volume} maximumValue={100} onValueChange={setVolume} />
|
|
@@ -169,7 +169,7 @@ Kyant's iOS 26 style tab bar: a glass capsule with a liquid selection droplet yo
|
|
|
169
169
|
between tabs. Under the droplet the tab content takes the accent colour and is magnified while
|
|
170
170
|
pressed.
|
|
171
171
|
|
|
172
|
-
<img src=".github/assets/tabbar.gif" alt="AndroidGlassBottomTabs" width="480" />
|
|
172
|
+
<img src="https://raw.githubusercontent.com/kagantemizkan/expo-android-glass-view/5a563ac/.github/assets/tabbar.gif" alt="AndroidGlassBottomTabs" width="480" />
|
|
173
173
|
|
|
174
174
|
```tsx
|
|
175
175
|
<AndroidGlassBottomTabs
|
package/android/build.gradle
CHANGED
|
@@ -14,14 +14,13 @@ plugins {
|
|
|
14
14
|
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
|
|
15
15
|
|
|
16
16
|
group = 'expo.modules.androidglassview'
|
|
17
|
-
version = '0.1.
|
|
17
|
+
version = '0.1.0'
|
|
18
18
|
|
|
19
19
|
android {
|
|
20
20
|
namespace "expo.modules.androidglassview"
|
|
21
21
|
defaultConfig {
|
|
22
22
|
versionCode 1
|
|
23
|
-
versionName "0.1.
|
|
24
|
-
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
|
23
|
+
versionName "0.1.0"
|
|
25
24
|
}
|
|
26
25
|
buildFeatures {
|
|
27
26
|
compose true
|
|
@@ -37,6 +36,4 @@ dependencies {
|
|
|
37
36
|
// Same Compose version as @expo/ui for this Expo SDK, so apps using both resolve one runtime.
|
|
38
37
|
implementation 'androidx.compose.foundation:foundation-android:1.10.6'
|
|
39
38
|
implementation 'androidx.compose.ui:ui-android:1.10.6'
|
|
40
|
-
androidTestImplementation 'androidx.test:runner:1.6.2'
|
|
41
|
-
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
|
42
39
|
}
|
|
@@ -13,7 +13,7 @@ class ExpoAndroidGlassViewModule : Module() {
|
|
|
13
13
|
// Bumped when the backdrop capture changes in a way JS may need to know about.
|
|
14
14
|
// 2: ancestors of a sampling glass view are never drawn again through their own draw()
|
|
15
15
|
// (0.1.1 crashed inside react-native-screens stacks).
|
|
16
|
-
Constant("captureRevision") {
|
|
16
|
+
Constant("captureRevision") { 3 }
|
|
17
17
|
|
|
18
18
|
View(AndroidGlassView::class) {
|
|
19
19
|
Name("AndroidGlassView")
|
|
@@ -82,26 +82,26 @@ abstract class GlassHostView(context: Context, appContext: AppContext) : ExpoVie
|
|
|
82
82
|
private var downY = 0f
|
|
83
83
|
private var dragClaimed = false
|
|
84
84
|
|
|
85
|
-
// Re-sample when the glass moves on screen (layout, an ancestor scrolling, transforms)
|
|
86
|
-
// container the capture drew inline changed its children, scroll or baked child transforms,
|
|
87
|
-
// or when a view the capture left out (too far away to be seen through the glass)
|
|
88
|
-
// moved and may now be. A list that is only referenced scrolls live, so scrolling it costs no
|
|
89
|
-
// capture. There is deliberately no global-layout listener: React Native lays out on every
|
|
90
|
-
// state change (e.g. each slider tick updating a label), and re-sampling every glass view each
|
|
91
|
-
// time made interactions stutter. Everything else behind the glass is referenced live (see
|
|
92
|
-
// ViewBackdropCapture).
|
|
85
|
+
// Re-sample when the glass moves on screen (layout, an ancestor scrolling, transforms).
|
|
93
86
|
private val preDrawListener = ViewTreeObserver.OnPreDrawListener {
|
|
94
87
|
getLocationOnScreen(location)
|
|
95
88
|
if (location[0] != lastLocation[0] || location[1] != lastLocation[1]) {
|
|
96
89
|
lastLocation[0] = location[0]
|
|
97
90
|
lastLocation[1] = location[1]
|
|
98
91
|
resampleIfVisible()
|
|
99
|
-
} else if (resamplePending
|
|
92
|
+
} else if (resamplePending) {
|
|
100
93
|
resampleIfVisible()
|
|
101
94
|
}
|
|
102
95
|
true
|
|
103
96
|
}
|
|
104
97
|
|
|
98
|
+
// Scrolling changes the containers that are drawn inline into the backdrop (the ones between
|
|
99
|
+
// the window root and a glass view), so re-sample. There is deliberately no global-layout
|
|
100
|
+
// listener: React Native lays out on every state change (e.g. each slider tick updating a
|
|
101
|
+
// label), and re-sampling every glass view each time made interactions stutter. Everything
|
|
102
|
+
// else behind the glass is referenced live (see ViewBackdropCapture).
|
|
103
|
+
private val scrollListener = ViewTreeObserver.OnScrollChangedListener { resampleIfVisible() }
|
|
104
|
+
|
|
105
105
|
/**
|
|
106
106
|
* Re-samples now if any part of this view is on screen. Sampling costs a capture plus the
|
|
107
107
|
* glass effects on the GPU, so glass scrolled out of view waits until it is visible again.
|
|
@@ -288,12 +288,18 @@ abstract class GlassHostView(context: Context, appContext: AppContext) : ExpoVie
|
|
|
288
288
|
override fun onAttachedToWindow() {
|
|
289
289
|
ensureViewTreeOwners()
|
|
290
290
|
super.onAttachedToWindow()
|
|
291
|
-
observer = viewTreeObserver.also {
|
|
291
|
+
observer = viewTreeObserver.also {
|
|
292
|
+
it.addOnPreDrawListener(preDrawListener)
|
|
293
|
+
it.addOnScrollChangedListener(scrollListener)
|
|
294
|
+
}
|
|
292
295
|
GlassRegistry.add(this)
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
override fun onDetachedFromWindow() {
|
|
296
|
-
observer?.takeIf { it.isAlive }?.
|
|
299
|
+
observer?.takeIf { it.isAlive }?.let {
|
|
300
|
+
it.removeOnPreDrawListener(preDrawListener)
|
|
301
|
+
it.removeOnScrollChangedListener(scrollListener)
|
|
302
|
+
}
|
|
297
303
|
observer = null
|
|
298
304
|
lastLocation[0] = Int.MIN_VALUE
|
|
299
305
|
lastLocation[1] = Int.MIN_VALUE
|
|
@@ -66,17 +66,9 @@ internal class ViewBackdrop(private val host: GlassHostView) : Backdrop {
|
|
|
66
66
|
Snapshot.sendApplyNotifications()
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
/**
|
|
70
|
-
* Whether the capture is out of date although the host didn't move: something it drew inline
|
|
71
|
-
* (not by reference) changed its children or baked geometry, or a view it left out moved
|
|
72
|
-
* (see ViewBackdropCapture).
|
|
73
|
-
*/
|
|
74
|
-
fun changedSinceCapture(): Boolean = capture?.changedSinceCapture() ?: false
|
|
75
|
-
|
|
76
69
|
/** Frees the cached capture; the next draw records a fresh one. */
|
|
77
70
|
fun release() {
|
|
78
71
|
captureNode?.discardDisplayList()
|
|
79
|
-
capture?.clear()
|
|
80
72
|
recordedGeneration = -1
|
|
81
73
|
}
|
|
82
74
|
|
package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/HighlightModifier.kt
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Vendored into expo-android-glass-view. Changes from upstream: package relocated
|
|
6
6
|
* from com.kyant.backdrop, Kotlin Multiplatform expect/actual merged into Android-only
|
|
7
|
-
* code, dependency on io.github.kyant0:shapes removed, Kotlin 2.1 compatible syntax
|
|
8
|
-
* the highlight layer is only re-recorded when its shape, size, width, blur or style change,
|
|
9
|
-
* and nothing is drawn at zero alpha.
|
|
7
|
+
* code, dependency on io.github.kyant0:shapes removed, Kotlin 2.1 compatible syntax.
|
|
10
8
|
*/
|
|
11
9
|
package expo.modules.androidglassview.backdrop.highlight
|
|
12
10
|
|
|
@@ -27,7 +25,6 @@ import androidx.compose.ui.node.invalidateDraw
|
|
|
27
25
|
import androidx.compose.ui.node.requireGraphicsContext
|
|
28
26
|
import androidx.compose.ui.platform.InspectorInfo
|
|
29
27
|
import androidx.compose.ui.unit.Density
|
|
30
|
-
import androidx.compose.ui.unit.Dp
|
|
31
28
|
import androidx.compose.ui.unit.IntSize
|
|
32
29
|
import androidx.compose.ui.util.fastCoerceAtMost
|
|
33
30
|
import expo.modules.androidglassview.backdrop.RuntimeShaderCacheImpl
|
|
@@ -95,17 +92,9 @@ internal class HighlightNode(
|
|
|
95
92
|
|
|
96
93
|
private var prevStyle: HighlightStyle? = null
|
|
97
94
|
|
|
98
|
-
// What the layer was last recorded with. Alpha and blend mode are layer properties, so
|
|
99
|
-
// animating them (e.g. a highlight fading in on press) doesn't re-record the rim, and neither
|
|
100
|
-
// does a redraw of the node for any other reason.
|
|
101
|
-
private var recordedOutline: Outline? = null
|
|
102
|
-
private var recordedWidth = Dp.Unspecified
|
|
103
|
-
private var recordedBlurRadius = Dp.Unspecified
|
|
104
|
-
private var recordedStyle: HighlightStyle? = null
|
|
105
|
-
|
|
106
95
|
override fun ContentDrawScope.draw() {
|
|
107
96
|
val highlight = highlight()
|
|
108
|
-
if (highlight == null || highlight.width.value <= 0f
|
|
97
|
+
if (highlight == null || highlight.width.value <= 0f) {
|
|
109
98
|
return drawContent()
|
|
110
99
|
}
|
|
111
100
|
|
|
@@ -117,43 +106,33 @@ internal class HighlightNode(
|
|
|
117
106
|
val density: Density = this
|
|
118
107
|
val layoutDirection = layoutDirection
|
|
119
108
|
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
val safeSize =
|
|
110
|
+
IntSize(
|
|
111
|
+
ceil(size.width).toInt() + 2,
|
|
112
|
+
ceil(size.height).toInt() + 2
|
|
113
|
+
)
|
|
122
114
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
ceil(size.height).toInt() + 2
|
|
130
|
-
)
|
|
131
|
-
val clipPath =
|
|
132
|
-
if (outline is Outline.Rounded) {
|
|
133
|
-
clipPath ?: Path().also { clipPath = it }
|
|
134
|
-
} else {
|
|
135
|
-
null
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
configurePaint(highlight)
|
|
139
|
-
|
|
140
|
-
highlightLayer.record(safeSize) {
|
|
141
|
-
translate(1f, 1f) {
|
|
142
|
-
val canvas = drawContext.canvas
|
|
143
|
-
canvas.save()
|
|
144
|
-
canvas.clipOutline(outline, clipPath)
|
|
145
|
-
canvas.drawOutline(outline, paint)
|
|
146
|
-
canvas.restore()
|
|
147
|
-
}
|
|
115
|
+
val outline = shapeProvider.shape.createOutline(size, layoutDirection, density)
|
|
116
|
+
val clipPath =
|
|
117
|
+
if (outline is Outline.Rounded) {
|
|
118
|
+
clipPath ?: Path().also { clipPath = it }
|
|
119
|
+
} else {
|
|
120
|
+
null
|
|
148
121
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
recordedBlurRadius = highlight.blurRadius
|
|
152
|
-
recordedStyle = highlight.style
|
|
153
|
-
}
|
|
122
|
+
|
|
123
|
+
configurePaint(highlight)
|
|
154
124
|
|
|
155
125
|
highlightLayer.alpha = highlight.alpha
|
|
156
126
|
highlightLayer.blendMode = highlight.style.blendMode
|
|
127
|
+
highlightLayer.record(safeSize) {
|
|
128
|
+
translate(1f, 1f) {
|
|
129
|
+
val canvas = drawContext.canvas
|
|
130
|
+
canvas.save()
|
|
131
|
+
canvas.clipOutline(outline, clipPath)
|
|
132
|
+
canvas.drawOutline(outline, paint)
|
|
133
|
+
canvas.restore()
|
|
134
|
+
}
|
|
135
|
+
}
|
|
157
136
|
|
|
158
137
|
translate(-1f, -1f) {
|
|
159
138
|
drawLayer(highlightLayer)
|
|
@@ -175,7 +154,6 @@ internal class HighlightNode(
|
|
|
175
154
|
clipPath = null
|
|
176
155
|
runtimeShaderCache.clear()
|
|
177
156
|
prevStyle = null
|
|
178
|
-
recordedOutline = null
|
|
179
157
|
}
|
|
180
158
|
|
|
181
159
|
private fun DrawScope.configurePaint(highlight: Highlight) {
|
package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/InnerShadowModifier.kt
CHANGED
|
@@ -4,16 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Vendored into expo-android-glass-view. Changes from upstream: package relocated
|
|
6
6
|
* from com.kyant.backdrop, Kotlin Multiplatform expect/actual merged into Android-only
|
|
7
|
-
* code, dependency on io.github.kyant0:shapes removed, Kotlin 2.1 compatible syntax
|
|
8
|
-
* the shadow layer is only re-recorded when its shape, size, offset or colour change, and
|
|
9
|
-
* nothing is drawn at zero alpha.
|
|
7
|
+
* code, dependency on io.github.kyant0:shapes removed, Kotlin 2.1 compatible syntax.
|
|
10
8
|
*/
|
|
11
9
|
package expo.modules.androidglassview.backdrop.shadow
|
|
12
10
|
|
|
13
11
|
import androidx.compose.ui.Modifier
|
|
14
12
|
import androidx.compose.ui.graphics.BlendMode
|
|
15
13
|
import androidx.compose.ui.graphics.BlurEffect
|
|
16
|
-
import androidx.compose.ui.graphics.Color
|
|
17
14
|
import androidx.compose.ui.graphics.Outline
|
|
18
15
|
import androidx.compose.ui.graphics.Paint
|
|
19
16
|
import androidx.compose.ui.graphics.Path
|
|
@@ -86,20 +83,12 @@ internal class InnerShadowNode(
|
|
|
86
83
|
|
|
87
84
|
private var prevRadius = Float.NaN
|
|
88
85
|
|
|
89
|
-
// What the layer was last recorded with. Radius (a render effect), alpha and blend mode are
|
|
90
|
-
// layer properties, so animating them doesn't re-record the shape.
|
|
91
|
-
private var recordedOutline: Outline? = null
|
|
92
|
-
private var recordedOffsetX = Float.NaN
|
|
93
|
-
private var recordedOffsetY = Float.NaN
|
|
94
|
-
private var recordedColor = Color.Unspecified
|
|
95
|
-
|
|
96
86
|
override fun ContentDrawScope.draw() {
|
|
97
87
|
drawContent()
|
|
98
88
|
|
|
99
89
|
if (!isRenderEffectSupported()) return
|
|
100
90
|
|
|
101
91
|
val shadow = shadow() ?: return
|
|
102
|
-
if (shadow.alpha <= 0f) return
|
|
103
92
|
|
|
104
93
|
val shadowLayer = shadowLayer
|
|
105
94
|
if (shadowLayer != null) {
|
|
@@ -119,6 +108,8 @@ internal class InnerShadowNode(
|
|
|
119
108
|
null
|
|
120
109
|
}
|
|
121
110
|
|
|
111
|
+
configurePaint(shadow)
|
|
112
|
+
|
|
122
113
|
shadowLayer.alpha = shadow.alpha
|
|
123
114
|
shadowLayer.blendMode = shadow.blendMode
|
|
124
115
|
if (prevRadius != radius) {
|
|
@@ -130,25 +121,15 @@ internal class InnerShadowNode(
|
|
|
130
121
|
}
|
|
131
122
|
prevRadius = radius
|
|
132
123
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
canvas.drawOutline(outline, paint)
|
|
143
|
-
canvas.translate(offsetX, offsetY)
|
|
144
|
-
canvas.drawOutline(outline, ShadowMaskPaint)
|
|
145
|
-
canvas.translate(-offsetX, -offsetY)
|
|
146
|
-
canvas.restore()
|
|
147
|
-
}
|
|
148
|
-
recordedOutline = outline
|
|
149
|
-
recordedOffsetX = offsetX
|
|
150
|
-
recordedOffsetY = offsetY
|
|
151
|
-
recordedColor = shadow.color
|
|
124
|
+
shadowLayer.record {
|
|
125
|
+
val canvas = drawContext.canvas
|
|
126
|
+
canvas.save()
|
|
127
|
+
canvas.clipOutline(outline, clipPath)
|
|
128
|
+
canvas.drawOutline(outline, paint)
|
|
129
|
+
canvas.translate(offsetX, offsetY)
|
|
130
|
+
canvas.drawOutline(outline, ShadowMaskPaint)
|
|
131
|
+
canvas.translate(-offsetX, -offsetY)
|
|
132
|
+
canvas.restore()
|
|
152
133
|
}
|
|
153
134
|
|
|
154
135
|
val canvas = drawContext.canvas
|
|
@@ -173,8 +154,6 @@ internal class InnerShadowNode(
|
|
|
173
154
|
graphicsContext.releaseGraphicsLayer(layer)
|
|
174
155
|
shadowLayer = null
|
|
175
156
|
}
|
|
176
|
-
prevRadius = Float.NaN
|
|
177
|
-
recordedOutline = null
|
|
178
157
|
}
|
|
179
158
|
|
|
180
159
|
private fun DrawScope.configurePaint(shadow: InnerShadow) {
|
package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/ShadowModifier.kt
CHANGED
|
@@ -4,16 +4,12 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Vendored into expo-android-glass-view. Changes from upstream: package relocated
|
|
6
6
|
* from com.kyant.backdrop, Kotlin Multiplatform expect/actual merged into Android-only
|
|
7
|
-
* code, dependency on io.github.kyant0:shapes removed, Kotlin 2.1 compatible syntax
|
|
8
|
-
* the shadow layer is only re-recorded when its shape, size, radius, offset or colour change,
|
|
9
|
-
* and nothing is drawn at zero alpha.
|
|
7
|
+
* code, dependency on io.github.kyant0:shapes removed, Kotlin 2.1 compatible syntax.
|
|
10
8
|
*/
|
|
11
9
|
package expo.modules.androidglassview.backdrop.shadow
|
|
12
10
|
|
|
13
11
|
import androidx.compose.ui.Modifier
|
|
14
12
|
import androidx.compose.ui.graphics.BlendMode
|
|
15
|
-
import androidx.compose.ui.graphics.Color
|
|
16
|
-
import androidx.compose.ui.graphics.Outline
|
|
17
13
|
import androidx.compose.ui.graphics.Paint
|
|
18
14
|
import androidx.compose.ui.graphics.drawOutline
|
|
19
15
|
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
|
|
@@ -82,18 +78,8 @@ internal class ShadowNode(
|
|
|
82
78
|
|
|
83
79
|
private val paint = Paint()
|
|
84
80
|
|
|
85
|
-
// What the layer was last recorded with. Alpha and blend mode are layer properties, so
|
|
86
|
-
// animating them (e.g. a shadow fading in on press) doesn't re-record the blurred shape, and
|
|
87
|
-
// neither does a redraw of the node for any other reason.
|
|
88
|
-
private var recordedOutline: Outline? = null
|
|
89
|
-
private var recordedRadius = Float.NaN
|
|
90
|
-
private var recordedOffsetX = Float.NaN
|
|
91
|
-
private var recordedOffsetY = Float.NaN
|
|
92
|
-
private var recordedColor = Color.Unspecified
|
|
93
|
-
|
|
94
81
|
override fun ContentDrawScope.draw() {
|
|
95
|
-
val shadow = shadow()
|
|
96
|
-
if (shadow == null || shadow.alpha <= 0f) return drawContent()
|
|
82
|
+
val shadow = shadow() ?: return drawContent()
|
|
97
83
|
|
|
98
84
|
val shadowLayer = shadowLayer
|
|
99
85
|
if (shadowLayer != null) {
|
|
@@ -104,36 +90,25 @@ internal class ShadowNode(
|
|
|
104
90
|
val radius = shadow.radius.toPx()
|
|
105
91
|
val offsetX = shadow.offset.x.toPx()
|
|
106
92
|
val offsetY = shadow.offset.y.toPx()
|
|
107
|
-
|
|
93
|
+
val shadowSize = IntSize(
|
|
94
|
+
ceil(size.width + radius * 4f + offsetX).toInt(),
|
|
95
|
+
ceil(size.height + radius * 4f + offsetY).toInt()
|
|
96
|
+
)
|
|
108
97
|
val outline = shapeProvider.shape.createOutline(size, layoutDirection, density)
|
|
109
98
|
|
|
110
|
-
|
|
111
|
-
offsetX != recordedOffsetX || offsetY != recordedOffsetY ||
|
|
112
|
-
shadow.color != recordedColor
|
|
113
|
-
) {
|
|
114
|
-
val shadowSize = IntSize(
|
|
115
|
-
ceil(size.width + radius * 4f + offsetX).toInt(),
|
|
116
|
-
ceil(size.height + radius * 4f + offsetY).toInt()
|
|
117
|
-
)
|
|
118
|
-
configurePaint(shadow)
|
|
119
|
-
shadowLayer.record(shadowSize) {
|
|
120
|
-
translate(radius * 2f + offsetX, radius * 2f + offsetY) {
|
|
121
|
-
val canvas = drawContext.canvas
|
|
122
|
-
canvas.drawOutline(outline, paint)
|
|
123
|
-
canvas.translate(-offsetX, -offsetY)
|
|
124
|
-
canvas.drawOutline(outline, ShadowMaskPaint)
|
|
125
|
-
canvas.translate(offsetX, offsetY)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
recordedOutline = outline
|
|
129
|
-
recordedRadius = radius
|
|
130
|
-
recordedOffsetX = offsetX
|
|
131
|
-
recordedOffsetY = offsetY
|
|
132
|
-
recordedColor = shadow.color
|
|
133
|
-
}
|
|
99
|
+
configurePaint(shadow)
|
|
134
100
|
|
|
135
101
|
shadowLayer.alpha = shadow.alpha
|
|
136
102
|
shadowLayer.blendMode = shadow.blendMode
|
|
103
|
+
shadowLayer.record(shadowSize) {
|
|
104
|
+
translate(radius * 2f + offsetX, radius * 2f + offsetY) {
|
|
105
|
+
val canvas = drawContext.canvas
|
|
106
|
+
canvas.drawOutline(outline, paint)
|
|
107
|
+
canvas.translate(-offsetX, -offsetY)
|
|
108
|
+
canvas.drawOutline(outline, ShadowMaskPaint)
|
|
109
|
+
canvas.translate(offsetX, offsetY)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
137
112
|
|
|
138
113
|
translate(-radius * 2f, -radius * 2f) {
|
|
139
114
|
drawLayer(shadowLayer)
|
|
@@ -157,7 +132,6 @@ internal class ShadowNode(
|
|
|
157
132
|
graphicsContext.releaseGraphicsLayer(layer)
|
|
158
133
|
shadowLayer = null
|
|
159
134
|
}
|
|
160
|
-
recordedOutline = null
|
|
161
135
|
}
|
|
162
136
|
|
|
163
137
|
private fun DrawScope.configurePaint(shadow: Shadow) {
|
|
@@ -6,20 +6,16 @@
|
|
|
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
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, the ancestors of the
|
|
10
|
-
* sampling view are drawn child by child instead of through their own draw()
|
|
11
|
-
* cannot reach the recorded area are left out (culled).
|
|
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().
|
|
12
11
|
*/
|
|
13
12
|
package expo.modules.androidglassview.capture
|
|
14
13
|
|
|
15
14
|
import android.graphics.Canvas
|
|
16
|
-
import android.graphics.RectF
|
|
17
15
|
import android.os.Build
|
|
18
16
|
import android.view.View
|
|
19
17
|
import android.view.ViewGroup
|
|
20
|
-
import android.view.animation.Animation
|
|
21
18
|
import androidx.annotation.RequiresApi
|
|
22
|
-
import kotlin.math.max
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* Draws a source view's content into a canvas while leaving glass views out of it.
|
|
@@ -58,22 +54,10 @@ import kotlin.math.max
|
|
|
58
54
|
* Glass views that are *ancestors* of the sampling one are not skipped: glass on top of a glass
|
|
59
55
|
* card sees the card. That cannot form a cycle, because an ancestor never samples its own subtree.
|
|
60
56
|
*
|
|
61
|
-
* **Culling.** The capture only covers the area around the glass, but a reference to a subtree
|
|
62
|
-
* anywhere on screen makes the RenderThread re-render this glass — capture, blur and refraction —
|
|
63
|
-
* whenever that subtree changes, even when none of it can be seen through the glass. With a few
|
|
64
|
-
* glass views on a screen with an animation, that is every glass view on every frame. So a child
|
|
65
|
-
* is left out when nothing it draws can reach the recorded area ([reachesRecordedArea]): neither
|
|
66
|
-
* its bounds (plus a margin for shadows) nor, as long as it doesn't clip them, those of its
|
|
67
|
-
* descendants. A left-out child is not referenced, so it is not live: [changedSinceCapture]
|
|
68
|
-
* reports when one of them moved, resized or scrolled, and the glass then captures again.
|
|
69
|
-
*
|
|
70
57
|
* Known trade-offs: the children of ancestors are drawn without their view Animation and
|
|
71
58
|
* elevation shadow; inside an expanded container that is not an ancestor, glass-containing
|
|
72
59
|
* branches are drawn after their siblings, so a sibling that normally paints above such a branch
|
|
73
|
-
* ends up below it in the backdrop
|
|
74
|
-
* the cull margin, e.g. a large box shadow) is missing from glass views that its view is away
|
|
75
|
-
* from, and so is content a left-out subtree animates into the glass area without its own root
|
|
76
|
-
* moving.
|
|
60
|
+
* ends up below it in the backdrop.
|
|
77
61
|
*/
|
|
78
62
|
@RequiresApi(Build.VERSION_CODES.Q) // View.setTransitionVisibility, ViewGroup.getChildDrawingOrder(int)
|
|
79
63
|
internal class ViewBackdropCapture {
|
|
@@ -93,138 +77,14 @@ internal class ViewBackdropCapture {
|
|
|
93
77
|
private val hidden = ArrayList<View>()
|
|
94
78
|
|
|
95
79
|
/**
|
|
96
|
-
*
|
|
97
|
-
* pairs in [bakedScroll]). Every other scrolling view is referenced through its RenderNode, so
|
|
98
|
-
* the capture follows it without being recorded again.
|
|
99
|
-
*/
|
|
100
|
-
private val bakedViews = ArrayList<View>()
|
|
101
|
-
private var bakedScroll = IntArray(32)
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Child lists dispatched inline, rather than through the group's own RenderNode. A screen
|
|
105
|
-
* replacement can discard a referenced child's display list without moving any views.
|
|
106
|
-
*/
|
|
107
|
-
private val inlineGroups = ArrayList<InlineGroup>()
|
|
108
|
-
|
|
109
|
-
/** Culled children, and children whose transform/clip/alpha we applied ourselves. */
|
|
110
|
-
private val geometryViews = ArrayList<View>()
|
|
111
|
-
private var geometry = FloatArray(GEOMETRY_FIELDS * 16)
|
|
112
|
-
private var geometryTracksAlpha = BooleanArray(16)
|
|
113
|
-
private val culledSet = HashSet<View>()
|
|
114
|
-
|
|
115
|
-
/** Margin around a view's bounds that its drawing may still reach (shadows, borders), in px. */
|
|
116
|
-
private var cullPadding = 0f
|
|
117
|
-
private val cullRect = RectF()
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Whether the last capture is out of date although the glass itself didn't move: a view whose
|
|
121
|
-
* scroll offset or transform it baked in changed, an inline group changed its children, or a
|
|
122
|
-
* view it left out moved (and may now reach the glass). RenderNode subtrees stay live without
|
|
123
|
-
* being traversed here. This check allocates nothing.
|
|
124
|
-
*/
|
|
125
|
-
fun changedSinceCapture(): Boolean {
|
|
126
|
-
for (i in bakedViews.indices) {
|
|
127
|
-
val view = bakedViews[i]
|
|
128
|
-
if (view.scrollX != bakedScroll[i * 2] || view.scrollY != bakedScroll[i * 2 + 1]) return true
|
|
129
|
-
}
|
|
130
|
-
for (i in geometryViews.indices) {
|
|
131
|
-
if (!hasGeometry(geometryViews[i], i)) return true
|
|
132
|
-
}
|
|
133
|
-
for (i in inlineGroups.indices) {
|
|
134
|
-
if (inlineGroups[i].hasChanged()) return true
|
|
135
|
-
}
|
|
136
|
-
return false
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Forgets the views of the last capture (they may belong to a window that is going away). */
|
|
140
|
-
fun clear() {
|
|
141
|
-
expanded.clear()
|
|
142
|
-
excluded.clear()
|
|
143
|
-
selfPath.clear()
|
|
144
|
-
path.clear()
|
|
145
|
-
hidden.clear()
|
|
146
|
-
bakedViews.clear()
|
|
147
|
-
inlineGroups.clear()
|
|
148
|
-
geometryViews.clear()
|
|
149
|
-
culledSet.clear()
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private fun bakeScroll(view: View) {
|
|
153
|
-
val index = bakedViews.size
|
|
154
|
-
if (bakedScroll.size < (index + 1) * 2) bakedScroll = bakedScroll.copyOf(bakedScroll.size * 2)
|
|
155
|
-
bakedViews.add(view)
|
|
156
|
-
bakedScroll[index * 2] = view.scrollX
|
|
157
|
-
bakedScroll[index * 2 + 1] = view.scrollY
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private fun cull(view: View) {
|
|
161
|
-
culledSet.add(view)
|
|
162
|
-
// A fade outside the capture cannot bring any content into it.
|
|
163
|
-
bakeGeometry(view, trackAlpha = false)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private fun bakeGeometry(view: View, trackAlpha: Boolean = true) {
|
|
167
|
-
val index = geometryViews.size
|
|
168
|
-
val offset = index * GEOMETRY_FIELDS
|
|
169
|
-
if (geometry.size < offset + GEOMETRY_FIELDS) {
|
|
170
|
-
geometry = geometry.copyOf(geometry.size * 2)
|
|
171
|
-
geometryTracksAlpha = geometryTracksAlpha.copyOf(geometryTracksAlpha.size * 2)
|
|
172
|
-
}
|
|
173
|
-
geometryTracksAlpha[index] = trackAlpha
|
|
174
|
-
geometryViews.add(view)
|
|
175
|
-
val g = geometry
|
|
176
|
-
g[offset] = view.left.toFloat()
|
|
177
|
-
g[offset + 1] = view.top.toFloat()
|
|
178
|
-
g[offset + 2] = view.right.toFloat()
|
|
179
|
-
g[offset + 3] = view.bottom.toFloat()
|
|
180
|
-
g[offset + 4] = view.translationX
|
|
181
|
-
g[offset + 5] = view.translationY
|
|
182
|
-
g[offset + 6] = view.scaleX
|
|
183
|
-
g[offset + 7] = view.scaleY
|
|
184
|
-
g[offset + 8] = view.rotation
|
|
185
|
-
g[offset + 9] = view.rotationX
|
|
186
|
-
g[offset + 10] = view.rotationY
|
|
187
|
-
g[offset + 11] = view.scrollX.toFloat()
|
|
188
|
-
g[offset + 12] = view.scrollY.toFloat()
|
|
189
|
-
g[offset + 13] = view.z
|
|
190
|
-
g[offset + 14] = view.pivotX
|
|
191
|
-
g[offset + 15] = view.pivotY
|
|
192
|
-
g[offset + 16] = view.alpha
|
|
193
|
-
g[offset + 17] = view.cameraDistance
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private fun hasGeometry(view: View, index: Int): Boolean {
|
|
197
|
-
val offset = index * GEOMETRY_FIELDS
|
|
198
|
-
val g = geometry
|
|
199
|
-
return g[offset] == view.left.toFloat() &&
|
|
200
|
-
g[offset + 1] == view.top.toFloat() &&
|
|
201
|
-
g[offset + 2] == view.right.toFloat() &&
|
|
202
|
-
g[offset + 3] == view.bottom.toFloat() &&
|
|
203
|
-
g[offset + 4] == view.translationX &&
|
|
204
|
-
g[offset + 5] == view.translationY &&
|
|
205
|
-
g[offset + 6] == view.scaleX &&
|
|
206
|
-
g[offset + 7] == view.scaleY &&
|
|
207
|
-
g[offset + 8] == view.rotation &&
|
|
208
|
-
g[offset + 9] == view.rotationX &&
|
|
209
|
-
g[offset + 10] == view.rotationY &&
|
|
210
|
-
g[offset + 11] == view.scrollX.toFloat() &&
|
|
211
|
-
g[offset + 12] == view.scrollY.toFloat() &&
|
|
212
|
-
g[offset + 13] == view.z &&
|
|
213
|
-
g[offset + 14] == view.pivotX &&
|
|
214
|
-
g[offset + 15] == view.pivotY &&
|
|
215
|
-
(!geometryTracksAlpha[index] || g[offset + 16] == view.alpha) &&
|
|
216
|
-
g[offset + 17] == view.cameraDistance
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @param canvas a hardware canvas whose origin is aligned with [source]'s top-left corner, and
|
|
221
|
-
* whose clip is the area to record (children that cannot reach it are left out).
|
|
80
|
+
* @param canvas a hardware canvas whose origin is aligned with [source]'s top-left corner.
|
|
222
81
|
* @param self the glass view that is sampling.
|
|
223
82
|
* @param glassViews every glass view; the ones outside [source] are ignored.
|
|
224
83
|
*/
|
|
225
84
|
fun draw(canvas: Canvas, source: View, self: View, glassViews: Collection<View>) {
|
|
226
|
-
clear()
|
|
227
|
-
|
|
85
|
+
expanded.clear()
|
|
86
|
+
excluded.clear()
|
|
87
|
+
selfPath.clear()
|
|
228
88
|
|
|
229
89
|
var ancestor = self.parent
|
|
230
90
|
while (ancestor is View) {
|
|
@@ -266,8 +126,6 @@ internal class ViewBackdropCapture {
|
|
|
266
126
|
}
|
|
267
127
|
|
|
268
128
|
private fun drawLevel(canvas: Canvas, host: View) {
|
|
269
|
-
// Snapshot before temporarily hiding children; otherwise every pre-draw sees a change.
|
|
270
|
-
if (host is ViewGroup) inlineGroups.add(InlineGroup(host))
|
|
271
129
|
if (host is ViewGroup && host in selfPath) {
|
|
272
130
|
drawAncestor(canvas, host)
|
|
273
131
|
return
|
|
@@ -278,14 +136,10 @@ internal class ViewBackdropCapture {
|
|
|
278
136
|
if (group != null) {
|
|
279
137
|
for (i in 0 until group.childCount) {
|
|
280
138
|
val child = group.getChildAt(i)
|
|
281
|
-
if (child.visibility
|
|
282
|
-
val outside = child !in excluded && child.animation == null &&
|
|
283
|
-
!reachesRecordedArea(canvas, child, (child.left - host.scrollX).toFloat(), (child.top - host.scrollY).toFloat())
|
|
284
|
-
if (child in excluded || child in expanded || outside) {
|
|
139
|
+
if (child.visibility == View.VISIBLE && (child in excluded || child in expanded)) {
|
|
285
140
|
// Only flips the visibility flag; does not invalidate anything.
|
|
286
141
|
child.setTransitionVisibility(View.INVISIBLE)
|
|
287
142
|
hidden.add(child)
|
|
288
|
-
if (outside) cull(child)
|
|
289
143
|
}
|
|
290
144
|
}
|
|
291
145
|
}
|
|
@@ -295,7 +149,6 @@ internal class ViewBackdropCapture {
|
|
|
295
149
|
try {
|
|
296
150
|
// The public View.draw() does not apply the view's own scroll offset (the framework does
|
|
297
151
|
// that in updateDisplayListIfDirty), so apply it here.
|
|
298
|
-
bakeScroll(host)
|
|
299
152
|
canvas.translate(-host.scrollX.toFloat(), -host.scrollY.toFloat())
|
|
300
153
|
host.draw(canvas)
|
|
301
154
|
} finally {
|
|
@@ -309,7 +162,7 @@ internal class ViewBackdropCapture {
|
|
|
309
162
|
val clipChildren = group.clipChildren
|
|
310
163
|
for (i in firstHidden until lastHidden) {
|
|
311
164
|
val child = hidden[i]
|
|
312
|
-
if (child in excluded
|
|
165
|
+
if (child in excluded) continue
|
|
313
166
|
val childSave = canvas.save()
|
|
314
167
|
// Same transform the parent applies when it draws the child normally.
|
|
315
168
|
canvas.translate((child.left - host.scrollX).toFloat(), (child.top - host.scrollY).toFloat())
|
|
@@ -333,25 +186,18 @@ internal class ViewBackdropCapture {
|
|
|
333
186
|
try {
|
|
334
187
|
// View.draw() paints the background at the view's origin, whatever its scroll offset.
|
|
335
188
|
host.background?.draw(canvas)
|
|
336
|
-
bakeScroll(host)
|
|
337
189
|
canvas.translate(-host.scrollX.toFloat(), -host.scrollY.toFloat())
|
|
338
190
|
val clipChildren = host.clipChildren
|
|
339
191
|
for (child in childrenInDrawingOrder(host)) {
|
|
340
192
|
if (child in excluded) continue
|
|
341
193
|
// Same visibility rule as ViewGroup.dispatchDraw.
|
|
342
194
|
if (child.visibility != View.VISIBLE && child.animation == null) continue
|
|
343
|
-
if (child.animation == null && !reachesRecordedArea(canvas, child, child.left.toFloat(), child.top.toFloat())) {
|
|
344
|
-
cull(child)
|
|
345
|
-
continue
|
|
346
|
-
}
|
|
347
195
|
val childSave = canvas.save()
|
|
348
196
|
canvas.translate(child.left.toFloat(), child.top.toFloat())
|
|
349
197
|
applyChildTransform(canvas, child, clipChildren)
|
|
350
198
|
if (child in expanded) {
|
|
351
199
|
drawLevel(canvas, child)
|
|
352
200
|
} else {
|
|
353
|
-
if (child is ViewGroup) inlineGroups.add(InlineGroup(child))
|
|
354
|
-
bakeScroll(child)
|
|
355
201
|
canvas.translate(-child.scrollX.toFloat(), -child.scrollY.toFloat())
|
|
356
202
|
child.draw(canvas)
|
|
357
203
|
}
|
|
@@ -362,40 +208,8 @@ internal class ViewBackdropCapture {
|
|
|
362
208
|
}
|
|
363
209
|
}
|
|
364
210
|
|
|
365
|
-
/**
|
|
366
|
-
* Whether anything [view] draws can land in the area being recorded (the canvas clip). [x], [y]
|
|
367
|
-
* is the view's position in the current canvas coordinates. A view that doesn't clip its
|
|
368
|
-
* children lets them draw outside its bounds, so they are checked too, recursively.
|
|
369
|
-
*/
|
|
370
|
-
private fun reachesRecordedArea(canvas: Canvas, view: View, x: Float, y: Float): Boolean {
|
|
371
|
-
val save = canvas.save()
|
|
372
|
-
try {
|
|
373
|
-
canvas.translate(x, y)
|
|
374
|
-
val matrix = view.matrix
|
|
375
|
-
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
376
|
-
val padding = cullPadding + max(view.z, 0f) * 2f
|
|
377
|
-
cullRect.set(-padding, -padding, view.width + padding, view.height + padding)
|
|
378
|
-
@Suppress("DEPRECATION") // quickReject(RectF) needs API 30
|
|
379
|
-
if (!canvas.quickReject(cullRect, Canvas.EdgeType.BW)) return true
|
|
380
|
-
if (view is ViewGroup && !view.clipChildren) {
|
|
381
|
-
for (i in 0 until view.childCount) {
|
|
382
|
-
val child = view.getChildAt(i)
|
|
383
|
-
if (child.visibility != View.VISIBLE && child.animation == null) continue
|
|
384
|
-
if (child.animation != null) return true
|
|
385
|
-
val childX = (child.left - view.scrollX).toFloat()
|
|
386
|
-
val childY = (child.top - view.scrollY).toFloat()
|
|
387
|
-
if (reachesRecordedArea(canvas, child, childX, childY)) return true
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return false
|
|
391
|
-
} finally {
|
|
392
|
-
canvas.restoreToCount(save)
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
211
|
/** The child's matrix, clip and alpha, as its parent applies them; the canvas is at its left/top. */
|
|
397
212
|
private fun applyChildTransform(canvas: Canvas, child: View, clipChildren: Boolean) {
|
|
398
|
-
bakeGeometry(child)
|
|
399
213
|
val matrix = child.matrix
|
|
400
214
|
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
401
215
|
if (clipChildren) canvas.clipRect(0f, 0f, child.width.toFloat(), child.height.toFloat())
|
|
@@ -420,41 +234,9 @@ internal class ViewBackdropCapture {
|
|
|
420
234
|
return children
|
|
421
235
|
}
|
|
422
236
|
|
|
423
|
-
/** Only the direct dispatch boundary is frozen; descendants keep their live RenderNodes. */
|
|
424
|
-
private class InlineGroup(private val group: ViewGroup) {
|
|
425
|
-
private val count = group.childCount
|
|
426
|
-
private val children = Array(count) { group.getChildAt(it) }
|
|
427
|
-
private val visibility = IntArray(count) { children[it].visibility }
|
|
428
|
-
private val order = IntArray(count) { group.getChildDrawingOrder(it) }
|
|
429
|
-
private val z = FloatArray(count) { children[it].z }
|
|
430
|
-
private val animations = arrayOfNulls<Animation>(count).also { values ->
|
|
431
|
-
for (i in 0 until count) values[i] = children[i].animation
|
|
432
|
-
}
|
|
433
|
-
private val clipChildren = group.clipChildren
|
|
434
|
-
private val clipToPadding = group.clipToPadding
|
|
435
|
-
|
|
436
|
-
fun hasChanged(): Boolean {
|
|
437
|
-
if (group.childCount != count || group.clipChildren != clipChildren ||
|
|
438
|
-
group.clipToPadding != clipToPadding) return true
|
|
439
|
-
for (i in 0 until count) {
|
|
440
|
-
val child = group.getChildAt(i)
|
|
441
|
-
if (child !== children[i] || child.visibility != visibility[i] ||
|
|
442
|
-
group.getChildDrawingOrder(i) != order[i] || child.z != z[i] ||
|
|
443
|
-
child.animation !== animations[i]) return true
|
|
444
|
-
}
|
|
445
|
-
return false
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
237
|
companion object {
|
|
450
238
|
private var depth = 0
|
|
451
239
|
|
|
452
|
-
/** Geometry values stored per culled or manually transformed view. */
|
|
453
|
-
private const val GEOMETRY_FIELDS = 18
|
|
454
|
-
|
|
455
|
-
/** How far outside its bounds a view's drawing is assumed to reach (shadows, borders). */
|
|
456
|
-
private const val CULL_PADDING_DP = 8f
|
|
457
|
-
|
|
458
240
|
/** True while any glass view is sampling (main thread only). */
|
|
459
241
|
val isCapturing: Boolean
|
|
460
242
|
get() = depth > 0
|
|
@@ -46,7 +46,7 @@ export type AndroidGlassBottomTabsProps = ViewProps & {
|
|
|
46
46
|
/** Called when the user taps a tab or drops the droplet on one. */
|
|
47
47
|
onTabSelected?: (index: number) => void;
|
|
48
48
|
/**
|
|
49
|
-
* Minimizes the bar
|
|
49
|
+
* Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps
|
|
50
50
|
* only its first child (the icon) and the rest (the label) fades out. Animated natively. Inside a
|
|
51
51
|
* `MinimizeOnScrollProvider`, leave it out: the bar follows the provider. Android only.
|
|
52
52
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AndroidGlassComponents.types.js","sourceRoot":"","sources":["../src/AndroidGlassComponents.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactNode } from 'react';\nimport type { ColorValue, StyleProp, TextStyle, ViewProps } from 'react-native';\n\nimport type { AndroidGlassViewProps } from './AndroidGlassView.types';\n\n/**\n * Accepts every `AndroidGlassView` glass prop. `cornerRadius` defaults to a capsule.\n * Children (label, icon, …) are drawn inside the glass and follow its press deformation; they\n * are decorative, so don't put interactive elements in a button.\n */\nexport type AndroidGlassButtonProps = AndroidGlassViewProps & {\n /** Called when the button is tapped. */\n onPress?: () => void;\n /** Convenience label, rendered before the children. */\n title?: string;\n titleStyle?: StyleProp<TextStyle>;\n /**\n * Press and drag feedback: the glass stretches towards the finger and a highlight follows it.\n * Default true.\n */\n interactive?: boolean;\n};\n\nexport type AndroidGlassToggleProps = ViewProps & {\n value?: boolean;\n onValueChange?: (value: boolean) => void;\n /** Track colour when on. Default iOS green. */\n accentColor?: ColorValue;\n /** Track colour when off. */\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassSliderProps = ViewProps & {\n value?: number;\n /** Default 0. */\n minimumValue?: number;\n /** Default 1. */\n maximumValue?: number;\n /** Called continuously while the thumb is dragged. */\n onValueChange?: (value: number) => void;\n /** Called once when the finger is lifted, or after a tap on the track. */\n onSlidingComplete?: (value: number) => void;\n /** Colour of the filled part of the track. Default system blue. */\n accentColor?: ColorValue;\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassBottomTabsProps = ViewProps & {\n /** Index of the selected tab. */\n selectedIndex?: number;\n /** Called when the user taps a tab or drops the droplet on one. */\n onTabSelected?: (index: number) => void;\n /**\n * Minimizes the bar
|
|
1
|
+
{"version":3,"file":"AndroidGlassComponents.types.js","sourceRoot":"","sources":["../src/AndroidGlassComponents.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactNode } from 'react';\nimport type { ColorValue, StyleProp, TextStyle, ViewProps } from 'react-native';\n\nimport type { AndroidGlassViewProps } from './AndroidGlassView.types';\n\n/**\n * Accepts every `AndroidGlassView` glass prop. `cornerRadius` defaults to a capsule.\n * Children (label, icon, …) are drawn inside the glass and follow its press deformation; they\n * are decorative, so don't put interactive elements in a button.\n */\nexport type AndroidGlassButtonProps = AndroidGlassViewProps & {\n /** Called when the button is tapped. */\n onPress?: () => void;\n /** Convenience label, rendered before the children. */\n title?: string;\n titleStyle?: StyleProp<TextStyle>;\n /**\n * Press and drag feedback: the glass stretches towards the finger and a highlight follows it.\n * Default true.\n */\n interactive?: boolean;\n};\n\nexport type AndroidGlassToggleProps = ViewProps & {\n value?: boolean;\n onValueChange?: (value: boolean) => void;\n /** Track colour when on. Default iOS green. */\n accentColor?: ColorValue;\n /** Track colour when off. */\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassSliderProps = ViewProps & {\n value?: number;\n /** Default 0. */\n minimumValue?: number;\n /** Default 1. */\n maximumValue?: number;\n /** Called continuously while the thumb is dragged. */\n onValueChange?: (value: number) => void;\n /** Called once when the finger is lifted, or after a tap on the track. */\n onSlidingComplete?: (value: number) => void;\n /** Colour of the filled part of the track. Default system blue. */\n accentColor?: ColorValue;\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassBottomTabsProps = ViewProps & {\n /** Index of the selected tab. */\n selectedIndex?: number;\n /** Called when the user taps a tab or drops the droplet on one. */\n onTabSelected?: (index: number) => void;\n /**\n * Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps\n * only its first child (the icon) and the rest (the label) fades out. Animated natively. Inside a\n * `MinimizeOnScrollProvider`, leave it out: the bar follows the provider. Android only.\n */\n minimized?: boolean;\n /**\n * Called with `false` when the user expands the minimized bar by touching it. With\n * `useMinimizeOnScroll`, pass its `setMinimized`; inside a `MinimizeOnScrollProvider` it isn't\n * needed.\n */\n onMinimizedChange?: (minimized: boolean) => void;\n /** Colour the selected tab's content takes under the droplet. Default system blue. */\n accentColor?: ColorValue;\n /** Colour of the glass bar. */\n containerColor?: ColorValue;\n /** One child per tab, e.g. `AndroidGlassTab`. Tabs get equal widths. */\n children?: ReactNode;\n};\n\nexport type AndroidGlassTabProps = {\n icon?: ReactNode;\n label?: string;\n labelStyle?: StyleProp<TextStyle>;\n};\n"]}
|
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.9",
|
|
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",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/kagantemizkan/expo-android-glass-view/issues"
|
|
28
28
|
},
|
|
29
|
-
"author": "
|
|
29
|
+
"author": "Ka\u011fan Temizkan <info@sailatlas.app> (https://sailatlas.app)",
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"homepage": "https://github.com/kagantemizkan/expo-android-glass-view#readme",
|
|
32
32
|
"dependencies": {},
|
|
@@ -51,7 +51,7 @@ export type AndroidGlassBottomTabsProps = ViewProps & {
|
|
|
51
51
|
/** Called when the user taps a tab or drops the droplet on one. */
|
|
52
52
|
onTabSelected?: (index: number) => void;
|
|
53
53
|
/**
|
|
54
|
-
* Minimizes the bar
|
|
54
|
+
* Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps
|
|
55
55
|
* only its first child (the icon) and the rest (the label) fades out. Animated natively. Inside a
|
|
56
56
|
* `MinimizeOnScrollProvider`, leave it out: the bar follows the provider. Android only.
|
|
57
57
|
*/
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"lib": [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"esnext"
|
|
7
|
-
],
|
|
8
|
-
"types": [
|
|
9
|
-
"jest"
|
|
10
|
-
],
|
|
11
|
-
"typeRoots": [
|
|
12
|
-
"./ts-declarations",
|
|
13
|
-
"./node_modules/@types"
|
|
14
|
-
],
|
|
3
|
+
"lib": ["dom", "DOM.Iterable", "esnext"],
|
|
4
|
+
"types": ["jest"],
|
|
5
|
+
"typeRoots": ["./ts-declarations", "./node_modules/@types"],
|
|
15
6
|
"jsx": "react-native",
|
|
16
7
|
"target": "esnext",
|
|
17
8
|
"moduleResolution": "bundler",
|
|
@@ -30,14 +21,8 @@
|
|
|
30
21
|
"noUnusedLocals": true,
|
|
31
22
|
"noUnusedParameters": false,
|
|
32
23
|
"rootDir": "./src",
|
|
33
|
-
"outDir": "./build"
|
|
34
|
-
"noEmit": false
|
|
24
|
+
"outDir": "./build"
|
|
35
25
|
},
|
|
36
|
-
"include": [
|
|
37
|
-
|
|
38
|
-
],
|
|
39
|
-
"exclude": [
|
|
40
|
-
"**/__mocks__/*",
|
|
41
|
-
"**/__tests__/*"
|
|
42
|
-
]
|
|
26
|
+
"include": ["./src"],
|
|
27
|
+
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
|
|
43
28
|
}
|