@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,215 @@
1
+ package so.oxy.bloom.glassmenu.backdrop
2
+
3
+ import android.graphics.Rect
4
+ import android.graphics.RectF
5
+ import android.graphics.RenderNode
6
+ import android.os.Build
7
+ import android.os.SystemClock
8
+ import android.view.View
9
+ import android.view.ViewGroup
10
+ import android.view.ViewTreeObserver
11
+ import androidx.annotation.RequiresApi
12
+ import java.util.WeakHashMap
13
+
14
+ // The window backdrop: the page behind every glass surface of the window (menus, tab bar, search, create circle).
15
+ // One per window root. It is recorded in the root's preDraw, never inside a surface's own draw, so a surface that is
16
+ // a descendant of the recorded page cannot record itself (that recursion overflowed RenderThread).
17
+ //
18
+ // Consumers call register(view, baseColor) and unregister(view). A registered view that is a direct child of the root
19
+ // (the menu overlay) is left out of the recording. Surfaces that live inside the page skip their own drawing while
20
+ // `recording` is true (dispatchDraw / onDraw check it), so they are not recorded into the backdrop.
21
+ //
22
+ // The recording holds the page by reference: drawing a child of the root draws each of its children as that view's own
23
+ // RenderNode, so whatever redraws in the page (a scroll, a video, an animation) reaches every glass surface through
24
+ // those nodes, and no surface records again for it. The recording itself changes only with the window's layout (its
25
+ // size and children), the registered surfaces and the base colour. Recorded again for any redraw in the page, it would
26
+ // make every surface record again too, at the page's frame rate, for an animation nowhere near the glass.
27
+ //
28
+ // A surface samples the page through a lens of its own (GlassLens), which holds the page only while the region behind
29
+ // the surface changes. Before each frame the backdrop finds what changed, in window rects, and tells every lens.
30
+ internal class GlassBackdrop private constructor(private val root: ViewGroup) :
31
+ ViewTreeObserver.OnPreDrawListener, ViewTreeObserver.OnGlobalLayoutListener {
32
+ val node = RenderNode("GlassBackdrop")
33
+
34
+ private val excluded = HashSet<View>()
35
+ private var baseColor: () -> Int = { android.graphics.Color.BLACK }
36
+ private var users = 0
37
+ private var stale = true
38
+ private var recordedColor = 0
39
+ private val lenses = ArrayList<GlassLens>()
40
+ private val dirt = ArrayList<Rect>()
41
+ private val dirtRect = RectF()
42
+ // The place, transform, scroll, alpha and visibility of each view seen on a dirty path, as of the last frame.
43
+ private val seen = WeakHashMap<View, FloatArray>()
44
+ private val shape = FloatArray(ShapeSize)
45
+
46
+ // Bumped each time the page is recorded: consumers that cache the backdrop regenerate when it changes.
47
+ var version: Int = 0
48
+ private set
49
+
50
+ fun register(view: View, color: () -> Int) {
51
+ excluded.add(view)
52
+ baseColor = color
53
+ users += 1
54
+ stale = true
55
+ if (users == 1) {
56
+ root.viewTreeObserver.addOnPreDrawListener(this)
57
+ root.viewTreeObserver.addOnGlobalLayoutListener(this)
58
+ }
59
+ }
60
+
61
+ fun unregister(view: View) {
62
+ excluded.remove(view)
63
+ users -= 1
64
+ stale = true
65
+ if (users <= 0) {
66
+ users = 0
67
+ if (root.viewTreeObserver.isAlive) {
68
+ root.viewTreeObserver.removeOnPreDrawListener(this)
69
+ root.viewTreeObserver.removeOnGlobalLayoutListener(this)
70
+ }
71
+ }
72
+ }
73
+
74
+ override fun onGlobalLayout() {
75
+ stale = true
76
+ }
77
+
78
+ @RequiresApi(Build.VERSION_CODES.TIRAMISU)
79
+ fun lens(): GlassLens = GlassLens(this).also { lenses.add(it) }
80
+
81
+ fun drop(lens: GlassLens) {
82
+ lenses.remove(lens)
83
+ }
84
+
85
+ override fun onPreDraw(): Boolean {
86
+ val color = baseColor()
87
+ val whole = stale || color != recordedColor
88
+ if (whole) record(color)
89
+ if (lenses.isNotEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
90
+ dirt.clear()
91
+ if (!whole && root.isDirty) collectDirt(root)
92
+ val now = SystemClock.uptimeMillis()
93
+ for (lens in lenses) lens.frame(if (whole) null else dirt, now)
94
+ }
95
+ return true
96
+ }
97
+
98
+ // What redraws in this frame, from the dirty flags Android keeps under hardware rendering (it keeps no dirty rects):
99
+ // each dirty view none of whose children is dirty, and each child of a dirty view whose place, transform, scroll,
100
+ // alpha or visibility changed (a change of those marks only its parent), with that parent, which holds where it was.
101
+ // Left out: the glass surfaces, views drawn off the page (OffPage), views that show nothing (hidden or clear), and
102
+ // views off the window. A pager's off-screen page is one: Compose draws an interop page only while it is on screen,
103
+ // so the page's holder keeps the dirty flag it took when it moved away, frame after frame, with nothing under it
104
+ // redrawing.
105
+ private fun collectDirt(group: ViewGroup) {
106
+ var dirtyChild = false
107
+ for (index in 0 until group.childCount) {
108
+ val child = group.getChildAt(index)
109
+ if (child in excluded || (child as? OffPage)?.offPage == true) {
110
+ dirtyChild = dirtyChild || child.isDirty
111
+ continue
112
+ }
113
+ if (moved(child)) {
114
+ addDirt(group)
115
+ addDirt(child)
116
+ }
117
+ if (!child.isDirty) continue
118
+ dirtyChild = true
119
+ if (child.visibility != View.VISIBLE || child.alpha == 0f) continue
120
+ if (child is ViewGroup) collectDirt(child) else addDirt(child)
121
+ }
122
+ if (!dirtyChild) addDirt(group)
123
+ }
124
+
125
+ // A view in the page whose drawing is not part of it while [offPage] (a trigger whose lens and content the menu
126
+ // overlay draws): what redraws in it does not change what the glass samples.
127
+ interface OffPage {
128
+ val offPage: Boolean
129
+ }
130
+
131
+ private fun moved(view: View): Boolean {
132
+ shape[0] = view.left.toFloat()
133
+ shape[1] = view.top.toFloat()
134
+ shape[2] = view.right.toFloat()
135
+ shape[3] = view.bottom.toFloat()
136
+ shape[4] = view.scrollX.toFloat()
137
+ shape[5] = view.scrollY.toFloat()
138
+ shape[6] = view.translationX
139
+ shape[7] = view.translationY
140
+ shape[8] = view.scaleX
141
+ shape[9] = view.scaleY
142
+ shape[10] = view.rotation
143
+ shape[11] = view.alpha
144
+ shape[12] = view.visibility.toFloat()
145
+ val last = seen[view]
146
+ if (last != null && last.contentEquals(shape)) return false
147
+ if (last == null) seen[view] = shape.copyOf() else shape.copyInto(last)
148
+ return true
149
+ }
150
+
151
+ // The view's bounds in the root's coordinates (the backdrop's), through every transform and scroll above it.
152
+ private fun addDirt(view: View) {
153
+ dirtRect.set(0f, 0f, view.width.toFloat(), view.height.toFloat())
154
+ var current = view
155
+ while (current !== root) {
156
+ if (!current.matrix.isIdentity) current.matrix.mapRect(dirtRect)
157
+ dirtRect.offset(current.left.toFloat(), current.top.toFloat())
158
+ val parent = current.parent as? View ?: return
159
+ dirtRect.offset(-parent.scrollX.toFloat(), -parent.scrollY.toFloat())
160
+ current = parent
161
+ }
162
+ if (!dirtRect.intersects(0f, 0f, root.width.toFloat(), root.height.toFloat())) return
163
+ val rect = Rect()
164
+ dirtRect.roundOut(rect)
165
+ dirt.add(rect)
166
+ }
167
+
168
+ private fun record(color: Int) {
169
+ val width = root.width
170
+ val height = root.height
171
+ if (width <= 0 || height <= 0) return
172
+ node.setPosition(0, 0, width, height)
173
+ // Consumers below the root (the tab bar) are hidden while the page is recorded: ViewGroup does not draw invisible
174
+ // children, so their display lists are not re-recorded inside this recording (that recursed until RenderThread
175
+ // overflowed). Direct children of the root (the menu overlay) are excluded from the loop instead.
176
+ val hidden = ArrayList<View>()
177
+ for (view in excluded) {
178
+ if (view.parent !== root && view.visibility == View.VISIBLE) {
179
+ view.visibility = View.INVISIBLE
180
+ hidden.add(view)
181
+ }
182
+ }
183
+ recording = true
184
+ try {
185
+ val canvas = node.beginRecording(width, height)
186
+ canvas.drawColor(color)
187
+ root.background?.draw(canvas)
188
+ for (index in 0 until root.childCount) {
189
+ val child = root.getChildAt(index)
190
+ if (child in excluded || child.visibility != View.VISIBLE) continue
191
+ if (child.id == android.R.id.statusBarBackground || child.id == android.R.id.navigationBarBackground) continue
192
+ child.draw(canvas)
193
+ }
194
+ node.endRecording()
195
+ } finally {
196
+ recording = false
197
+ for (view in hidden) view.visibility = View.VISIBLE
198
+ }
199
+ stale = false
200
+ recordedColor = color
201
+ version += 1
202
+ }
203
+
204
+ companion object {
205
+ private val byRoot = WeakHashMap<ViewGroup, GlassBackdrop>()
206
+ private const val ShapeSize = 13
207
+
208
+ // True while a backdrop is being recorded. Surfaces inside the page must not draw then.
209
+ @Volatile
210
+ var recording: Boolean = false
211
+ private set
212
+
213
+ fun forRoot(root: ViewGroup): GlassBackdrop = byRoot.getOrPut(root) { GlassBackdrop(root) }
214
+ }
215
+ }
@@ -0,0 +1,103 @@
1
+ package so.oxy.bloom.glassmenu.backdrop
2
+
3
+ import android.graphics.Bitmap
4
+ import android.graphics.Rect
5
+ import android.graphics.RenderNode
6
+ import android.os.Build
7
+ import android.os.SystemClock
8
+ import androidx.annotation.RequiresApi
9
+ import so.oxy.bloom.glassmenu.render.GlassStill
10
+
11
+ // What one glass surface samples of the page: the page itself, by reference, while anything behind the surface
12
+ // changes, and a still of the region behind it once that region has been quiet for a moment (StillAfterMs).
13
+ //
14
+ // Android draws a RenderNode reached from a second parent in the same frame as fully damaged: every glass that holds
15
+ // the page re-renders on every frame the window draws, for an animation anywhere on screen, and the page's tree is
16
+ // prepared once more for each of them. A lens that shows its still does not hold the page: its glass is not drawn
17
+ // again, and the page is prepared once. The still is the same pixels: the region of the same nodes (GlassStill).
18
+ //
19
+ // The backdrop tells each lens, before every frame, which window rects change in it (GlassBackdrop.onPreDraw); a lens
20
+ // whose region is touched shows the page again in that same frame. The region is the one the glass samples.
21
+ @RequiresApi(Build.VERSION_CODES.TIRAMISU)
22
+ internal class GlassLens(val page: GlassBackdrop) {
23
+ val node = RenderNode("GlassLens")
24
+ private val region = Rect()
25
+ private var showsStill = false
26
+ private var recorded = false
27
+ private var quietSince = 0L
28
+ // Bumped whenever the page is shown again: a still asked before then is dropped when it arrives.
29
+ private var generation = 0
30
+ private var askedGeneration = -1
31
+ private var still: GlassStill? = null
32
+
33
+ // The node the glass draws for [area] (window px): the region's still, or the page.
34
+ fun sample(area: Rect): RenderNode {
35
+ if (area != region || !recorded) {
36
+ region.set(area)
37
+ showPage(SystemClock.uptimeMillis())
38
+ }
39
+ return node
40
+ }
41
+
42
+ // Before a frame: [dirt] are the window rects that change in it (null: the whole page changed).
43
+ fun frame(dirt: List<Rect>?, now: Long) {
44
+ if (!recorded || region.isEmpty) return
45
+ if (dirt == null || dirt.any { Rect.intersects(it, region) }) {
46
+ showPage(now)
47
+ } else if (!showsStill && still == null && now - quietSince >= StillAfterMs) {
48
+ askStill()
49
+ }
50
+ }
51
+
52
+ // The page again, and the still let go: a lens holds a still only while it shows it (a menu's large region, a
53
+ // region that changes now and then, would otherwise keep buffers it does not draw).
54
+ private fun showPage(now: Long) {
55
+ quietSince = now
56
+ generation += 1
57
+ still?.release()
58
+ still = null
59
+ if (!showsStill && recorded && node.left == region.left && node.top == region.top &&
60
+ node.width == region.width() && node.height == region.height()) return
61
+ node.setPosition(region)
62
+ val canvas = node.beginRecording(region.width(), region.height())
63
+ canvas.translate(-region.left.toFloat(), -region.top.toFloat())
64
+ canvas.drawRenderNode(page.node)
65
+ node.endRecording()
66
+ showsStill = false
67
+ recorded = true
68
+ }
69
+
70
+ private fun askStill() {
71
+ val target = GlassStill(region.width(), region.height(), ::showStill).also { still = it }
72
+ askedGeneration = generation
73
+ val left = region.left.toFloat()
74
+ val top = region.top.toFloat()
75
+ target.render { canvas ->
76
+ canvas.translate(-left, -top)
77
+ canvas.drawRenderNode(page.node)
78
+ }
79
+ }
80
+
81
+ private fun showStill(bitmap: Bitmap) {
82
+ if (askedGeneration != generation || bitmap.width != region.width() || bitmap.height != region.height()) return
83
+ node.setPosition(region)
84
+ val canvas = node.beginRecording(region.width(), region.height())
85
+ canvas.drawBitmap(bitmap, 0f, 0f, null)
86
+ node.endRecording()
87
+ showsStill = true
88
+ }
89
+
90
+ fun release() {
91
+ page.drop(this)
92
+ still?.release()
93
+ still = null
94
+ node.discardDisplayList()
95
+ recorded = false
96
+ showsStill = false
97
+ }
98
+
99
+ private companion object {
100
+ // Longer than the gap between two frames of a video and than a press: a region that changes keeps the page.
101
+ const val StillAfterMs = 500L
102
+ }
103
+ }
@@ -0,0 +1,73 @@
1
+ package so.oxy.bloom.glassmenu.chrome
2
+
3
+ import kotlin.math.max
4
+ import kotlin.math.min
5
+
6
+ // Mirrors modules/glass-menu-android/src/components/chrome/compositor-geometry.ts. Same constants, same
7
+ // formulas, dp units. The view scales its canvas by the display density, so these values are drawn in dp.
8
+ internal data class ChromeShape(
9
+ val id: String,
10
+ val group: String,
11
+ val x0: Float,
12
+ val y0: Float,
13
+ val x1: Float,
14
+ val y1: Float,
15
+ val radius: Float,
16
+ )
17
+
18
+ internal data class ChromeLayer(val key: String, val x: Float, val y: Float, val width: Float, val height: Float)
19
+
20
+ internal object ChromeGeometry {
21
+ const val TAB_HEIGHT = 64f
22
+ const val REST_GAP = 16f
23
+ const val SIDE_MARGIN = 16f
24
+ const val MAX_WIDTH = 360f
25
+ const val BOTTOM = 24f
26
+ const val FAB_SIZE = 56f
27
+ const val FAB_GAP = 16f
28
+ const val MERGE_RADIUS = 12f
29
+ const val SMOOTH_BLEND = MERGE_RADIUS
30
+ const val PILL_INSET = 4f
31
+ const val LAYER_PAD = MERGE_RADIUS
32
+ const val MAX_SHADER_SHAPES = 8
33
+ const val FIELD_SIDE = 16f
34
+ const val FIELD_ICON = 18f
35
+ const val FIELD_GAP = 8f
36
+
37
+ fun tabBarWidth(windowWidth: Float): Float = min(windowWidth - 2f * SIDE_MARGIN, MAX_WIDTH)
38
+
39
+ // Same as tabBarShapes in compositor-geometry.ts. p in [0, 1]: search morph progress.
40
+ fun tabBarShapes(windowWidth: Float, windowHeight: Float, bottomInset: Float, p: Float): List<ChromeShape> {
41
+ val width = tabBarWidth(windowWidth)
42
+ val left = (windowWidth - width) / 2f
43
+ val top = windowHeight - bottomInset - BOTTOM - TAB_HEIGHT
44
+ val h = TAB_HEIGHT
45
+ val radius = h / 2f
46
+ val capsuleRight = left + (width - h - REST_GAP) + REST_GAP * p
47
+ val circleLeft = left + width - h
48
+ val fabRadius = (FAB_SIZE / 2f) * max(0f, 1f - p)
49
+ val fabCx = left + width - FAB_SIZE / 2f
50
+ val fabCy = top - FAB_GAP - FAB_SIZE / 2f
51
+ return listOf(
52
+ ChromeShape("tabs", "bar", left, top, capsuleRight, top + h, radius),
53
+ ChromeShape("search", "bar", circleLeft, top, left + width, top + h, radius),
54
+ ChromeShape("fab", "fab", fabCx - fabRadius, fabCy - fabRadius, fabCx + fabRadius, fabCy + fabRadius, fabRadius),
55
+ )
56
+ }
57
+
58
+ // Width of one tab slot inside the capsule at rest (same as itemWidth in ios-tab-bar-view.web.tsx).
59
+ fun itemWidth(windowWidth: Float, itemCount: Int): Float {
60
+ val restCapsule = tabBarWidth(windowWidth) - TAB_HEIGHT - REST_GAP
61
+ return (restCapsule - 2f * PILL_INSET) / itemCount
62
+ }
63
+
64
+ // Layer rectangle from the members' bounds plus the pad (same as layerFor in ios-tab-bar-view.web.tsx).
65
+ fun layerFor(key: String, shapes: List<ChromeShape>): ChromeLayer {
66
+ val members = shapes.filter { it.group == key }
67
+ val x0 = members.minOf { it.x0 }
68
+ val y0 = members.minOf { it.y0 }
69
+ val x1 = members.maxOf { it.x1 }
70
+ val y1 = members.maxOf { it.y1 }
71
+ return ChromeLayer(key, x0 - LAYER_PAD, y0 - LAYER_PAD, x1 - x0 + 2f * LAYER_PAD, y1 - y0 + 2f * LAYER_PAD)
72
+ }
73
+ }
@@ -0,0 +1,74 @@
1
+ package so.oxy.bloom.glassmenu.chrome
2
+
3
+ import android.graphics.Canvas
4
+ import android.graphics.Color
5
+ import android.graphics.Paint
6
+ import android.graphics.Path
7
+
8
+ // Icons on a 24-unit grid. Approximations of the Ionicons used by the web bar (same names). Not pixel-identical.
9
+ internal object ChromeIcons {
10
+ private class Icon(val path: Path, val stroke: Float?)
11
+
12
+ private val icons: Map<String, Icon> by lazy {
13
+ mapOf(
14
+ "home" to Icon(Path().apply {
15
+ moveTo(12f, 3f); lineTo(21.5f, 11.3f); lineTo(19f, 11.3f); lineTo(19f, 20.5f); lineTo(14.5f, 20.5f)
16
+ lineTo(14.5f, 15f); lineTo(9.5f, 15f); lineTo(9.5f, 20.5f); lineTo(5f, 20.5f); lineTo(5f, 11.3f)
17
+ lineTo(2.5f, 11.3f); close()
18
+ }, null),
19
+ "tv" to Icon(Path().apply {
20
+ addRoundRect(2.5f, 5.5f, 21.5f, 17.5f, 2.5f, 2.5f, Path.Direction.CW)
21
+ addRect(8f, 19f, 16f, 20.8f, Path.Direction.CW)
22
+ }, null),
23
+ "storefront" to Icon(Path().apply {
24
+ moveTo(3f, 9.5f); lineTo(4.8f, 3.5f); lineTo(19.2f, 3.5f); lineTo(21f, 9.5f); close()
25
+ addRect(4f, 10.5f, 20f, 21f, Path.Direction.CW)
26
+ addRect(9.5f, 14.5f, 14.5f, 21f, Path.Direction.CCW)
27
+ }, null),
28
+ "albums" to Icon(Path().apply {
29
+ addRoundRect(3f, 8f, 21f, 21f, 2f, 2f, Path.Direction.CW)
30
+ addRoundRect(6f, 4.5f, 18f, 7f, 1f, 1f, Path.Direction.CW)
31
+ addRoundRect(9f, 1f, 15f, 3.5f, 1f, 1f, Path.Direction.CW)
32
+ }, null),
33
+ "search" to Icon(Path().apply {
34
+ addCircle(10.5f, 10.5f, 6.5f, Path.Direction.CW)
35
+ moveTo(15.5f, 15.5f); lineTo(20.5f, 20.5f)
36
+ }, 2.4f),
37
+ "close" to Icon(Path().apply {
38
+ moveTo(6f, 6f); lineTo(18f, 18f); moveTo(18f, 6f); lineTo(6f, 18f)
39
+ }, 2.6f),
40
+ "add" to Icon(Path().apply {
41
+ moveTo(12f, 4f); lineTo(12f, 20f); moveTo(4f, 12f); lineTo(20f, 12f)
42
+ }, 2.6f),
43
+ )
44
+ }
45
+
46
+ // Draws icon `name` centred at (cx, cy) with a box of `size` dp. Canvas is already in dp units.
47
+ fun draw(canvas: Canvas, paint: Paint, name: String, cx: Float, cy: Float, size: Float, color: Int, alpha: Float) {
48
+ val icon = icons[name] ?: return
49
+ if (alpha <= 0f) return
50
+ val scale = size / 24f
51
+ canvas.save()
52
+ canvas.translate(cx - size / 2f, cy - size / 2f)
53
+ canvas.scale(scale, scale)
54
+ paint.reset()
55
+ paint.isAntiAlias = true
56
+ paint.color = withAlpha(color, alpha)
57
+ val stroke = icon.stroke
58
+ if (stroke != null) {
59
+ paint.style = Paint.Style.STROKE
60
+ paint.strokeWidth = stroke
61
+ paint.strokeCap = Paint.Cap.ROUND
62
+ paint.strokeJoin = Paint.Join.ROUND
63
+ } else {
64
+ paint.style = Paint.Style.FILL
65
+ }
66
+ canvas.drawPath(icon.path, paint)
67
+ canvas.restore()
68
+ }
69
+
70
+ fun withAlpha(color: Int, alpha: Float): Int {
71
+ val a = (Color.alpha(color) * alpha.coerceIn(0f, 1f)).toInt()
72
+ return Color.argb(a, Color.red(color), Color.green(color), Color.blue(color))
73
+ }
74
+ }
@@ -0,0 +1,74 @@
1
+ package so.oxy.bloom.glassmenu.chrome
2
+
3
+ import so.oxy.bloom.glassmenu.records.GlassMenuConfigRecord
4
+ import so.oxy.bloom.glassmenu.records.GlassTriggerConfigRecord
5
+ import so.oxy.bloom.glassmenu.motion.GlassJelly
6
+ import so.oxy.bloom.glassmenu.render.GlassSurfaceState
7
+ import android.graphics.RectF
8
+ import so.oxy.bloom.glassmenu.GlassMenuAndroidView
9
+
10
+ // The ONE material configuration of the chrome (Android twin of chrome-material.web.ts). Every chrome surface
11
+ // (tab bar, search circle, create circle, headers, toolbars, circular buttons) goes through apply(): the menu's
12
+ // material (same records, same recipes, same shadow and rim) with refraction zeroed. The menu is not changed.
13
+ internal object ChromeMaterial {
14
+ // Multiplies the menu's refraction in GlassRenderer.drawGlass. 0 = no lens, no outer displacement (option B).
15
+ const val REFRACTION_SCALE = 0f
16
+
17
+ // Magnification of the content under the selection lens (convex centre). Same value as chrome-material.web.ts.
18
+ const val PILL_MAGNIFY = 1.12f
19
+
20
+ // Refraction band of the selection lens (dp): the rim only. Same value as chrome-material.web.ts.
21
+ const val PILL_LENS_BAND = 6f
22
+
23
+ fun apply(state: GlassSurfaceState) {
24
+ state.config = GlassMenuConfigRecord()
25
+ state.trigger = GlassTriggerConfigRecord()
26
+ state.dark = true
27
+ state.refractionScale = REFRACTION_SCALE
28
+ state.lensHeight = 0f
29
+ state.lensAmount = 0f
30
+ state.materialProgress = 1f
31
+ state.surfaceOpacity = 1f
32
+ state.pressX = 0f
33
+ state.pressY = 0f
34
+ state.poolGain = 0f
35
+ state.pressLift = 0f
36
+ state.rimLift = 0f
37
+ }
38
+ }
39
+
40
+ // The selection pill: the same material as the menu's resting trigger (the "Prueba" button): the same records
41
+ // (GlassMenuConfigRecord and GlassTriggerConfigRecord defaults, which are the ones GlassMenuAndroidView uses unless the
42
+ // app sets them), the same recipe, and the same light as GlassMenuAndroidView.applyLight with the pill's jelly and rect.
43
+ // Refraction is on (refractionScale 1). The state is the one GlassMenuOverlay.drawRestingAnchor uses.
44
+ // `pill` is the pill rectangle in dp; ox and oy are the chrome's window offset in px.
45
+ internal fun ChromeMaterial.applyPill(
46
+ state: GlassSurfaceState,
47
+ jelly: GlassJelly,
48
+ pill: RectF,
49
+ ox: Float,
50
+ oy: Float,
51
+ density: Float,
52
+ ) {
53
+ state.config = GlassMenuConfigRecord()
54
+ state.trigger = GlassTriggerConfigRecord()
55
+ state.dark = true
56
+ state.refractionScale = 1f
57
+ state.magnify = PILL_MAGNIFY
58
+ state.lensBand = PILL_LENS_BAND
59
+ state.hasSource = false
60
+ state.smoothing = 0f
61
+ state.lensHeight = 0f
62
+ state.lensAmount = 0f
63
+ state.materialProgress = 0f
64
+ state.surfaceOpacity = 1f
65
+ // applyLight(state, origin, opacity = 1) of GlassMenuAndroidView, with the pill's jelly. The jelly works in dp here,
66
+ // so its light position is converted to px and offset to the window.
67
+ val glow = jelly.glowValue * state.trigger.shine
68
+ state.pressX = ox + (pill.left + jelly.lightPositionX) * density
69
+ state.pressY = oy + (pill.top + jelly.lightPositionY) * density
70
+ state.pressRadius = GlassMenuAndroidView.LightRadius * density
71
+ state.poolGain = GlassMenuAndroidView.LightPool * glow
72
+ state.pressLift = GlassMenuAndroidView.LightLift * glow
73
+ state.rimLift = GlassMenuAndroidView.LightRimLift * glow
74
+ }
@@ -0,0 +1,73 @@
1
+ package so.oxy.bloom.glassmenu.chrome
2
+
3
+ import android.graphics.Color
4
+ import android.view.ViewGroup
5
+ import android.widget.FrameLayout
6
+ import so.oxy.bloom.glassmenu.backdrop.GlassBackdrop
7
+ import so.oxy.bloom.glassmenu.overlay.GlassDevGuard
8
+ import expo.modules.kotlin.AppContext
9
+ import expo.modules.kotlin.viewevent.EventDispatcher
10
+ import expo.modules.kotlin.views.ExpoView
11
+
12
+ // Expo host of the chrome: an empty view in the React tree. Its drawing and touches live in GlassChromeView, which is
13
+ // attached to the window root as an overlay (see GlassChromeView). Props are forwarded; events go back to React.
14
+ class GlassChromeHost(context: android.content.Context, appContext: AppContext) : ExpoView(context, appContext) {
15
+ private val onTabSelect by EventDispatcher<Map<String, Any?>>()
16
+ private val onSearchChange by EventDispatcher<Map<String, Any?>>()
17
+ private val onCreate by EventDispatcher<Map<String, Any?>>()
18
+
19
+ private val overlay = GlassChromeView(context).apply {
20
+ emit = { name, payload ->
21
+ when (name) {
22
+ "onTabSelect" -> onTabSelect(payload)
23
+ "onSearchChange" -> onSearchChange(payload)
24
+ else -> onCreate(payload)
25
+ }
26
+ }
27
+ }
28
+ private var attachedRoot: ViewGroup? = null
29
+
30
+ var labels: List<String>
31
+ get() = overlay.labels
32
+ set(value) {
33
+ overlay.labels = value
34
+ }
35
+ var icons: List<String>
36
+ get() = overlay.icons
37
+ set(value) {
38
+ overlay.icons = value
39
+ }
40
+ var selectedIndex: Int
41
+ get() = overlay.selectedIndex
42
+ set(value) {
43
+ overlay.selectedIndex = value
44
+ }
45
+ var bottomInset: Float
46
+ get() = overlay.bottomInset
47
+ set(value) {
48
+ overlay.bottomInset = value
49
+ }
50
+ var searchPlaceholder: String
51
+ get() = overlay.searchPlaceholder
52
+ set(value) {
53
+ overlay.searchPlaceholder = value
54
+ }
55
+
56
+ override fun onAttachedToWindow() {
57
+ super.onAttachedToWindow()
58
+ val root = rootView as? ViewGroup ?: return
59
+ attachedRoot = root
60
+ GlassDevGuard.warnIfInOverscrollScroll(this)
61
+ if (overlay.parent == null) {
62
+ root.addView(overlay, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT))
63
+ }
64
+ GlassBackdrop.forRoot(root).register(overlay) { Color.BLACK }
65
+ }
66
+
67
+ override fun onDetachedFromWindow() {
68
+ attachedRoot?.let { GlassBackdrop.forRoot(it).unregister(overlay) }
69
+ (overlay.parent as? ViewGroup)?.removeView(overlay)
70
+ attachedRoot = null
71
+ super.onDetachedFromWindow()
72
+ }
73
+ }
@@ -0,0 +1,31 @@
1
+ package so.oxy.bloom.glassmenu.chrome
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+
6
+ // Native view of the chrome (tab bar, search circle, create circle). Registered in expo-module.config.json.
7
+ class GlassChromeModule : Module() {
8
+ override fun definition() = ModuleDefinition {
9
+ Name("GlassChrome")
10
+
11
+ View(GlassChromeHost::class) {
12
+ Events("onTabSelect", "onSearchChange", "onCreate")
13
+
14
+ Prop("labels") { view: GlassChromeHost, labels: List<String>? ->
15
+ view.labels = labels ?: emptyList()
16
+ }
17
+ Prop("icons") { view: GlassChromeHost, icons: List<String>? ->
18
+ view.icons = icons ?: emptyList()
19
+ }
20
+ Prop("selectedIndex") { view: GlassChromeHost, index: Int? ->
21
+ view.selectedIndex = index ?: 0
22
+ }
23
+ Prop("bottomInset") { view: GlassChromeHost, inset: Double? ->
24
+ view.bottomInset = (inset ?: 0.0).toFloat()
25
+ }
26
+ Prop("searchPlaceholder") { view: GlassChromeHost, text: String? ->
27
+ view.searchPlaceholder = text ?: "Search"
28
+ }
29
+ }
30
+ }
31
+ }