@oxyhq/bloom 0.79.0 → 0.79.1

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 (105) hide show
  1. package/README.md +3 -3
  2. package/lib/commonjs/provider/index.js +11 -7
  3. package/lib/commonjs/provider/index.js.map +1 -1
  4. package/lib/commonjs/scroll/context.js +96 -0
  5. package/lib/commonjs/scroll/context.js.map +1 -0
  6. package/lib/commonjs/scroll/expo-router/index.js +133 -0
  7. package/lib/commonjs/scroll/expo-router/index.js.map +1 -0
  8. package/lib/commonjs/scroll/index.js +85 -21
  9. package/lib/commonjs/scroll/index.js.map +1 -1
  10. package/lib/commonjs/scroll/index.web.js +184 -118
  11. package/lib/commonjs/scroll/index.web.js.map +1 -1
  12. package/lib/commonjs/scroll/scrollable.native.js +58 -0
  13. package/lib/commonjs/scroll/scrollable.native.js.map +1 -0
  14. package/lib/commonjs/scroll/store.js +47 -25
  15. package/lib/commonjs/scroll/store.js.map +1 -1
  16. package/lib/commonjs/theme/color-policy.js +11 -10
  17. package/lib/commonjs/theme/color-policy.js.map +1 -1
  18. package/lib/module/provider/index.js +10 -6
  19. package/lib/module/provider/index.js.map +1 -1
  20. package/lib/module/scroll/context.js +90 -0
  21. package/lib/module/scroll/context.js.map +1 -0
  22. package/lib/module/scroll/expo-router/index.js +128 -0
  23. package/lib/module/scroll/expo-router/index.js.map +1 -0
  24. package/lib/module/scroll/index.js +80 -21
  25. package/lib/module/scroll/index.js.map +1 -1
  26. package/lib/module/scroll/index.web.js +181 -119
  27. package/lib/module/scroll/index.web.js.map +1 -1
  28. package/lib/module/scroll/scrollable.native.js +54 -0
  29. package/lib/module/scroll/scrollable.native.js.map +1 -0
  30. package/lib/module/scroll/store.js +47 -25
  31. package/lib/module/scroll/store.js.map +1 -1
  32. package/lib/module/theme/color-policy.js +11 -10
  33. package/lib/module/theme/color-policy.js.map +1 -1
  34. package/lib/typescript/commonjs/provider/index.d.ts +7 -5
  35. package/lib/typescript/commonjs/provider/index.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/scroll/context.d.ts +14 -0
  37. package/lib/typescript/commonjs/scroll/context.d.ts.map +1 -0
  38. package/lib/typescript/commonjs/scroll/expo-router/index.d.ts +7 -0
  39. package/lib/typescript/commonjs/scroll/expo-router/index.d.ts.map +1 -0
  40. package/lib/typescript/commonjs/scroll/index.d.ts +14 -23
  41. package/lib/typescript/commonjs/scroll/index.d.ts.map +1 -1
  42. package/lib/typescript/commonjs/scroll/index.web.d.ts +17 -19
  43. package/lib/typescript/commonjs/scroll/index.web.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/scroll/scrollable.native.d.ts +23 -0
  45. package/lib/typescript/commonjs/scroll/scrollable.native.d.ts.map +1 -0
  46. package/lib/typescript/commonjs/scroll/store.d.ts +41 -22
  47. package/lib/typescript/commonjs/scroll/store.d.ts.map +1 -1
  48. package/lib/typescript/commonjs/scroll/types.d.ts +82 -12
  49. package/lib/typescript/commonjs/scroll/types.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/theme/color-policy.d.ts.map +1 -1
  51. package/lib/typescript/module/provider/index.d.ts +7 -5
  52. package/lib/typescript/module/provider/index.d.ts.map +1 -1
  53. package/lib/typescript/module/scroll/context.d.ts +14 -0
  54. package/lib/typescript/module/scroll/context.d.ts.map +1 -0
  55. package/lib/typescript/module/scroll/expo-router/index.d.ts +7 -0
  56. package/lib/typescript/module/scroll/expo-router/index.d.ts.map +1 -0
  57. package/lib/typescript/module/scroll/index.d.ts +14 -23
  58. package/lib/typescript/module/scroll/index.d.ts.map +1 -1
  59. package/lib/typescript/module/scroll/index.web.d.ts +17 -19
  60. package/lib/typescript/module/scroll/index.web.d.ts.map +1 -1
  61. package/lib/typescript/module/scroll/scrollable.native.d.ts +23 -0
  62. package/lib/typescript/module/scroll/scrollable.native.d.ts.map +1 -0
  63. package/lib/typescript/module/scroll/store.d.ts +41 -22
  64. package/lib/typescript/module/scroll/store.d.ts.map +1 -1
  65. package/lib/typescript/module/scroll/types.d.ts +82 -12
  66. package/lib/typescript/module/scroll/types.d.ts.map +1 -1
  67. package/lib/typescript/module/theme/color-policy.d.ts.map +1 -1
  68. package/package.json +15 -1
  69. package/src/__tests__/BloomProvider.web.test.tsx +8 -15
  70. package/src/__tests__/optional-peer-imports.test.ts +2 -2
  71. package/src/__tests__/scroll-expo-router-adapter.test.tsx +164 -0
  72. package/src/__tests__/scroll-native.test.tsx +465 -0
  73. package/src/__tests__/scroll-store.test.ts +41 -17
  74. package/src/__tests__/scroll-web.test.tsx +547 -111
  75. package/src/provider/index.tsx +10 -7
  76. package/src/scroll/context.tsx +107 -0
  77. package/src/scroll/expo-router/index.ts +140 -0
  78. package/src/scroll/index.ts +92 -25
  79. package/src/scroll/index.web.tsx +219 -162
  80. package/src/scroll/scrollable.native.ts +64 -0
  81. package/src/scroll/store.ts +47 -25
  82. package/src/scroll/types.ts +82 -12
  83. package/src/theme/__tests__/__fixtures__/golden-resolved-tokens.json +5 -5
  84. package/src/theme/__tests__/__snapshots__/visual-gallery.test.tsx.snap +11 -11
  85. package/src/theme/__tests__/policy-legibility.test.ts +10 -7
  86. package/src/theme/color-policy.ts +11 -10
  87. package/lib/commonjs/provider/scroll-provider.js +0 -13
  88. package/lib/commonjs/provider/scroll-provider.js.map +0 -1
  89. package/lib/commonjs/provider/scroll-provider.web.js +0 -13
  90. package/lib/commonjs/provider/scroll-provider.web.js.map +0 -1
  91. package/lib/module/provider/scroll-provider.js +0 -16
  92. package/lib/module/provider/scroll-provider.js.map +0 -1
  93. package/lib/module/provider/scroll-provider.web.js +0 -5
  94. package/lib/module/provider/scroll-provider.web.js.map +0 -1
  95. package/lib/typescript/commonjs/provider/scroll-provider.d.ts +0 -14
  96. package/lib/typescript/commonjs/provider/scroll-provider.d.ts.map +0 -1
  97. package/lib/typescript/commonjs/provider/scroll-provider.web.d.ts +0 -3
  98. package/lib/typescript/commonjs/provider/scroll-provider.web.d.ts.map +0 -1
  99. package/lib/typescript/module/provider/scroll-provider.d.ts +0 -14
  100. package/lib/typescript/module/provider/scroll-provider.d.ts.map +0 -1
  101. package/lib/typescript/module/provider/scroll-provider.web.d.ts +0 -3
  102. package/lib/typescript/module/provider/scroll-provider.web.d.ts.map +0 -1
  103. package/src/__tests__/scroll-native.test.ts +0 -25
  104. package/src/provider/scroll-provider.ts +0 -13
  105. package/src/provider/scroll-provider.web.ts +0 -2
package/README.md CHANGED
@@ -45,9 +45,9 @@ import { BloomProvider } from '@oxyhq/bloom/provider';
45
45
  </BloomProvider>
46
46
  ```
47
47
 
48
- Everything scrollable must be **under** it: on web `useScrollRestoration()` throws
49
- outside its provider, so a list rendered beside the root (a right rail, an overlay)
50
- crashes the screen.
48
+ Everything scrollable must be **under** it: `useScrollRestoration()` throws outside
49
+ its provider, so a list rendered beside the root (a right rail, an overlay) crashes
50
+ the screen.
51
51
 
52
52
  Outlets are **not** included — their position in the tree is a real app decision, and
53
53
  a second mount duplicates every surface they render. Mount these yourself, under
@@ -8,7 +8,8 @@ var _index = require("../image-resolver/index.js");
8
8
  var _useHaptics = require("../hooks/useHaptics.js");
9
9
  var _minimizeContext = require("../tab-bar/minimize-context.js");
10
10
  var _index2 = require("../theme/index.js");
11
- var _scrollProvider = require("./scroll-provider");
11
+ var _context = require("../scroll/context.js");
12
+ var _index3 = require("../scroll/expo-router/index.js");
12
13
  var _jsxRuntime = require("react/jsx-runtime");
13
14
  /**
14
15
  * `BloomProvider` — the ONE Bloom root an app mounts.
@@ -30,11 +31,13 @@ var _jsxRuntime = require("react/jsx-runtime");
30
31
  * Nesting extra contexts costs nothing at runtime — the win is that scope is no
31
32
  * longer a per-app decision.
32
33
  *
33
- * EXPO/EXPO-ROUTER APPS ONLY. The scroll-restoration provider it mounts imports
34
- * `expo-router` (its web implementation keys offsets on the focused route), so
35
- * a Vite/SPA consumer that has no expo-router cannot resolve this module. Those
36
- * apps keep mounting `BloomThemeProvider` (and any other piece they need)
37
- * directly that is not a lesser path, just the one without a router.
34
+ * EXPO/EXPO-ROUTER APPS ONLY, and now for one narrow reason: it binds the
35
+ * scroll store to the expo-router ADAPTER, which is the only module in the
36
+ * scroll primitive that imports `expo-router`. The scroll core itself is
37
+ * router-agnostic, so a Vite/SPA consumer can mount
38
+ * `<ScrollRestorationProvider adapter={...}>` from `@oxyhq/bloom/scroll` with
39
+ * an adapter for its own router — alongside `BloomThemeProvider` and whatever
40
+ * else it needs — rather than going without.
38
41
  *
39
42
  * NOT included, on purpose — these are OUTLETS, not state, and their placement
40
43
  * in the tree is a real app decision (z-order, safe areas, and mounting a
@@ -57,7 +60,8 @@ function BloomProvider({
57
60
  value: imageResolver ?? null,
58
61
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.BloomThemeProvider, {
59
62
  ...themeProps,
60
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_scrollProvider.ScrollRestorationProvider, {
63
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.ScrollRestorationProvider, {
64
+ adapter: _index3.expoRouterScrollAdapter,
61
65
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_useHaptics.BloomHapticsProvider, {
62
66
  enabled: haptics,
63
67
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_minimizeContext.TabBarMinimizeProvider, {
@@ -1 +1 @@
1
- {"version":3,"names":["_index","require","_useHaptics","_minimizeContext","_index2","_scrollProvider","_jsxRuntime","BloomProvider","children","imageResolver","haptics","themeProps","jsx","ImageResolverProvider","value","BloomThemeProvider","ScrollRestorationProvider","BloomHapticsProvider","enabled","TabBarMinimizeProvider","displayName"],"sourceRoot":"../../../src","sources":["provider/index.tsx"],"mappings":";;;;;;AAkCA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAA8D,IAAAK,WAAA,GAAAL,OAAA;AAtC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBO,SAASM,aAAaA,CAAC;EAC5BC,QAAQ;EACRC,aAAa;EACbC,OAAO,GAAG,IAAI;EACd,GAAGC;AACe,CAAC,EAAE;EACrB;IAAA;IACE;IACA;IACA,IAAAL,WAAA,CAAAM,GAAA,EAACZ,MAAA,CAAAa,qBAAqB;MAACC,KAAK,EAAEL,aAAa,IAAI,IAAK;MAAAD,QAAA,eAClD,IAAAF,WAAA,CAAAM,GAAA,EAACR,OAAA,CAAAW,kBAAkB;QAAA,GAAKJ,UAAU;QAAAH,QAAA,eAChC,IAAAF,WAAA,CAAAM,GAAA,EAACP,eAAA,CAAAW,yBAAyB;UAAAR,QAAA,eACxB,IAAAF,WAAA,CAAAM,GAAA,EAACV,WAAA,CAAAe,oBAAoB;YAACC,OAAO,EAAER,OAAQ;YAAAF,QAAA,eACrC,IAAAF,WAAA,CAAAM,GAAA,EAACT,gBAAA,CAAAgB,sBAAsB;cAAAX,QAAA,EAAEA;YAAQ,CAAyB;UAAC,CACvC;QAAC,CACE;MAAC,CACV;IAAC,CACA;EAAC;AAE5B;AAEAD,aAAa,CAACa,WAAW,GAAG,eAAe","ignoreList":[]}
1
+ {"version":3,"names":["_index","require","_useHaptics","_minimizeContext","_index2","_context","_index3","_jsxRuntime","BloomProvider","children","imageResolver","haptics","themeProps","jsx","ImageResolverProvider","value","BloomThemeProvider","ScrollRestorationProvider","adapter","expoRouterScrollAdapter","BloomHapticsProvider","enabled","TabBarMinimizeProvider","displayName"],"sourceRoot":"../../../src","sources":["provider/index.tsx"],"mappings":";;;;;;AAoCA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAAgE,IAAAM,WAAA,GAAAN,OAAA;AAzChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAsBO,SAASO,aAAaA,CAAC;EAC5BC,QAAQ;EACRC,aAAa;EACbC,OAAO,GAAG,IAAI;EACd,GAAGC;AACe,CAAC,EAAE;EACrB;IAAA;IACE;IACA;IACA,IAAAL,WAAA,CAAAM,GAAA,EAACb,MAAA,CAAAc,qBAAqB;MAACC,KAAK,EAAEL,aAAa,IAAI,IAAK;MAAAD,QAAA,eAClD,IAAAF,WAAA,CAAAM,GAAA,EAACT,OAAA,CAAAY,kBAAkB;QAAA,GAAKJ,UAAU;QAAAH,QAAA,eAChC,IAAAF,WAAA,CAAAM,GAAA,EAACR,QAAA,CAAAY,yBAAyB;UAACC,OAAO,EAAEC,+BAAwB;UAAAV,QAAA,eAC1D,IAAAF,WAAA,CAAAM,GAAA,EAACX,WAAA,CAAAkB,oBAAoB;YAACC,OAAO,EAAEV,OAAQ;YAAAF,QAAA,eACrC,IAAAF,WAAA,CAAAM,GAAA,EAACV,gBAAA,CAAAmB,sBAAsB;cAAAb,QAAA,EAAEA;YAAQ,CAAyB;UAAC,CACvC;QAAC,CACE;MAAC,CACV;IAAC,CACA;EAAC;AAE5B;AAEAD,aAAa,CAACe,WAAW,GAAG,eAAe","ignoreList":[]}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScrollRestorationProvider = ScrollRestorationProvider;
7
+ exports.useScrollRestorationContext = useScrollRestorationContext;
8
+ var _react = require("react");
9
+ var _store = require("./store.js");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * The provider and context both platform barrels share.
13
+ *
14
+ * Nothing here is platform-specific: the provider holds an offset store and the
15
+ * router adapter, and that composition is identical on web and native. Keeping
16
+ * it in one module also guarantees ONE context identity — a provider mounted
17
+ * from the native barrel and a hook imported from the web barrel would
18
+ * otherwise read two different contexts and the hook would throw.
19
+ */
20
+
21
+ const ScrollRestorationContext = /*#__PURE__*/(0, _react.createContext)(null);
22
+ ScrollRestorationContext.displayName = 'BloomScrollRestorationContext';
23
+
24
+ /**
25
+ * Holds the offset map and the router binding for the subtree. One provider
26
+ * near the app root is enough; the store lives as long as the provider, so
27
+ * offsets survive navigating away and back (including browser Back/Forward).
28
+ */
29
+ function ScrollRestorationProvider({
30
+ children,
31
+ adapter
32
+ }) {
33
+ const store = (0, _react.useMemo)(() => new _store.ScrollOffsetStore(), []);
34
+ const value = (0, _react.useMemo)(() => ({
35
+ store,
36
+ adapter
37
+ }), [store, adapter]);
38
+ useManualBrowserScrollRestoration();
39
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(ScrollRestorationContext.Provider, {
40
+ value: value,
41
+ children: children
42
+ });
43
+ }
44
+ function useScrollRestorationContext() {
45
+ const value = (0, _react.useContext)(ScrollRestorationContext);
46
+ if (value === null) {
47
+ throw new Error('useScrollRestoration must be used within a <ScrollRestorationProvider>.');
48
+ }
49
+ return value;
50
+ }
51
+
52
+ /**
53
+ * Take over scroll restoration from the browser for as long as this provider is
54
+ * mounted, and hand it back both on unmount and on `pagehide`.
55
+ *
56
+ * The browser's default `'auto'` restoration fights our restore on
57
+ * Back/Forward, so it has to be turned off — but only while something is
58
+ * actually going to restore instead. Two moments where that stops being true:
59
+ *
60
+ * - **Unmount.** This used to run at MODULE scope, which meant merely
61
+ * importing the module disabled the browser's own restoration. Now that the
62
+ * core is importable by apps that mount no provider (and by SSR and Node
63
+ * tooling), that would have left those apps with neither restoration. Tying
64
+ * the switch to the provider's lifetime makes it describe exactly the period
65
+ * during which a replacement exists. The provider mounts at the app root on
66
+ * the first commit, which is before any navigation can create a history
67
+ * entry, so nothing is lost by not doing it at module scope.
68
+ * - **`pagehide`.** The offset map lives in memory only. A reload starts with
69
+ * an empty one, and a bfcache restore resumes a document whose provider is
70
+ * already mounted and whose focus effects therefore never re-run — so in
71
+ * both cases `'manual'` means NOBODY restores. Handing the mode back to the
72
+ * browser on the way out lets it do the job we are no longer able to.
73
+ * (react-router does exactly this, for the same reason.)
74
+ *
75
+ * The feature detect is also the platform test — `history` exists on web and
76
+ * nowhere else — so this stays one implementation rather than a fork. On React
77
+ * Native and during SSR it is a no-op.
78
+ */
79
+ function useManualBrowserScrollRestoration() {
80
+ (0, _react.useEffect)(() => {
81
+ if (typeof window === 'undefined' || typeof history === 'undefined' || !('scrollRestoration' in history)) {
82
+ return undefined;
83
+ }
84
+ const previous = history.scrollRestoration;
85
+ history.scrollRestoration = 'manual';
86
+ const handBackToBrowser = () => {
87
+ history.scrollRestoration = 'auto';
88
+ };
89
+ window.addEventListener('pagehide', handBackToBrowser);
90
+ return () => {
91
+ window.removeEventListener('pagehide', handBackToBrowser);
92
+ history.scrollRestoration = previous;
93
+ };
94
+ }, []);
95
+ }
96
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_store","_jsxRuntime","ScrollRestorationContext","createContext","displayName","ScrollRestorationProvider","children","adapter","store","useMemo","ScrollOffsetStore","value","useManualBrowserScrollRestoration","jsx","Provider","useScrollRestorationContext","useContext","Error","useEffect","window","history","undefined","previous","scrollRestoration","handBackToBrowser","addEventListener","removeEventListener"],"sourceRoot":"../../../src","sources":["scroll/context.tsx"],"mappings":";;;;;;;AASA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAA4C,IAAAE,WAAA,GAAAF,OAAA;AAX5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,MAAMG,wBAAwB,gBAC5B,IAAAC,oBAAa,EAAuC,IAAI,CAAC;A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AAG,MAAM;IACpC,CAAC;IACDJ,MAAM,CAACM,gBAAgB,CAAC,UAAU,EAAED,iBAAiB,CAAC;IAEtD,OAAO,MAAM;MACXL,MAAM,CAACO,mBAAmB,CAAC,UAAU,EAAEF,iBAAiB,CAAC;MACzDJ,OAAO,CAACG,iBAAiB,GAAGD,QAAQ;IACtC,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR","ignoreList":[]}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.expoRouterScrollAdapter = void 0;
7
+ var _react = require("react");
8
+ var _expoRouter = require("expo-router");
9
+ /**
10
+ * The expo-router binding for `@oxyhq/bloom/scroll`.
11
+ *
12
+ * This is the only file in the scroll primitive that knows a router exists. It
13
+ * is separate from the core so a consumer with a different router — or none —
14
+ * can still use the core with its own adapter; before the split, a module-scope
15
+ * `expo-router` import made the whole subpath unresolvable for them.
16
+ *
17
+ * The navigation hooks come from `expo-router` (which re-exports React
18
+ * Navigation's) rather than from `@react-navigation/native` directly. Every Oxy
19
+ * app uses expo-router as its router, so it is always a DIRECT, top-level
20
+ * dependency that resolves cleanly under Bun's isolated linker — whereas
21
+ * `@react-navigation/native` is only a nested/transitive dependency of
22
+ * expo-router and would fail to resolve when bundling those apps.
23
+ */
24
+
25
+ /**
26
+ * Params that describe how a screen was REACHED rather than what it shows, and
27
+ * so must not contribute to a content id — the same screen showing the same
28
+ * thing would otherwise get two ids depending on how the user got there.
29
+ *
30
+ * - `screen` / `params` are React Navigation's nested-navigator plumbing.
31
+ * expo-router strips both wherever it derives a URL from state
32
+ * (`global-state/getRouteInfoFromState.js` deletes them before building the
33
+ * pathname; `global-state/stateUtils.js` deletes `screen` from a payload;
34
+ * `hooks/useSearchParams.js` skips both).
35
+ * - `initial` is React Navigation's reserved anchor flag, set by expo-router's
36
+ * `withAnchor` handling in `global-state/getNavigationAction.js` — which also
37
+ * warns if an app supplies it as a real param.
38
+ */
39
+ const NON_CONTENT_PARAM_KEYS = new Set(['screen', 'params', 'initial']);
40
+
41
+ /**
42
+ * expo-router's own internal params all carry this prefix
43
+ * (`build/navigationParams.js` — `__internal_expo_router_no_animation`,
44
+ * `__internal__expo_router_is_preview_navigation`, and the two zoom-transition
45
+ * ids, verified identical in expo-router 56.2.10 and 57.0.9). They are appended
46
+ * to the params of an ordinary navigation, so matching the prefix rather than
47
+ * the four literals means a fifth one added upstream cannot silently split one
48
+ * screen's content id in two.
49
+ */
50
+ const INTERNAL_PARAM_PREFIX = '__internal';
51
+
52
+ /**
53
+ * Depth at which nested param objects stop being described. React Navigation
54
+ * expects params to be serializable, but nothing enforces it, and a serializer
55
+ * that a cyclic value can hang is not one to put on a render path. Four levels
56
+ * is far past anything a URL produces.
57
+ */
58
+ const MAX_PARAM_DEPTH = 4;
59
+ function serializeValue(value, depth) {
60
+ if (value === undefined) return '~undefined';
61
+ if (value === null) return '~null';
62
+ // JSON.stringify quotes and escapes, so a string can never be confused with
63
+ // a marker above or with the punctuation of a nested structure below.
64
+ if (typeof value === 'string') return JSON.stringify(value);
65
+ if (typeof value === 'number' || typeof value === 'boolean') {
66
+ return String(value);
67
+ }
68
+ if (depth >= MAX_PARAM_DEPTH) return '~deep';
69
+ if (Array.isArray(value)) {
70
+ return `[${value.map(entry => serializeValue(entry, depth + 1)).join(',')}]`;
71
+ }
72
+ if (typeof value === 'object') {
73
+ const source = value;
74
+ return `{${Object.keys(source).sort().map(key => `${JSON.stringify(key)}:${serializeValue(source[key], depth + 1)}`).join(',')}}`;
75
+ }
76
+ // A function, symbol or bigint reached a screen's params. Nothing about it
77
+ // identifies content, and it cannot be compared across renders anyway.
78
+ return '~opaque';
79
+ }
80
+
81
+ /**
82
+ * Render a screen's params as a stable string. Keys are SORTED so params that
83
+ * differ only in insertion order — routinely, since expo-router rebuilds the
84
+ * object on every navigation — can never produce two ids for one screen.
85
+ *
86
+ * The exclusions apply at the top level only, because that is where React
87
+ * Navigation and expo-router inject theirs; a nested user object keeps every
88
+ * key it has.
89
+ */
90
+ function serializeContentParams(params) {
91
+ if (params === undefined) return '';
92
+ const source = params;
93
+ return Object.keys(source).filter(key => !NON_CONTENT_PARAM_KEYS.has(key) && !key.startsWith(INTERNAL_PARAM_PREFIX)).sort().map(key => `${JSON.stringify(key)}:${serializeValue(source[key], 1)}`).join(',');
94
+ }
95
+
96
+ /**
97
+ * Identify WHAT the calling screen is showing: its route name plus its params.
98
+ *
99
+ * `useRoute()` is the source, and it has to be: it reads the route object of
100
+ * the nearest screen, so a background screen keeps reporting its own content.
101
+ * `usePathname()` would not do — it reads the globally focused route, so a
102
+ * background screen would adopt the foreground one's pathname and save its
103
+ * offset under a key that is not its own.
104
+ *
105
+ * `route.key` is deliberately NOT part of this. An offset belongs to what the
106
+ * user was looking at, not to the history slot it occupied — see
107
+ * `deriveScrollKey` for the full reasoning and the trade it makes.
108
+ *
109
+ * Params are what separate two screens sharing a route name. That matters most
110
+ * where expo-router RECYCLES a route object: `layouts/StackClient.js` reuses
111
+ * the current route — key included — when `NAVIGATE` targets the current route
112
+ * name and `getSingularId` matches, i.e. when only the query changed. Measured
113
+ * on 56.2.10 and 57.0.9: `search?q=cats` -> `search?q=dogs` keeps one key and
114
+ * swaps `params`, so without the params the two searches would share an offset.
115
+ */
116
+ function useScreenContentId() {
117
+ const route = (0, _expoRouter.useRoute)();
118
+ const contentId = `${route.name}?${serializeContentParams(route.params)}`;
119
+ return (0, _react.useMemo)(() => contentId, [contentId]);
120
+ }
121
+ function useScreenFocusEffect(effect) {
122
+ (0, _expoRouter.useFocusEffect)(effect);
123
+ }
124
+
125
+ /**
126
+ * The adapter to hand `<ScrollRestorationProvider adapter={...}>` in an
127
+ * expo-router app. A module-level constant, as the adapter contract requires.
128
+ */
129
+ const expoRouterScrollAdapter = exports.expoRouterScrollAdapter = {
130
+ useScreenContentId,
131
+ useScreenFocusEffect
132
+ };
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_expoRouter","NON_CONTENT_PARAM_KEYS","Set","INTERNAL_PARAM_PREFIX","MAX_PARAM_DEPTH","serializeValue","value","depth","undefined","JSON","stringify","String","Array","isArray","map","entry","join","source","Object","keys","sort","key","serializeContentParams","params","filter","has","startsWith","useScreenContentId","route","useRoute","contentId","name","useMemo","useScreenFocusEffect","effect","useFocusEffect","expoRouterScrollAdapter","exports"],"sourceRoot":"../../../../src","sources":["scroll/expo-router/index.ts"],"mappings":";;;;;;AAeA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAhBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,sBAAsB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,qBAAqB,GAAG,YAAY;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAG,CAAC;AAEzB,SAASC,cAAcA,CAACC,KAAc,EAAEC,KAAa,EAAU;EAC7D,IAAID,KAAK,KAAKE,SAAS,EAAE,OAAO,YAAY;EAC5C,IAAIF,KAAK,KAAK,IAAI,EAAE,OAAO,OAAO;EAClC;EACA;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE,OAAOG,IAAI,CAACC,SAAS,CAACJ,KAAK,CAAC;EAC3D,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,SAAS,EAAE;IAC3D,OAAOK,MAAM,CAACL,KAAK,CAAC;EACtB;EACA,IAAIC,KAAK,IAAIH,eAAe,EAAE,OAAO,OAAO;EAC5C,IAAIQ,KAAK,CAACC,OAAO,CAACP,KAAK,CAAC,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,SAASW,kBAAkBA,CAAA,EAAkB;EAC3C,MAAMC,KAAK,GAAG,IAAAC,oBAAQ,EAAC,CAAC;EACxB,MAAMC,SAAS,GAAG,GAAGF,KAAK,CAACG,IAAI,IAAIT,sBAAsB,CAACM,KAAK,CAACL,MAAM,CAAC,EAAE;EACzE,OAAO,IAAAS,cAAO,EAAC,MAAMF,SAAS,EAAE,CAACA,SAAS,CAAC,CAAC;AAC9C;AAEA,SAASG,oBAAoBA,CAACC,MAAyB,EAAQ;EAC7D,IAAAC,0BAAc,EAACD,MAAM,CAAC;AACxB;;AAEA;AACA;AACA;AACA;AACO,MAAME,uBAA4C,GAAAC,OAAA,CAAAD,uBAAA,GAAG;EAC1DT,kBAAkB;EAClBM;AACF,CAAC","ignoreList":[]}
@@ -3,37 +3,101 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ScrollRestorationProvider = ScrollRestorationProvider;
6
+ Object.defineProperty(exports, "ScrollRestorationProvider", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _context.ScrollRestorationProvider;
10
+ }
11
+ });
7
12
  exports.useScrollRestoration = useScrollRestoration;
13
+ var _react = require("react");
14
+ var _context = require("./context.js");
15
+ var _scrollableNative = require("./scrollable.native.js");
16
+ var _store = require("./store.js");
8
17
  /**
9
- * Native variant of the scroll-restoration primitive — a deliberate no-op.
18
+ * Native variant of the scroll-restoration primitive.
19
+ *
20
+ * React Navigation's native-stack keeps every screen MOUNTED while it is in the
21
+ * stack, so a list's scroll position survives a push/pop for free — this file
22
+ * must not interfere with that, and does not: nothing here runs on focus.
10
23
  *
11
- * React Navigation's native-stack keeps every screen mounted while it is in the
12
- * stack, so a list's scroll position survives a push/pop for free. There is
13
- * nothing to save or restore. We still ship the full API surface (provider +
14
- * hook) so consumers write one set of call sites that compile and run on every
15
- * platform; on native the provider just renders its children and the hook does
16
- * nothing.
24
+ * What native does not survive is a KEY CHANGE: an in-screen tab or folder swap
25
+ * that re-keys a list, and a screen that genuinely unmounts and remounts. The
26
+ * effect below is therefore keyed on the storage key (plus `enabled`) rather
27
+ * than on focus, which draws exactly that line with no bookkeeping: React
28
+ * re-runs it when the key changes and leaves it alone when a push/pop merely
29
+ * re-focuses the same screen showing the same content.
17
30
  *
18
31
  * Web bundlers select `./index.web` via the `"browser"` export condition in
19
32
  * `package.json`; native bundlers fall through to this file.
20
33
  */
21
34
 
22
35
  /**
23
- * No-op provider. Renders children unchanged native scroll persistence is
24
- * handled by the navigator, so no per-route state is kept.
36
+ * Preserve and restore the scroll offset of `target` across content changes,
37
+ * keyed by the content its screen is showing plus an optional `options.key`.
38
+ *
39
+ * Behaviour (native):
40
+ * - Offsets are recorded from the returned `onScroll` binding, which the caller
41
+ * wires onto the list. There is no other way to observe a list's offset.
42
+ * - When the storage key changes — a re-keyed list, a remount, or `enabled`
43
+ * turning on — the saved offset is applied, or 0 when the key was never seen.
44
+ * - A push/pop that re-focuses the same screen scrolls nothing. The navigator
45
+ * already preserved the position, and re-applying it would at best be a
46
+ * no-op and at worst fight a list that has legitimately moved on.
25
47
  */
26
- function ScrollRestorationProvider({
27
- children
28
- }) {
29
- return children;
30
- }
48
+ function useScrollRestoration(target, options) {
49
+ const {
50
+ store,
51
+ adapter
52
+ } = (0, _context.useScrollRestorationContext)();
53
+ const contentId = adapter.useScreenContentId();
54
+ const enabled = options?.enabled ?? true;
55
+ const scrollKey = (0, _store.deriveScrollKey)(contentId, options?.key);
31
56
 
32
- /**
33
- * No-op hook. Accepts the same arguments as the web implementation so call
34
- * sites are identical across platforms.
35
- */
36
- function useScrollRestoration(_target, _options) {
37
- // Intentionally empty: native-stack already preserves scroll position.
57
+ // The key the live `onScroll` binding is allowed to record against. It is
58
+ // assigned by the effect below only AFTER that effect's own write has landed,
59
+ // and cleared by its cleanup — so the relayout the outgoing content emits
60
+ // while a new key is already rendered is never attributed to the new key.
61
+ const recordingKeyRef = (0, _react.useRef)(null);
62
+ (0, _react.useEffect)(() => {
63
+ if (!enabled || scrollKey === null) return undefined;
64
+ const scroller = (0, _scrollableNative.createScroller)(target);
65
+ let frame = null;
66
+
67
+ // Restore and reset are ONE write: a miss reads 0, and 0 is exactly what a
68
+ // list showing content never seen this session must be sent to rather than
69
+ // left at the offset its predecessor had.
70
+ const apply = () => {
71
+ frame = null;
72
+ scroller.setOffset(store.read(scrollKey));
73
+ recordingKeyRef.current = scrollKey;
74
+ };
75
+
76
+ // Defer one frame. This effect fires in the same commit that rendered the
77
+ // incoming rows, and a list cannot honour an offset before it has laid them
78
+ // out — the write would be clamped to whatever height it has reached so
79
+ // far, with no second chance (unlike web, native gets no scroll event to
80
+ // re-apply from). One frame is all that is needed because `enabled` has
81
+ // already guaranteed the rows are there; what remains is the layout pass.
82
+ if (typeof requestAnimationFrame === 'function') {
83
+ frame = requestAnimationFrame(apply);
84
+ } else {
85
+ // No frame scheduler (SSR, or a bare Node import of this barrel).
86
+ // Applying immediately is still the correct write; only the wait is lost.
87
+ apply();
88
+ }
89
+ return () => {
90
+ if (frame !== null) cancelAnimationFrame(frame);
91
+ recordingKeyRef.current = null;
92
+ };
93
+ }, [store, scrollKey, enabled, target]);
94
+ const onScroll = (0, _react.useCallback)(event => {
95
+ const key = recordingKeyRef.current;
96
+ if (key === null) return;
97
+ store.save(key, event.nativeEvent.contentOffset.y);
98
+ }, [store]);
99
+ return (0, _react.useMemo)(() => ({
100
+ onScroll
101
+ }), [onScroll]);
38
102
  }
39
103
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ScrollRestorationProvider","children","useScrollRestoration","_target","_options"],"sourceRoot":"../../../src","sources":["scroll/index.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACO,SAASA,yBAAyBA,CAAC;EACxCC;AAC8B,CAAC,EAAgB;EAC/C,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAClCC,OAAgC,EAChCC,QAAsC,EAChC;EACN;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_context","_scrollableNative","_store","useScrollRestoration","target","options","store","adapter","useScrollRestorationContext","contentId","useScreenContentId","enabled","scrollKey","deriveScrollKey","key","recordingKeyRef","useRef","useEffect","undefined","scroller","createScroller","frame","apply","setOffset","read","current","requestAnimationFrame","cancelAnimationFrame","onScroll","useCallback","event","save","nativeEvent","contentOffset","y","useMemo"],"sourceRoot":"../../../src","sources":["scroll/index.ts"],"mappings":";;;;;;;;;;;;AAiBA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AArBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,oBAAoBA,CAClCC,MAA+B,EAC/BC,OAAqC,EACX;EAC1B,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAAC,oCAA2B,EAAC,CAAC;EACxD,MAAMC,SAAS,GAAGF,OAAO,CAACG,kBAAkB,CAAC,CAAC;EAC9C,MAAMC,OAAO,GAAGN,OAAO,EAAEM,OAAO,IAAI,IAAI;EACxC,MAAMC,SAAS,GAAG,IAAAC,sBAAe,EAACJ,SAAS,EAAEJ,OAAO,EAAES,GAAG,CAAC;;EAE1D;EACA;EACA;EACA;EACA,MAAMC,eAAe,GAAG,IAAAC,aAAM,EAAgB,IAAI,CAAC;EAEnD,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAI,CAACN,OAAO,IAAIC,SAAS,KAAK,IAAI,EAAE,OAAOM,SAAS;IAEpD,MAAMC,QAAQ,GAAG,IAAAC,gCAAc,EAAChB,MAAM,CAAC;IACvC,IAAIiB,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