@luckylca/react-native-liquid-glass 0.2.0 → 0.3.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 (228) hide show
  1. package/README.md +20 -33
  2. package/README.zh-CN.md +20 -33
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/android/build.gradle +4 -4
  5. package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/EffectiveScrollInputBridge.kt +2 -2
  6. package/android/src/main/java/expo/modules/{newhuliquidglass/ExpoGlassProviderCoreView.kt → liquidglass/GlassCaptureView.kt} +39 -39
  7. package/android/src/main/java/expo/modules/{newhuliquidglass/CoreLiquidGlassRegistry.kt → liquidglass/GlassRegistry.kt} +7 -7
  8. package/android/src/main/java/expo/modules/{newhuliquidglass/ExpoGlassSurfaceCoreView.kt → liquidglass/GlassSurfaceView.kt} +17 -17
  9. package/android/src/main/java/expo/modules/liquidglass/LiquidGlassModule.kt +205 -0
  10. package/android/src/main/java/expo/modules/{localglass/ExpoLocalGlassEngineModule.kt → liquidglass/LocalMaterialView.kt} +24 -27
  11. package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/PassSurfaceSuppression.kt +1 -1
  12. package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/SharedGlassPassProbeLog.kt +1 -1
  13. package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/SharedGlassPassWiring.kt +3 -3
  14. package/android-core/build.gradle +1 -1
  15. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/BackdropRecorder.kt +4 -4
  16. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/FrozenBackdrop.kt +1 -1
  17. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassBackdropCoordinator.kt +5 -5
  18. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassBackdropSourceHandle.kt +1 -1
  19. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassScrollSource.kt +1 -1
  20. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassViewController.kt +119 -722
  21. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/LiquidGlassProviderLayout.kt +2 -2
  22. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/LiquidGlassView.kt +2 -2
  23. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/ReferenceSourceWindowPolicy.kt +1 -1
  24. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/StableSceneTexturePolicy.kt +1 -1
  25. package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceFrameBuilder.kt +278 -0
  26. package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceInteraction.kt +359 -0
  27. package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/GlassFrame.kt +110 -0
  28. package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/GlassViewRenderer.kt +728 -0
  29. package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/ReferenceParityPasses.kt +705 -0
  30. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/internal/ReferenceTabSampling.kt +1 -1
  31. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/internal/SharedSceneCapture.kt +1 -1
  32. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassCapabilities.kt +1 -1
  33. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassEngine.kt +7 -7
  34. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassMaterial.kt +1 -1
  35. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassMath.kt +1 -1
  36. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassOpticalInsets.kt +1 -1
  37. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassRenderTier.kt +1 -1
  38. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassShapePacker.kt +1 -1
  39. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassSurfaceState.kt +1 -1
  40. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassUniforms.kt +1 -1
  41. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/LiquidGlassShaders.kt +1 -1
  42. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/SharedGlassPass.kt +6 -6
  43. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/geometry/G2RoundedRectangle.kt +2 -2
  44. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/geometry/ReferenceG2MaskTexture.kt +1 -1
  45. package/android-core/src/main/java/io/github/luckylca/liquidglass/core/shader/HeightFieldGlassShader.kt +7 -0
  46. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceBackdropBlurShader.kt +1 -1
  47. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceGaussianDiscBackdropBlur.kt +1 -1
  48. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceGlassUniforms.kt +4 -4
  49. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceParityGlassShader.kt +1 -1
  50. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceParityMultiShapeShader.kt +1 -1
  51. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/SdfScaleLensShader.kt +1 -1
  52. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassHardwareLayerExperiment.kt +1 -1
  53. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassMaterial.kt +1 -1
  54. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassRenderer.kt +2 -2
  55. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassRuntimeShader.kt +2 -2
  56. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassShader.kt +1 -1
  57. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassView.kt +2 -2
  58. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/GlassMotionDriver.kt +1 -1
  59. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/GlassMotionState.kt +1 -1
  60. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/PointerVelocityTracker.kt +1 -1
  61. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/SpringSpec.kt +1 -1
  62. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/G2Corner.kt +1 -1
  63. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassMaterial.kt +3 -3
  64. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassOpticsShader.kt +3 -3
  65. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassParityProbe.kt +1 -1
  66. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassShapeGeometry.kt +1 -1
  67. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassUniformBinder.kt +2 -2
  68. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/PixelDiff.kt +1 -1
  69. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/ReferenceOptics.kt +1 -1
  70. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/GlassSurfaceHost.kt +17 -17
  71. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/GlassSurfaceRenderer.kt +9 -9
  72. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/RetainedBackdropLayer.kt +1 -1
  73. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/scheduler/GlassFrameScheduler.kt +2 -2
  74. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/EffectiveScrollFpsProbe.kt +13 -13
  75. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/GlassTelemetry.kt +1 -1
  76. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LiquidGlassPerfTelemetry.kt +13 -13
  77. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LiquidGlassTrace.kt +3 -3
  78. package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LocalGlassTelemetry.kt +1 -1
  79. package/docs/architecture.md +61 -0
  80. package/docs/migration-0.3.md +19 -0
  81. package/docs/publishing.md +29 -7
  82. package/expo-module.config.json +4 -4
  83. package/lib/commonjs/GlassSurface.js +157 -585
  84. package/lib/commonjs/GlassSurface.js.map +1 -1
  85. package/lib/commonjs/GlassTabBar.js +18 -957
  86. package/lib/commonjs/GlassTabBar.js.map +1 -1
  87. package/lib/commonjs/LocalGlassMaterial.js +3 -9
  88. package/lib/commonjs/LocalGlassMaterial.js.map +1 -1
  89. package/lib/commonjs/glassController.js +3 -7
  90. package/lib/commonjs/glassController.js.map +1 -1
  91. package/lib/commonjs/glassRuntime.js +7 -19
  92. package/lib/commonjs/glassRuntime.js.map +1 -1
  93. package/lib/commonjs/localGlassTelemetry.js +4 -13
  94. package/lib/commonjs/localGlassTelemetry.js.map +1 -1
  95. package/lib/commonjs/nativeGlassViews.js +8 -11
  96. package/lib/commonjs/nativeGlassViews.js.map +1 -1
  97. package/lib/commonjs/performanceTelemetry.js +2 -6
  98. package/lib/commonjs/performanceTelemetry.js.map +1 -1
  99. package/lib/commonjs/surface/InlineSurface.js +134 -0
  100. package/lib/commonjs/surface/InlineSurface.js.map +1 -0
  101. package/lib/commonjs/surface/MaterialProvider.js +78 -0
  102. package/lib/commonjs/surface/MaterialProvider.js.map +1 -0
  103. package/lib/commonjs/surface/NativeSurface.js +55 -0
  104. package/lib/commonjs/surface/NativeSurface.js.map +1 -0
  105. package/lib/commonjs/surface/PortalLayers.js +331 -0
  106. package/lib/commonjs/surface/PortalLayers.js.map +1 -0
  107. package/lib/commonjs/surface/contexts.js +108 -0
  108. package/lib/commonjs/surface/contexts.js.map +1 -0
  109. package/lib/commonjs/surface/registry.js +113 -0
  110. package/lib/commonjs/surface/registry.js.map +1 -0
  111. package/lib/commonjs/surface/styles.js +34 -0
  112. package/lib/commonjs/surface/styles.js.map +1 -0
  113. package/lib/commonjs/surface/types.js +3 -0
  114. package/lib/commonjs/surface/types.js.map +1 -0
  115. package/lib/commonjs/tabs/GlassTabItem.js +66 -0
  116. package/lib/commonjs/tabs/GlassTabItem.js.map +1 -0
  117. package/lib/commonjs/tabs/InlineTabBar.js +867 -0
  118. package/lib/commonjs/tabs/InlineTabBar.js.map +1 -0
  119. package/lib/commonjs/tabs/tabConstants.js +22 -0
  120. package/lib/commonjs/tabs/tabConstants.js.map +1 -0
  121. package/lib/commonjs/tabs/tabDebug.js +50 -0
  122. package/lib/commonjs/tabs/tabDebug.js.map +1 -0
  123. package/lib/commonjs/tabs/tabStyles.js +107 -0
  124. package/lib/commonjs/tabs/tabStyles.js.map +1 -0
  125. package/lib/commonjs/tabs/useInlineTabGesture.js +227 -0
  126. package/lib/commonjs/tabs/useInlineTabGesture.js.map +1 -0
  127. package/lib/commonjs/theme/buildTheme.js +1 -1
  128. package/lib/commonjs/theme/buildTheme.js.map +1 -1
  129. package/lib/module/GlassSurface.js +135 -563
  130. package/lib/module/GlassSurface.js.map +1 -1
  131. package/lib/module/GlassTabBar.js +18 -925
  132. package/lib/module/GlassTabBar.js.map +1 -1
  133. package/lib/module/LocalGlassMaterial.js +5 -11
  134. package/lib/module/LocalGlassMaterial.js.map +1 -1
  135. package/lib/module/glassController.js +3 -7
  136. package/lib/module/glassController.js.map +1 -1
  137. package/lib/module/glassRuntime.js +7 -19
  138. package/lib/module/glassRuntime.js.map +1 -1
  139. package/lib/module/localGlassTelemetry.js +4 -13
  140. package/lib/module/localGlassTelemetry.js.map +1 -1
  141. package/lib/module/nativeGlassViews.js +7 -10
  142. package/lib/module/nativeGlassViews.js.map +1 -1
  143. package/lib/module/performanceTelemetry.js +2 -6
  144. package/lib/module/performanceTelemetry.js.map +1 -1
  145. package/lib/module/surface/InlineSurface.js +97 -0
  146. package/lib/module/surface/InlineSurface.js.map +1 -0
  147. package/lib/module/surface/MaterialProvider.js +74 -0
  148. package/lib/module/surface/MaterialProvider.js.map +1 -0
  149. package/lib/module/surface/NativeSurface.js +47 -0
  150. package/lib/module/surface/NativeSurface.js.map +1 -0
  151. package/lib/module/surface/PortalLayers.js +292 -0
  152. package/lib/module/surface/PortalLayers.js.map +1 -0
  153. package/lib/module/surface/contexts.js +96 -0
  154. package/lib/module/surface/contexts.js.map +1 -0
  155. package/lib/module/surface/registry.js +103 -0
  156. package/lib/module/surface/registry.js.map +1 -0
  157. package/lib/module/surface/styles.js +31 -0
  158. package/lib/module/surface/styles.js.map +1 -0
  159. package/lib/module/surface/types.js +2 -0
  160. package/lib/module/surface/types.js.map +1 -0
  161. package/lib/module/tabs/GlassTabItem.js +30 -0
  162. package/lib/module/tabs/GlassTabItem.js.map +1 -0
  163. package/lib/module/tabs/InlineTabBar.js +829 -0
  164. package/lib/module/tabs/InlineTabBar.js.map +1 -0
  165. package/lib/module/tabs/tabConstants.js +19 -0
  166. package/lib/module/tabs/tabConstants.js.map +1 -0
  167. package/lib/module/tabs/tabDebug.js +13 -0
  168. package/lib/module/tabs/tabDebug.js.map +1 -0
  169. package/lib/module/tabs/tabStyles.js +104 -0
  170. package/lib/module/tabs/tabStyles.js.map +1 -0
  171. package/lib/module/tabs/useInlineTabGesture.js +221 -0
  172. package/lib/module/tabs/useInlineTabGesture.js.map +1 -0
  173. package/lib/module/theme/buildTheme.js +1 -1
  174. package/lib/module/theme/buildTheme.js.map +1 -1
  175. package/lib/types/GlassSurface.d.ts +17 -86
  176. package/lib/types/GlassTabBar.d.ts +1 -0
  177. package/lib/types/glassNativeEngine.d.ts +1 -1
  178. package/lib/types/glassRuntime.d.ts +5 -2
  179. package/lib/types/localGlassTelemetry.d.ts +2 -2
  180. package/lib/types/nativeGlassViews.d.ts +2 -4
  181. package/lib/types/surface/InlineSurface.d.ts +42 -0
  182. package/lib/types/surface/MaterialProvider.d.ts +46 -0
  183. package/lib/types/surface/NativeSurface.d.ts +11 -0
  184. package/lib/types/surface/PortalLayers.d.ts +33 -0
  185. package/lib/types/surface/contexts.d.ts +66 -0
  186. package/lib/types/surface/registry.d.ts +6 -0
  187. package/lib/types/surface/styles.d.ts +74 -0
  188. package/lib/types/surface/types.d.ts +118 -0
  189. package/lib/types/tabs/GlassTabItem.d.ts +20 -0
  190. package/lib/types/tabs/InlineTabBar.d.ts +5 -0
  191. package/lib/types/tabs/tabConstants.d.ts +34 -0
  192. package/lib/types/tabs/tabDebug.d.ts +15 -0
  193. package/lib/types/tabs/tabStyles.d.ts +119 -0
  194. package/lib/types/tabs/useInlineTabGesture.d.ts +34 -0
  195. package/package.json +6 -14
  196. package/src/GlassSurface.tsx +227 -1337
  197. package/src/GlassTabBar.tsx +43 -1241
  198. package/src/LocalGlassMaterial.tsx +5 -11
  199. package/src/glassController.ts +3 -7
  200. package/src/glassRuntime.ts +9 -26
  201. package/src/localGlassTelemetry.ts +6 -15
  202. package/src/nativeGlassViews.ts +7 -10
  203. package/src/performanceTelemetry.ts +2 -6
  204. package/src/surface/InlineSurface.tsx +299 -0
  205. package/src/surface/MaterialProvider.tsx +235 -0
  206. package/src/surface/NativeSurface.tsx +115 -0
  207. package/src/surface/PortalLayers.tsx +574 -0
  208. package/src/surface/contexts.tsx +188 -0
  209. package/src/surface/registry.ts +109 -0
  210. package/src/surface/styles.ts +31 -0
  211. package/src/surface/types.ts +139 -0
  212. package/src/tabs/GlassTabItem.tsx +100 -0
  213. package/src/tabs/InlineTabBar.tsx +1193 -0
  214. package/src/tabs/tabConstants.ts +35 -0
  215. package/src/tabs/tabDebug.ts +29 -0
  216. package/src/tabs/tabStyles.ts +104 -0
  217. package/src/tabs/useInlineTabGesture.ts +306 -0
  218. package/src/theme/buildTheme.ts +1 -1
  219. package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassModule.kt +0 -341
  220. package/android/src/main/java/expo/modules/localglass/LocalGlassShader.kt +0 -59
  221. package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassCoreModule.kt +0 -226
  222. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/GlassViewRenderer.kt +0 -1459
  223. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/HeightFieldGlassShader.kt +0 -7
  224. package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassEngineSelection.kt +0 -30
  225. package/patches/liquid-glass-kit+1.0.0.patch +0 -2015
  226. package/patches/liquid-glass-kit-invalidation-coalescing.diff +0 -249
  227. package/patches/liquid-glass-kit-native-infra.diff +0 -624
  228. package/scripts/apply-legacy-patches.mjs +0 -116
@@ -0,0 +1,188 @@
1
+ import React, { createContext, useContext, useId, useMemo } from 'react';
2
+ import { Platform } from 'react-native';
3
+ import type { StyleProp, ViewStyle } from 'react-native';
4
+ import type { SharedValue } from 'react-native-reanimated';
5
+ import type { GlassCaptureSourceProps } from '../nativeGlassViews';
6
+ import type {
7
+ GlassRuntime,
8
+ GlassSamplingSource,
9
+ GlassHostContextValue,
10
+ GlassOverlayHostContextValue,
11
+ } from './types';
12
+ import { GlassCaptureSourceView } from './NativeSurface';
13
+ import { GlassSurfacePortalLayer } from './PortalLayers';
14
+ import { styles } from './styles';
15
+
16
+ export const GlassRuntimeContext = createContext<GlassRuntime | null>(null);
17
+
18
+ export const GlassCaptureSourceContext = createContext<string | null>(null);
19
+
20
+ export const GlassRouteTransitionContext = createContext<SharedValue<number> | null>(null);
21
+
22
+ export const GlassPortalScrollContext = createContext<{
23
+ offsets: readonly SharedValue<number>[];
24
+ layoutRevision: number;
25
+ groupKey: string;
26
+ }>({ offsets: [], layoutRevision: 0, groupKey: '' });
27
+
28
+ export const GlassMeasureOnlyContext = createContext<boolean>(false);
29
+
30
+ /** Keeps backdrop surfaces aligned with content inside a scroll container. */
31
+ export function GlassPortalScrollScope({
32
+ scrollOffset,
33
+ layoutRevision = 0,
34
+ children,
35
+ }: {
36
+ scrollOffset: SharedValue<number>;
37
+ /** Increment after content reflow so surfaces can refresh their window frames. */
38
+ layoutRevision?: number;
39
+ children: React.ReactNode;
40
+ }) {
41
+ const scopeId = useId();
42
+ const parent = useContext(GlassPortalScrollContext);
43
+ const value = useMemo(
44
+ () => ({
45
+ offsets: [...parent.offsets, scrollOffset],
46
+ layoutRevision: parent.layoutRevision + layoutRevision,
47
+ groupKey: parent.groupKey ? `${parent.groupKey}|${scopeId}` : scopeId,
48
+ }),
49
+ [layoutRevision, parent, scopeId, scrollOffset],
50
+ );
51
+ return <GlassPortalScrollContext.Provider value={value}>{children}</GlassPortalScrollContext.Provider>;
52
+ }
53
+
54
+ /**
55
+ * Shares a route's horizontal transition with portaled glass surfaces.
56
+ * Backdrop surfaces live in a host-level overlay, so an ancestor transform is
57
+ * not inherited automatically. This scope keeps their window frames and the
58
+ * visible React Native content on the same animation value.
59
+ */
60
+ export function GlassRouteTransitionScope({
61
+ translateX,
62
+ children,
63
+ }: {
64
+ translateX: SharedValue<number>;
65
+ children: React.ReactNode;
66
+ }) {
67
+ return (
68
+ <GlassRouteTransitionContext.Provider value={translateX}>
69
+ {children}
70
+ </GlassRouteTransitionContext.Provider>
71
+ );
72
+ }
73
+
74
+ export function useGlassReducedMotion() {
75
+ return useContext(GlassRuntimeContext)?.reducedMotion ?? false;
76
+ }
77
+
78
+ export function useGlassInsideScroll() {
79
+ return useContext(GlassPortalScrollContext).offsets.length > 0;
80
+ }
81
+
82
+ export function useGlassInsideCaptureScope() {
83
+ return useContext(GlassCaptureSourceContext) !== null;
84
+ }
85
+
86
+ export function useGlassAppearance() {
87
+ return useContext(GlassRuntimeContext);
88
+ }
89
+
90
+ /** Resolve the provider that represents the visible scene for a glass consumer. */
91
+ export function useGlassSamplingProviderId(source: GlassSamplingSource = 'routeScene') {
92
+ const host = useContext(GlassHostContext);
93
+ const captureSourceProviderId = useContext(GlassCaptureSourceContext);
94
+ if (!host) return null;
95
+ return source === 'themeBackdrop'
96
+ ? host.themeBackdropProviderId
97
+ : (captureSourceProviderId ?? host.routeSceneProviderId ?? host.themeBackdropProviderId);
98
+ }
99
+
100
+ export const GlassHostContext = createContext<GlassHostContextValue | null>(null);
101
+
102
+ export function RouteGlassCaptureScope({
103
+ children,
104
+ active = true,
105
+ scopeId = 'page-content',
106
+ }: {
107
+ children: React.ReactNode;
108
+ active?: boolean;
109
+ scopeId?: string;
110
+ }) {
111
+ const host = useContext(GlassHostContext);
112
+ const parentActive = useContext(GlassScopeActiveContext);
113
+ const parentProviderId = useContext(GlassCaptureSourceContext);
114
+ const baseId = parentProviderId ?? host?.providerId ?? null;
115
+ const providerId = baseId ? `${baseId}:${scopeId}` : null;
116
+ return (
117
+ <GlassScopeActiveContext.Provider value={active && parentActive}>
118
+ <GlassCaptureSourceContext.Provider value={providerId}>
119
+ {children}
120
+ </GlassCaptureSourceContext.Provider>
121
+ </GlassScopeActiveContext.Provider>
122
+ );
123
+ }
124
+
125
+ export function RouteGlassCaptureSource({
126
+ children,
127
+ captureMode,
128
+ captureOnly = false,
129
+ sourceRevision,
130
+ underlayProviderId,
131
+ style,
132
+ }: {
133
+ children: React.ReactNode;
134
+ captureMode?: 'live' | 'oneShotPassThrough' | 'livePassThrough' | 'oneShot' | 'static';
135
+ /** A private pass-through scene used only by other glass consumers. */
136
+ captureOnly?: boolean;
137
+ sourceRevision?: string;
138
+ underlayProviderId?: string | null;
139
+ style?: StyleProp<ViewStyle>;
140
+ }) {
141
+ const host = useContext(GlassHostContext);
142
+ const runtime = useContext(GlassRuntimeContext);
143
+ const scopedProviderId = useContext(GlassCaptureSourceContext);
144
+ const scopeActive = useContext(GlassScopeActiveContext);
145
+ const inactiveId = useId();
146
+ // Pager siblings share a route-scene alias. A hidden page must retain its
147
+ // native tree without replacing the visible page in the provider registry.
148
+ const providerId =
149
+ !scopeActive && scopedProviderId ? `${scopedProviderId}:inactive:${inactiveId}` : scopedProviderId;
150
+ if (!host || !providerId || !runtime?.tokens.enabled) return <>{children}</>;
151
+ const resolvedCaptureMode = !scopeActive
152
+ ? 'frozen'
153
+ : (captureMode ?? (Platform.OS === 'android' ? 'oneShotPassThrough' : 'live'));
154
+ const resolvedUnderlay =
155
+ underlayProviderId === null
156
+ ? undefined
157
+ : (underlayProviderId ?? host.routeSceneProviderId ?? host.themeBackdropProviderId);
158
+ return (
159
+ <GlassCaptureSourceView
160
+ providerId={providerId}
161
+ underlayProviderId={resolvedUnderlay}
162
+ captureMode={resolvedCaptureMode as GlassCaptureSourceProps['captureMode']}
163
+ captureOnly={captureOnly}
164
+ sourceRevision={sourceRevision}
165
+ pointerEvents="box-none"
166
+ style={[styles.captureSource, style]}
167
+ >
168
+ {children}
169
+ </GlassCaptureSourceView>
170
+ );
171
+ }
172
+
173
+ export const GlassOverlayHostContext = createContext<GlassOverlayHostContextValue | null>(null);
174
+
175
+ /**
176
+ * Page-level scope for glass surfaces.
177
+ *
178
+ * Every page under a PagerView shares one provider id (`host.providerId +
179
+ * ':page-content'`) and one registry, and GlassSurfacePortalLayer draws every
180
+ * registered entry in a provider-level layer above page content. So a kept-alive
181
+ * page's surfaces paint on top of whichever page is actually visible: on Home
182
+ * that showed up as an empty 344x55dp panel under the search bar, which turned
183
+ * out to be the User page's segmented control.
184
+ *
185
+ * A surface whose scope is inactive stops publishing. Layout is untouched; only
186
+ * the registry entry goes away, so nothing is drawn for it.
187
+ */
188
+ export const GlassScopeActiveContext = createContext<boolean>(true);
@@ -0,0 +1,109 @@
1
+ import React, { useSyncExternalStore } from 'react';
2
+ import type { SurfaceEntry, OverlayEntry, EntryRegistry } from './types';
3
+
4
+ export function createEntryRegistry<Entry>(): EntryRegistry<Entry> {
5
+ const entries = new Map<string, Entry>();
6
+ const listeners = new Set<() => void>();
7
+ let snapshot: [string, Entry][] = [];
8
+ const publish = () => {
9
+ snapshot = Array.from(entries.entries());
10
+ for (const listener of listeners) listener();
11
+ };
12
+ return {
13
+ getSnapshot: () => snapshot,
14
+ subscribe: (listener) => {
15
+ listeners.add(listener);
16
+ return () => listeners.delete(listener);
17
+ },
18
+ update: (id, entry, equals) => {
19
+ const previous = entries.get(id);
20
+ if (previous !== undefined && equals(previous, entry)) return;
21
+ entries.set(id, entry);
22
+ publish();
23
+ },
24
+ remove: (id) => {
25
+ if (!entries.delete(id)) return;
26
+ publish();
27
+ },
28
+ };
29
+ }
30
+
31
+ export function useRegistrySnapshot<Entry>(registry: EntryRegistry<Entry>) {
32
+ return React.useSyncExternalStore(registry.subscribe, registry.getSnapshot, registry.getSnapshot);
33
+ }
34
+
35
+ export function sameSurface(previous: SurfaceEntry, next: SurfaceEntry) {
36
+ return (
37
+ previous.frame.x === next.frame.x &&
38
+ previous.frame.y === next.frame.y &&
39
+ previous.frame.width === next.frame.width &&
40
+ previous.frame.height === next.frame.height &&
41
+ previous.positioning === next.positioning &&
42
+ previous.samplingSource === next.samplingSource &&
43
+ previous.samplingProviderId === next.samplingProviderId &&
44
+ previous.tintColor === next.tintColor &&
45
+ previous.portalContent === next.portalContent &&
46
+ previous.contentAboveGlass === next.contentAboveGlass &&
47
+ previous.content === next.content &&
48
+ previous.contentStyle === next.contentStyle &&
49
+ previous.variant === next.variant &&
50
+ previous.interactive === next.interactive &&
51
+ previous.continuous === next.continuous &&
52
+ previous.sharedSource === next.sharedSource &&
53
+ previous.captureProbe === next.captureProbe &&
54
+ previous.opticalProgress === next.opticalProgress &&
55
+ previous.scrollGroupKey === next.scrollGroupKey &&
56
+ previous.scrollOffsets === next.scrollOffsets &&
57
+ previous.routeTransitionX === next.routeTransitionX &&
58
+ previous.portalOffsetStyle === next.portalOffsetStyle &&
59
+ previous.portalTranslateX === next.portalTranslateX &&
60
+ previous.portalTranslateY === next.portalTranslateY &&
61
+ previous.portalScaleX === next.portalScaleX &&
62
+ previous.portalScaleY === next.portalScaleY &&
63
+ previous.pointerEvent === next.pointerEvent &&
64
+ previous.pointerEventValue === next.pointerEventValue &&
65
+ previous.pointerEventSink === next.pointerEventSink &&
66
+ previous.valueEvent === next.valueEvent &&
67
+ previous.valueEventSink === next.valueEventSink &&
68
+ previous.opticalToggleFraction === next.opticalToggleFraction &&
69
+ previous.opticalProgressValue === next.opticalProgressValue &&
70
+ previous.opticalPointX === next.opticalPointX &&
71
+ previous.opticalPointY === next.opticalPointY &&
72
+ previous.opticalMotionX === next.opticalMotionX &&
73
+ previous.opticalMotionY === next.opticalMotionY &&
74
+ previous.opticalVelocityX === next.opticalVelocityX &&
75
+ previous.opticalVelocityY === next.opticalVelocityY &&
76
+ previous.materialOverrides === next.materialOverrides &&
77
+ previous.displacementOnlyDebug === next.displacementOnlyDebug &&
78
+ previous.syncContentTransform === next.syncContentTransform &&
79
+ previous.shapeMaskText === next.shapeMaskText &&
80
+ previous.shapeMaskFontSize === next.shapeMaskFontSize &&
81
+ previous.shapeMaskFontWeight === next.shapeMaskFontWeight &&
82
+ previous.progressiveBlurIntensity === next.progressiveBlurIntensity &&
83
+ previous.animatedStyle === next.animatedStyle &&
84
+ previous.placement === next.placement &&
85
+ previous.bottomInset === next.bottomInset &&
86
+ previous.zIndex === next.zIndex
87
+ );
88
+ }
89
+
90
+ export function sameOverlay(previous: OverlayEntry, next: OverlayEntry) {
91
+ return (
92
+ previous.children === next.children &&
93
+ previous.style === next.style &&
94
+ previous.frame?.x === next.frame?.x &&
95
+ previous.frame?.y === next.frame?.y &&
96
+ previous.frame?.width === next.frame?.width &&
97
+ previous.frame?.height === next.frame?.height &&
98
+ previous.scrollOffsets === next.scrollOffsets &&
99
+ previous.routeTransitionX === next.routeTransitionX &&
100
+ previous.portalOffsetStyle === next.portalOffsetStyle &&
101
+ previous.zIndex === next.zIndex
102
+ );
103
+ }
104
+
105
+ export function selectBalancedShaderSurfaces(entries: [string, SurfaceEntry][]) {
106
+ // Every mounted backdrop surface keeps the same renderer regardless of
107
+ // quality preset; display cadence is selected by the native provider.
108
+ return new Set(entries.map(([id]) => id));
109
+ }
@@ -0,0 +1,31 @@
1
+ import { StyleSheet } from 'react-native';
2
+
3
+ export const styles = StyleSheet.create({
4
+ root: { flex: 1 },
5
+ routeContent: { ...StyleSheet.flatten(StyleSheet.absoluteFill) },
6
+ measureOnly: {},
7
+ localSurface: { position: 'relative', overflow: 'hidden' },
8
+ // In-flow local surfaces wrap their content by default. A default flex:1
9
+ // makes controls inside a virtualized list header consume the viewport,
10
+ // pushing the actual feed cells below the visible area. Callers that need
11
+ // a filling surface opt into flex through contentStyle.
12
+ localContent: { overflow: 'hidden' },
13
+ portalSurface: { position: 'absolute', overflow: 'visible' },
14
+ portalContentOverlay: { alignItems: 'center', justifyContent: 'center', overflow: 'hidden' },
15
+ contentAboveGlass: { overflow: 'hidden' },
16
+ contentAboveGlassMeasure: { alignSelf: 'stretch' },
17
+ nativeSurface: { backgroundColor: 'transparent', overflow: 'hidden' },
18
+ fallbackSurface: {
19
+ backgroundColor: 'transparent',
20
+ borderWidth: StyleSheet.hairlineWidth,
21
+ overflow: 'hidden',
22
+ },
23
+ portalContentLayout: { flex: 1, overflow: 'hidden' },
24
+ portalContentWrap: { flexGrow: 1, flexShrink: 1, overflow: 'hidden' },
25
+ portalContentIntrinsic: { alignSelf: 'stretch', overflow: 'hidden' },
26
+ captureSource: { flex: 1 },
27
+ inlineBackdropSurface: { flex: 1 },
28
+ inlineBackdropIntrinsicSurface: { flexGrow: 1 },
29
+ bottomPlacement: { alignItems: 'center', justifyContent: 'flex-end' },
30
+ centerPlacement: { alignItems: 'center', justifyContent: 'center' },
31
+ });
@@ -0,0 +1,139 @@
1
+ import React from 'react';
2
+ import { View } from 'react-native';
3
+ import type { ColorValue, StyleProp, ViewStyle } from 'react-native';
4
+ import type { AnimatedStyle, SharedValue } from 'react-native-reanimated';
5
+ import type { NativeGlassSurfaceProps } from '../nativeGlassViews';
6
+ import type { GlassMaterialTokens, GlassTokens, GlassVariant } from '../types';
7
+ import type { GlassPointerEventSink, GlassValueEventSink } from '../pointerEventBridge';
8
+
9
+ export type NativeBackdropSurfaceProps = NativeGlassSurfaceProps & {
10
+ /** Direct high-frequency event channel; consumed here and never sent as a native prop. */
11
+ pointerEventSink?: GlassPointerEventSink;
12
+ /** Direct high-frequency knob channel; consumed here and never sent as a native prop. */
13
+ valueEventSink?: GlassValueEventSink;
14
+ animatedProps?: Partial<
15
+ Pick<
16
+ NativeGlassSurfaceProps,
17
+ | 'interactionProgress'
18
+ | 'interactionPointX'
19
+ | 'interactionPointY'
20
+ | 'interactionVelocityX'
21
+ | 'interactionVelocityY'
22
+ | 'motionX'
23
+ | 'motionY'
24
+ | 'toggleFraction'
25
+ >
26
+ >;
27
+ };
28
+
29
+ export interface GlassRuntime {
30
+ tokens: GlassTokens;
31
+ dark: boolean;
32
+ reducedMotion: boolean;
33
+ }
34
+
35
+ export interface SurfaceFrame {
36
+ x: number;
37
+ y: number;
38
+ width: number;
39
+ height: number;
40
+ }
41
+
42
+ export type GlassSamplingSource = 'routeScene' | 'themeBackdrop';
43
+
44
+ export interface SurfaceEntry {
45
+ frame: SurfaceFrame;
46
+ positioning: 'inFlow' | 'floating';
47
+ variant: GlassVariant;
48
+ samplingSource: GlassSamplingSource;
49
+ /** Native provider selected when the source-tree surface was registered. */
50
+ samplingProviderId: string;
51
+ tintColor?: ColorValue;
52
+ portalContent?: React.ReactNode;
53
+ /** Paint the surface's own children above the glass instead of into the scene it samples. */
54
+ contentAboveGlass: boolean;
55
+ content?: React.ReactNode;
56
+ /** Layout applied to the visible copy when content is portaled above the glass. */
57
+ contentStyle?: StyleProp<ViewStyle>;
58
+ interactive: boolean;
59
+ continuous: boolean;
60
+ sharedSource: boolean;
61
+ captureProbe: boolean;
62
+ opticalProgress?: SharedValue<number>;
63
+ scrollGroupKey: string;
64
+ scrollOffsets: readonly SharedValue<number>[];
65
+ routeTransitionX?: SharedValue<number> | null;
66
+ portalOffsetStyle?: AnimatedStyle<ViewStyle>;
67
+ portalTranslateX?: SharedValue<number>;
68
+ portalTranslateY?: SharedValue<number>;
69
+ portalScaleX?: SharedValue<number>;
70
+ portalScaleY?: SharedValue<number>;
71
+ /** Pointer event stream for the native motion driver; it owns the spring. */
72
+ pointerEvent?: SharedValue<string>;
73
+ /** The same stream as plain state; this is what the native prop receives. */
74
+ pointerEventValue?: string;
75
+ /** Direct native path for pointer samples that should not rerender portal surfaces. */
76
+ pointerEventSink?: GlassPointerEventSink;
77
+ /** Knob value stream for value-driven lenses; see useGlassKnobMotion. */
78
+ valueEvent?: string;
79
+ /** Direct native path for knob values that should not rerender portal surfaces. */
80
+ valueEventSink?: GlassValueEventSink;
81
+ opticalToggleFraction?: SharedValue<number>;
82
+ /** Deterministic progress used by reference-capture fixtures. */
83
+ opticalProgressValue?: number;
84
+ opticalPointX?: SharedValue<number>;
85
+ opticalPointY?: SharedValue<number>;
86
+ /** UI-thread pointer velocity in local dp/s for the reference release spring. */
87
+ opticalVelocityX?: SharedValue<number>;
88
+ opticalVelocityY?: SharedValue<number>;
89
+ opticalMotionX?: SharedValue<number>;
90
+ opticalMotionY?: SharedValue<number>;
91
+ materialOverrides?: Partial<GlassMaterialTokens>;
92
+ shapeMaskText?: string;
93
+ shapeMaskFontSize?: number;
94
+ shapeMaskFontWeight?: number;
95
+ progressiveBlurIntensity?: number;
96
+ displacementOnlyDebug: boolean;
97
+ syncContentTransform?: boolean;
98
+ animatedStyle?: AnimatedStyle<ViewStyle>;
99
+ placement?: 'layout' | 'bottom' | 'center';
100
+ bottomInset?: number;
101
+ zIndex: number;
102
+ }
103
+
104
+ export interface OverlayEntry {
105
+ children: React.ReactNode;
106
+ style?: AnimatedStyle<ViewStyle>;
107
+ frame?: SurfaceFrame;
108
+ scrollOffsets?: readonly SharedValue<number>[];
109
+ routeTransitionX?: SharedValue<number> | null;
110
+ portalOffsetStyle?: AnimatedStyle<ViewStyle>;
111
+ zIndex: number;
112
+ }
113
+
114
+ export interface EntryRegistry<Entry> {
115
+ getSnapshot: () => [string, Entry][];
116
+ subscribe: (listener: () => void) => () => void;
117
+ update: (id: string, entry: Entry, equals: (previous: Entry, next: Entry) => boolean) => void;
118
+ remove: (id: string) => void;
119
+ }
120
+
121
+ export interface GlassHostContextValue {
122
+ providerId: string;
123
+ routeSceneProviderId: string | null;
124
+ themeBackdropProviderId: string;
125
+ inlineBackdropByDefault: boolean;
126
+ hasSeparateBackdrop: boolean;
127
+ defaultSamplingSource: GlassSamplingSource;
128
+ hostRef: React.RefObject<View | null>;
129
+ updateSurface: (id: string, entry: SurfaceEntry) => void;
130
+ updateOverlay: (id: string, entry: OverlayEntry) => void;
131
+ removeOverlay: (id: string) => void;
132
+ remove: (id: string) => void;
133
+ }
134
+
135
+ export interface GlassOverlayHostContextValue {
136
+ providerId: string;
137
+ updateOverlay: (id: string, entry: OverlayEntry) => void;
138
+ remove: (id: string) => void;
139
+ }
@@ -0,0 +1,100 @@
1
+ import type { ReactNode } from 'react';
2
+ import { View } from 'react-native';
3
+ import Animated, { useAnimatedStyle } from 'react-native-reanimated';
4
+ import type { SharedValue } from 'react-native-reanimated';
5
+ import { useGlassSamplingProviderId } from '../GlassSurface';
6
+ import type { GlassTabBarItem } from '../GlassTabBar';
7
+ import type { GlassTabBarProps } from '../GlassTabBar';
8
+ import { styles } from './tabStyles';
9
+
10
+ export // Floating overlays mount in the host's context, outside the calling page's
11
+ // capture scope. Resolve the id here so source and lens share that actual scope.
12
+ function TabLensScene({ children }: { children: (providerId: string) => ReactNode }) {
13
+ const providerId = useGlassSamplingProviderId('routeScene');
14
+ return <>{children(providerId ?? '')}</>;
15
+ }
16
+
17
+ export function GlassTabItem({
18
+ item,
19
+ index,
20
+ selected,
21
+ itemWidth,
22
+ horizontalPadding,
23
+ barHeight,
24
+ renderVisual,
25
+ customContent,
26
+ sampled = false,
27
+ lensLeft,
28
+ lensRight,
29
+ }: {
30
+ item: GlassTabBarItem;
31
+ index: number;
32
+ selected: boolean;
33
+ itemWidth: number;
34
+ horizontalPadding: number;
35
+ barHeight: number;
36
+ renderVisual: NonNullable<GlassTabBarProps['renderItem']>;
37
+ customContent: boolean;
38
+ sampled?: boolean;
39
+ lensLeft: SharedValue<number>;
40
+ lensRight: SharedValue<number>;
41
+ }) {
42
+ const itemFocusStyle = useAnimatedStyle(() => {
43
+ const center = (lensLeft.value + lensRight.value) / 2;
44
+ const tabCenter = horizontalPadding + itemWidth * (index + 0.5);
45
+ const strength = Math.max(
46
+ 0,
47
+ Math.min(1, 1 - Math.abs(center - tabCenter) / Math.max(itemWidth * 0.92, 1)),
48
+ );
49
+ return {
50
+ transform: [{ scale: 1 + strength * 0.025 }],
51
+ };
52
+ }, [horizontalPadding, index, itemWidth]);
53
+ const activeIconStyle = useAnimatedStyle(() => {
54
+ const center = (lensLeft.value + lensRight.value) / 2;
55
+ const tabCenter = horizontalPadding + itemWidth * (index + 0.5);
56
+ const strength = Math.max(
57
+ 0,
58
+ Math.min(1, 1 - Math.abs(center - tabCenter) / Math.max(itemWidth * 0.92, 1)),
59
+ );
60
+ return { opacity: strength };
61
+ }, [horizontalPadding, index, itemWidth]);
62
+ const baseVisual = renderVisual(item, index, sampled);
63
+ const activeVisual = sampled ? null : renderVisual(item, index, true);
64
+
65
+ return (
66
+ <View
67
+ pointerEvents="none"
68
+ accessible={false}
69
+ accessibilityElementsHidden
70
+ importantForAccessibility="no-hide-descendants"
71
+ style={[styles.item, { height: barHeight }]}
72
+ >
73
+ <Animated.View
74
+ style={[customContent ? styles.itemContentInline : styles.itemContent, itemFocusStyle]}
75
+ >
76
+ {customContent ? (
77
+ <View style={styles.customContent}>
78
+ <View style={styles.baseIcon}>{baseVisual}</View>
79
+ <Animated.View
80
+ pointerEvents="none"
81
+ accessible={false}
82
+ accessibilityElementsHidden
83
+ importantForAccessibility="no-hide-descendants"
84
+ style={[styles.customActive, activeIconStyle]}
85
+ >
86
+ {activeVisual}
87
+ </Animated.View>
88
+ </View>
89
+ ) : (
90
+ <View style={styles.icon}>
91
+ <View style={styles.baseIcon}>{baseVisual}</View>
92
+ <Animated.View pointerEvents="none" style={[styles.activeIcon, activeIconStyle]}>
93
+ {activeVisual}
94
+ </Animated.View>
95
+ </View>
96
+ )}
97
+ </Animated.View>
98
+ </View>
99
+ );
100
+ }