@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.
Files changed (108) hide show
  1. package/LICENSE +673 -0
  2. package/NOTICE +26 -0
  3. package/android/build.gradle +19 -0
  4. package/android/src/main/AndroidManifest.xml +1 -0
  5. package/android/src/main/assets/fonts/Inter-OFL.txt +93 -0
  6. package/android/src/main/assets/fonts/Inter-Regular.ttf +0 -0
  7. package/android/src/main/java/so/oxy/bloom/glassmenu/220 +0 -0
  8. package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidModule.kt +71 -0
  9. package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidView.kt +548 -0
  10. package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassBackdrop.kt +215 -0
  11. package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassLens.kt +103 -0
  12. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeGeometry.kt +73 -0
  13. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeIcons.kt +74 -0
  14. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeMaterial.kt +74 -0
  15. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeHost.kt +73 -0
  16. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeModule.kt +31 -0
  17. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeView.kt +609 -0
  18. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/StaticGlassCache.kt +73 -0
  19. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceIcons.kt +114 -0
  20. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesHost.kt +71 -0
  21. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesModule.kt +22 -0
  22. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesView.kt +527 -0
  23. package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassIcons.kt +68 -0
  24. package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassMenuContent.kt +349 -0
  25. package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassRow.kt +19 -0
  26. package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassFieldTexture.kt +102 -0
  27. package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassGaussianField.kt +161 -0
  28. package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassShapes.kt +37 -0
  29. package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedField.kt +119 -0
  30. package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedUnion.kt +81 -0
  31. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassGroup.kt +225 -0
  32. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassJelly.kt +118 -0
  33. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphFrame.kt +22 -0
  34. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphTuning.kt +31 -0
  35. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMotion.kt +475 -0
  36. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassSpring.kt +78 -0
  37. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassDevGuard.kt +31 -0
  38. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassFeedback.kt +18 -0
  39. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuOverlay.kt +433 -0
  40. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuSession.kt +750 -0
  41. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassScrub.kt +41 -0
  42. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassSubmenuLayer.kt +290 -0
  43. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassAbsorbRecord.kt +9 -0
  44. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMemberRecord.kt +14 -0
  45. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuConfigRecord.kt +24 -0
  46. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuItemRecord.kt +23 -0
  47. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassShrinkRecord.kt +10 -0
  48. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassTriggerConfigRecord.kt +19 -0
  49. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRecipe.kt +18 -0
  50. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRenderer.kt +361 -0
  51. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassShaders.kt +318 -0
  52. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassStill.kt +115 -0
  53. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassSurfaceState.kt +38 -0
  54. package/expo-module.config.json +10 -0
  55. package/package.json +29 -4
  56. package/patches/bloom.patch +1908 -0
  57. package/patches/menu/bloom.patch +148 -0
  58. package/src/base.tsx +208 -0
  59. package/src/chrome/compositor-geometry.ts +163 -0
  60. package/src/chrome/glass-header.tsx +155 -0
  61. package/src/chrome/glass-search-fab.tsx +113 -0
  62. package/src/chrome/glass-size-class.tsx +150 -0
  63. package/src/chrome/glass-toolbar.tsx +45 -0
  64. package/src/chrome/interface.ts +17 -0
  65. package/src/chrome/ios-tab-bar.tsx +49 -0
  66. package/src/chrome/surface-layer.ts +91 -0
  67. package/src/chrome/surface-nodes.tsx +54 -0
  68. package/src/index.ts +19 -0
  69. package/src/menu/components/menu/index.ts +22 -0
  70. package/src/menu/components/menu/menu.tsx +97 -0
  71. package/src/menu/components/menu-action-row/index.ts +1 -0
  72. package/src/menu/components/menu-action-row/menu-action-row.tsx +12 -0
  73. package/src/menu/components/menu-content/index.ts +2 -0
  74. package/src/menu/components/menu-content/menu-content.tsx +11 -0
  75. package/src/menu/components/menu-item/index.ts +13 -0
  76. package/src/menu/components/menu-item/menu-item-icon.tsx +10 -0
  77. package/src/menu/components/menu-item/menu-item-subtitle.tsx +14 -0
  78. package/src/menu/components/menu-item/menu-item-title.tsx +11 -0
  79. package/src/menu/components/menu-item/menu-item.tsx +11 -0
  80. package/src/menu/components/menu-label/index.ts +3 -0
  81. package/src/menu/components/menu-label/menu-label.tsx +11 -0
  82. package/src/menu/components/menu-separator/index.ts +3 -0
  83. package/src/menu/components/menu-separator/menu-separator.tsx +7 -0
  84. package/src/menu/components/menu-submenu/index.ts +1 -0
  85. package/src/menu/components/menu-submenu/menu-submenu.tsx +12 -0
  86. package/src/menu/components/menu-trigger/index.ts +3 -0
  87. package/src/menu/components/menu-trigger/interface.ts +41 -0
  88. package/src/menu/components/menu-trigger/menu-trigger.android.tsx +97 -0
  89. package/src/menu/components/menu-trigger/menu-trigger.tsx +15 -0
  90. package/src/menu/components/menu-trigger/native-menu.android.ts +9 -0
  91. package/src/menu/components/menu-trigger-button/index.ts +3 -0
  92. package/src/menu/components/menu-trigger-button/menu-trigger-button.android.tsx +38 -0
  93. package/src/menu/components/menu-trigger-button/menu-trigger-button.tsx +17 -0
  94. package/src/menu/constants/interface.ts +6 -0
  95. package/src/menu/constants/menu.const.ts +11 -0
  96. package/src/menu/context/interface.ts +63 -0
  97. package/src/menu/context/menu.context.ts +7 -0
  98. package/src/menu/index.ts +53 -0
  99. package/src/menu/interface.ts +229 -0
  100. package/src/menu/utils/create-compound-component.util.ts +18 -0
  101. package/src/menu/utils/find-menu-content.util.ts +17 -0
  102. package/src/menu/utils/flatten-elements.util.ts +18 -0
  103. package/src/menu/utils/parse-menu-content.util.ts +98 -0
  104. package/src/menu/utils/parse-menu-item.util.ts +56 -0
  105. package/src/menu/utils/register-component.util.ts +13 -0
  106. package/src/menu/utils/to-native-item.util.ts +24 -0
  107. package/src/rows.tsx +61 -0
  108. package/README.md +0 -3
@@ -0,0 +1,475 @@
1
+ package so.oxy.bloom.glassmenu.motion
2
+
3
+ import android.graphics.RectF
4
+ import kotlin.math.abs
5
+ import kotlin.math.ceil
6
+ import kotlin.math.floor
7
+ import kotlin.math.max
8
+ import kotlin.math.min
9
+
10
+ internal class GlassMotion {
11
+ val frame = GlassMorphFrame()
12
+ var initialized = false
13
+ private set
14
+ var expanded = false
15
+ private set
16
+
17
+ private val source = RectF()
18
+ private val through = RectF()
19
+ private val destination = RectF()
20
+ private var destinationRadius = 0f
21
+ private var zoomReferenceHeight = 0f
22
+ private var density = 1f
23
+ private var followsPress = false
24
+ private var tuning = GlassMorphTuning(null, null)
25
+ private var elapsed = 0f
26
+ private var correctionApplied = false
27
+ private var smoothingReleased = false
28
+ private var lensReleased = false
29
+ private var closingKickReleased = false
30
+ private var sourceKickReleased = false
31
+ private var portalBlurReleased = false
32
+
33
+ private val x = GlassSpring()
34
+ private val y = GlassSpring()
35
+ private val width = GlassSpring()
36
+ private val height = GlassSpring()
37
+ private val radiusX = GlassSpring()
38
+ private val radiusY = GlassSpring()
39
+ private val sourceX = GlassSpring()
40
+ private val sourceY = GlassSpring()
41
+ private val sourceWidth = GlassSpring()
42
+ private val sourceHeight = GlassSpring()
43
+ private val sourceScale = GlassSpring(0.0005f, 0.01f)
44
+ private val incomingScale = GlassSpring(0.0005f, 0.01f)
45
+ private val kick = GlassSpring()
46
+ private val sourceKick = GlassSpring()
47
+ private val content = GlassSpring(0.001f, 0.01f)
48
+ private val rowsReveal = GlassSpring(0.001f, 0.01f)
49
+ private val sourceContent = GlassSpring(0.001f, 0.01f)
50
+ private val lens = GlassSpring(0.001f, 0.01f)
51
+ private val portalBlur = GlassSpring(0.001f, 0.01f)
52
+ private val smoothing = GlassSpring(0.05f, 1f)
53
+ private val channels = listOf(
54
+ x, y, width, height, radiusX, radiusY,
55
+ sourceX, sourceY, sourceWidth, sourceHeight, sourceScale, incomingScale,
56
+ kick, sourceKick, content, rowsReveal, sourceContent, lens, portalBlur, smoothing,
57
+ )
58
+
59
+ fun initialize(
60
+ sourceRect: RectF,
61
+ target: RectF,
62
+ targetRadius: Float,
63
+ pixelDensity: Float,
64
+ throughRect: RectF,
65
+ fromPress: Boolean,
66
+ morphTuning: GlassMorphTuning,
67
+ ) {
68
+ followsPress = fromPress
69
+ tuning = morphTuning
70
+ source.set(sourceRect)
71
+ through.set(throughRect)
72
+ destination.set(target)
73
+ destinationRadius = min(targetRadius, min(target.width(), target.height()) / 2f)
74
+ zoomReferenceHeight = target.height()
75
+ density = pixelDensity
76
+ val diameter = initialIncomingDiameter()
77
+ x.reset(pressedCenterX())
78
+ y.reset(pressedCenterY())
79
+ width.reset(target.width())
80
+ height.reset(target.width())
81
+ radiusX.reset(target.width() / 2f)
82
+ radiusY.reset(target.width() / 2f)
83
+ incomingScale.reset(diameter / target.width())
84
+ sourceX.reset(source.centerX())
85
+ sourceY.reset(source.centerY())
86
+ sourceWidth.reset(source.width())
87
+ sourceHeight.reset(source.height())
88
+ sourceScale.reset(1f)
89
+ kick.reset(0f)
90
+ sourceKick.reset(0f)
91
+ content.reset(0f)
92
+ rowsReveal.reset(0f)
93
+ sourceContent.reset(1f)
94
+ lens.reset(1f)
95
+ portalBlur.reset(0f)
96
+ smoothing.reset(0f)
97
+ expanded = false
98
+ elapsed = 0f
99
+ correctionApplied = false
100
+ smoothingReleased = false
101
+ lensReleased = false
102
+ closingKickReleased = false
103
+ sourceKickReleased = false
104
+ portalBlurReleased = false
105
+ initialized = true
106
+ publish()
107
+ }
108
+
109
+ fun updateSource(sourceRect: RectF, throughRect: RectF) {
110
+ if (!initialized) return
111
+ source.set(sourceRect)
112
+ through.set(throughRect)
113
+ if (!expanded) configureCollapse()
114
+ }
115
+
116
+ fun updateTarget(target: RectF, targetRadius: Float) {
117
+ if (!initialized) return
118
+ destination.set(target)
119
+ destinationRadius = min(targetRadius, min(target.width(), target.height()) / 2f)
120
+ if (expanded) configureExpansionGeometry() else configureCollapse()
121
+ publish()
122
+ }
123
+
124
+ // Scrubbed morph (predictive back). beginScrub saves the state after retarget(false): the close timeline, not yet
125
+ // advanced. scrubTo(progress) restores that state and advances the same timeline to the time at which the shape has
126
+ // collapsed by `progress` of its total collapse, so the frame at a progress is the frame the close shows then. endScrub(commit) keeps the timeline where it
127
+ // is (commit: the normal close runs on from there) or reopens it with the normal open timeline (cancel).
128
+ var scrubbing = false
129
+ private set
130
+ // The close timeline sampled at gesture start: time, and the shape's area at that time. scrubTo maps the finger's
131
+ // progress to the time at which the shape has covered that fraction of its own collapse, so the shape moves in
132
+ // proportion to the finger, from the first frame (no new constants: the samples come from the same timeline).
133
+ private val scrubTimes = ArrayList<Float>()
134
+ private val scrubAreas = ArrayList<Float>()
135
+ private val savedChannels = List(20) { GlassSpring() }
136
+ private var savedFlags = BooleanArray(6)
137
+ private var savedElapsed = 0f
138
+ private var savedExpanded = false
139
+
140
+ fun beginScrub() {
141
+ if (!initialized || expanded) return
142
+ saveState()
143
+ sampleCollapse()
144
+ restoreState()
145
+ scrubbing = true
146
+ publish()
147
+ }
148
+
149
+ fun scrubTo(progress: Float) {
150
+ if (!scrubbing) return
151
+ restoreState()
152
+ advanceBy(scrubTimeFor(progress.coerceIn(0f, 1f)))
153
+ }
154
+
155
+ // The time whose shape has collapsed by `fraction` of the total collapse (linear between samples).
156
+ private fun scrubTimeFor(fraction: Float): Float {
157
+ val count = scrubTimes.size
158
+ if (count < 2) return 0f
159
+ val start = scrubAreas[0]
160
+ val end = scrubAreas[count - 1]
161
+ val total = start - end
162
+ if (total <= 0f) return fraction * scrubTimes[count - 1]
163
+ val target = start - fraction * total
164
+ for (i in 1 until count) {
165
+ if (scrubAreas[i] <= target) {
166
+ val a = scrubAreas[i - 1]
167
+ val b = scrubAreas[i]
168
+ val t = if (a == b) 0f else (a - target) / (a - b)
169
+ return scrubTimes[i - 1] + t * (scrubTimes[i] - scrubTimes[i - 1])
170
+ }
171
+ }
172
+ return scrubTimes[count - 1]
173
+ }
174
+
175
+ fun endScrub(commit: Boolean) {
176
+ if (!scrubbing) return
177
+ scrubbing = false
178
+ if (!commit) retarget(true)
179
+ }
180
+
181
+ private fun saveState() {
182
+ channels.forEachIndexed { i, spring -> savedChannels[i].copyFrom(spring) }
183
+ savedFlags = booleanArrayOf(correctionApplied, smoothingReleased, lensReleased, closingKickReleased, sourceKickReleased, portalBlurReleased)
184
+ savedElapsed = elapsed
185
+ savedExpanded = expanded
186
+ }
187
+
188
+ private fun restoreState() {
189
+ channels.forEachIndexed { i, spring -> spring.copyFrom(savedChannels[i]) }
190
+ correctionApplied = savedFlags[0]
191
+ smoothingReleased = savedFlags[1]
192
+ lensReleased = savedFlags[2]
193
+ closingKickReleased = savedFlags[3]
194
+ sourceKickReleased = savedFlags[4]
195
+ portalBlurReleased = savedFlags[5]
196
+ elapsed = savedElapsed
197
+ expanded = savedExpanded
198
+ }
199
+
200
+ // Samples the close timeline (until it is visually collapsed) on the saved state: the time and the shape's area.
201
+ // Fixed step, so the same close always gives the same samples.
202
+ private fun sampleCollapse() {
203
+ scrubTimes.clear()
204
+ scrubAreas.clear()
205
+ scrubTimes.add(0f)
206
+ scrubAreas.add(frame.bounds.width() * frame.bounds.height())
207
+ var time = 0f
208
+ while (time < MaxScrubSeconds) {
209
+ val done = advanceBy(ScrubStepSeconds)
210
+ time += ScrubStepSeconds
211
+ scrubTimes.add(time)
212
+ scrubAreas.add(frame.bounds.width() * frame.bounds.height())
213
+ if (done) break
214
+ }
215
+ restoreState()
216
+ }
217
+
218
+ fun retarget(nextExpanded: Boolean) {
219
+ if (!initialized) return
220
+ expanded = nextExpanded
221
+ zoomReferenceHeight = destination.height()
222
+ elapsed = 0f
223
+ correctionApplied = false
224
+ smoothingReleased = false
225
+ lensReleased = false
226
+ closingKickReleased = false
227
+ sourceKickReleased = nextExpanded
228
+ portalBlurReleased = false
229
+ portalBlur.target(1f, BlurInSpring)
230
+ lens.target(1f, LensOnSpring)
231
+ if (nextExpanded) {
232
+ configureExpansionGeometry()
233
+ incomingScale.target(1f, EjectSpring)
234
+ sourceKick.target(0f, KickSpring)
235
+ sourceContent.target(0f, tuning.eject)
236
+ content.target(1f, EjectSpring)
237
+ rowsReveal.target(1f, RowsRevealSpring)
238
+ smoothing.target(20f * density, CollapseSpring)
239
+ } else {
240
+ configureCollapse()
241
+ }
242
+ publish()
243
+ }
244
+
245
+ private fun configureExpansionGeometry() {
246
+ val side = min(source.width(), source.height())
247
+ val inset = side / 8f
248
+ sourceX.target(alignedCenter(boundedCenter(through.centerX() * .75f + destination.centerX() * .25f, destination.left, destination.right, inset), side), tuning.eject)
249
+ sourceY.target(alignedCenter(boundedCenter(through.centerY() * .75f + destination.centerY() * .25f, destination.top, destination.bottom, inset), side), tuning.eject)
250
+ sourceWidth.target(side, tuning.collapse)
251
+ sourceHeight.target(side, tuning.collapse)
252
+ sourceScale.target(tuning.shrinkScale, tuning.eject)
253
+ x.target(destination.centerX(), EjectSpring)
254
+ y.target(destination.centerY(), EjectSpring)
255
+ width.target(destination.width(), EjectSpring)
256
+ height.target(destination.height(), EjectSpring)
257
+ radiusX.target(if (correctionApplied) destinationRadius else destination.width(), EjectSpring)
258
+ radiusY.target(if (correctionApplied) destinationRadius else destination.width(), EjectSpring)
259
+ kick.target(if (correctionApplied) 0f else kickAmount(-80f), KickSpring)
260
+ }
261
+
262
+ fun advanceBy(seconds: Float): Boolean {
263
+ if (!initialized) return true
264
+ var remaining = if (seconds.isFinite()) max(seconds, 0f) else 0f
265
+ while (remaining > 0f) {
266
+ applyTimelineActions()
267
+ var next = Float.POSITIVE_INFINITY
268
+ if (expanded && !correctionApplied) next = min(next, CorrectionDelay)
269
+ if (!lensReleased || !portalBlurReleased) next = min(next, opticalReleaseDelay())
270
+ if (!smoothingReleased) next = min(next, if (expanded) SmoothingReleaseDelay * tuning.neckHold else AbsorbSmoothingReleaseDelay)
271
+ if (!expanded && !closingKickReleased) next = min(next, AbsorbEjecteeUnkickDelay)
272
+ if (!expanded && !sourceKickReleased) next = min(next, AbsorbSourceUnkickDelay)
273
+ val step = min(remaining, max(next - elapsed, 0f))
274
+ if (step <= 0f) {
275
+ applyTimelineActions()
276
+ continue
277
+ }
278
+ channels.forEach { it.advance(step) }
279
+ elapsed += step
280
+ remaining -= step
281
+ }
282
+ applyTimelineActions()
283
+ publish()
284
+ if (!expanded && visuallyCollapsed()) {
285
+ channels.forEach { it.finish() }
286
+ publish()
287
+ return true
288
+ }
289
+ return (!expanded || smoothingReleased) && channels.all { it.isSettled }
290
+ }
291
+
292
+ private fun applyTimelineActions() {
293
+ val now = elapsed + 0.000001f
294
+ if (!portalBlurReleased && now >= opticalReleaseDelay()) {
295
+ portalBlurReleased = true
296
+ portalBlur.target(0f, BlurOutSpring)
297
+ }
298
+ if (!lensReleased && now >= opticalReleaseDelay()) {
299
+ lensReleased = true
300
+ lens.target(0f, if (expanded) EjectLensOffSpring else AbsorbLensOffSpring)
301
+ }
302
+ if (!expanded) {
303
+ if (!closingKickReleased && now >= AbsorbEjecteeUnkickDelay) {
304
+ closingKickReleased = true
305
+ kick.target(0f, KickSpring)
306
+ }
307
+ if (!sourceKickReleased && now >= AbsorbSourceUnkickDelay) {
308
+ sourceKickReleased = true
309
+ sourceKick.target(0f, KickSpring)
310
+ }
311
+ if (!smoothingReleased && now >= AbsorbSmoothingReleaseDelay) {
312
+ smoothingReleased = true
313
+ smoothing.target(0f, SmoothingReleaseSpring)
314
+ }
315
+ return
316
+ }
317
+ if (!correctionApplied && now >= CorrectionDelay) {
318
+ correctionApplied = true
319
+ radiusX.target(destinationRadius, CorrectionSpring)
320
+ radiusY.target(destinationRadius, CorrectionSpring)
321
+ kick.target(0f, KickSpring)
322
+ }
323
+ if (!smoothingReleased && now >= SmoothingReleaseDelay * tuning.neckHold) {
324
+ smoothingReleased = true
325
+ smoothing.target(0f, SmoothingReleaseSpring)
326
+ }
327
+ }
328
+
329
+ private fun configureCollapse() {
330
+ val diameter = initialIncomingDiameter()
331
+ x.target(if (followsPress) pressedCenterX() else source.centerX(), tuning.absorb)
332
+ y.target(if (followsPress) pressedCenterY() else source.centerY(), tuning.absorb)
333
+ width.target(destination.width() * ClosePinch, tuning.absorb)
334
+ height.target(destination.width(), tuning.absorb)
335
+ incomingScale.target(diameter / destination.width(), tuning.absorb)
336
+ radiusX.target(destination.width() / 2f, tuning.absorb)
337
+ radiusY.target(destination.width() / 2f, tuning.absorb)
338
+ sourceX.target(source.centerX(), tuning.absorb)
339
+ sourceY.target(source.centerY(), tuning.absorb)
340
+ sourceWidth.target(source.width(), tuning.absorb)
341
+ sourceHeight.target(source.height(), tuning.absorb)
342
+ sourceScale.target(1f, tuning.absorb)
343
+ kick.target(if (closingKickReleased) 0f else kickAmount(-80f), KickSpring)
344
+ sourceKick.target(if (sourceKickReleased) 0f else kickAmount(40f), KickSpring)
345
+ content.target(0f, AbsorbContentSpring)
346
+ rowsReveal.target(0f, AbsorbContentSpring)
347
+ sourceContent.target(1f, tuning.absorb)
348
+ smoothing.target(
349
+ if (smoothingReleased) 0f else 20f * density,
350
+ if (smoothingReleased) SmoothingReleaseSpring else AbsorbSmoothingSpring,
351
+ )
352
+ }
353
+
354
+ private fun visuallyCollapsed(): Boolean {
355
+ val shell = frame.sourceLobe
356
+ val epsilon = density * 0.5f
357
+ if (abs(shell.left - source.left) > epsilon || abs(shell.top - source.top) > epsilon ||
358
+ abs(shell.right - source.right) > epsilon || abs(shell.bottom - source.bottom) > epsilon
359
+ ) return false
360
+ val incoming = frame.bounds
361
+ return incoming.left >= source.left - epsilon && incoming.top >= source.top - epsilon &&
362
+ incoming.right <= source.right + epsilon && incoming.bottom <= source.bottom + epsilon &&
363
+ frame.contentProgress < 0.02f && frame.sourceOpacity > 0.98f &&
364
+ abs(kick.value) < epsilon && abs(sourceKick.value) < epsilon &&
365
+ frame.smoothing < epsilon && lens.value < 0.02f
366
+ }
367
+
368
+ private fun pressedCenterX(): Float =
369
+ alignedCenter(boundedCenter(through.centerX(), source.left, source.right, through.width() / 2f), destination.width())
370
+
371
+ private fun pressedCenterY(): Float =
372
+ alignedCenter(boundedCenter(through.centerY(), source.top, source.bottom, through.height() / 2f), destination.width())
373
+
374
+ private fun initialIncomingDiameter(): Float =
375
+ max(destination.width() * 0.5f * through.height() / max(destination.width(), destination.height()), 1f)
376
+
377
+ private fun boundedCenter(value: Float, start: Float, end: Float, inset: Float): Float {
378
+ val minimum = start + inset
379
+ val maximum = end - inset
380
+ return if (minimum <= maximum) value.coerceIn(minimum, maximum) else start + (end - start) / 2f
381
+ }
382
+
383
+ private fun alignedCenter(center: Float, side: Float): Float {
384
+ val points = (center - side / 2f) / density
385
+ val aligned = (if (points < 0f) ceil(points - 0.5f) else floor(points + 0.5f)) * density
386
+ return aligned + side / 2f
387
+ }
388
+
389
+ private fun kickAmount(points: Float): Float {
390
+ val heightPoints = destination.height() / density
391
+ val heightFactor = ((heightPoints - 60f) / 140f).coerceIn(0.5f, 1f)
392
+ val anchorY = ((through.centerY() - destination.top) / destination.height()).coerceIn(0f, 1f)
393
+ return points * density * heightFactor * (2f * anchorY - 1f)
394
+ }
395
+
396
+ private fun publish() {
397
+ val scaleIn = max(incomingScale.value, 0.001f)
398
+ val w = max(width.value * scaleIn, 1f)
399
+ val h = max(height.value * scaleIn, 1f)
400
+ val restingScale = initialIncomingDiameter() / max(destination.width(), 1f)
401
+ val growth = if (followsPress) {
402
+ ((scaleIn - restingScale) / max(1f - restingScale, 0.001f)).coerceIn(0f, MaxGrowth)
403
+ } else 1f
404
+ val originX = pressedCenterX()
405
+ val originY = pressedCenterY()
406
+ val cx = originX + (x.value - originX) * growth
407
+ val cy = originY + (y.value + kick.value * scaleIn - originY) * growth
408
+ frame.bounds.set(cx - w / 2f, cy - h / 2f, cx + w / 2f, cy + h / 2f)
409
+ val scale = max(sourceScale.value, 0.01f)
410
+ val sw = max(sourceWidth.value * scale, 1f)
411
+ val sh = max(sourceHeight.value * scale, 1f)
412
+ val scy = sourceY.value + sourceKick.value * scale
413
+ frame.sourceLobe.set(sourceX.value - sw / 2f, scy - sh / 2f, sourceX.value + sw / 2f, scy + sh / 2f)
414
+ val contentValue = content.value.coerceIn(0f, 1f)
415
+ val sourceValue = sourceContent.value.coerceIn(0f, 1f)
416
+ val lensValue = lens.value.coerceIn(0f, 1f)
417
+ val lensDimension = min(w, h)
418
+ val lensHeight = 75f * density * lensValue * min(lensDimension / (250f * density), 1f)
419
+ val zoom = 1f + (portalZoomScale() - 1f) * portalBlur.value
420
+ frame.radiusX = max(radiusX.value * scaleIn, 0f)
421
+ frame.radiusY = max(radiusY.value * scaleIn, 0f)
422
+ frame.contentProgress = contentValue
423
+ frame.sourceRadius = min(sw, sh) / 2f
424
+ frame.smoothing = max(smoothing.value, 0f)
425
+ frame.sourceOpacity = sourceValue
426
+ frame.sourceBlur = 4f * density * (1f - sourceValue)
427
+ frame.sourceZoom = zoom
428
+ val reveal = rowsReveal.value.coerceIn(0f, 1f)
429
+ frame.rowsOpacity = reveal
430
+ frame.contentBlur = RowsBlur * density * (1f - reveal)
431
+ frame.contentZoom = zoom
432
+ frame.portalBlur = PortalBlur * density * max(portalBlur.value, 0f)
433
+ frame.lensHeight = lensHeight
434
+ frame.lensAmount = min(-lensHeight, -0.001f * density)
435
+ }
436
+
437
+ private fun opticalReleaseDelay(): Float = if (expanded) EjectOpticalReleaseDelay else AbsorbOpticalReleaseDelay
438
+
439
+ private fun portalZoomScale(): Float {
440
+ val heightFactor = ((zoomReferenceHeight / density - 215f) / 305f).coerceIn(0f, 1f)
441
+ return 1.65f + (1.2f - 1.65f) * heightFactor
442
+ }
443
+
444
+ // internal: the submenu navigation (GlassMenuSession) reuses RowsRevealSpring.
445
+ internal companion object {
446
+ // Measurement only (the length of the close timeline for a scrub): not tuning values.
447
+ const val ScrubStepSeconds = 1f / 240f
448
+ const val MaxScrubSeconds = 3f
449
+ const val GeometrySpeed = 0.7f
450
+ const val MaxGrowth = 1.2f
451
+ const val ClosePinch = .84f
452
+ const val RowsBlur = 18f
453
+ const val PortalBlur = 6f
454
+ const val CorrectionDelay = 0.1f * GeometrySpeed
455
+ const val SmoothingReleaseDelay = 0.3f * GeometrySpeed
456
+ const val EjectOpticalReleaseDelay = 0.12f * GeometrySpeed
457
+ const val AbsorbOpticalReleaseDelay = 0.1f * GeometrySpeed
458
+ const val AbsorbEjecteeUnkickDelay = 0.1f * GeometrySpeed
459
+ const val AbsorbSourceUnkickDelay = 0.15f * GeometrySpeed
460
+ const val AbsorbSmoothingReleaseDelay = 0.1f * GeometrySpeed
461
+ val CollapseSpring = GlassSpringSpec(1f, 0.3f * GeometrySpeed)
462
+ val EjectSpring = GlassSpringSpec(0.75f, 0.32f)
463
+ val CorrectionSpring = EjectSpring
464
+ val KickSpring = GlassSpringSpec(1f, 0.2f * GeometrySpeed)
465
+ val BlurInSpring = GlassSpringSpec(1f, 0.3f * GeometrySpeed)
466
+ val BlurOutSpring = GlassSpringSpec(0.8f, 0.45f * GeometrySpeed)
467
+ val LensOnSpring = GlassSpringSpec(1f, 0.2f * GeometrySpeed)
468
+ val EjectLensOffSpring = GlassSpringSpec(1f, 0.6f * GeometrySpeed)
469
+ val AbsorbLensOffSpring = GlassSpringSpec(1f, 0.4f * GeometrySpeed)
470
+ val AbsorbContentSpring = GlassSpringSpec(1f, 0.15f)
471
+ val RowsRevealSpring = GlassSpringSpec(1f, 0.3f)
472
+ val AbsorbSmoothingSpring = GlassSpringSpec(1f, 0.1f * GeometrySpeed)
473
+ val SmoothingReleaseSpring = GlassSpringSpec(1f, 0.6f * GeometrySpeed)
474
+ }
475
+ }
@@ -0,0 +1,78 @@
1
+ package so.oxy.bloom.glassmenu.motion
2
+
3
+ import kotlin.math.PI
4
+ import kotlin.math.abs
5
+ import kotlin.math.cos
6
+ import kotlin.math.exp
7
+ import kotlin.math.sin
8
+ import kotlin.math.sqrt
9
+
10
+ internal class GlassSpringSpec(val dampingRatio: Float, val response: Float) {
11
+ val omega = (2.0 * PI / response).toFloat()
12
+ val alpha = dampingRatio * omega
13
+ val frequency = if (dampingRatio >= 0.9999f) 0f else omega * sqrt(1f - dampingRatio * dampingRatio)
14
+ }
15
+ internal class GlassSpring(
16
+ private val valueTolerance: Float = 0.2f,
17
+ private val velocityTolerance: Float = 3f,
18
+ ) {
19
+ var value = 0f
20
+ private set
21
+ private var velocity = 0f
22
+ private var destination = 0f
23
+ private var spec = GlassSpringSpec(1f, 0.3f)
24
+ val isSettled: Boolean
25
+ get() = abs(value - destination) < valueTolerance && abs(velocity) < velocityTolerance
26
+
27
+ fun reset(next: Float) {
28
+ value = next
29
+ destination = next
30
+ velocity = 0f
31
+ }
32
+
33
+ fun target(next: Float, nextSpec: GlassSpringSpec) {
34
+ destination = next
35
+ spec = nextSpec
36
+ }
37
+
38
+ // Copies the whole state (value, velocity, target, spec) of another spring: used by the scrubbed morph.
39
+ internal fun copyFrom(other: GlassSpring) {
40
+ value = other.value
41
+ velocity = other.velocity
42
+ destination = other.destination
43
+ spec = other.spec
44
+ }
45
+
46
+ fun finish() {
47
+ value = destination
48
+ velocity = 0f
49
+ }
50
+
51
+ fun advance(seconds: Float) {
52
+ val omega = spec.omega
53
+ val displacement = value - destination
54
+ val alpha = spec.alpha
55
+ val decay = exp(-alpha * seconds)
56
+ if (spec.dampingRatio >= 0.9999f) {
57
+ val coefficient = velocity + omega * displacement
58
+ val nextDisplacement = decay * (displacement + coefficient * seconds)
59
+ velocity = decay * (velocity - omega * coefficient * seconds)
60
+ value = destination + nextDisplacement
61
+ } else {
62
+ val frequency = spec.frequency
63
+ val cosine = cos(frequency * seconds)
64
+ val sine = sin(frequency * seconds)
65
+ val coefficient = (velocity + alpha * displacement) / frequency
66
+ val nextDisplacement = decay * (displacement * cosine + coefficient * sine)
67
+ velocity = decay * (
68
+ -alpha * (displacement * cosine + coefficient * sine) +
69
+ frequency * (-displacement * sine + coefficient * cosine)
70
+ )
71
+ value = destination + nextDisplacement
72
+ }
73
+ if (isSettled) {
74
+ value = destination
75
+ velocity = 0f
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,31 @@
1
+ package so.oxy.bloom.glassmenu.overlay
2
+
3
+ import android.content.pm.ApplicationInfo
4
+ import android.util.Log
5
+ import android.view.View
6
+ import android.view.ViewParent
7
+
8
+ // Development guard for glass controls (docs/design-system-ios.md, "Glass controls and scroll views"). A glass control
9
+ // inside a scroll view that overscrolls does not follow the stretch of the content, so it is a bug in the layout.
10
+ // Logs a warning in debuggable builds only. No reflection, no per-frame work: it runs once when the control attaches.
11
+ internal object GlassDevGuard {
12
+ private const val TAG = "GlassMenu"
13
+
14
+ fun warnIfInOverscrollScroll(view: View) {
15
+ if ((view.context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) == 0) return
16
+ var ancestor: ViewParent? = view.parent
17
+ while (ancestor is View) {
18
+ if (ancestor.javaClass.name.contains("ScrollView") || ancestor.javaClass.name.contains("ScrollContainer")) {
19
+ if (ancestor.overScrollMode != View.OVER_SCROLL_NEVER) {
20
+ Log.w(
21
+ TAG,
22
+ "A glass control (${view.javaClass.simpleName}) is inside a scroll view with overScrollMode != never. " +
23
+ "It will not follow the overscroll stretch. Move it to a fixed header outside the scroll view.",
24
+ )
25
+ }
26
+ return
27
+ }
28
+ ancestor = ancestor.parent
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,18 @@
1
+ package so.oxy.bloom.glassmenu.overlay
2
+
3
+ import android.os.Build
4
+ import android.view.HapticFeedbackConstants
5
+ import android.view.View
6
+
7
+ // The haptic feedback of the glass gestures. Used by the menu (a row changes under the finger) and by the chrome
8
+ // (a tab changes under the dragged pill): the same constant on the same API levels.
9
+ internal object GlassFeedback {
10
+ fun tick(view: View) {
11
+ val constant = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
12
+ HapticFeedbackConstants.SEGMENT_FREQUENT_TICK
13
+ } else {
14
+ HapticFeedbackConstants.CLOCK_TICK
15
+ }
16
+ view.performHapticFeedback(constant)
17
+ }
18
+ }