@oxy.so/bloom-lens 0.0.0-stage → 1.0.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.
- package/LICENSE +673 -0
- package/NOTICE +26 -0
- package/android/build.gradle +19 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/assets/fonts/Inter-OFL.txt +93 -0
- package/android/src/main/assets/fonts/Inter-Regular.ttf +0 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/220 +0 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidModule.kt +71 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidView.kt +548 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassBackdrop.kt +215 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassLens.kt +103 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeGeometry.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeIcons.kt +74 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeMaterial.kt +74 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeHost.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeModule.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeView.kt +609 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/StaticGlassCache.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceIcons.kt +114 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesHost.kt +71 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesModule.kt +22 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesView.kt +527 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassIcons.kt +68 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassMenuContent.kt +349 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassRow.kt +19 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassFieldTexture.kt +102 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassGaussianField.kt +161 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassShapes.kt +37 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedField.kt +119 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedUnion.kt +81 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassGroup.kt +225 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassJelly.kt +118 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphFrame.kt +22 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphTuning.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMotion.kt +475 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassSpring.kt +78 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassDevGuard.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassFeedback.kt +18 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuOverlay.kt +433 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuSession.kt +750 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassScrub.kt +41 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassSubmenuLayer.kt +290 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassAbsorbRecord.kt +9 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMemberRecord.kt +14 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuConfigRecord.kt +24 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuItemRecord.kt +23 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassShrinkRecord.kt +10 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassTriggerConfigRecord.kt +19 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRecipe.kt +18 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRenderer.kt +361 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassShaders.kt +318 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassStill.kt +115 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassSurfaceState.kt +38 -0
- package/expo-module.config.json +10 -0
- package/package.json +29 -4
- package/patches/bloom.patch +1908 -0
- package/patches/menu/bloom.patch +148 -0
- package/src/base.tsx +208 -0
- package/src/chrome/compositor-geometry.ts +163 -0
- package/src/chrome/glass-header.tsx +155 -0
- package/src/chrome/glass-search-fab.tsx +113 -0
- package/src/chrome/glass-size-class.tsx +150 -0
- package/src/chrome/glass-toolbar.tsx +45 -0
- package/src/chrome/interface.ts +17 -0
- package/src/chrome/ios-tab-bar.tsx +49 -0
- package/src/chrome/surface-layer.ts +91 -0
- package/src/chrome/surface-nodes.tsx +54 -0
- package/src/index.ts +19 -0
- package/src/menu/components/menu/index.ts +22 -0
- package/src/menu/components/menu/menu.tsx +97 -0
- package/src/menu/components/menu-action-row/index.ts +1 -0
- package/src/menu/components/menu-action-row/menu-action-row.tsx +12 -0
- package/src/menu/components/menu-content/index.ts +2 -0
- package/src/menu/components/menu-content/menu-content.tsx +11 -0
- package/src/menu/components/menu-item/index.ts +13 -0
- package/src/menu/components/menu-item/menu-item-icon.tsx +10 -0
- package/src/menu/components/menu-item/menu-item-subtitle.tsx +14 -0
- package/src/menu/components/menu-item/menu-item-title.tsx +11 -0
- package/src/menu/components/menu-item/menu-item.tsx +11 -0
- package/src/menu/components/menu-label/index.ts +3 -0
- package/src/menu/components/menu-label/menu-label.tsx +11 -0
- package/src/menu/components/menu-separator/index.ts +3 -0
- package/src/menu/components/menu-separator/menu-separator.tsx +7 -0
- package/src/menu/components/menu-submenu/index.ts +1 -0
- package/src/menu/components/menu-submenu/menu-submenu.tsx +12 -0
- package/src/menu/components/menu-trigger/index.ts +3 -0
- package/src/menu/components/menu-trigger/interface.ts +41 -0
- package/src/menu/components/menu-trigger/menu-trigger.android.tsx +97 -0
- package/src/menu/components/menu-trigger/menu-trigger.tsx +15 -0
- package/src/menu/components/menu-trigger/native-menu.android.ts +9 -0
- package/src/menu/components/menu-trigger-button/index.ts +3 -0
- package/src/menu/components/menu-trigger-button/menu-trigger-button.android.tsx +38 -0
- package/src/menu/components/menu-trigger-button/menu-trigger-button.tsx +17 -0
- package/src/menu/constants/interface.ts +6 -0
- package/src/menu/constants/menu.const.ts +11 -0
- package/src/menu/context/interface.ts +63 -0
- package/src/menu/context/menu.context.ts +7 -0
- package/src/menu/index.ts +53 -0
- package/src/menu/interface.ts +229 -0
- package/src/menu/utils/create-compound-component.util.ts +18 -0
- package/src/menu/utils/find-menu-content.util.ts +17 -0
- package/src/menu/utils/flatten-elements.util.ts +18 -0
- package/src/menu/utils/parse-menu-content.util.ts +98 -0
- package/src/menu/utils/parse-menu-item.util.ts +56 -0
- package/src/menu/utils/register-component.util.ts +13 -0
- package/src/menu/utils/to-native-item.util.ts +24 -0
- package/src/rows.tsx +61 -0
- package/README.md +0 -3
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.field
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import kotlin.math.abs
|
|
5
|
+
import kotlin.math.max
|
|
6
|
+
import kotlin.math.min
|
|
7
|
+
import kotlin.math.sqrt
|
|
8
|
+
|
|
9
|
+
internal class RoundedField {
|
|
10
|
+
private var centerX = 0f
|
|
11
|
+
private var centerY = 0f
|
|
12
|
+
private var inverseAxisX = 1f
|
|
13
|
+
private var inverseAxisY = 1f
|
|
14
|
+
private var halfWidth = 0f
|
|
15
|
+
private var halfHeight = 0f
|
|
16
|
+
private var radius = 0f
|
|
17
|
+
private var expandedRadius = 0f
|
|
18
|
+
private var curvatureX = 0f
|
|
19
|
+
private var curvatureY = 0f
|
|
20
|
+
private var baseRadius = 0f
|
|
21
|
+
private var circular = false
|
|
22
|
+
var gradientX = 0f
|
|
23
|
+
private set
|
|
24
|
+
var gradientY = 0f
|
|
25
|
+
private set
|
|
26
|
+
|
|
27
|
+
fun set(bounds: RectF, radiusXIn: Float, radiusYIn: Float) {
|
|
28
|
+
centerX = bounds.centerX()
|
|
29
|
+
centerY = bounds.centerY()
|
|
30
|
+
val rx = max(radiusXIn, 0.01f)
|
|
31
|
+
val ry = max(radiusYIn, 0.01f)
|
|
32
|
+
radius = min(rx, ry)
|
|
33
|
+
inverseAxisX = radius / rx
|
|
34
|
+
inverseAxisY = radius / ry
|
|
35
|
+
halfWidth = bounds.width() / 2f * inverseAxisX
|
|
36
|
+
halfHeight = bounds.height() / 2f * inverseAxisY
|
|
37
|
+
expandedRadius = radius * CornerExpansion
|
|
38
|
+
curvatureX = (2.8915570351735034f - 1.4457785175867517f * (halfWidth * 2f) / expandedRadius).coerceIn(0f, 1f)
|
|
39
|
+
curvatureY = (2.8915570351735034f - 1.4457785175867517f * (halfHeight * 2f) / expandedRadius).coerceIn(0f, 1f)
|
|
40
|
+
baseRadius = radius * (CornerExpansion - CornerAdjustment * max(curvatureX, curvatureY))
|
|
41
|
+
circular = curvatureX == 1f && curvatureY == 1f
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun distance(x: Float, y: Float): Float {
|
|
45
|
+
val qx = abs((x - centerX) * inverseAxisX) - halfWidth
|
|
46
|
+
val qy = abs((y - centerY) * inverseAxisY) - halfHeight
|
|
47
|
+
val circularX = qx + baseRadius
|
|
48
|
+
val circularY = qy + baseRadius
|
|
49
|
+
val interior = min(max(circularX, circularY), 0f)
|
|
50
|
+
if (circular) {
|
|
51
|
+
val dx = max(circularX, 0f)
|
|
52
|
+
val dy = max(circularY, 0f)
|
|
53
|
+
return interior + sqrt(dx * dx + dy * dy) - radius
|
|
54
|
+
}
|
|
55
|
+
val ux = (qx + expandedRadius) / expandedRadius
|
|
56
|
+
val uy = (qy + expandedRadius) / expandedRadius
|
|
57
|
+
val zx = max(ux, 0f)
|
|
58
|
+
val zy = max(uy, 0f)
|
|
59
|
+
val maximum = max(zx, zy)
|
|
60
|
+
val t = if (maximum > 0f) min(zx, zy) / maximum else 0f
|
|
61
|
+
val length = sqrt(zx * zx + zy * zy)
|
|
62
|
+
val polynomial = ((((-0.9260540008544922f * t + 3.1560099124908447f) * t -
|
|
63
|
+
3.6412200927734375f) * t + 1.268030047416687f) * t + 0.2685309946537018f) * t * t
|
|
64
|
+
val continuous = length + 1f - 1f / (1f - polynomial * min(length, 1f))
|
|
65
|
+
val ax = max(CornerExpansion * ux - CornerAdjustment, 0f)
|
|
66
|
+
val ay = max(CornerExpansion * uy - CornerAdjustment, 0f)
|
|
67
|
+
val correction = 0.3458344340324402f - continuous + 0.6541655659675598f * sqrt(ax * ax + ay * ay)
|
|
68
|
+
val weight = ((if (zx < zy) 1f else -1f) * (t - 1f) + 0.5f).coerceIn(0f, 1f)
|
|
69
|
+
val corner = continuous - 1f + correction * (curvatureX + (curvatureY - curvatureX) * weight)
|
|
70
|
+
return interior + expandedRadius * corner
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fun gradient(x: Float, y: Float) {
|
|
74
|
+
val localX = (x - centerX) * inverseAxisX
|
|
75
|
+
val localY = (y - centerY) * inverseAxisY
|
|
76
|
+
val qx = abs(localX) - halfWidth + baseRadius
|
|
77
|
+
val qy = abs(localY) - halfHeight + baseRadius
|
|
78
|
+
var nx = max(qx, 0f)
|
|
79
|
+
var ny = max(qy, 0f)
|
|
80
|
+
val cornerLength = sqrt(nx * nx + ny * ny)
|
|
81
|
+
if (cornerLength > 0.000001f) {
|
|
82
|
+
nx /= cornerLength
|
|
83
|
+
ny /= cornerLength
|
|
84
|
+
} else if (qx > qy) {
|
|
85
|
+
nx = 1f
|
|
86
|
+
ny = 0f
|
|
87
|
+
} else {
|
|
88
|
+
nx = 0f
|
|
89
|
+
ny = 1f
|
|
90
|
+
}
|
|
91
|
+
if (localX < 0f) nx = -nx
|
|
92
|
+
if (localY < 0f) ny = -ny
|
|
93
|
+
var ovalX = localX
|
|
94
|
+
var ovalY = localY * halfWidth / max(halfHeight, 0.000001f)
|
|
95
|
+
val ovalLength = sqrt(ovalX * ovalX + ovalY * ovalY)
|
|
96
|
+
if (ovalLength > 0.000001f) {
|
|
97
|
+
ovalX /= ovalLength
|
|
98
|
+
ovalY /= ovalLength
|
|
99
|
+
} else {
|
|
100
|
+
ovalX = nx
|
|
101
|
+
ovalY = ny
|
|
102
|
+
}
|
|
103
|
+
nx += ovalX
|
|
104
|
+
ny += ovalY
|
|
105
|
+
val length = sqrt(nx * nx + ny * ny)
|
|
106
|
+
if (length <= 0.000001f) {
|
|
107
|
+
gradientX = 0f
|
|
108
|
+
gradientY = 0f
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
gradientX = nx / length * inverseAxisX
|
|
112
|
+
gradientY = ny / length * inverseAxisY
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private companion object {
|
|
116
|
+
const val CornerExpansion = 1.5286649465560913f
|
|
117
|
+
const val CornerAdjustment = 0.5286649465560913f
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.field
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import kotlin.math.abs
|
|
5
|
+
import kotlin.math.min
|
|
6
|
+
import kotlin.math.sqrt
|
|
7
|
+
|
|
8
|
+
// One shape of the field (a rounded rect) or several blended into one (GlassShapes): the distance and gradient at a
|
|
9
|
+
// point, sampled into [distance], [gradientX] and [gradientY].
|
|
10
|
+
internal class RoundedUnion {
|
|
11
|
+
private val shapes = Array(GlassShapes.Capacity) { RoundedField() }
|
|
12
|
+
private var count = 0
|
|
13
|
+
private var blend = 0f
|
|
14
|
+
val bounds = RectF()
|
|
15
|
+
var distance = 0f
|
|
16
|
+
private set
|
|
17
|
+
var gradientX = 0f
|
|
18
|
+
private set
|
|
19
|
+
var gradientY = 0f
|
|
20
|
+
private set
|
|
21
|
+
|
|
22
|
+
fun set(rect: RectF, radiusX: Float, radiusY: Float) {
|
|
23
|
+
shapes[0].set(rect, radiusX, radiusY)
|
|
24
|
+
count = 1
|
|
25
|
+
bounds.set(rect)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun set(members: GlassShapes) {
|
|
29
|
+
count = members.count
|
|
30
|
+
blend = members.blend
|
|
31
|
+
for (index in 0 until count) shapes[index].set(members.rects[index], members.radii[index], members.radii[index])
|
|
32
|
+
members.bounds(bounds)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fun sample(x: Float, y: Float) {
|
|
36
|
+
val first = shapes[0]
|
|
37
|
+
distance = first.distance(x, y)
|
|
38
|
+
first.gradient(x, y)
|
|
39
|
+
gradientX = first.gradientX
|
|
40
|
+
gradientY = first.gradientY
|
|
41
|
+
for (index in 1 until count) {
|
|
42
|
+
val shape = shapes[index]
|
|
43
|
+
val d = shape.distance(x, y)
|
|
44
|
+
shape.gradient(x, y)
|
|
45
|
+
blendWith(d, shape.gradientX, shape.gradientY, blend)
|
|
46
|
+
}
|
|
47
|
+
// Several shapes: a unit normal where they meet, as the shader's (liquidMemberField).
|
|
48
|
+
if (count > 1) {
|
|
49
|
+
val length = sqrt(gradientX * gradientX + gradientY * gradientY)
|
|
50
|
+
if (length > 0.000001f) {
|
|
51
|
+
gradientX /= length
|
|
52
|
+
gradientY /= length
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The smooth union of this sample with another shape's, within [smoothing] px: the closer two surfaces face each
|
|
58
|
+
// other, the more they flow together (none where their normals agree).
|
|
59
|
+
fun blendWith(b: Float, bx: Float, by: Float, smoothing: Float) {
|
|
60
|
+
val a = distance
|
|
61
|
+
val ax = gradientX
|
|
62
|
+
val ay = gradientY
|
|
63
|
+
if (abs(a - b) >= smoothing) {
|
|
64
|
+
val first = a <= b
|
|
65
|
+
distance = min(a, b)
|
|
66
|
+
gradientX = if (first) ax else bx
|
|
67
|
+
gradientY = if (first) ay else by
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
val alignment = ax * bx + ay * by
|
|
71
|
+
val radius = smoothing * (0.5f - 0.5f * alignment).coerceIn(0f, 1f)
|
|
72
|
+
val weight = if (radius <= 0.000001f) {
|
|
73
|
+
if (a <= b) 0f else 1f
|
|
74
|
+
} else {
|
|
75
|
+
(0.5f + 0.5f * (a - b) / radius).coerceIn(0f, 1f)
|
|
76
|
+
}
|
|
77
|
+
distance = a + (b - a) * weight - radius * weight * (1f - weight)
|
|
78
|
+
gradientX = ax + (bx - ax) * weight
|
|
79
|
+
gradientY = ay + (by - ay) * weight
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.motion
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import com.facebook.react.R
|
|
7
|
+
import so.oxy.bloom.glassmenu.field.GlassShapes
|
|
8
|
+
import so.oxy.bloom.glassmenu.records.GlassMemberRecord
|
|
9
|
+
import kotlin.math.max
|
|
10
|
+
import kotlin.math.min
|
|
11
|
+
|
|
12
|
+
// The glasses of a group on one base (SwiftUI's GlassEffectContainer), in the base's own pixels. A member is the views
|
|
13
|
+
// in the base that carry its key as their nativeID: one view, or several drawn as one shape around them all (a union).
|
|
14
|
+
// Each member's glass is where its views are drawn, transforms included, so what moves a view (a matched geometry, an
|
|
15
|
+
// animation) moves its glass with it. What a view cannot do the group does here, on a spring: a key that moves to
|
|
16
|
+
// another view takes its glass there, a member that arrives grows out of the nearest glass and one that leaves goes
|
|
17
|
+
// back into the nearest one ('materialize': out of and into its own centre). The first members of a group are where
|
|
18
|
+
// they are, with no motion.
|
|
19
|
+
internal class GlassGroup {
|
|
20
|
+
private class Member(val key: String) {
|
|
21
|
+
var radius: Float? = null
|
|
22
|
+
var materialize = false
|
|
23
|
+
var leaving = false
|
|
24
|
+
// The view its glass is on (the first, for a union): another one takes the glass there on a spring.
|
|
25
|
+
var view: View? = null
|
|
26
|
+
val target = RectF()
|
|
27
|
+
val centerX = GlassSpring(.5f, 8f)
|
|
28
|
+
val centerY = GlassSpring(.5f, 8f)
|
|
29
|
+
val width = GlassSpring(.5f, 8f)
|
|
30
|
+
val height = GlassSpring(.5f, 8f)
|
|
31
|
+
val isSettled get() = centerX.isSettled && centerY.isSettled && width.isSettled && height.isSettled
|
|
32
|
+
|
|
33
|
+
fun reset(rect: RectF) {
|
|
34
|
+
centerX.reset(rect.centerX())
|
|
35
|
+
centerY.reset(rect.centerY())
|
|
36
|
+
width.reset(rect.width())
|
|
37
|
+
height.reset(rect.height())
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fun spring(rect: RectF) {
|
|
41
|
+
centerX.target(rect.centerX(), Spring)
|
|
42
|
+
centerY.target(rect.centerY(), Spring)
|
|
43
|
+
width.target(rect.width(), Spring)
|
|
44
|
+
height.target(rect.height(), Spring)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun advance(seconds: Float) {
|
|
48
|
+
centerX.advance(seconds)
|
|
49
|
+
centerY.advance(seconds)
|
|
50
|
+
width.advance(seconds)
|
|
51
|
+
height.advance(seconds)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fun current(out: RectF) {
|
|
55
|
+
val w = max(width.value, 0f)
|
|
56
|
+
val h = max(height.value, 0f)
|
|
57
|
+
out.set(centerX.value - w / 2f, centerY.value - h / 2f, centerX.value + w / 2f, centerY.value + h / 2f)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Null: the base is not a group, and is its own rect.
|
|
62
|
+
private var records: List<GlassMemberRecord>? = null
|
|
63
|
+
private val members = LinkedHashMap<String, Member>()
|
|
64
|
+
private val found = HashMap<String, RectF>()
|
|
65
|
+
private val owners = HashMap<String, View>()
|
|
66
|
+
// The rects [found] holds, kept from frame to frame (measuring runs before every frame the window draws).
|
|
67
|
+
private val pool = ArrayList<RectF>()
|
|
68
|
+
private var pooled = 0
|
|
69
|
+
private val measured = RectF()
|
|
70
|
+
private val placed = RectF()
|
|
71
|
+
var blend = 0f
|
|
72
|
+
|
|
73
|
+
val isGroup get() = records != null
|
|
74
|
+
val isSettled get() = members.values.all { it.isSettled && !it.leaving }
|
|
75
|
+
|
|
76
|
+
fun setRecords(value: List<GlassMemberRecord>?) {
|
|
77
|
+
records = value
|
|
78
|
+
if (value == null) members.clear()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Where the members' views are in [base] now. True when a member's glass changed (the caller draws it again).
|
|
82
|
+
fun measure(base: ViewGroup): Boolean {
|
|
83
|
+
val list = records ?: return false
|
|
84
|
+
found.clear()
|
|
85
|
+
owners.clear()
|
|
86
|
+
pooled = 0
|
|
87
|
+
collect(base, base)
|
|
88
|
+
val drawn = members.values.any { !it.leaving }
|
|
89
|
+
var changed = false
|
|
90
|
+
for (record in list) {
|
|
91
|
+
val rect = found[record.key] ?: continue
|
|
92
|
+
val owner = owners[record.key]
|
|
93
|
+
val member = members[record.key]
|
|
94
|
+
if (member == null) {
|
|
95
|
+
val arriving = Member(record.key).also { members[record.key] = it }
|
|
96
|
+
arriving.radius = record.cornerRadius
|
|
97
|
+
arriving.materialize = record.transition == Materialize
|
|
98
|
+
arriving.view = owner
|
|
99
|
+
arriving.target.set(rect)
|
|
100
|
+
if (drawn) {
|
|
101
|
+
arriving.reset(origin(arriving, rect))
|
|
102
|
+
arriving.spring(rect)
|
|
103
|
+
} else {
|
|
104
|
+
arriving.reset(rect)
|
|
105
|
+
}
|
|
106
|
+
changed = true
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
member.radius = record.cornerRadius
|
|
110
|
+
member.materialize = record.transition == Materialize
|
|
111
|
+
if (member.leaving) {
|
|
112
|
+
member.leaving = false
|
|
113
|
+
member.target.set(rect)
|
|
114
|
+
member.spring(rect)
|
|
115
|
+
changed = true
|
|
116
|
+
} else if (member.target != rect || member.view !== owner) {
|
|
117
|
+
// Its own view moved: settled, the glass follows it. Moving still, or on another view now (the key moved
|
|
118
|
+
// there), it springs to where the view is.
|
|
119
|
+
val moved = member.view !== owner
|
|
120
|
+
member.view = owner
|
|
121
|
+
member.target.set(rect)
|
|
122
|
+
if (member.isSettled && !moved) member.reset(rect) else member.spring(rect)
|
|
123
|
+
changed = true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (member in members.values) {
|
|
127
|
+
if (member.leaving || list.any { it.key == member.key && found.containsKey(it.key) }) continue
|
|
128
|
+
member.leaving = true
|
|
129
|
+
member.view = null
|
|
130
|
+
member.spring(origin(member, member.target))
|
|
131
|
+
changed = true
|
|
132
|
+
}
|
|
133
|
+
return changed
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Where a member grows out of or goes back into: the nearest other glass, or its own centre.
|
|
137
|
+
private fun origin(member: Member, rect: RectF): RectF {
|
|
138
|
+
if (!member.materialize) {
|
|
139
|
+
var nearest: Member? = null
|
|
140
|
+
var best = Float.MAX_VALUE
|
|
141
|
+
for (other in members.values) {
|
|
142
|
+
if (other === member || other.leaving || !found.containsKey(other.key)) continue
|
|
143
|
+
val dx = other.target.centerX() - rect.centerX()
|
|
144
|
+
val dy = other.target.centerY() - rect.centerY()
|
|
145
|
+
val distance = dx * dx + dy * dy
|
|
146
|
+
if (distance < best) {
|
|
147
|
+
best = distance
|
|
148
|
+
nearest = other
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (nearest != null) {
|
|
152
|
+
nearest.current(placed)
|
|
153
|
+
return placed
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
placed.set(rect.centerX(), rect.centerY(), rect.centerX(), rect.centerY())
|
|
157
|
+
return placed
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// The views in [view] that carry a member's key, each shape the union of its views' rects in [base].
|
|
161
|
+
private fun collect(view: View, base: ViewGroup) {
|
|
162
|
+
if (view !== base) {
|
|
163
|
+
val key = view.getTag(R.id.view_tag_native_id) as? String
|
|
164
|
+
if (key != null && view.visibility == View.VISIBLE && measure(view, base)) {
|
|
165
|
+
val shape = found[key]
|
|
166
|
+
if (shape != null) {
|
|
167
|
+
shape.union(measured)
|
|
168
|
+
} else {
|
|
169
|
+
found[key] = take().apply { set(measured) }
|
|
170
|
+
owners[key] = view
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (view is ViewGroup) for (index in 0 until view.childCount) collect(view.getChildAt(index), base)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private fun take(): RectF = (pool.getOrNull(pooled) ?: RectF().also { pool.add(it) }).also { pooled += 1 }
|
|
178
|
+
|
|
179
|
+
// The view's bounds in the base's pixels, through every transform and scroll between them.
|
|
180
|
+
private fun measure(view: View, base: ViewGroup): Boolean {
|
|
181
|
+
measured.set(0f, 0f, view.width.toFloat(), view.height.toFloat())
|
|
182
|
+
var current = view
|
|
183
|
+
while (current !== base) {
|
|
184
|
+
if (!current.matrix.isIdentity) current.matrix.mapRect(measured)
|
|
185
|
+
measured.offset(current.left.toFloat(), current.top.toFloat())
|
|
186
|
+
val parent = current.parent as? View ?: return false
|
|
187
|
+
measured.offset(-parent.scrollX.toFloat(), -parent.scrollY.toFloat())
|
|
188
|
+
current = parent
|
|
189
|
+
}
|
|
190
|
+
return measured.width() > 0f && measured.height() > 0f
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
fun advance(seconds: Float) {
|
|
194
|
+
if (members.isEmpty()) return
|
|
195
|
+
for (member in members.values) member.advance(seconds)
|
|
196
|
+
members.values.removeAll { it.leaving && it.isSettled }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// The members as they are now into [out], from the base's pixels ([baseWidth] x [baseHeight]) into [rect], where
|
|
200
|
+
// the base is drawn now (its press and its morph stretch it). False for a group with nothing to draw.
|
|
201
|
+
fun place(out: GlassShapes, rect: RectF, baseWidth: Int, baseHeight: Int, density: Float): Boolean {
|
|
202
|
+
out.clear()
|
|
203
|
+
out.blend = blend * density
|
|
204
|
+
if (records == null) return true
|
|
205
|
+
val scaleX = rect.width() / max(baseWidth, 1)
|
|
206
|
+
val scaleY = rect.height() / max(baseHeight, 1)
|
|
207
|
+
for (member in members.values) {
|
|
208
|
+
member.current(placed)
|
|
209
|
+
if (placed.width() < MinimumSize || placed.height() < MinimumSize) continue
|
|
210
|
+
placed.set(
|
|
211
|
+
rect.left + placed.left * scaleX, rect.top + placed.top * scaleY,
|
|
212
|
+
rect.left + placed.right * scaleX, rect.top + placed.bottom * scaleY,
|
|
213
|
+
)
|
|
214
|
+
val radius = member.radius?.let { it * density * min(scaleX, scaleY) } ?: Float.MAX_VALUE
|
|
215
|
+
out.add(placed, radius)
|
|
216
|
+
}
|
|
217
|
+
return out.count > 0
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private companion object {
|
|
221
|
+
const val Materialize = "materialize"
|
|
222
|
+
const val MinimumSize = .5f
|
|
223
|
+
val Spring = GlassSpringSpec(.75f, .32f)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.motion
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import kotlin.math.abs
|
|
5
|
+
import kotlin.math.atan2
|
|
6
|
+
import kotlin.math.cos
|
|
7
|
+
import kotlin.math.min
|
|
8
|
+
import kotlin.math.sin
|
|
9
|
+
import kotlin.math.tanh
|
|
10
|
+
|
|
11
|
+
internal class GlassJelly {
|
|
12
|
+
private val press = GlassSpring(.002f, .02f)
|
|
13
|
+
private val glow = GlassSpring(.002f, .02f)
|
|
14
|
+
private val dragX = GlassSpring(.3f, 6f)
|
|
15
|
+
private val dragY = GlassSpring(.3f, 6f)
|
|
16
|
+
private val lightX = GlassSpring(.3f, 6f)
|
|
17
|
+
private val lightY = GlassSpring(.3f, 6f)
|
|
18
|
+
private var startX = 0f
|
|
19
|
+
private var startY = 0f
|
|
20
|
+
|
|
21
|
+
val glowValue get() = glow.value.coerceIn(0f, 1f)
|
|
22
|
+
val lightPositionX get() = lightX.value
|
|
23
|
+
val lightPositionY get() = lightY.value
|
|
24
|
+
val isSettled
|
|
25
|
+
get() = press.isSettled && glow.isSettled && dragX.isSettled && dragY.isSettled &&
|
|
26
|
+
lightX.isSettled && lightY.isSettled
|
|
27
|
+
|
|
28
|
+
fun down(x: Float, y: Float) {
|
|
29
|
+
startX = x
|
|
30
|
+
startY = y
|
|
31
|
+
if (glow.value < .02f) {
|
|
32
|
+
lightX.reset(x)
|
|
33
|
+
lightY.reset(y)
|
|
34
|
+
} else {
|
|
35
|
+
lightX.target(x, LightFollow)
|
|
36
|
+
lightY.target(y, LightFollow)
|
|
37
|
+
}
|
|
38
|
+
press.target(1f, JellySpring)
|
|
39
|
+
glow.target(1f, GlowIn)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fun move(x: Float, y: Float) {
|
|
43
|
+
dragX.target(x - startX, DragFollow)
|
|
44
|
+
dragY.target(y - startY, DragFollow)
|
|
45
|
+
lightX.target(x, LightFollow)
|
|
46
|
+
lightY.target(y, LightFollow)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fun release() {
|
|
50
|
+
press.target(0f, JellySpring)
|
|
51
|
+
glow.target(0f, GlowOut)
|
|
52
|
+
dragX.target(0f, JellySpring)
|
|
53
|
+
dragY.target(0f, JellySpring)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fun advance(seconds: Float) {
|
|
57
|
+
press.advance(seconds)
|
|
58
|
+
glow.advance(seconds)
|
|
59
|
+
dragX.advance(seconds)
|
|
60
|
+
dragY.advance(seconds)
|
|
61
|
+
lightX.advance(seconds)
|
|
62
|
+
lightY.advance(seconds)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fun deformMenu(out: RectF, awayX: Float, awayY: Float, density: Float, amount: Float) {
|
|
66
|
+
val reach = MenuReach * density
|
|
67
|
+
val dx = dragX.value
|
|
68
|
+
val dy = dragY.value
|
|
69
|
+
val pullX = tanh(dx * awayX / reach)
|
|
70
|
+
val pullY = tanh(dy * awayY / reach)
|
|
71
|
+
val width = out.width() + (MenuStretch * pullX - MenuSquash * pullY) * density * amount
|
|
72
|
+
val height = out.height() + (MenuStretch * pullY - MenuSquash * pullX) * density * amount
|
|
73
|
+
val centerX = out.centerX() + MenuShift * tanh(dx / reach) * density * amount
|
|
74
|
+
val centerY = out.centerY() + MenuShift * tanh(dy / reach) * density * amount
|
|
75
|
+
out.set(centerX - width / 2f, centerY - height / 2f, centerX + width / 2f, centerY + height / 2f)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fun swell(height: Float, density: Float, amount: Float): Float =
|
|
79
|
+
1f + press.value * ControlLift * density * amount / height.coerceAtLeast(1f)
|
|
80
|
+
|
|
81
|
+
fun deformControl(out: RectF, density: Float, amount: Float) {
|
|
82
|
+
val width = out.width().coerceAtLeast(1f)
|
|
83
|
+
val height = out.height().coerceAtLeast(1f)
|
|
84
|
+
val longest = maxOf(width, height)
|
|
85
|
+
val shortest = min(width, height)
|
|
86
|
+
val dx = dragX.value
|
|
87
|
+
val dy = dragY.value
|
|
88
|
+
val scale = swell(height, density, amount)
|
|
89
|
+
val angle = atan2(dy, dx)
|
|
90
|
+
val stretch = ControlLift * density * amount / height
|
|
91
|
+
val scaleX = scale + stretch * abs(cos(angle) * dx / longest) * min(width / height, 1f)
|
|
92
|
+
val scaleY = scale + stretch * abs(sin(angle) * dy / longest) * min(height / width, 1f)
|
|
93
|
+
val centerX = out.centerX() + shortest * tanh(DragLean * dx / shortest) * amount
|
|
94
|
+
val centerY = out.centerY() + shortest * tanh(DragLean * dy / shortest) * amount
|
|
95
|
+
val halfWidth = width * scaleX / 2f
|
|
96
|
+
val halfHeight = height * scaleY / 2f
|
|
97
|
+
out.set(centerX - halfWidth, centerY - halfHeight, centerX + halfWidth, centerY + halfHeight)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fun releaseDrag() {
|
|
101
|
+
dragX.target(0f, JellySpring)
|
|
102
|
+
dragY.target(0f, JellySpring)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private companion object {
|
|
106
|
+
const val MenuReach = 260f
|
|
107
|
+
const val MenuStretch = 16f
|
|
108
|
+
const val MenuSquash = 21f
|
|
109
|
+
const val MenuShift = 21f
|
|
110
|
+
const val ControlLift = 4f
|
|
111
|
+
const val DragLean = .05f
|
|
112
|
+
val JellySpring = GlassSpringSpec(.5f, .45f)
|
|
113
|
+
val DragFollow = GlassSpringSpec(.65f, .18f)
|
|
114
|
+
val LightFollow = GlassSpringSpec(.8f, .16f)
|
|
115
|
+
val GlowIn = GlassSpringSpec(1f, .1f)
|
|
116
|
+
val GlowOut = GlassSpringSpec(1f, .5f)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.motion
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
|
|
5
|
+
internal class GlassMorphFrame {
|
|
6
|
+
val bounds = RectF()
|
|
7
|
+
var radiusX = 0f
|
|
8
|
+
var radiusY = 0f
|
|
9
|
+
var contentProgress = 0f
|
|
10
|
+
var rowsOpacity = 0f
|
|
11
|
+
val sourceLobe = RectF()
|
|
12
|
+
var sourceRadius = 0f
|
|
13
|
+
var smoothing = 0f
|
|
14
|
+
var sourceOpacity = 1f
|
|
15
|
+
var sourceBlur = 0f
|
|
16
|
+
var sourceZoom = 1f
|
|
17
|
+
var contentBlur = 0f
|
|
18
|
+
var contentZoom = 1f
|
|
19
|
+
var portalBlur = 0f
|
|
20
|
+
var lensHeight = 0f
|
|
21
|
+
var lensAmount = 0f
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.motion
|
|
2
|
+
|
|
3
|
+
import so.oxy.bloom.glassmenu.records.GlassAbsorbRecord
|
|
4
|
+
import so.oxy.bloom.glassmenu.records.GlassShrinkRecord
|
|
5
|
+
import kotlin.math.max
|
|
6
|
+
|
|
7
|
+
// absorbScale shortens the close (absorb) spring only: the submenu layer uses it so its collapse ends sooner.
|
|
8
|
+
internal class GlassMorphTuning(shrink: GlassShrinkRecord?, absorb: GlassAbsorbRecord?, absorbScale: Float = 1f) {
|
|
9
|
+
private val shrinkDuration = max(shrink?.duration ?: DefaultShrinkDuration, MinimumDuration)
|
|
10
|
+
private val shrinkDamping = shrink?.damping?.coerceIn(MinimumDamping, 1f)
|
|
11
|
+
|
|
12
|
+
val shrinkScale = (shrink?.scale ?: DefaultShrinkScale).coerceIn(.05f, 1f)
|
|
13
|
+
val collapse = GlassSpringSpec(shrinkDamping ?: 1f, shrinkDuration)
|
|
14
|
+
val eject = GlassSpringSpec(shrinkDamping ?: DefaultEjectDamping, shrinkDuration * EjectRatio)
|
|
15
|
+
val absorb = GlassSpringSpec(
|
|
16
|
+
absorb?.damping?.coerceIn(MinimumDamping, 1f) ?: DefaultAbsorbDamping,
|
|
17
|
+
max((absorb?.duration ?: DefaultAbsorbDuration) * absorbScale, MinimumDuration),
|
|
18
|
+
)
|
|
19
|
+
val neckHold = max(shrinkDuration / DefaultShrinkDuration, 1f)
|
|
20
|
+
|
|
21
|
+
private companion object {
|
|
22
|
+
const val DefaultShrinkDuration = .21f
|
|
23
|
+
const val DefaultShrinkScale = .25f
|
|
24
|
+
const val DefaultEjectDamping = .75f
|
|
25
|
+
const val DefaultAbsorbDuration = .35f
|
|
26
|
+
const val DefaultAbsorbDamping = .8f
|
|
27
|
+
const val EjectRatio = .32f / .21f
|
|
28
|
+
const val MinimumDuration = .02f
|
|
29
|
+
const val MinimumDamping = .1f
|
|
30
|
+
}
|
|
31
|
+
}
|