@oxy.so/bloom-lens 0.0.0-bootstrap.0 → 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 +31 -1
  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 -1
@@ -0,0 +1,113 @@
1
+ // Search with a FAB, inline variant: one bar at the bottom: a field (glass, with its text input) and a circular create
2
+ // button at its right. Tapping the field opens the search: the FAB shrinks away, the field takes the width, and a
3
+ // "Cancelar" label appears at the right end. Cancel (or the keyboard going away) closes it.
4
+ // Geometry is computed here; the material, motion and gesture are SurfaceNodes (shared with the web and native layers).
5
+ import { useState, type ReactElement } from "react";
6
+
7
+ import { SurfaceNodes } from "./surface-nodes";
8
+ import { CHROME_METRICS, type TBox, type TNode } from "./surface-layer";
9
+
10
+ const CIRCLE = CHROME_METRICS.circle;
11
+ const CANCEL_WIDTH = 88;
12
+ const ACCENT = "#0A84FF";
13
+
14
+ export type TGlassSearchFabProps = {
15
+ // Area the bar is laid out in (window dp).
16
+ box: TBox;
17
+ insetBottom: number;
18
+ value: string;
19
+ onChangeText: (text: string) => void;
20
+ placeholder?: string;
21
+ onCreate: () => void;
22
+ onOpenChange?: (open: boolean) => void;
23
+ };
24
+
25
+ // The nodes of the bar for a given state (exported for the layout check; the component is the only user).
26
+ export const searchFabNodes = (box: TBox, insetBottom: number, open: boolean, value: string, placeholder: string): TNode[] => {
27
+ const margin = CHROME_METRICS.margin;
28
+ const gap = CHROME_METRICS.gap;
29
+ const y = box.y + box.height - insetBottom - margin - CIRCLE;
30
+ const fabX = box.x + box.width - margin - CIRCLE;
31
+ const fieldLeft = box.x + margin;
32
+ const fieldRight = open ? box.x + box.width - margin - CANCEL_WIDTH - gap : fabX - gap;
33
+ const nodes: TNode[] = [
34
+ {
35
+ id: "search",
36
+ kind: "field",
37
+ x: fieldLeft,
38
+ y,
39
+ w: fieldRight - fieldLeft,
40
+ h: CIRCLE,
41
+ r: CIRCLE / 2,
42
+ icon: "search",
43
+ placeholder,
44
+ value,
45
+ },
46
+ {
47
+ id: "fab",
48
+ kind: "glass",
49
+ x: open ? box.x + box.width - margin : fabX,
50
+ y,
51
+ w: open ? 0 : CIRCLE,
52
+ h: CIRCLE,
53
+ r: CIRCLE / 2,
54
+ icon: "add",
55
+ textSize: 30,
56
+ },
57
+ ];
58
+ if (open) {
59
+ nodes.push({
60
+ id: "cancel",
61
+ kind: "label",
62
+ x: box.x + box.width - margin - CANCEL_WIDTH,
63
+ y,
64
+ w: CANCEL_WIDTH,
65
+ h: CIRCLE,
66
+ r: 0,
67
+ text: "Cancelar",
68
+ textSize: 17,
69
+ color: ACCENT,
70
+ });
71
+ }
72
+ return nodes;
73
+ };
74
+
75
+ const GlassSearchFab = ({
76
+ box,
77
+ insetBottom,
78
+ value,
79
+ onChangeText,
80
+ placeholder = "Buscar",
81
+ onCreate,
82
+ onOpenChange,
83
+ }: TGlassSearchFabProps): ReactElement => {
84
+ const [open, setOpen] = useState(false);
85
+ // The field that holds the keyboard, mirrored from the platform focus (so Cancel can give it up).
86
+ const [focusedField, setFocusedField] = useState<string | null>(null);
87
+
88
+ const setOpenState = (next: boolean): void => {
89
+ setOpen(next);
90
+ onOpenChange?.(next);
91
+ };
92
+
93
+ return (
94
+ <SurfaceNodes
95
+ nodes={searchFabNodes(box, insetBottom, open, value, placeholder)}
96
+ focusedField={focusedField}
97
+ onFieldText={(_id, text): void => onChangeText(text)}
98
+ onFieldFocus={(id, focused): void => {
99
+ setFocusedField(focused ? id : null);
100
+ if (focused) setOpenState(true);
101
+ }}
102
+ onNodePress={(id): void => {
103
+ if (id === "fab") onCreate();
104
+ if (id === "cancel") {
105
+ setFocusedField(null);
106
+ setOpenState(false);
107
+ }
108
+ }}
109
+ />
110
+ );
111
+ };
112
+
113
+ export { GlassSearchFab };
@@ -0,0 +1,150 @@
1
+ // Adaptive navigation chrome by size class (window width, see sizeClassOf in surface-layer.ts):
2
+ // compact: a bottom capsule of tabs with the search circle at its right (phone portrait)
3
+ // regular: a top capsule of tabs across the width (from 480 dp)
4
+ // expanded: a sidebar at the left with the tabs as rows (from 840 dp); the content is to its right
5
+ // It returns the nodes and the content box, so the page lays its content where the chrome leaves room.
6
+ // Geometry here; the material and motion are SurfaceNodes.
7
+ import type { ReactElement } from "react";
8
+
9
+ import { SurfaceNodes } from "./surface-nodes";
10
+ import { CHROME_METRICS, type TBox, type TNode, type TSizeClass, type TTabItem } from "./surface-layer";
11
+
12
+ const CIRCLE = CHROME_METRICS.circle;
13
+ const BAR = CHROME_METRICS.bar;
14
+ const MARGIN = CHROME_METRICS.margin;
15
+ const GAP = CHROME_METRICS.gap;
16
+ const SIDEBAR_WIDTH = 240;
17
+ const ROW_HEIGHT = 48;
18
+ const ROW_INSET = 4;
19
+ const INACTIVE = "#A1A1A6";
20
+ const ACCENT = "#0A84FF";
21
+
22
+ export type TAdaptiveChrome = {
23
+ nodes: TNode[];
24
+ // Where the page content goes (window dp).
25
+ content: TBox;
26
+ };
27
+
28
+ // The chrome of one size class: the nodes and the content box. Exported for the layout check.
29
+ export const adaptiveChrome = (
30
+ sizeClass: TSizeClass,
31
+ box: TBox,
32
+ insetBottom: number,
33
+ items: readonly TTabItem[],
34
+ selected: number,
35
+ ): TAdaptiveChrome => {
36
+ const n = items.length;
37
+
38
+ if (sizeClass === "compact") {
39
+ const y = box.y + box.height - insetBottom - MARGIN - CIRCLE;
40
+ const searchX = box.x + box.width - MARGIN - CIRCLE;
41
+ const capsuleLeft = box.x + MARGIN;
42
+ const capsuleRight = searchX - GAP;
43
+ const tabW = (capsuleRight - capsuleLeft - 2 * ROW_INSET) / n;
44
+ const nodes: TNode[] = [
45
+ { id: "tabs", kind: "glass", x: capsuleLeft, y, w: capsuleRight - capsuleLeft, h: CIRCLE, r: CIRCLE / 2 },
46
+ { id: "selection", kind: "selection", x: capsuleLeft + ROW_INSET + selected * tabW, y: y + ROW_INSET, w: tabW, h: CIRCLE - 2 * ROW_INSET, r: (CIRCLE - 2 * ROW_INSET) / 2, pressable: false },
47
+ ];
48
+ items.forEach((item, index): void => {
49
+ nodes.push({
50
+ id: `tab-${index}`,
51
+ kind: "label",
52
+ x: capsuleLeft + ROW_INSET + index * tabW,
53
+ y,
54
+ w: tabW,
55
+ h: CIRCLE,
56
+ r: 0,
57
+ icon: item.icon,
58
+ text: item.label,
59
+ textSize: 13,
60
+ color: index === selected ? ACCENT : INACTIVE,
61
+ });
62
+ });
63
+ nodes.push({ id: "search", kind: "glass", x: searchX, y, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "search", textSize: 24 });
64
+ const contentBottom = y - MARGIN;
65
+ return {
66
+ nodes,
67
+ content: { x: box.x + MARGIN, y: box.y, width: box.width - 2 * MARGIN, height: contentBottom - box.y },
68
+ };
69
+ }
70
+
71
+ if (sizeClass === "regular") {
72
+ const y = box.y;
73
+ const left = box.x + MARGIN;
74
+ const right = box.x + box.width - MARGIN;
75
+ const tabW = (right - left - 2 * ROW_INSET) / n;
76
+ const nodes: TNode[] = [
77
+ { id: "tabs", kind: "glass", x: left, y, w: right - left, h: BAR + 8, r: (BAR + 8) / 2 },
78
+ { id: "selection", kind: "selection", x: left + ROW_INSET + selected * tabW, y: y + ROW_INSET, w: tabW, h: BAR, r: BAR / 2, pressable: false },
79
+ ];
80
+ items.forEach((item, index): void => {
81
+ nodes.push({
82
+ id: `tab-${index}`,
83
+ kind: "label",
84
+ x: left + ROW_INSET + index * tabW,
85
+ y,
86
+ w: tabW,
87
+ h: BAR + 8,
88
+ r: 0,
89
+ icon: item.icon,
90
+ text: item.label,
91
+ textSize: 14,
92
+ color: index === selected ? "#FFFFFF" : INACTIVE,
93
+ });
94
+ });
95
+ const top = y + BAR + 8 + GAP * 2;
96
+ return { nodes, content: { x: box.x + MARGIN, y: top, width: box.width - 2 * MARGIN, height: box.y + box.height - top } };
97
+ }
98
+
99
+ // expanded: a sidebar with one row per tab.
100
+ const sidebarHeight = Math.max(box.height - MARGIN, 0);
101
+ const y = box.y;
102
+ const x = box.x + MARGIN;
103
+ const nodes: TNode[] = [
104
+ { id: "sidebar", kind: "glass", x, y, w: SIDEBAR_WIDTH, h: sidebarHeight, r: 28 },
105
+ { id: "selection", kind: "selection", x: x + ROW_INSET, y: y + 16 + selected * ROW_HEIGHT, w: SIDEBAR_WIDTH - 2 * ROW_INSET, h: ROW_HEIGHT, r: ROW_HEIGHT / 2, pressable: false },
106
+ ];
107
+ items.forEach((item, index): void => {
108
+ nodes.push({
109
+ id: `tab-${index}`,
110
+ kind: "label",
111
+ x: x + ROW_INSET,
112
+ y: y + 16 + index * ROW_HEIGHT,
113
+ w: SIDEBAR_WIDTH - 2 * ROW_INSET,
114
+ h: ROW_HEIGHT,
115
+ r: 0,
116
+ icon: item.icon,
117
+ text: item.label,
118
+ textSize: 17,
119
+ color: index === selected ? "#FFFFFF" : INACTIVE,
120
+ });
121
+ });
122
+ const contentLeft = x + SIDEBAR_WIDTH + MARGIN;
123
+ return { nodes, content: { x: contentLeft, y, width: box.x + box.width - MARGIN - contentLeft, height: box.height - MARGIN } };
124
+ };
125
+
126
+ export type TGlassSizeChromeProps = {
127
+ sizeClass: TSizeClass;
128
+ box: TBox;
129
+ insetBottom: number;
130
+ items: readonly TTabItem[];
131
+ selected: number;
132
+ onSelect: (index: number) => void;
133
+ onSearch?: () => void;
134
+ };
135
+
136
+ // Renders the chrome. The page places its content with adaptiveChrome(...).content.
137
+ const GlassSizeChrome = ({ sizeClass, box, insetBottom, items, selected, onSelect, onSearch }: TGlassSizeChromeProps): ReactElement => {
138
+ const { nodes } = adaptiveChrome(sizeClass, box, insetBottom, items, selected);
139
+ return (
140
+ <SurfaceNodes
141
+ nodes={nodes}
142
+ onNodePress={(id): void => {
143
+ if (id === "search") onSearch?.();
144
+ else if (id.startsWith("tab-")) onSelect(Number(id.slice("tab-".length)));
145
+ }}
146
+ />
147
+ );
148
+ };
149
+
150
+ export { GlassSizeChrome };
@@ -0,0 +1,45 @@
1
+ // Bottom toolbar with a central pill (the WWDC25 pattern): a circular filter button at the left, the central glass
2
+ // pill with a text, and a circular search button at the right. Geometry here; the material and motion are SurfaceNodes.
3
+ import type { ReactElement } from "react";
4
+
5
+ import { SurfaceNodes } from "./surface-nodes";
6
+ import { CHROME_METRICS, type TBox, type TNode } from "./surface-layer";
7
+
8
+ const CIRCLE = CHROME_METRICS.circle;
9
+
10
+ export type TGlassToolbarProps = {
11
+ box: TBox;
12
+ insetBottom: number;
13
+ // Text of the central pill.
14
+ title: string;
15
+ onFilter: () => void;
16
+ onPress: () => void;
17
+ onSearch: () => void;
18
+ };
19
+
20
+ // The toolbar nodes for a box (exported so the layout can be checked without a render).
21
+ export const toolbarNodes = (box: TBox, insetBottom: number, title: string): TNode[] => {
22
+ const margin = CHROME_METRICS.margin;
23
+ const gap = CHROME_METRICS.gap;
24
+ const y = box.y + box.height - insetBottom - margin - CIRCLE;
25
+ const pillLeft = box.x + margin + CIRCLE + gap;
26
+ const pillRight = box.x + box.width - margin - CIRCLE - gap;
27
+ return [
28
+ { id: "filter", kind: "glass", x: box.x + margin, y, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "options", textSize: 22 },
29
+ { id: "pill", kind: "glass", x: pillLeft, y, w: pillRight - pillLeft, h: CIRCLE, r: CIRCLE / 2, text: title, textSize: 17 },
30
+ { id: "search", kind: "glass", x: box.x + box.width - margin - CIRCLE, y, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "search", textSize: 24 },
31
+ ];
32
+ };
33
+
34
+ const GlassToolbar = ({ box, insetBottom, title, onFilter, onPress, onSearch }: TGlassToolbarProps): ReactElement => (
35
+ <SurfaceNodes
36
+ nodes={toolbarNodes(box, insetBottom, title)}
37
+ onNodePress={(id): void => {
38
+ if (id === "filter") onFilter();
39
+ else if (id === "pill") onPress();
40
+ else if (id === "search") onSearch();
41
+ }}
42
+ />
43
+ );
44
+
45
+ export { GlassToolbar };
@@ -0,0 +1,17 @@
1
+ import type { ComponentProps } from "react";
2
+ import type Ionicons from "@expo/vector-icons/Ionicons";
3
+
4
+ export type TTabBarItem = {
5
+ key: string;
6
+ label: string;
7
+ icon: ComponentProps<typeof Ionicons>["name"];
8
+ };
9
+
10
+ export type TIosTabBarProps = {
11
+ items: readonly TTabBarItem[];
12
+ selectedIndex: number;
13
+ onSelect: (index: number) => void;
14
+ onCreate: () => void;
15
+ bottomInset: number;
16
+ searchPlaceholder?: string;
17
+ };
@@ -0,0 +1,49 @@
1
+ // Native entry (Android): the chrome is one native view (GlassChrome, Kotlin). Geometry, springs and fills are the
2
+ // same as the web bar (ios-tab-bar-view.web.tsx); the native view runs its own frame loop and emits taps.
3
+ import { requireNativeView } from "expo";
4
+ import type { ReactElement } from "react";
5
+ import type { NativeSyntheticEvent } from "react-native";
6
+
7
+ import type { TIosTabBarProps } from "./interface";
8
+
9
+ type TNativeEvent<T> = NativeSyntheticEvent<T>;
10
+
11
+ type TNativeChromeProps = {
12
+ labels: readonly string[];
13
+ icons: readonly string[];
14
+ selectedIndex: number;
15
+ bottomInset: number;
16
+ searchPlaceholder: string;
17
+ onTabSelect: (event: TNativeEvent<{ index: number }>) => void;
18
+ onSearchChange: (event: TNativeEvent<{ open: boolean }>) => void;
19
+ onCreate: (event: TNativeEvent<Record<string, never>>) => void;
20
+ style?: object;
21
+ };
22
+
23
+ const NativeChrome = requireNativeView<TNativeChromeProps>("GlassChrome");
24
+
25
+ // The native host is an empty view in the React tree: the chrome draws as a window overlay (GlassChromeView).
26
+ const HOST_STYLE = { position: "absolute" as const, left: 0, bottom: 0, width: 0, height: 0 };
27
+
28
+ const IosTabBar = ({
29
+ items,
30
+ selectedIndex,
31
+ onSelect,
32
+ onCreate,
33
+ bottomInset,
34
+ searchPlaceholder,
35
+ }: TIosTabBarProps): ReactElement => (
36
+ <NativeChrome
37
+ labels={items.map((item): string => item.label)}
38
+ icons={items.map((item): string => item.icon)}
39
+ selectedIndex={selectedIndex}
40
+ bottomInset={bottomInset}
41
+ searchPlaceholder={searchPlaceholder ?? "Search"}
42
+ onTabSelect={(event): void => onSelect(event.nativeEvent.index)}
43
+ onSearchChange={(): void => undefined}
44
+ onCreate={(): void => onCreate()}
45
+ style={HOST_STYLE}
46
+ />
47
+ );
48
+
49
+ export { IosTabBar };
@@ -0,0 +1,91 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ // Platform-neutral description of one glass layer (the gallery components of chrome/). Imported as "./surface-layer";
4
+ // the platform entries are surface-nodes.web.tsx and surface-nodes.tsx. A layer is a list of nodes in
5
+ // window dp; the web renderer (surface-nodes.web.tsx) and the native renderer (surface-nodes.tsx, Kotlin
6
+ // SurfaceNodesView) draw the same list with the same material (ChromeMaterial / chromeGlassState) and the same springs.
7
+ // Components only compute nodes; they hold no material, motion or gesture code of their own.
8
+
9
+ // glass: circle or rounded rectangle of the chrome material (no refraction)
10
+ // selection: the selection pill (refractive: the one material with refraction in the chrome)
11
+ // field: glass rectangle with a text input on it (search field)
12
+ // label: no material, only text (and a tap area); e.g. the segments of a segmented control
13
+ export type TNodeKind = "glass" | "selection" | "field" | "label";
14
+
15
+ export type TNode = {
16
+ id: string;
17
+ kind: TNodeKind;
18
+ // window dp
19
+ x: number;
20
+ y: number;
21
+ w: number;
22
+ h: number;
23
+ // corner radius dp (h / 2 for a pill or a circle)
24
+ r: number;
25
+ // Ionicons name, drawn centred (glass, label) or at the left inside a field
26
+ icon?: string;
27
+ // Index of a React child of SurfaceNodes (the `icons` prop) drawn centred in the node: the same mechanism as the
28
+ // menu's iconSlot. Takes the place of `icon` when set. The child is a React view, so any icon set can be used.
29
+ iconSlot?: number;
30
+ // text drawn centred on the node (labels, title on a capsule, selection text)
31
+ text?: string;
32
+ textSize?: number;
33
+ // colour of the icon and the text, #RRGGBB
34
+ color?: string;
35
+ // field: hint and current value
36
+ placeholder?: string;
37
+ value?: string;
38
+ // a tap on the node emits onNodePress(id). Default true.
39
+ pressable?: boolean;
40
+ };
41
+
42
+ export type TBox = { x: number; y: number; width: number; height: number };
43
+
44
+ export type TNodeRect = { x: number; y: number; w: number; h: number; r: number };
45
+
46
+ // Size classes (window dp). Compact: phone portrait; regular: from 480 dp (the Pixel 10 Pro is ~412 dp wide, so it
47
+ // is compact); expanded: from 840 dp, where the sidebar is shown.
48
+ export const REGULAR_MIN_WIDTH = 480;
49
+ export const EXPANDED_MIN_WIDTH = 840;
50
+ export type TSizeClass = "compact" | "regular" | "expanded";
51
+ export const sizeClassOf = (width: number): TSizeClass =>
52
+ width >= EXPANDED_MIN_WIDTH ? "expanded" : width >= REGULAR_MIN_WIDTH ? "regular" : "compact";
53
+
54
+ // Metrics shared by the components (one place, so web and Android agree).
55
+ export const CHROME_METRICS = {
56
+ // Circular glass button (search, FAB, toolbar circles, call buttons).
57
+ circle: 56,
58
+ // Height of a capsule bar (compact header, segmented control, toolbar pill).
59
+ bar: 52,
60
+ // Gap between separate glass shapes and the window side.
61
+ gap: 8,
62
+ margin: 16,
63
+ } as const;
64
+
65
+ // The rectangle of a node as it is at a given position of its spring (0 = from, 1 = to).
66
+ export const lerpRect = (from: TNodeRect, to: TNodeRect, t: number): TNodeRect => ({
67
+ x: from.x + (to.x - from.x) * t,
68
+ y: from.y + (to.y - from.y) * t,
69
+ w: from.w + (to.w - from.w) * t,
70
+ h: from.h + (to.h - from.h) * t,
71
+ r: from.r + (to.r - from.r) * t,
72
+ });
73
+
74
+ export const rectOfNode = (node: TNode): TNodeRect => ({ x: node.x, y: node.y, w: node.w, h: node.h, r: node.r });
75
+
76
+ // One tab of an adaptive bar: an icon (Ionicons name) and its label.
77
+ export type TTabItem = { label: string; icon: string };
78
+
79
+ export type TSurfaceNodesProps = {
80
+ nodes: readonly TNode[];
81
+ // React views for the nodes' iconSlot (index = slot).
82
+ icons?: readonly ReactNode[];
83
+ // Tap on a pressable node (glass, selection, label).
84
+ onNodePress?: (id: string) => void;
85
+ // Text typed in a field node.
86
+ onFieldText?: (id: string, text: string) => void;
87
+ // A field gained (true) or lost (false) focus.
88
+ onFieldFocus?: (id: string, focused: boolean) => void;
89
+ // The field that must hold the keyboard, or null for none. Set by the component, not by the user's touch.
90
+ focusedField?: string | null;
91
+ };
@@ -0,0 +1,54 @@
1
+ // Native entry of a node layer (Android): the layer is one native view (GlassSurfaceNodes, Kotlin SurfaceNodesView).
2
+ // The host is an empty view in the React tree; the layer draws as a window overlay with the same geometry and
3
+ // material as the web renderer (surface-nodes-view.web.tsx).
4
+ import { requireNativeView } from "expo";
5
+ import type { ReactElement, ReactNode } from "react";
6
+ import { View } from "react-native";
7
+ import type { NativeSyntheticEvent } from "react-native";
8
+
9
+ import type { TNode, TSurfaceNodesProps } from "./surface-layer";
10
+
11
+ type TNativeNodeEvent = NativeSyntheticEvent<{ id: string }>;
12
+ type TNativeFieldTextEvent = NativeSyntheticEvent<{ id: string; text: string }>;
13
+ type TNativeFieldFocusEvent = NativeSyntheticEvent<{ id: string; focused: boolean }>;
14
+
15
+ type TNativeNodesProps = {
16
+ nodes: readonly TNode[];
17
+ onNodePress: (event: TNativeNodeEvent) => void;
18
+ onFieldText: (event: TNativeFieldTextEvent) => void;
19
+ onFieldFocus: (event: TNativeFieldFocusEvent) => void;
20
+ focusedField: string | null;
21
+ style?: object;
22
+ children?: ReactNode;
23
+ };
24
+
25
+ const NativeNodes = requireNativeView<TNativeNodesProps>("GlassSurfaceNodes");
26
+
27
+ // The native host has no size of its own: the layer draws over the window.
28
+ const HOST_STYLE = { position: "absolute" as const, left: 0, top: 0, width: 0, height: 0 };
29
+ const ICON_HOST_ID = "glass-surface-icons";
30
+ const ICON_HOST_STYLE = { position: "absolute" as const, left: 0, top: 0, width: 0, height: 0, opacity: 0 };
31
+ const SLOT_STYLE = { position: "absolute" as const, left: 0, top: 0 };
32
+
33
+ // Native icons: the React views of `icons` are children of the native host. The host keeps them at opacity 0 (not drawn
34
+ // by the hierarchy) and the layer draws them with view.draw at each node's centre (SurfaceNodesView, iconSlot).
35
+ const SurfaceNodes = ({ nodes, icons = [], onNodePress, onFieldText, onFieldFocus, focusedField = null }: TSurfaceNodesProps): ReactElement => (
36
+ <NativeNodes
37
+ nodes={nodes}
38
+ focusedField={focusedField}
39
+ onNodePress={(event): void => onNodePress?.(event.nativeEvent.id)}
40
+ onFieldText={(event): void => onFieldText?.(event.nativeEvent.id, event.nativeEvent.text)}
41
+ onFieldFocus={(event): void => onFieldFocus?.(event.nativeEvent.id, event.nativeEvent.focused)}
42
+ style={HOST_STYLE}
43
+ >
44
+ <View nativeID={ICON_HOST_ID} collapsable={false} pointerEvents="none" style={ICON_HOST_STYLE}>
45
+ {icons.map((icon: ReactNode, index: number): ReactElement => (
46
+ <View key={index} collapsable={false} style={SLOT_STYLE}>
47
+ {icon}
48
+ </View>
49
+ ))}
50
+ </View>
51
+ </NativeNodes>
52
+ );
53
+
54
+ export { SurfaceNodes };
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `@oxy.so/bloom-lens`: the lens engine (`android/`, the upstream app's Kotlin with
3
+ * `patches/bloom.patch`), the upstream app's menu component (`src/menu`, verbatim with
4
+ * `patches/menu/bloom.patch`), and the lens base Bloom's controls and menus share (`base.tsx`).
5
+ * Android 13+ only; Bloom resolves this module lazily and keeps its own material where it is absent.
6
+ */
7
+ export { Menu } from './menu';
8
+ export type { IMenuHandle, TMenuConfig, TMenuRect, TMenuTriggerConfig } from './menu';
9
+ export type { LensRow } from './rows';
10
+ export {
11
+ LensBase,
12
+ LensBaseContext,
13
+ useInLensBase,
14
+ useLensBaseMenu,
15
+ type LensBaseProps,
16
+ type LensGroupMember,
17
+ type LensMenu,
18
+ type LensMenuHandle,
19
+ } from './base';
@@ -0,0 +1,22 @@
1
+ import { createCompoundComponent } from "../../utils/create-compound-component.util";
2
+ import { MenuActionRow } from "../menu-action-row";
3
+ import { MenuContent } from "../menu-content";
4
+ import { MenuItem } from "../menu-item";
5
+ import { MenuLabel } from "../menu-label";
6
+ import { MenuSeparator } from "../menu-separator";
7
+ import { MenuSubmenu } from "../menu-submenu";
8
+ import { MenuTrigger } from "../menu-trigger";
9
+ import { MenuTriggerButton } from "../menu-trigger-button";
10
+ import { MenuRoot } from "./menu";
11
+ const Menu = createCompoundComponent("Menu", MenuRoot, {
12
+ Trigger: MenuTrigger,
13
+ TriggerButton: MenuTriggerButton,
14
+ Content: MenuContent,
15
+ Item: MenuItem,
16
+ Separator: MenuSeparator,
17
+ ActionRow: MenuActionRow,
18
+ Submenu: MenuSubmenu,
19
+ Label: MenuLabel,
20
+ });
21
+
22
+ export { Menu };
@@ -0,0 +1,97 @@
1
+ import {
2
+ useCallback,
3
+ useImperativeHandle,
4
+ useMemo,
5
+ useRef,
6
+ type FC,
7
+ type ReactElement,
8
+ type RefObject,
9
+ } from "react";
10
+ import { useColorScheme } from "react-native";
11
+ import type {
12
+ IMenuContext,
13
+ INativeMenuHandle,
14
+ TNativeMenuItem,
15
+ TParsedMenu,
16
+ } from "../../context/interface";
17
+ import { MenuContext } from "../../context/menu.context";
18
+ import type {
19
+ IMenu,
20
+ IMenuContent,
21
+ IMenuHandle,
22
+ TMenuRect,
23
+ TMenuSelectEvent,
24
+ } from "../../interface";
25
+ import { findMenuContent } from "../../utils/find-menu-content.util";
26
+ import { parseMenuContent } from "../../utils/parse-menu-content.util";
27
+ import { registerComponent } from "../../utils/register-component.util";
28
+
29
+ const MenuBase: FC<IMenu> = ({
30
+ ref,
31
+ colorScheme = "auto",
32
+ onSelect,
33
+ onOpenChange,
34
+ children,
35
+ }: IMenu & React.ComponentProps<typeof MenuBase>): React.ReactNode &
36
+ React.JSX.Element => {
37
+ const system = useColorScheme();
38
+ const scheme =
39
+ colorScheme === "auto"
40
+ ? system === "light"
41
+ ? "light"
42
+ : "dark"
43
+ : colorScheme;
44
+ const native: RefObject<INativeMenuHandle | null> =
45
+ useRef<INativeMenuHandle | null>(null);
46
+
47
+ const handle = useMemo<IMenuHandle>(
48
+ () => ({
49
+ open: (from?: TMenuRect) =>
50
+ void native.current?.open(from?.x, from?.y, from?.width, from?.height),
51
+ close: (): void => void native.current?.close(),
52
+ }),
53
+ [],
54
+ );
55
+ useImperativeHandle<IMenuHandle, IMenuHandle>(ref, () => handle, [handle]);
56
+
57
+ const contentElement: ReactElement<IMenuContent> | null =
58
+ findMenuContent(children);
59
+ const contentProps = contentElement?.props ?? null;
60
+ const parsed: TParsedMenu = parseMenuContent(contentProps, scheme);
61
+ const itemsKey = JSON.stringify(parsed.items);
62
+ const items = useMemo<TNativeMenuItem[]>(
63
+ () => JSON.parse(itemsKey) as TNativeMenuItem[],
64
+ [itemsKey],
65
+ );
66
+
67
+ const handlers = parsed.handlers;
68
+ const select = useCallback(
69
+ (event: TMenuSelectEvent) => {
70
+ handlers[event.id]?.();
71
+ onSelect?.(event);
72
+ },
73
+ [handlers, onSelect],
74
+ );
75
+
76
+ const value: IMenuContext = {
77
+ handle,
78
+ native,
79
+ scheme,
80
+ items,
81
+ icons: parsed.icons,
82
+ content: {
83
+ width: contentProps?.width,
84
+ alignment: contentProps?.alignment,
85
+ fontFamily: contentProps?.fontFamily,
86
+ config: contentProps?.config,
87
+ },
88
+ select,
89
+ openChange: onOpenChange,
90
+ };
91
+
92
+ return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>;
93
+ };
94
+
95
+ const MenuRoot = registerComponent("Menu", MenuBase);
96
+
97
+ export { MenuRoot };
@@ -0,0 +1 @@
1
+ export { MenuActionRow } from "./menu-action-row";
@@ -0,0 +1,12 @@
1
+ import type { FC } from "react";
2
+ import type { IMenuActionRow } from "../../interface";
3
+ import { registerComponent } from "../../utils/register-component.util";
4
+
5
+ // Declarative only: parseMenuContent reads its items (the actions of the top row of the content).
6
+ const MenuActionRowBase: FC<IMenuActionRow> = (
7
+ _props: IMenuActionRow & React.ComponentProps<typeof MenuActionRowBase>,
8
+ ): React.ReactNode & React.JSX.Element => <></>;
9
+
10
+ const MenuActionRow = registerComponent("MenuActionRow", MenuActionRowBase);
11
+
12
+ export { MenuActionRow };
@@ -0,0 +1,2 @@
1
+ import { MenuContent } from "./menu-content";
2
+ export { MenuContent };