@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,750 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.overlay
|
|
2
|
+
|
|
3
|
+
import android.graphics.Canvas
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.graphics.Paint
|
|
6
|
+
import android.graphics.Rect
|
|
7
|
+
import android.graphics.RectF
|
|
8
|
+
import android.graphics.RenderEffect
|
|
9
|
+
import android.graphics.RenderNode
|
|
10
|
+
import so.oxy.bloom.glassmenu.backdrop.GlassBackdrop
|
|
11
|
+
import android.graphics.Shader
|
|
12
|
+
import android.os.Build
|
|
13
|
+
import android.view.MotionEvent
|
|
14
|
+
import so.oxy.bloom.glassmenu.GlassMenuAndroidView
|
|
15
|
+
import so.oxy.bloom.glassmenu.content.GlassMenuContent
|
|
16
|
+
import so.oxy.bloom.glassmenu.content.GlassRow
|
|
17
|
+
import so.oxy.bloom.glassmenu.motion.GlassJelly
|
|
18
|
+
import so.oxy.bloom.glassmenu.motion.GlassMorphTuning
|
|
19
|
+
import so.oxy.bloom.glassmenu.motion.GlassMotion
|
|
20
|
+
import so.oxy.bloom.glassmenu.motion.GlassSpring
|
|
21
|
+
import so.oxy.bloom.glassmenu.motion.GlassSpringSpec
|
|
22
|
+
import so.oxy.bloom.glassmenu.records.GlassMenuItemRecord
|
|
23
|
+
import so.oxy.bloom.glassmenu.render.GlassSurfaceState
|
|
24
|
+
import kotlin.math.abs
|
|
25
|
+
import kotlin.math.max
|
|
26
|
+
import kotlin.math.min
|
|
27
|
+
|
|
28
|
+
// Stacked submenu panels (iOS-style): the submenu is a second glass surface over the root, with its own
|
|
29
|
+
// renderer and GlassMotion. Off until the stacked model is verified; the navigation model is the default.
|
|
30
|
+
internal const val GLASS_SUBMENU_LAYERS = true
|
|
31
|
+
|
|
32
|
+
internal class GlassMenuSession(
|
|
33
|
+
private val overlay: GlassMenuOverlay,
|
|
34
|
+
val anchor: GlassMenuAndroidView,
|
|
35
|
+
private val density: Float,
|
|
36
|
+
private val supportsGlass: Boolean,
|
|
37
|
+
through: RectF?,
|
|
38
|
+
windowWidth: Int,
|
|
39
|
+
windowHeight: Int,
|
|
40
|
+
insets: Rect,
|
|
41
|
+
) {
|
|
42
|
+
private val motion = GlassMotion()
|
|
43
|
+
private val content = GlassMenuContent(overlay.context, density) { slot -> anchor.iconView(slot) }
|
|
44
|
+
private val target = RectF()
|
|
45
|
+
private val source = RectF()
|
|
46
|
+
private val throughRect = RectF()
|
|
47
|
+
private val state = GlassSurfaceState()
|
|
48
|
+
private val rowsNode: RenderNode? = if (supportsGlass) RenderNode("GlassMenu.rows") else null
|
|
49
|
+
private var rowsDirty = true
|
|
50
|
+
private val shown = RectF()
|
|
51
|
+
private val captureBounds = RectF()
|
|
52
|
+
private var lockedFieldStep = 0f
|
|
53
|
+
|
|
54
|
+
private val plateTop = GlassSpring(.25f, 8f)
|
|
55
|
+
private val plateHeight = GlassSpring(.25f, 8f)
|
|
56
|
+
// Horizontal extent of the plate: a list row spans the plate inset; an action cell its column (plateSpan).
|
|
57
|
+
private val plateLeft = GlassSpring(.25f, 8f)
|
|
58
|
+
private val plateRight = GlassSpring(.25f, 8f)
|
|
59
|
+
private val plateAlpha = GlassSpring(.004f, .05f)
|
|
60
|
+
private val jelly = GlassJelly()
|
|
61
|
+
private val scrub = GlassScrub(jelly)
|
|
62
|
+
private val plateRect = RectF()
|
|
63
|
+
private val plateNode: RenderNode? = if (supportsGlass) RenderNode("GlassMenu.plate") else null
|
|
64
|
+
private var plateVisible = false
|
|
65
|
+
private var activeRow: GlassRow? = null
|
|
66
|
+
|
|
67
|
+
private var scroll = 0f
|
|
68
|
+
private var maximumScroll = 0f
|
|
69
|
+
private var touchStartX = 0f
|
|
70
|
+
private var touchStartY = 0f
|
|
71
|
+
private var touchStartScroll = 0f
|
|
72
|
+
private var scrolling = false
|
|
73
|
+
private var touchInside = false
|
|
74
|
+
private var animating = true
|
|
75
|
+
private var dismissOnUp = false
|
|
76
|
+
// Submenu navigation: the submenu panel being shown (null at the root), and the content reveal.
|
|
77
|
+
private var levelItems: GlassMenuItemRecord? = null
|
|
78
|
+
private val nav = GlassSpring(0.001f, 0.01f)
|
|
79
|
+
// Stacked submenu (flag GLASS_SUBMENU_LAYERS): the panel over the root, and the root's recede amount.
|
|
80
|
+
private var child: GlassSubmenuLayer? = null
|
|
81
|
+
// The root row that opened the submenu: it is drawn by the submenu (as its header), not by the root.
|
|
82
|
+
private var openedRow: GlassRow? = null
|
|
83
|
+
// A tap that arrived during a submenu transition, run when it ends.
|
|
84
|
+
private var hasPendingUp = false
|
|
85
|
+
private var pendingUpX = 0f
|
|
86
|
+
private var pendingUpY = 0f
|
|
87
|
+
private val parentDim = GlassSpring(0.001f, 0.01f)
|
|
88
|
+
private val availableWidth: Float
|
|
89
|
+
private val maximumHeight: Float
|
|
90
|
+
private val opensAbove: Boolean
|
|
91
|
+
private val opensFromRight: Boolean
|
|
92
|
+
|
|
93
|
+
var expanded = true
|
|
94
|
+
private set
|
|
95
|
+
val needsFrame: Boolean
|
|
96
|
+
get() = animating || !plateAlpha.isSettled || !plateTop.isSettled || !plateHeight.isSettled || !plateLeft.isSettled || !plateRight.isSettled ||
|
|
97
|
+
!jelly.isSettled || !nav.isSettled || !parentDim.isSettled || child?.needsFrame == true
|
|
98
|
+
|
|
99
|
+
init {
|
|
100
|
+
val margin = 16f * density
|
|
101
|
+
availableWidth = windowWidth - margin * 2f
|
|
102
|
+
content.dark = anchor.isDark()
|
|
103
|
+
content.ink = anchor.config
|
|
104
|
+
levelItems = null
|
|
105
|
+
nav.reset(1f)
|
|
106
|
+
parentDim.reset(0f)
|
|
107
|
+
content.contentAlpha = 1f
|
|
108
|
+
content.setItems(anchor.items, anchor.menuWidth, availableWidth, anchor.fontFamily)
|
|
109
|
+
overlay.anchorRect(anchor, source)
|
|
110
|
+
throughRect.set(through ?: source)
|
|
111
|
+
|
|
112
|
+
val top = insets.top.toFloat()
|
|
113
|
+
val bottom = windowHeight - insets.bottom.toFloat()
|
|
114
|
+
maximumHeight = bottom - top - margin
|
|
115
|
+
val height = min(content.height, maximumHeight)
|
|
116
|
+
maximumScroll = max(content.height - height, 0f)
|
|
117
|
+
val width = content.width
|
|
118
|
+
val alignment = anchor.alignment
|
|
119
|
+
opensFromRight = alignment == "end" || alignment == "auto" && throughRect.centerX() > windowWidth / 2f
|
|
120
|
+
val left = when {
|
|
121
|
+
alignment == "center" -> throughRect.centerX() - width / 2f
|
|
122
|
+
opensFromRight -> source.right - width
|
|
123
|
+
else -> source.left
|
|
124
|
+
}.coerceIn(margin, max(windowWidth - width - margin, margin))
|
|
125
|
+
val roomBelow = bottom - source.top
|
|
126
|
+
val roomAbove = source.bottom - top
|
|
127
|
+
opensAbove = roomBelow < height && roomAbove > roomBelow
|
|
128
|
+
val menuTop = (if (opensAbove) source.bottom - height else source.top)
|
|
129
|
+
.coerceIn(top, max(bottom - height, top))
|
|
130
|
+
target.set(left, menuTop, left + width, menuTop + height)
|
|
131
|
+
updateCaptureBounds()
|
|
132
|
+
|
|
133
|
+
motion.initialize(
|
|
134
|
+
source, target, CornerRadius * density, density, throughRect, anchor.followsPress,
|
|
135
|
+
GlassMorphTuning(anchor.triggerConfig.shrink, anchor.triggerConfig.absorb))
|
|
136
|
+
motion.retarget(true)
|
|
137
|
+
plateAlpha.reset(0f)
|
|
138
|
+
plateTop.reset(0f)
|
|
139
|
+
plateHeight.reset(0f)
|
|
140
|
+
plateLeft.reset(0f)
|
|
141
|
+
plateRight.reset(0f)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fun refreshItems() {
|
|
145
|
+
if (!expanded) return
|
|
146
|
+
content.setItems(levelItems?.items ?: anchor.items, anchor.menuWidth, availableWidth, anchor.fontFamily, levelItems)
|
|
147
|
+
val height = min(content.height, maximumHeight)
|
|
148
|
+
maximumScroll = max(content.height - height, 0f)
|
|
149
|
+
scroll = min(scroll, maximumScroll)
|
|
150
|
+
activeRow = null
|
|
151
|
+
plateVisible = false
|
|
152
|
+
plateAlpha.reset(0f)
|
|
153
|
+
rowsDirty = true
|
|
154
|
+
if (height != target.height() || content.width != target.width()) {
|
|
155
|
+
val left = if (opensFromRight) target.right - content.width else target.left
|
|
156
|
+
val top = if (opensAbove) target.bottom - height else target.top
|
|
157
|
+
target.set(left, top, left + content.width, top + height)
|
|
158
|
+
updateCaptureBounds()
|
|
159
|
+
motion.updateTarget(target, CornerRadius * density)
|
|
160
|
+
animating = true
|
|
161
|
+
}
|
|
162
|
+
overlay.requestFrame()
|
|
163
|
+
overlay.invalidate()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fun reopen() {
|
|
167
|
+
expanded = true
|
|
168
|
+
animating = true
|
|
169
|
+
motion.retarget(true)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
fun close() {
|
|
173
|
+
expanded = false
|
|
174
|
+
animating = true
|
|
175
|
+
plateVisible = false
|
|
176
|
+
// Closing the menu takes the submenu away at once: the root's own close (the same one the tap uses) takes its
|
|
177
|
+
// rows, header included, back to the trigger. A submenu that closed on its own timeline would leave its header
|
|
178
|
+
// on screen after the rest of the menu had gone.
|
|
179
|
+
child?.release()
|
|
180
|
+
child = null
|
|
181
|
+
openedRow = null
|
|
182
|
+
rowsDirty = true
|
|
183
|
+
parentDim.target(0f, GlassMotion.CollapseSpring)
|
|
184
|
+
plateAlpha.target(0f, PlateFade)
|
|
185
|
+
jelly.release()
|
|
186
|
+
overlay.anchorRect(anchor, source)
|
|
187
|
+
motion.updateSource(source, if (throughRect.isEmpty) source else throughRect)
|
|
188
|
+
// A scrub that is committed keeps its timeline (the position it reached); a tap starts the close.
|
|
189
|
+
if (motion.scrubbing) motion.endScrub(true) else motion.retarget(false)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Predictive back with a submenu open: the gesture drives the submenu back into its row (progress 0 = open,
|
|
193
|
+
// 1 = in the row) and the root recedes with it. The system decides the commit on release: an invoke completes
|
|
194
|
+
// the back, a cancel reopens the submenu. The session adds no threshold of its own.
|
|
195
|
+
private var gesturing = false
|
|
196
|
+
private var gestureProgress = 0f
|
|
197
|
+
|
|
198
|
+
fun backGestureStart() {
|
|
199
|
+
if (closing()) return
|
|
200
|
+
gesturing = true
|
|
201
|
+
gestureProgress = 0f
|
|
202
|
+
// Root: the close timeline is set up and scrubbed by the finger (the same timeline the tap uses).
|
|
203
|
+
if (child == null) {
|
|
204
|
+
motion.retarget(false)
|
|
205
|
+
motion.beginScrub()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
fun backGestureProgress(progress: Float) {
|
|
210
|
+
if (!gesturing) backGestureStart()
|
|
211
|
+
if (!gesturing) return
|
|
212
|
+
gestureProgress = progress.coerceIn(0f, 1f)
|
|
213
|
+
val layer = child
|
|
214
|
+
if (layer != null) {
|
|
215
|
+
// Android's progress runs 0 (open) to 1 (back); the layer's runs 1 (open) to 0 (in the row).
|
|
216
|
+
layer.dragTo(1f - gestureProgress)
|
|
217
|
+
} else {
|
|
218
|
+
motion.scrubTo(gestureProgress)
|
|
219
|
+
animating = false
|
|
220
|
+
}
|
|
221
|
+
overlay.requestFrame()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
fun backGestureCancel() {
|
|
225
|
+
if (!gesturing) return
|
|
226
|
+
gesturing = false
|
|
227
|
+
val layer = child
|
|
228
|
+
if (layer != null) layer.reopen() else {
|
|
229
|
+
// The root's timeline reopens with the normal open timeline, from where the scrub left it.
|
|
230
|
+
motion.endScrub(false)
|
|
231
|
+
animating = true
|
|
232
|
+
}
|
|
233
|
+
overlay.requestFrame()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Returns true when the back event was taken (the menu stays open, or finishes its own close).
|
|
237
|
+
fun backGestureInvoke(): Boolean {
|
|
238
|
+
// The system decides the commit on release. Once it invokes, the back completes: no second threshold.
|
|
239
|
+
val layer = child
|
|
240
|
+
if (layer == null) {
|
|
241
|
+
// Root: the commit is the normal close: the same timeline the tap uses, continued from the scrub's position.
|
|
242
|
+
gesturing = false
|
|
243
|
+
return false
|
|
244
|
+
}
|
|
245
|
+
gesturing = false
|
|
246
|
+
closeChild()
|
|
247
|
+
overlay.requestFrame()
|
|
248
|
+
return true
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private fun closing(): Boolean = child?.closing == true
|
|
252
|
+
|
|
253
|
+
fun tick(seconds: Float): Boolean {
|
|
254
|
+
val settled = if (animating) motion.advanceBy(seconds) else true
|
|
255
|
+
if (settled) animating = false
|
|
256
|
+
nav.advance(seconds)
|
|
257
|
+
parentDim.advance(seconds)
|
|
258
|
+
// A drag holds the layer where the finger leaves it: it is removed only when the gesture is over.
|
|
259
|
+
// The root recedes with the layer's progress: one state, so the two cannot drift apart.
|
|
260
|
+
val current = child
|
|
261
|
+
if (current != null) parentDim.reset(current.progressValue)
|
|
262
|
+
current?.let { layer ->
|
|
263
|
+
if (layer.tick(seconds) && !gesturing) {
|
|
264
|
+
child = null
|
|
265
|
+
openedRow = null
|
|
266
|
+
rowsDirty = true
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
runPendingUp()
|
|
270
|
+
content.contentAlpha = nav.value
|
|
271
|
+
// The rows are recorded into a RenderNode: while the level fades in, they must be re-recorded.
|
|
272
|
+
if (!nav.isSettled || rowsDirty) rowsDirty = true
|
|
273
|
+
plateTop.advance(seconds)
|
|
274
|
+
plateHeight.advance(seconds)
|
|
275
|
+
plateLeft.advance(seconds)
|
|
276
|
+
plateRight.advance(seconds)
|
|
277
|
+
plateAlpha.advance(seconds)
|
|
278
|
+
jelly.advance(seconds)
|
|
279
|
+
return settled && !expanded && nav.isSettled && child == null
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private fun updateCaptureBounds() {
|
|
283
|
+
captureBounds.set(source)
|
|
284
|
+
captureBounds.union(target)
|
|
285
|
+
captureBounds.inset(-CaptureMargin * density, -CaptureMargin * density)
|
|
286
|
+
lockedFieldStep = max(
|
|
287
|
+
NeckSigma * density / FieldCellsPerSigma,
|
|
288
|
+
max(captureBounds.width(), captureBounds.height()) / FieldCells,
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private fun liveBounds(out: RectF) {
|
|
293
|
+
out.set(motion.frame.bounds)
|
|
294
|
+
jelly.deformMenu(out, if (opensFromRight) -1f else 1f, if (opensAbove) -1f else 1f, density, anchor.config.jelly)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
fun draw(canvas: Canvas, backdrop: GlassBackdrop, limits: Rect) {
|
|
298
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return
|
|
299
|
+
drawRoot(canvas, backdrop, limits)
|
|
300
|
+
child?.draw(canvas, backdrop, limits)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private fun drawRoot(canvas: Canvas, backdrop: GlassBackdrop, limits: Rect) {
|
|
304
|
+
val frame = motion.frame
|
|
305
|
+
liveBounds(shown)
|
|
306
|
+
// While a stacked submenu is open the root recedes: the glass shrinks and the rows dim.
|
|
307
|
+
val dim = parentDim.value.coerceIn(0f, 1f)
|
|
308
|
+
val scale = 1f - ParentScaleDrop * dim
|
|
309
|
+
if (scale < 1f) shown.inset(shown.width() * (1f - scale) / 2f, shown.height() * (1f - scale) / 2f)
|
|
310
|
+
state.incoming.set(shown)
|
|
311
|
+
state.captureBounds.set(captureBounds)
|
|
312
|
+
state.lockedFieldStep = lockedFieldStep
|
|
313
|
+
state.radiusX = frame.radiusX
|
|
314
|
+
state.radiusY = frame.radiusY
|
|
315
|
+
state.hasSource = anchor.morphs
|
|
316
|
+
state.source.set(frame.sourceLobe)
|
|
317
|
+
val swell = anchor.jelly.swell(anchor.height.toFloat(), density, anchor.triggerConfig.jelly) - 1f
|
|
318
|
+
state.source.inset(-state.source.width() * swell / 2f, -state.source.height() * swell / 2f)
|
|
319
|
+
// A plain trigger keeps its own corner radius (cornerRadius), not the capsule of a glass lobe.
|
|
320
|
+
state.sourceRadius = if (anchor.glass) min(state.source.width(), state.source.height()) / 2f
|
|
321
|
+
else anchor.cornerRadiusPx(state.source)
|
|
322
|
+
// A group's glasses are its lobe: they follow it as its content does, scaled into it.
|
|
323
|
+
if (anchor.morphs) anchor.group.place(state.members, state.source, anchor.width, anchor.height, density)
|
|
324
|
+
else state.members.clear()
|
|
325
|
+
state.smoothing = frame.smoothing
|
|
326
|
+
state.lensHeight = frame.lensHeight
|
|
327
|
+
state.lensAmount = frame.lensAmount
|
|
328
|
+
state.materialProgress = frame.contentProgress
|
|
329
|
+
state.surfaceOpacity = if (anchor.morphs) 1f else frame.contentProgress
|
|
330
|
+
state.dark = content.dark
|
|
331
|
+
state.config = anchor.config
|
|
332
|
+
state.trigger = anchor.triggerConfig
|
|
333
|
+
applyLight(frame.contentProgress)
|
|
334
|
+
val renderer = anchor.renderer(density)
|
|
335
|
+
renderer.prepare(state)
|
|
336
|
+
renderer.drawGlass(canvas, backdrop, state, limits)
|
|
337
|
+
|
|
338
|
+
val rows = recordRows() ?: return
|
|
339
|
+
val width = target.width()
|
|
340
|
+
val height = target.height()
|
|
341
|
+
val zoom = frame.contentZoom
|
|
342
|
+
rows.setPivotX(0f)
|
|
343
|
+
rows.setPivotY(0f)
|
|
344
|
+
rows.setScaleX(shown.width() / width * zoom)
|
|
345
|
+
rows.setScaleY(shown.height() / height * zoom)
|
|
346
|
+
rows.setTranslationX(shown.left + shown.width() * .5f * (1f - zoom))
|
|
347
|
+
rows.setTranslationY(shown.top + shown.height() * .5f * (1f - zoom))
|
|
348
|
+
// Closing: the rows (text included) never outlive the glass they sit in. Their alpha is capped by the glass's own
|
|
349
|
+
// progress, so no text is left on the page once the glass has gone. Opening is unchanged.
|
|
350
|
+
val glassAlpha = if (expanded) 1f else frame.contentProgress
|
|
351
|
+
rows.setAlpha(minOf(frame.rowsOpacity, glassAlpha) * (1f - ParentRowsDim * dim))
|
|
352
|
+
val morphBlur = anchor.config.morphBlur
|
|
353
|
+
rows.setRenderEffect(blur(frame.contentBlur * morphBlur / max(min(rows.scaleX, rows.scaleY), MinimumRowsScale)))
|
|
354
|
+
|
|
355
|
+
val trigger = anchor.recordContent()
|
|
356
|
+
val lobe = state.source
|
|
357
|
+
val sourceZoom = frame.sourceZoom
|
|
358
|
+
val triggerWidth = max(anchor.width, 1)
|
|
359
|
+
val triggerHeight = max(anchor.height, 1)
|
|
360
|
+
trigger.setPivotX(triggerWidth / 2f)
|
|
361
|
+
trigger.setPivotY(triggerHeight / 2f)
|
|
362
|
+
trigger.setScaleX(lobe.width() / triggerWidth * sourceZoom)
|
|
363
|
+
trigger.setScaleY(lobe.height() / triggerHeight * sourceZoom)
|
|
364
|
+
trigger.setTranslationX(lobe.centerX() - triggerWidth / 2f)
|
|
365
|
+
trigger.setTranslationY(lobe.centerY() - triggerHeight / 2f)
|
|
366
|
+
trigger.setAlpha(frame.sourceOpacity)
|
|
367
|
+
trigger.setRenderEffect(blur(frame.sourceBlur))
|
|
368
|
+
|
|
369
|
+
val plate = recordPlate()
|
|
370
|
+
if (plate != null) {
|
|
371
|
+
plate.setPivotX(0f)
|
|
372
|
+
plate.setPivotY(0f)
|
|
373
|
+
plate.setScaleX(rows.scaleX)
|
|
374
|
+
plate.setScaleY(rows.scaleY)
|
|
375
|
+
plate.setTranslationX(rows.translationX)
|
|
376
|
+
plate.setTranslationY(rows.translationY)
|
|
377
|
+
plate.setAlpha(frame.rowsOpacity)
|
|
378
|
+
}
|
|
379
|
+
renderer.drawForeground(canvas, state, animating, frame.portalBlur * morphBlur) { recording ->
|
|
380
|
+
if (anchor.morphs && frame.sourceOpacity > .001f) recording.drawRenderNode(trigger)
|
|
381
|
+
if (frame.rowsOpacity > .001f) {
|
|
382
|
+
if (plate != null) recording.drawRenderNode(plate)
|
|
383
|
+
recording.drawRenderNode(rows)
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (!anchor.morphs && frame.sourceOpacity > .001f) canvas.drawRenderNode(trigger)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private fun blur(radius: Float): RenderEffect? =
|
|
390
|
+
if (radius > .01f) RenderEffect.createBlurEffect(radius, radius, Shader.TileMode.DECAL) else null
|
|
391
|
+
|
|
392
|
+
private fun applyLight(progress: Float) {
|
|
393
|
+
val shine = anchor.config.shine
|
|
394
|
+
val glow = jelly.glowValue * shine * progress
|
|
395
|
+
if (glow > anchor.jelly.glowValue * (1f - progress)) {
|
|
396
|
+
state.pressX = jelly.lightPositionX
|
|
397
|
+
state.pressY = jelly.lightPositionY
|
|
398
|
+
state.pressRadius = MenuLightRadius * density
|
|
399
|
+
state.poolGain = MenuPool * glow
|
|
400
|
+
state.pressLift = MenuLift * glow
|
|
401
|
+
state.rimLift = MenuRimLift * glow
|
|
402
|
+
} else if (expanded) {
|
|
403
|
+
// The trigger's light only while the menu opens: as it closes, the glass must not brighten into the trigger's glow.
|
|
404
|
+
anchor.applyLight(state, source, 1f - progress)
|
|
405
|
+
} else {
|
|
406
|
+
state.poolGain = 0f
|
|
407
|
+
state.pressLift = 0f
|
|
408
|
+
state.rimLift = 0f
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private fun recordRows(): RenderNode? {
|
|
413
|
+
val node = rowsNode ?: return null
|
|
414
|
+
val width = target.width().toInt()
|
|
415
|
+
val height = target.height().toInt()
|
|
416
|
+
if (rowsDirty) {
|
|
417
|
+
rowsDirty = false
|
|
418
|
+
node.setPosition(0, 0, width, height)
|
|
419
|
+
content.draw(node.beginRecording(width, height), scroll) { it === openedRow }
|
|
420
|
+
node.endRecording()
|
|
421
|
+
}
|
|
422
|
+
return node
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
private fun recordPlate(): RenderNode? {
|
|
426
|
+
val node = plateNode ?: return null
|
|
427
|
+
if (plateAlpha.value <= .001f) return null
|
|
428
|
+
val width = target.width().toInt()
|
|
429
|
+
val height = target.height().toInt()
|
|
430
|
+
node.setPosition(0, 0, width, height)
|
|
431
|
+
val recording = node.beginRecording(width, height)
|
|
432
|
+
updatePlateRect()
|
|
433
|
+
content.drawPlate(
|
|
434
|
+
recording, plateRect, plateAlpha.value, jelly.lightPositionX - target.left,
|
|
435
|
+
anchor.config.highlightOpacity, anchor.config.shine,
|
|
436
|
+
)
|
|
437
|
+
node.endRecording()
|
|
438
|
+
return node
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Horizontal extent of the plate for a row, in px: an action cell spans its column; a list row spans the plate inset.
|
|
442
|
+
private fun plateSpan(row: GlassRow): Pair<Float, Float> =
|
|
443
|
+
if (row.isAction) row.rect.left to row.rect.right
|
|
444
|
+
else PlateInset * density to target.width() - PlateInset * density
|
|
445
|
+
|
|
446
|
+
private fun updatePlateRect() {
|
|
447
|
+
val top = plateTop.value - scroll
|
|
448
|
+
plateRect.set(plateLeft.value, top, plateRight.value, top + plateHeight.value)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
fun drawFallback(canvas: Canvas) {
|
|
452
|
+
val frame = motion.frame
|
|
453
|
+
liveBounds(shown)
|
|
454
|
+
val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
455
|
+
color = if (content.dark) Color.rgb(30, 30, 32) else Color.rgb(245, 245, 247)
|
|
456
|
+
alpha = (255 * frame.contentProgress).toInt()
|
|
457
|
+
}
|
|
458
|
+
val radius = min(frame.radiusX, frame.radiusY)
|
|
459
|
+
canvas.drawRoundRect(shown, radius, radius, paint)
|
|
460
|
+
val save = canvas.saveLayerAlpha(shown, (255 * frame.contentProgress).toInt())
|
|
461
|
+
canvas.clipRect(shown)
|
|
462
|
+
canvas.translate(shown.left, shown.top)
|
|
463
|
+
canvas.scale(shown.width() / target.width(), shown.height() / target.height())
|
|
464
|
+
updatePlateRect()
|
|
465
|
+
content.drawPlate(canvas, plateRect, plateAlpha.value, plateRect.centerX(), anchor.config.highlightOpacity, 0f)
|
|
466
|
+
content.draw(canvas, scroll)
|
|
467
|
+
canvas.restoreToCount(save)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
fun onTouch(event: MotionEvent) {
|
|
471
|
+
val layer = child
|
|
472
|
+
// A tap while the submenu is opening or closing is queued, not lost: it runs when the transition ends.
|
|
473
|
+
if (layer != null && (layer.closing || !layer.isOpen)) {
|
|
474
|
+
if (event.actionMasked == MotionEvent.ACTION_UP) {
|
|
475
|
+
pendingUpX = event.x
|
|
476
|
+
pendingUpY = event.y
|
|
477
|
+
hasPendingUp = true
|
|
478
|
+
}
|
|
479
|
+
return
|
|
480
|
+
}
|
|
481
|
+
if (layer != null) {
|
|
482
|
+
onChildTouch(layer, event)
|
|
483
|
+
return
|
|
484
|
+
}
|
|
485
|
+
val x = event.x
|
|
486
|
+
val y = event.y
|
|
487
|
+
when (event.actionMasked) {
|
|
488
|
+
MotionEvent.ACTION_DOWN -> {
|
|
489
|
+
touchInside = target.contains(x, y)
|
|
490
|
+
dismissOnUp = !touchInside
|
|
491
|
+
touchStartX = x
|
|
492
|
+
touchStartY = y
|
|
493
|
+
touchStartScroll = scroll
|
|
494
|
+
scrolling = false
|
|
495
|
+
if (touchInside) {
|
|
496
|
+
scrub.press(x, y, rowFor(x, y)?.index ?: GlassScrub.NONE)
|
|
497
|
+
highlight(rowFor(x, y), immediate = true)
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
MotionEvent.ACTION_MOVE -> {
|
|
501
|
+
if (!touchInside) return
|
|
502
|
+
val dy = y - touchStartY
|
|
503
|
+
if (maximumScroll > 0f && (scrolling || abs(dy) > 10f * density)) {
|
|
504
|
+
if (!scrolling) {
|
|
505
|
+
highlight(null, immediate = false)
|
|
506
|
+
jelly.releaseDrag()
|
|
507
|
+
}
|
|
508
|
+
scrolling = true
|
|
509
|
+
scroll = (touchStartScroll - dy).coerceIn(0f, maximumScroll)
|
|
510
|
+
rowsDirty = true
|
|
511
|
+
overlay.invalidate()
|
|
512
|
+
return
|
|
513
|
+
}
|
|
514
|
+
scrub.drag(x, y, rowFor(x, y)?.index ?: GlassScrub.NONE)
|
|
515
|
+
highlight(rowFor(x, y), immediate = false)
|
|
516
|
+
}
|
|
517
|
+
MotionEvent.ACTION_UP -> {
|
|
518
|
+
scrub.release()
|
|
519
|
+
val row = content.rowAt(x - target.left, y - target.top + scroll)
|
|
520
|
+
when {
|
|
521
|
+
dismissOnUp -> overlay.requestClose()
|
|
522
|
+
row != null && row.back && !scrolling -> leaveLevel()
|
|
523
|
+
row != null && row.submenu && !scrolling && GLASS_SUBMENU_LAYERS -> enterLayer(row)
|
|
524
|
+
row != null && row.submenu && !scrolling -> enterLevel(row.item)
|
|
525
|
+
row != null && !scrolling -> select(row.index)
|
|
526
|
+
else -> highlight(null, immediate = false)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
MotionEvent.ACTION_CANCEL -> {
|
|
530
|
+
scrub.cancel()
|
|
531
|
+
highlight(null, immediate = false)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Submenu navigation (touch): the root panel becomes the submenu panel. The panel resizes with the
|
|
537
|
+
// morph spring (refreshItems -> GlassMotion.updateTarget) and the content reveals with the same
|
|
538
|
+
// RowsRevealSpring as the morph, so the material and the physics are the root menu's.
|
|
539
|
+
private fun enterLevel(sub: GlassMenuItemRecord) {
|
|
540
|
+
levelItems = sub
|
|
541
|
+
navigateLevel()
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private fun leaveLevel() {
|
|
545
|
+
levelItems = null
|
|
546
|
+
navigateLevel()
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
private fun navigateLevel() {
|
|
550
|
+
refreshItems()
|
|
551
|
+
nav.reset(0f)
|
|
552
|
+
nav.target(1f, GlassMotion.RowsRevealSpring)
|
|
553
|
+
rowsDirty = true
|
|
554
|
+
animating = true
|
|
555
|
+
overlay.requestFrame()
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// Stacked submenu (flag on): the panel grows out of the tapped row over the root, which recedes.
|
|
559
|
+
private fun enterLayer(row: GlassRow) {
|
|
560
|
+
val sub = row.item.items ?: return
|
|
561
|
+
val layer = GlassSubmenuLayer(
|
|
562
|
+
anchor, density,
|
|
563
|
+
GlassMenuContent(overlay.context, density) { slot -> anchor.iconView(slot) }.also {
|
|
564
|
+
it.dark = content.dark
|
|
565
|
+
it.ink = content.ink
|
|
566
|
+
it.forceCheckColumn = content.reservesCheckColumn
|
|
567
|
+
},
|
|
568
|
+
if (supportsGlass) RenderNode("GlassMenu.submenu.rows") else null,
|
|
569
|
+
if (supportsGlass) RenderNode("GlassMenu.submenu.plate") else null,
|
|
570
|
+
anchor.newRenderer(density),
|
|
571
|
+
)
|
|
572
|
+
layer.content.setItems(sub, target.width() / density, availableWidth, anchor.fontFamily, row.item)
|
|
573
|
+
val height = min(layer.content.height, maximumHeight)
|
|
574
|
+
val rowRect = RectF(
|
|
575
|
+
target.left + row.rect.left, target.top + row.rect.top - scroll,
|
|
576
|
+
target.left + row.rect.right, target.top + row.rect.bottom - scroll,
|
|
577
|
+
)
|
|
578
|
+
// The panel's header is the tapped row: the panel starts at the row and stays inside the root's bounds.
|
|
579
|
+
// The header row is the parent's row: the panel is placed so that the header row's rect is the tapped row's rect.
|
|
580
|
+
val headerTop = layer.content.rows.firstOrNull { it.back }?.rect?.top ?: 0f
|
|
581
|
+
val panelTop = rowRect.top - headerTop
|
|
582
|
+
val panel = RectF(target.left, panelTop, target.right, panelTop + height)
|
|
583
|
+
layer.open(rowRect, panel)
|
|
584
|
+
layer.drawHeader = { canvas, rotation ->
|
|
585
|
+
canvas.save()
|
|
586
|
+
canvas.translate(target.left, target.top - scroll)
|
|
587
|
+
content.drawRow(canvas, row, rotation)
|
|
588
|
+
canvas.restore()
|
|
589
|
+
}
|
|
590
|
+
child = layer
|
|
591
|
+
openedRow = row
|
|
592
|
+
rowsDirty = true
|
|
593
|
+
// The row that opens the submenu leaves its press/hover state at once: the tap's highlight must not fade
|
|
594
|
+
// out over the header while it is opened.
|
|
595
|
+
clearPlate()
|
|
596
|
+
overlay.requestFrame()
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// A queued tap: the submenu's own row logic once it is open, the root's once no submenu is left.
|
|
600
|
+
private fun runPendingUp() {
|
|
601
|
+
if (!hasPendingUp) return
|
|
602
|
+
val layer = child
|
|
603
|
+
if (layer != null && !layer.isOpen) return
|
|
604
|
+
if (layer != null && layer.closing) return
|
|
605
|
+
hasPendingUp = false
|
|
606
|
+
val x = pendingUpX
|
|
607
|
+
val y = pendingUpY
|
|
608
|
+
if (layer != null) {
|
|
609
|
+
if (!layer.contains(x, y)) {
|
|
610
|
+
closeChild()
|
|
611
|
+
return
|
|
612
|
+
}
|
|
613
|
+
when (val row = layer.rowAt(x, y)) {
|
|
614
|
+
null -> layer.highlight(null, immediate = false)
|
|
615
|
+
else -> when {
|
|
616
|
+
row.back -> closeChild()
|
|
617
|
+
row.selectable -> selectChild(layer, row)
|
|
618
|
+
else -> layer.highlight(null, immediate = false)
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return
|
|
622
|
+
}
|
|
623
|
+
val row = content.rowAt(x - target.left, y - target.top + scroll) ?: return
|
|
624
|
+
if (row.submenu) enterLayer(row) else if (row.selectable) select(row.index)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Clears the root's press/hover plate at once (no animation): the highlight is a state of the tap, not of the panel.
|
|
628
|
+
private fun clearPlate() {
|
|
629
|
+
activeRow = null
|
|
630
|
+
plateVisible = false
|
|
631
|
+
plateAlpha.reset(0f)
|
|
632
|
+
rowsDirty = true
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
private fun closeChild() {
|
|
636
|
+
val layer = child ?: return
|
|
637
|
+
layer.close()
|
|
638
|
+
overlay.requestFrame()
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Touch while a stacked submenu is open: taps inside act on its rows (its header collapses it); a tap outside
|
|
642
|
+
// collapses it. The root gets no touches until the submenu is closed.
|
|
643
|
+
private fun onChildTouch(layer: GlassSubmenuLayer, event: MotionEvent) {
|
|
644
|
+
val x = event.x
|
|
645
|
+
val y = event.y
|
|
646
|
+
when (event.actionMasked) {
|
|
647
|
+
MotionEvent.ACTION_DOWN -> {
|
|
648
|
+
touchInside = layer.contains(x, y)
|
|
649
|
+
dismissOnUp = !touchInside
|
|
650
|
+
if (touchInside) layer.highlight(layer.nearestRow(x, y), immediate = true)
|
|
651
|
+
}
|
|
652
|
+
MotionEvent.ACTION_MOVE -> {
|
|
653
|
+
if (touchInside) layer.highlight(layer.nearestRow(x, y), immediate = false)
|
|
654
|
+
}
|
|
655
|
+
MotionEvent.ACTION_UP -> {
|
|
656
|
+
val row = layer.rowAt(x, y)
|
|
657
|
+
when {
|
|
658
|
+
// A tap outside the submenu goes back to the root, as the header does.
|
|
659
|
+
dismissOnUp -> closeChild()
|
|
660
|
+
row != null && row.back -> closeChild()
|
|
661
|
+
row != null && row.selectable -> selectChild(layer, row)
|
|
662
|
+
else -> layer.highlight(null, immediate = false)
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
MotionEvent.ACTION_CANCEL -> layer.highlight(null, immediate = false)
|
|
666
|
+
}
|
|
667
|
+
overlay.requestFrame()
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
private fun selectChild(layer: GlassSubmenuLayer, row: GlassRow) {
|
|
671
|
+
anchor.notifySelect(row.item, row.index)
|
|
672
|
+
if (row.item.keepOpen) layer.highlight(null, immediate = false) else overlay.requestClose()
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
private fun rowFor(x: Float, y: Float): GlassRow? =
|
|
676
|
+
content.nearestRow(x - target.left, y - target.top + scroll, ScrubSlack * density)
|
|
677
|
+
|
|
678
|
+
private fun highlight(row: GlassRow?, immediate: Boolean) {
|
|
679
|
+
if (row === activeRow) return
|
|
680
|
+
val hadRow = activeRow != null
|
|
681
|
+
activeRow = row
|
|
682
|
+
if (row == null) {
|
|
683
|
+
plateVisible = false
|
|
684
|
+
plateAlpha.target(0f, PlateFade)
|
|
685
|
+
} else {
|
|
686
|
+
val span = plateSpan(row)
|
|
687
|
+
if (!plateVisible && !hadRow) {
|
|
688
|
+
plateTop.reset(row.rect.top)
|
|
689
|
+
plateHeight.reset(row.rect.height())
|
|
690
|
+
plateLeft.reset(span.first)
|
|
691
|
+
plateRight.reset(span.second)
|
|
692
|
+
} else {
|
|
693
|
+
plateTop.target(row.rect.top, PlateSlide)
|
|
694
|
+
plateHeight.target(row.rect.height(), PlateSlide)
|
|
695
|
+
plateLeft.target(span.first, PlateSlide)
|
|
696
|
+
plateRight.target(span.second, PlateSlide)
|
|
697
|
+
overlay.hapticTick()
|
|
698
|
+
}
|
|
699
|
+
plateVisible = true
|
|
700
|
+
if (immediate) plateAlpha.reset(1f) else plateAlpha.target(1f, PlateFade)
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
fun select(index: Int) {
|
|
705
|
+
val row = content.rows.firstOrNull { it.index == index }?.takeIf { it.selectable } ?: return
|
|
706
|
+
anchor.notifySelect(row.item, row.index)
|
|
707
|
+
if (row.item.keepOpen) {
|
|
708
|
+
highlight(null, immediate = false)
|
|
709
|
+
} else {
|
|
710
|
+
overlay.requestClose()
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
fun rowIndexAt(x: Float, y: Float): Int = content.rowAt(x - target.left, y - target.top + scroll)?.index ?: -1
|
|
715
|
+
|
|
716
|
+
fun accessibleRows(): List<GlassRow> = if (expanded) content.rows.filter { !it.isSeparator } else emptyList()
|
|
717
|
+
|
|
718
|
+
fun screenRect(row: GlassRow?): Rect {
|
|
719
|
+
val rect = row?.rect ?: return Rect(0, 0, 1, 1)
|
|
720
|
+
return Rect(
|
|
721
|
+
(target.left + rect.left).toInt(), (target.top + rect.top - scroll).toInt(),
|
|
722
|
+
(target.left + rect.right).toInt(), (target.top + rect.bottom - scroll).toInt(),
|
|
723
|
+
)
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
fun release() {
|
|
727
|
+
rowsNode?.discardDisplayList()
|
|
728
|
+
plateNode?.discardDisplayList()
|
|
729
|
+
child?.release()
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
private companion object {
|
|
733
|
+
const val CornerRadius = 34f
|
|
734
|
+
const val ParentScaleDrop = .05f
|
|
735
|
+
const val ParentRowsDim = .65f
|
|
736
|
+
const val PlateInset = 8f
|
|
737
|
+
const val ScrubSlack = 24f
|
|
738
|
+
const val CaptureMargin = 48f
|
|
739
|
+
const val MinimumRowsScale = .25f
|
|
740
|
+
const val NeckSigma = 20f
|
|
741
|
+
const val FieldCellsPerSigma = 4f
|
|
742
|
+
const val FieldCells = 64f
|
|
743
|
+
const val MenuLightRadius = 80f
|
|
744
|
+
const val MenuLift = .018f
|
|
745
|
+
const val MenuPool = .03f
|
|
746
|
+
const val MenuRimLift = .12f
|
|
747
|
+
val PlateSlide = GlassSpringSpec(.85f, .13f)
|
|
748
|
+
val PlateFade = GlassSpringSpec(1f, .14f)
|
|
749
|
+
}
|
|
750
|
+
}
|