@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,148 @@
1
+ diff -ruN a/components/menu-trigger/interface.ts b/components/menu-trigger/interface.ts
2
+ --- a/components/menu-trigger/interface.ts
3
+ +++ b/components/menu-trigger/interface.ts
4
+ @@ -8,6 +8,7 @@
5
+ import type {
6
+ TMenuAlignment,
7
+ TMenuConfig,
8
+ + TMenuGroupMember,
9
+ TMenuScheme,
10
+ TMenuSelectEvent,
11
+ TMenuTriggerConfig,
12
+ @@ -18,7 +19,7 @@
13
+ items: TNativeMenuItem[];
14
+ onItemSelect?: (event: { nativeEvent: TMenuSelectEvent }) => void;
15
+ onMenuOpenChange?: (event: { nativeEvent: { open: boolean } }) => void;
16
+ - glass?: boolean;
17
+ + lens?: boolean;
18
+ morph?: boolean;
19
+ cornerRadius?: number;
20
+ colorScheme?: TMenuScheme;
21
+ @@ -27,6 +28,12 @@
22
+ alignment?: TMenuAlignment;
23
+ config?: TMenuConfig;
24
+ triggerConfig?: TMenuTriggerConfig;
25
+ + openWithItems?: boolean;
26
+ + restBackdrop?: string;
27
+ + openOnTap?: boolean;
28
+ + members?: readonly TMenuGroupMember[];
29
+ + blend?: number;
30
+ + onMenuClosed?: () => void;
31
+ style?: StyleProp<ViewStyle>;
32
+ children?: ReactNode;
33
+ }
34
+ diff -ruN a/components/menu-trigger/menu-trigger.android.tsx b/components/menu-trigger/menu-trigger.android.tsx
35
+ --- a/components/menu-trigger/menu-trigger.android.tsx
36
+ +++ b/components/menu-trigger/menu-trigger.android.tsx
37
+ @@ -8,11 +8,17 @@
38
+ import { NativeMenu } from "./native-menu.android";
39
+
40
+ const MenuTriggerBase: FC<IMenuTrigger> = ({
41
+ - glass,
42
+ + lens,
43
+ morph,
44
+ cornerRadius,
45
+ config,
46
+ openOnPress = true,
47
+ + openWithItems,
48
+ + onMenuClosed,
49
+ + restBackdrop,
50
+ + openOnTap,
51
+ + members,
52
+ + blend,
53
+ accessibilityLabel,
54
+ style,
55
+ children,
56
+ @@ -30,10 +36,16 @@
57
+ fontFamily={menu?.content.fontFamily}
58
+ alignment={menu?.content.alignment}
59
+ config={menu?.content.config}
60
+ - glass={glass}
61
+ + lens={lens}
62
+ morph={morph}
63
+ cornerRadius={cornerRadius}
64
+ triggerConfig={config}
65
+ + openWithItems={openWithItems}
66
+ + onMenuClosed={onMenuClosed}
67
+ + restBackdrop={restBackdrop}
68
+ + openOnTap={openOnTap}
69
+ + members={members}
70
+ + blend={blend}
71
+ style={style}
72
+ onItemSelect={(event: { nativeEvent: TMenuSelectEvent }): void =>
73
+ menu?.select(event.nativeEvent)
74
+ diff -ruN a/constants/menu.const.ts b/constants/menu.const.ts
75
+ --- a/constants/menu.const.ts
76
+ +++ b/constants/menu.const.ts
77
+ @@ -5,7 +5,7 @@
78
+ dark: { base: "rgba(255, 255, 255, 0.96)", destructive: "#FF5254" },
79
+ light: { base: "rgba(0, 0, 0, 0.92)", destructive: "#DC1E30" },
80
+ };
81
+ -const MENU_ICON_HOST_ID: string = "glass-menu-icons";
82
+ -const MENU_NATIVE_VIEW: string = "GlassMenuAndroid";
83
+ +const MENU_ICON_HOST_ID: string = "lens-icons";
84
+ +const MENU_NATIVE_VIEW: string = "BloomLensMenu";
85
+
86
+ export { MENU_ICON_COLORS, MENU_ICON_HOST_ID, MENU_NATIVE_VIEW };
87
+ diff -ruN a/interface.ts b/interface.ts
88
+ --- a/interface.ts
89
+ +++ b/interface.ts
90
+ @@ -56,6 +56,11 @@
91
+ morphBlur?: number;
92
+ tintColor?: string;
93
+ tintOpacity?: number;
94
+ + // Bloom: the rows' ink (the engine's patch); a missing colour keeps the engine's own.
95
+ + textColor?: string;
96
+ + mutedColor?: string;
97
+ + destructiveColor?: string;
98
+ + separatorColor?: string;
99
+ saturation?: number;
100
+ refraction?: number;
101
+ rim?: number;
102
+ @@ -111,14 +116,36 @@
103
+ children?: ReactNode;
104
+ }
105
+
106
+ +// Bloom: a glass of a group on one trigger. Views with one key are one shape around them all (a union).
107
+ +type TMenuGroupMember = {
108
+ + key: string;
109
+ + // The corner radius in points; unset is a capsule.
110
+ + cornerRadius?: number;
111
+ + // How it arrives and leaves: out of and into the nearest glass (default), or where it is.
112
+ + transition?: "matchedGeometry" | "materialize";
113
+ +};
114
+ +
115
+ interface IMenuTrigger {
116
+ - glass?: boolean;
117
+ - // Morph from the trigger when it has no glass (glass={false}): the panel grows out of the trigger's rectangle,
118
+ + lens?: boolean;
119
+ + // Morph from the trigger when it has no glass (lens={false}): the panel grows out of the trigger's rectangle,
120
+ // corner radius and tint, as with glass. Default true. Ignored with glass (a glass trigger always morphs).
121
+ morph?: boolean;
122
+ cornerRadius?: number;
123
+ config?: TMenuTriggerConfig;
124
+ openOnPress?: boolean;
125
+ + // Bloom: the rows arrive only as the menu opens; the view opens itself with them, again after they are emptied.
126
+ + openWithItems?: boolean;
127
+ + // Bloom: the menu has finished closing (its motion ended).
128
+ + onMenuClosed?: () => void;
129
+ + // Bloom: the colour the trigger sits on. Set, the trigger draws its glass at rest in its place in the view hierarchy
130
+ + // (a trigger in a scroll, under the bars) against that colour; the overlay draws it only while the menu is open.
131
+ + restBackdrop?: string;
132
+ + // Bloom: a tap on the trigger opens the menu natively, with no round trip to JS.
133
+ + openOnTap?: boolean;
134
+ + // Bloom: the trigger is a group of glasses: it draws each member's glass (found by the nativeID of its views), not its
135
+ + // own rect, and they blend within `blend` points.
136
+ + members?: readonly TMenuGroupMember[];
137
+ + blend?: number;
138
+ accessibilityLabel?: string;
139
+ style?: StyleProp<ViewStyle>;
140
+ children?: ReactNode;
141
+ @@ -189,6 +216,7 @@
142
+ type TMenuColorScheme,
143
+ type TMenuConfig,
144
+ type TMenuEntry,
145
+ + type TMenuGroupMember,
146
+ type TMenuIconName,
147
+ type TMenuItemIconState,
148
+ type TMenuMorphOrigin,
package/src/base.tsx ADDED
@@ -0,0 +1,208 @@
1
+ /**
2
+ * The lens base: the upstream app's glass trigger (`Menu` around `Menu.Trigger`), the one glass of
3
+ * Bloom's controls. A button, a group of buttons, a bar: each is one base, and a menu opened from
4
+ * anything inside it grows out of that whole base and goes back into it, as the upstream app's
5
+ * toolbar pill does. A press anywhere on the base springs it.
6
+ *
7
+ * The base is the upstream app's glass trigger with its trigger config (`absorb` over 0.48 s: the
8
+ * menu goes back into it as into the upstream app's toolbar pill); a caller's config adds to it.
9
+ *
10
+ * Menus inside a base give it their rows (`useLensBaseMenu`). The base holds the first menu's rows,
11
+ * so opening that menu is one call to the engine; another menu of the same base swaps its rows in
12
+ * and the view opens itself with them (`openWithItems`), as does a menu whose rows are built only
13
+ * by the press that opens it.
14
+ *
15
+ * A base can be a group of glasses (SwiftUI's `GlassEffectContainer`): given `members`, it draws
16
+ * each member's glass where that member's views are (the views whose `nativeID` is the member's
17
+ * key, several of them one shape around them all), not its own rect, and they blend within
18
+ * `blend` points. A member that arrives grows out of the nearest glass and one that leaves goes
19
+ * back into it; a key that moves to another view takes its glass there with it.
20
+ */
21
+ import {
22
+ createContext,
23
+ useContext,
24
+ useLayoutEffect,
25
+ useMemo,
26
+ useRef,
27
+ useState,
28
+ type ReactNode,
29
+ } from 'react';
30
+ import type { StyleProp, ViewStyle } from 'react-native';
31
+
32
+ import { Menu } from './menu';
33
+ import type { IMenuHandle, TMenuConfig, TMenuRect, TMenuTriggerConfig } from './menu';
34
+ import { lensRows, type LensRow } from './rows';
35
+
36
+ /** A menu as a base opens it. */
37
+ export interface LensMenu {
38
+ rows: readonly LensRow[];
39
+ /** The panel's material and the rows' ink. */
40
+ config?: TMenuConfig;
41
+ fontFamily?: string;
42
+ /** The menu opened or started closing. */
43
+ onOpenChange?: (open: boolean) => void;
44
+ /** The menu has finished closing. */
45
+ onClosed?: () => void;
46
+ }
47
+
48
+ /** A glass of a group on one base. */
49
+ export interface LensGroupMember {
50
+ /** The `nativeID` of the member's views; several views with one key are one shape (a union). */
51
+ key: string;
52
+ /** The corner radius in points; unset is a capsule. */
53
+ cornerRadius?: number;
54
+ /** How it arrives and leaves: out of and into the nearest glass (default), or where it is. */
55
+ transition?: 'matchedGeometry' | 'materialize';
56
+ }
57
+
58
+ /** What a menu inside a base calls. */
59
+ export interface LensMenuHandle {
60
+ /** Opens the menu from the base, out of `from` (a press point's box) when given. */
61
+ open: (from?: TMenuRect) => void;
62
+ close: () => void;
63
+ }
64
+
65
+ interface Held {
66
+ key: object;
67
+ menu: LensMenu;
68
+ }
69
+
70
+ interface BaseHandle {
71
+ hold: (key: object, menu: LensMenu) => void;
72
+ release: (key: object) => void;
73
+ open: (key: object, menu: LensMenu, from?: TMenuRect) => void;
74
+ close: () => void;
75
+ }
76
+
77
+ export const LensBaseContext = createContext<BaseHandle | null>(null);
78
+ LensBaseContext.displayName = 'BloomLensBase';
79
+
80
+ export interface LensBaseProps {
81
+ /** Draw the base's lens; without it, a menu still grows out of the base's shape. */
82
+ lens?: boolean;
83
+ colorScheme?: 'light' | 'dark';
84
+ /** The corner radius in points; `undefined` is a capsule. */
85
+ cornerRadius?: number;
86
+ config?: TMenuTriggerConfig;
87
+ /** The colour the base sits on: its lens is drawn in its place in the page (a base in a scroll). */
88
+ restBackdrop?: string;
89
+ /**
90
+ * The base is one menu's trigger: a tap opens the menu it holds natively, on the UI thread, with no
91
+ * round trip to JS. Not for a group, whose items open their own menus or do their own thing.
92
+ */
93
+ openOnTap?: boolean;
94
+ /** The base is a group of glasses: each member's glass, not the base's rect. */
95
+ members?: readonly LensGroupMember[];
96
+ /** The distance in points within which a group's glasses blend into one another. */
97
+ blend?: number;
98
+ style?: StyleProp<ViewStyle>;
99
+ children?: ReactNode;
100
+ }
101
+
102
+ export function LensBase({
103
+ lens = true,
104
+ colorScheme,
105
+ cornerRadius,
106
+ config,
107
+ restBackdrop,
108
+ openOnTap,
109
+ members,
110
+ blend,
111
+ style,
112
+ children,
113
+ }: LensBaseProps) {
114
+ const native = useRef<IMenuHandle | null>(null);
115
+ const [held, setHeld] = useState<Held | null>(null);
116
+ const [pending, setPending] = useState(false);
117
+ const current = useRef(held);
118
+ current.current = held;
119
+ const handle = useMemo<BaseHandle>(
120
+ () => ({
121
+ hold: (key, menu) =>
122
+ setHeld((last) =>
123
+ last === null || last.key === key ? (last?.menu === menu ? last : { key, menu }) : last,
124
+ ),
125
+ release: (key) => setHeld((last) => (last?.key === key ? null : last)),
126
+ open: (key, menu, from) => {
127
+ const last = current.current;
128
+ if (last?.key === key && last.menu === menu) {
129
+ native.current?.open(from);
130
+ return;
131
+ }
132
+ setHeld({ key, menu });
133
+ setPending(true);
134
+ },
135
+ close: () => native.current?.close(),
136
+ }),
137
+ [],
138
+ );
139
+ const menu = held?.menu;
140
+ const trigger = useMemo(() => ({ ...UPSTREAM_TRIGGER, ...config }), [config]);
141
+ return (
142
+ <Menu
143
+ ref={native}
144
+ colorScheme={colorScheme}
145
+ onOpenChange={(open) => {
146
+ if (open) setPending(false);
147
+ current.current?.menu.onOpenChange?.(open);
148
+ }}
149
+ >
150
+ <Menu.Trigger
151
+ lens={lens}
152
+ cornerRadius={cornerRadius}
153
+ config={trigger}
154
+ restBackdrop={restBackdrop}
155
+ openOnTap={openOnTap}
156
+ members={members}
157
+ blend={blend}
158
+ openOnPress={false}
159
+ openWithItems={pending}
160
+ onMenuClosed={() => current.current?.menu.onClosed?.()}
161
+ style={style}
162
+ >
163
+ <LensBaseContext.Provider value={handle}>{children}</LensBaseContext.Provider>
164
+ </Menu.Trigger>
165
+ <Menu.Content fontFamily={menu?.fontFamily} config={menu?.config}>
166
+ {menu ? lensRows(menu.rows) : null}
167
+ </Menu.Content>
168
+ </Menu>
169
+ );
170
+ }
171
+
172
+ /** The upstream app's glass trigger config: its toolbar pill takes the menu back over 0.48 s. */
173
+ const UPSTREAM_TRIGGER: TMenuTriggerConfig = { absorb: { duration: 0.48 } };
174
+
175
+ /** Whether a view is inside a base (it then draws no lens of its own). */
176
+ export function useInLensBase(): boolean {
177
+ return useContext(LensBaseContext) !== null;
178
+ }
179
+
180
+ /**
181
+ * A menu inside the nearest base: the base holds its rows (`null` while it has none, as a menu
182
+ * whose rows are built by its press) and opens it. `null` outside a base.
183
+ */
184
+ export function useLensBaseMenu(menu: LensMenu | null): LensMenuHandle | null {
185
+ const base = useContext(LensBaseContext);
186
+ const key = useRef({}).current;
187
+ const latest = useRef(menu);
188
+ latest.current = menu;
189
+ // A menu with no rows (one built only while open, now closed) lets the base go: no row work.
190
+ useLayoutEffect(() => {
191
+ if (!base) return;
192
+ if (menu) base.hold(key, menu);
193
+ else base.release(key);
194
+ }, [base, key, menu]);
195
+ useLayoutEffect(() => () => base?.release(key), [base, key]);
196
+ return useMemo(
197
+ () =>
198
+ base
199
+ ? {
200
+ open: (from) => {
201
+ if (latest.current) base.open(key, latest.current, from);
202
+ },
203
+ close: base.close,
204
+ }
205
+ : null,
206
+ [base, key],
207
+ );
208
+ }
@@ -0,0 +1,163 @@
1
+ // Platform-neutral geometry of the chrome compositor (docs/design-system-ios.md, section b).
2
+ // Pure functions only: no React, no Skia, no DOM. Tested with `node --experimental-strip-types`.
3
+ //
4
+ // Coordinates are window dp (the chrome container is the whole window). A shape is an axis-aligned
5
+ // rounded rectangle; a circle is a rectangle with radius = half its side.
6
+
7
+ export type TShape = {
8
+ id: string;
9
+ // Explicit group: shapes with the same group always share one canvas.
10
+ group: string;
11
+ x0: number;
12
+ y0: number;
13
+ x1: number;
14
+ y1: number;
15
+ radius: number;
16
+ };
17
+
18
+ // Radius of fusion (dp). Two shapes of different groups whose gap is <= this join one canvas.
19
+ export const MERGE_RADIUS = 12;
20
+
21
+ // Smooth-min blend width used by the shader (dp). Equal to MERGE_RADIUS so that a gap of 0 fuses fully
22
+ // and a gap above it does not bridge.
23
+ export const SMOOTH_BLEND = MERGE_RADIUS;
24
+
25
+ // Axis-aligned distance between two shapes (0 when they overlap or touch).
26
+ export const shapeGap = (a: TShape, b: TShape): number => {
27
+ const dx = Math.max(a.x0 - b.x1, b.x0 - a.x1, 0);
28
+ const dy = Math.max(a.y0 - b.y1, b.y0 - a.y1, 0);
29
+ return Math.hypot(dx, dy);
30
+ };
31
+
32
+ // Union-find grouping: shapes join when they share an explicit group, or when their gap is within
33
+ // `mergeRadius`. Returns the member indices of every component, in input order.
34
+ export const groupShapes = (shapes: readonly TShape[], mergeRadius: number = MERGE_RADIUS): number[][] => {
35
+ const parent = shapes.map((_, index): number => index);
36
+ const find = (index: number): number => {
37
+ let root = index;
38
+ while (parent[root] !== root) root = parent[root];
39
+ parent[index] = root;
40
+ return root;
41
+ };
42
+ const join = (a: number, b: number): void => {
43
+ const ra = find(a);
44
+ const rb = find(b);
45
+ if (ra !== rb) parent[Math.max(ra, rb)] = Math.min(ra, rb);
46
+ };
47
+ for (let i = 0; i < shapes.length; i++) {
48
+ for (let j = i + 1; j < shapes.length; j++) {
49
+ const sameGroup = shapes[i].group === shapes[j].group;
50
+ if (sameGroup || shapeGap(shapes[i], shapes[j]) <= mergeRadius) join(i, j);
51
+ }
52
+ }
53
+ const components = new Map<number, number[]>();
54
+ shapes.forEach((_, index): void => {
55
+ const root = find(index);
56
+ const list = components.get(root) ?? [];
57
+ list.push(index);
58
+ components.set(root, list);
59
+ });
60
+ return [...components.values()];
61
+ };
62
+
63
+ // Reference smooth-min (polynomial), the same formula as the shader. Used by the tests.
64
+ export const smoothMin = (a: number, b: number, k: number): number => {
65
+ if (k <= 0) return Math.min(a, b);
66
+ const h = Math.min(Math.max(0.5 + (0.5 * (b - a)) / k, 0), 1);
67
+ return b * (1 - h) + a * h - k * h * (1 - h);
68
+ };
69
+
70
+ // Signed distance to a rounded rectangle (negative inside). Reference for the tests.
71
+ export const sdRoundRect = (px: number, py: number, s: TShape): number => {
72
+ const cx = (s.x0 + s.x1) / 2;
73
+ const cy = (s.y0 + s.y1) / 2;
74
+ const hx = (s.x1 - s.x0) / 2 - s.radius;
75
+ const hy = (s.y1 - s.y0) / 2 - s.radius;
76
+ const qx = Math.abs(px - cx) - hx;
77
+ const qy = Math.abs(py - cy) - hy;
78
+ return Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - s.radius;
79
+ };
80
+
81
+ // ---------------------------------------------------------------------------------------------
82
+ // Tab bar layout (compact class). Lengths in dp.
83
+ // ---------------------------------------------------------------------------------------------
84
+
85
+ export const TAB_BAR = {
86
+ height: 64,
87
+ // Gap between the tab capsule and the search circle at rest.
88
+ restGap: 16,
89
+ // Compact width: window minus 2 * 16 margin, at most 360.
90
+ sideMargin: 16,
91
+ maxWidth: 360,
92
+ // Bottom offset from the window bottom (above the safe area).
93
+ bottom: 24,
94
+ // Create (FAB) circle, separate from the bar.
95
+ fabSize: 56,
96
+ fabGap: 16,
97
+ } as const;
98
+
99
+ export const tabBarWidth = (windowWidth: number): number =>
100
+ Math.min(windowWidth - 2 * TAB_BAR.sideMargin, TAB_BAR.maxWidth);
101
+
102
+ // Search morph progress p in [0, 1] (0 = rest, 1 = search open).
103
+ // capsule right edge grows by restGap, so the gap to the search circle goes to 0 (fusion);
104
+ // the FAB shrinks away with p.
105
+ export const tabBarShapes = (windowWidth: number, windowHeight: number, bottomInset: number, p: number): TShape[] => {
106
+ const width = tabBarWidth(windowWidth);
107
+ const left = (windowWidth - width) / 2;
108
+ const top = windowHeight - bottomInset - TAB_BAR.bottom - TAB_BAR.height;
109
+ const h = TAB_BAR.height;
110
+ const radius = h / 2;
111
+ const capsuleRight = left + (width - h - TAB_BAR.restGap) + TAB_BAR.restGap * p;
112
+ const circleLeft = left + width - h;
113
+ const fabScale = Math.max(0, 1 - p);
114
+ const fabRadius = (TAB_BAR.fabSize / 2) * fabScale;
115
+ const fabCx = left + width - TAB_BAR.fabSize / 2;
116
+ const fabCy = top - TAB_BAR.fabGap - TAB_BAR.fabSize / 2;
117
+ return [
118
+ { id: "tabs", group: "bar", x0: left, y0: top, x1: capsuleRight, y1: top + h, radius },
119
+ { id: "search", group: "bar", x0: circleLeft, y0: top, x1: left + width, y1: top + h, radius },
120
+ {
121
+ id: "fab",
122
+ group: "fab",
123
+ x0: fabCx - fabRadius,
124
+ y0: fabCy - fabRadius,
125
+ x1: fabCx + fabRadius,
126
+ y1: fabCy + fabRadius,
127
+ radius: fabRadius,
128
+ },
129
+ ];
130
+ };
131
+
132
+ // Bounding box of a set of shapes.
133
+ export const boundsOf = (shapes: readonly TShape[]): { x: number; y: number; width: number; height: number } => {
134
+ const x0 = Math.min(...shapes.map((s): number => s.x0));
135
+ const y0 = Math.min(...shapes.map((s): number => s.y0));
136
+ const x1 = Math.max(...shapes.map((s): number => s.x1));
137
+ const y1 = Math.max(...shapes.map((s): number => s.y1));
138
+ return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
139
+ };
140
+
141
+ // Max shapes per canvas: the shader has a fixed uniform array.
142
+ export const MAX_SHADER_SHAPES = 8;
143
+
144
+ // Packs the shapes of one canvas into the uniform layout of the shader, relative to the canvas origin.
145
+ // boxes: x0, y0, x1, y1 per shape. radii: radius per shape (4-float stride for std140-style alignment).
146
+ export const packShapes = (
147
+ shapes: readonly TShape[],
148
+ origin: { x: number; y: number },
149
+ ): { boxes: number[]; radii: number[]; count: number } => {
150
+ if (shapes.length > MAX_SHADER_SHAPES) {
151
+ throw new Error(`packShapes: ${shapes.length} shapes exceed ${MAX_SHADER_SHAPES}`);
152
+ }
153
+ const boxes = new Array<number>(MAX_SHADER_SHAPES * 4).fill(0);
154
+ const radii = new Array<number>(MAX_SHADER_SHAPES * 4).fill(0);
155
+ shapes.forEach((s, i): void => {
156
+ boxes[i * 4] = s.x0 - origin.x;
157
+ boxes[i * 4 + 1] = s.y0 - origin.y;
158
+ boxes[i * 4 + 2] = s.x1 - origin.x;
159
+ boxes[i * 4 + 3] = s.y1 - origin.y;
160
+ radii[i * 4] = s.radius;
161
+ });
162
+ return { boxes, radii, count: shapes.length };
163
+ };
@@ -0,0 +1,155 @@
1
+ // Headers in four variants, one component:
2
+ // large: a large title on the page, with circular glass actions at the top right (search, more)
3
+ // compact: a circular back button and a capsule with the title centred on it
4
+ // actions: compact, with two circular actions at the right (share, more)
5
+ // segmented: a glass capsule split in segments with the selection pill (refractive) over the chosen one
6
+ // The title text of "large" and the segmented caption sit on the page (outside the glass); the rest is glass nodes.
7
+ import { useState, type ReactElement } from "react";
8
+ import { StyleSheet, Text, View } from "react-native";
9
+
10
+ import { SurfaceNodes } from "./surface-nodes";
11
+ import { CHROME_METRICS, type TBox, type TNode } from "./surface-layer";
12
+
13
+ const CIRCLE = CHROME_METRICS.circle;
14
+ const BAR = CHROME_METRICS.bar;
15
+ const GAP = CHROME_METRICS.gap;
16
+ const MARGIN = CHROME_METRICS.margin;
17
+ const SEGMENT_HEIGHT = 44;
18
+ const SEGMENT_INSET = 4;
19
+ const INACTIVE = "#A1A1A6";
20
+
21
+ export type THeaderVariant = "large" | "compact" | "actions" | "segmented";
22
+
23
+ export type TGlassHeaderProps = {
24
+ variant: THeaderVariant;
25
+ box: TBox;
26
+ title: string;
27
+ // segmented only
28
+ segments?: readonly string[];
29
+ // Controlled segment index; when omitted the header keeps its own.
30
+ segment?: number;
31
+ onSegment?: (index: number) => void;
32
+ onBack?: () => void;
33
+ onAction?: (id: string) => void;
34
+ };
35
+
36
+ // Top row of the glass (the circles and the capsule centre on it). `box` already starts below the status bar.
37
+ const rowTop = (box: TBox): number => box.y + 8;
38
+
39
+ // Nodes of one variant.
40
+ export const headerNodes = (
41
+ variant: THeaderVariant,
42
+ box: TBox,
43
+ title: string,
44
+ segments: readonly string[],
45
+ segment: number,
46
+ ): TNode[] => {
47
+ const top = rowTop(box);
48
+ const left = box.x + MARGIN;
49
+ const right = box.x + box.width - MARGIN;
50
+ const capsuleY = top + (CIRCLE - BAR) / 2;
51
+
52
+ if (variant === "large") {
53
+ const more = { id: "more", kind: "glass" as const, x: right - CIRCLE - GAP - CIRCLE, y: top, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "ellipsis-horizontal", textSize: 24 };
54
+ const search = { id: "search", kind: "glass" as const, x: right - CIRCLE, y: top, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "search", textSize: 24 };
55
+ return [more, search];
56
+ }
57
+
58
+ if (variant === "segmented") {
59
+ // The caption (outside the glass) sits in the first 22 dp of the row; the capsule below it.
60
+ const y = top + 28;
61
+ const x = left;
62
+ const w = right - left;
63
+ const segW = w / segments.length;
64
+ const nodes: TNode[] = [{ id: "capsule", kind: "glass", x, y, w, h: SEGMENT_HEIGHT, r: SEGMENT_HEIGHT / 2 }];
65
+ nodes.push({
66
+ id: "selection",
67
+ kind: "selection",
68
+ x: x + SEGMENT_INSET + segment * segW,
69
+ y: y + SEGMENT_INSET,
70
+ w: segW - 2 * SEGMENT_INSET,
71
+ h: SEGMENT_HEIGHT - 2 * SEGMENT_INSET,
72
+ r: (SEGMENT_HEIGHT - 2 * SEGMENT_INSET) / 2,
73
+ pressable: false,
74
+ });
75
+ segments.forEach((label, index): void => {
76
+ nodes.push({
77
+ id: `segment-${index}`,
78
+ kind: "label",
79
+ x: x + index * segW,
80
+ y,
81
+ w: segW,
82
+ h: SEGMENT_HEIGHT,
83
+ r: 0,
84
+ text: label,
85
+ textSize: 15,
86
+ color: index === segment ? "#FFFFFF" : INACTIVE,
87
+ });
88
+ });
89
+ return nodes;
90
+ }
91
+
92
+ // compact and actions: the back circle at the left, the capsule with the title, and (actions) the two circles at the right.
93
+ const nodes: TNode[] = [{ id: "back", kind: "glass", x: left, y: top, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "chevron-back", textSize: 24 }];
94
+ const actionsWidth = variant === "actions" ? 2 * CIRCLE + GAP : 0;
95
+ const capsuleLeft = left + CIRCLE + GAP;
96
+ const capsuleRight = right - actionsWidth - (variant === "actions" ? GAP : 0);
97
+ nodes.push({ id: "capsule", kind: "glass", x: capsuleLeft, y: capsuleY, w: capsuleRight - capsuleLeft, h: BAR, r: BAR / 2, text: title, textSize: 17 });
98
+ if (variant === "actions") {
99
+ nodes.push({ id: "share", kind: "glass", x: right - 2 * CIRCLE - GAP, y: top, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "share-outline", textSize: 22 });
100
+ nodes.push({ id: "more", kind: "glass", x: right - CIRCLE, y: top, w: CIRCLE, h: CIRCLE, r: CIRCLE / 2, icon: "ellipsis-horizontal", textSize: 24 });
101
+ }
102
+ return nodes;
103
+ };
104
+
105
+ const GlassHeader = ({
106
+ variant,
107
+ box,
108
+ title,
109
+ segments = [],
110
+ segment,
111
+ onSegment,
112
+ onBack,
113
+ onAction,
114
+ }: TGlassHeaderProps): ReactElement => {
115
+ const [ownSegment, setOwnSegment] = useState(0);
116
+ const current = segment ?? ownSegment;
117
+ const top = rowTop(box);
118
+
119
+ const nodes = headerNodes(variant, box, title, segments, current);
120
+
121
+ return (
122
+ <>
123
+ {variant === "large" ? (
124
+ <View pointerEvents="none" style={[styles.large, { top: top + CIRCLE + 12, left: box.x + MARGIN, right: MARGIN }]}>
125
+ <Text style={styles.largeTitle}>{title}</Text>
126
+ </View>
127
+ ) : null}
128
+ {variant === "segmented" ? (
129
+ <View pointerEvents="none" style={[styles.caption, { top, left: box.x + MARGIN }]}>
130
+ <Text style={styles.captionText}>{title}</Text>
131
+ </View>
132
+ ) : null}
133
+ <SurfaceNodes
134
+ nodes={nodes}
135
+ onNodePress={(id): void => {
136
+ if (id === "back") onBack?.();
137
+ else if (id.startsWith("segment-")) {
138
+ const index = Number(id.slice("segment-".length));
139
+ if (segment === undefined) setOwnSegment(index);
140
+ onSegment?.(index);
141
+ } else onAction?.(id);
142
+ }}
143
+ />
144
+ </>
145
+ );
146
+ };
147
+
148
+ const styles = StyleSheet.create({
149
+ large: { position: "absolute" },
150
+ largeTitle: { color: "#FFFFFF", fontSize: 34, fontWeight: "700" },
151
+ caption: { position: "absolute" },
152
+ captionText: { color: INACTIVE, fontSize: 13, fontWeight: "600", textTransform: "uppercase" },
153
+ });
154
+
155
+ export { GlassHeader };