@oxyhq/bloom 0.6.21 → 0.6.23

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 (49) hide show
  1. package/lib/commonjs/scroll/index.js +39 -0
  2. package/lib/commonjs/scroll/index.js.map +1 -0
  3. package/lib/commonjs/scroll/index.web.js +226 -0
  4. package/lib/commonjs/scroll/index.web.js.map +1 -0
  5. package/lib/commonjs/scroll/scrollable.web.js +69 -0
  6. package/lib/commonjs/scroll/scrollable.web.js.map +1 -0
  7. package/lib/commonjs/scroll/store.js +90 -0
  8. package/lib/commonjs/scroll/store.js.map +1 -0
  9. package/lib/commonjs/scroll/types.js +6 -0
  10. package/lib/commonjs/scroll/types.js.map +1 -0
  11. package/lib/module/scroll/index.js +34 -0
  12. package/lib/module/scroll/index.js.map +1 -0
  13. package/lib/module/scroll/index.web.js +220 -0
  14. package/lib/module/scroll/index.web.js.map +1 -0
  15. package/lib/module/scroll/scrollable.web.js +65 -0
  16. package/lib/module/scroll/scrollable.web.js.map +1 -0
  17. package/lib/module/scroll/store.js +84 -0
  18. package/lib/module/scroll/store.js.map +1 -0
  19. package/lib/module/scroll/types.js +4 -0
  20. package/lib/module/scroll/types.js.map +1 -0
  21. package/lib/typescript/commonjs/scroll/index.d.ts +27 -0
  22. package/lib/typescript/commonjs/scroll/index.d.ts.map +1 -0
  23. package/lib/typescript/commonjs/scroll/index.web.d.ts +26 -0
  24. package/lib/typescript/commonjs/scroll/index.web.d.ts.map +1 -0
  25. package/lib/typescript/commonjs/scroll/scrollable.web.d.ts +29 -0
  26. package/lib/typescript/commonjs/scroll/scrollable.web.d.ts.map +1 -0
  27. package/lib/typescript/commonjs/scroll/store.d.ts +46 -0
  28. package/lib/typescript/commonjs/scroll/store.d.ts.map +1 -0
  29. package/lib/typescript/commonjs/scroll/types.d.ts +46 -0
  30. package/lib/typescript/commonjs/scroll/types.d.ts.map +1 -0
  31. package/lib/typescript/module/scroll/index.d.ts +27 -0
  32. package/lib/typescript/module/scroll/index.d.ts.map +1 -0
  33. package/lib/typescript/module/scroll/index.web.d.ts +26 -0
  34. package/lib/typescript/module/scroll/index.web.d.ts.map +1 -0
  35. package/lib/typescript/module/scroll/scrollable.web.d.ts +29 -0
  36. package/lib/typescript/module/scroll/scrollable.web.d.ts.map +1 -0
  37. package/lib/typescript/module/scroll/store.d.ts +46 -0
  38. package/lib/typescript/module/scroll/store.d.ts.map +1 -0
  39. package/lib/typescript/module/scroll/types.d.ts +46 -0
  40. package/lib/typescript/module/scroll/types.d.ts.map +1 -0
  41. package/package.json +22 -1
  42. package/src/__tests__/scroll-native.test.ts +25 -0
  43. package/src/__tests__/scroll-store.test.ts +85 -0
  44. package/src/__tests__/scroll-web.test.tsx +325 -0
  45. package/src/scroll/index.ts +47 -0
  46. package/src/scroll/index.web.tsx +253 -0
  47. package/src/scroll/scrollable.web.ts +92 -0
  48. package/src/scroll/store.ts +84 -0
  49. package/src/scroll/types.ts +48 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Native variant of the scroll-restoration primitive — a deliberate no-op.
3
+ *
4
+ * React Navigation's native-stack keeps every screen mounted while it is in the
5
+ * stack, so a list's scroll position survives a push/pop for free. There is
6
+ * nothing to save or restore. We still ship the full API surface (provider +
7
+ * hook) so consumers write one set of call sites that compile and run on every
8
+ * platform; on native the provider just renders its children and the hook does
9
+ * nothing.
10
+ *
11
+ * Web bundlers select `./index.web` via the `"browser"` export condition in
12
+ * `package.json`; native bundlers fall through to this file.
13
+ */
14
+ import type { ReactElement } from 'react';
15
+ import type {
16
+ ScrollRestorationProviderProps,
17
+ ScrollRestorationTarget,
18
+ UseScrollRestorationOptions,
19
+ } from './types';
20
+
21
+ export type {
22
+ ScrollableHandle,
23
+ ScrollRestorationProviderProps,
24
+ ScrollRestorationTarget,
25
+ UseScrollRestorationOptions,
26
+ } from './types';
27
+
28
+ /**
29
+ * No-op provider. Renders children unchanged — native scroll persistence is
30
+ * handled by the navigator, so no per-route state is kept.
31
+ */
32
+ export function ScrollRestorationProvider({
33
+ children,
34
+ }: ScrollRestorationProviderProps): ReactElement {
35
+ return children as ReactElement;
36
+ }
37
+
38
+ /**
39
+ * No-op hook. Accepts the same arguments as the web implementation so call
40
+ * sites are identical across platforms.
41
+ */
42
+ export function useScrollRestoration(
43
+ _target: ScrollRestorationTarget,
44
+ _options?: UseScrollRestorationOptions,
45
+ ): void {
46
+ // Intentionally empty: native-stack already preserves scroll position.
47
+ }
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Web variant of the scroll-restoration primitive.
3
+ *
4
+ * Mirrors the proven Bluesky pattern (`history.scrollRestoration = 'manual'`
5
+ * plus an in-memory `Map<routeKey, offset>`) with two deliberate differences
6
+ * forced by Oxy's layouts and the behaviour of React Navigation's web stack:
7
+ *
8
+ * 1. Bluesky restores the WINDOW scroller, whereas Oxy apps keep multi-column
9
+ * layouts whose feed scrolls an INNER container. So we restore the offset
10
+ * of a caller-registered scrollable (a ref to an element / RN scroll
11
+ * component, or the `'window'` sentinel), keyed by the active route.
12
+ *
13
+ * 2. React Navigation's web stack HIDES the background screen on push. While
14
+ * hidden, the previous screen's scroll container collapses
15
+ * (`scrollHeight === clientHeight`) and the navigator forces its
16
+ * `scrollTop` to 0. The screen is NOT unmounted, so a virtualized list
17
+ * (e.g. FlashList) keeps its rows but re-lays them out over SEVERAL frames
18
+ * once the screen is re-shown. Two problems follow, both handled here:
19
+ *
20
+ * (a) A blur-time read of `scrollTop` returns the navigator's forced 0,
21
+ * not the user's real offset — saving it would clobber the good
22
+ * value. We therefore persist the last offset OBSERVED by the live
23
+ * scroll listener, never a fresh read taken at blur time.
24
+ *
25
+ * (b) A single-frame restore writes `scrollTop` while the list is still
26
+ * collapsed; the write is clamped to 0 and never re-applied once the
27
+ * content grows. We therefore re-apply the target offset across a
28
+ * bounded run of animation frames, stopping as soon as the write
29
+ * sticks (the content has grown tall enough) or a small frame cap is
30
+ * reached.
31
+ *
32
+ * Native bundlers use `./index.ts` (a no-op); web bundlers select this file via
33
+ * the `"browser"` export condition in `package.json`.
34
+ */
35
+ import { createContext, useCallback, useContext, useMemo, useRef } from 'react';
36
+ import { useFocusEffect, useRoute } from '@react-navigation/native';
37
+
38
+ import { createScroller } from './scrollable.web';
39
+ import { ScrollOffsetStore, deriveScrollKey } from './store';
40
+ import type {
41
+ ScrollRestorationProviderProps,
42
+ ScrollRestorationTarget,
43
+ UseScrollRestorationOptions,
44
+ } from './types';
45
+
46
+ export type {
47
+ ScrollableHandle,
48
+ ScrollRestorationProviderProps,
49
+ ScrollRestorationTarget,
50
+ UseScrollRestorationOptions,
51
+ } from './types';
52
+
53
+ const ScrollOffsetContext = createContext<ScrollOffsetStore | null>(null);
54
+ ScrollOffsetContext.displayName = 'BloomScrollOffsetContext';
55
+
56
+ /**
57
+ * Maximum number of animation frames the focus restore will re-apply the saved
58
+ * offset before giving up. A virtualized list re-lays out its rows over a
59
+ * handful of frames after its screen is re-shown; ~30 frames (≈0.5s at 60fps)
60
+ * is comfortably longer than any observed relayout while staying short enough
61
+ * that the loop never lingers as a perceptible cost. The loop normally exits
62
+ * far earlier — as soon as the write sticks.
63
+ */
64
+ const RESTORE_FRAME_CAP = 30;
65
+
66
+ /**
67
+ * Tolerance (in CSS pixels) for considering a restore "stuck". After writing
68
+ * `element.scrollTop = target`, the browser may clamp it to the current
69
+ * `scrollHeight - clientHeight`; if the resulting offset is within this many
70
+ * pixels of the target we treat the restore as complete. Sub-pixel rounding and
71
+ * fractional device-pixel ratios make an exact equality check unreliable.
72
+ */
73
+ const RESTORE_STICK_TOLERANCE_PX = 2;
74
+
75
+ /**
76
+ * Switch the browser to manual scroll restoration exactly once per document.
77
+ *
78
+ * The browser's default `'auto'` restoration fights our manual restore on
79
+ * Back/Forward navigations. Doing this at module scope (guarded for SSR) means
80
+ * it is set before any provider mounts, matching Bluesky's module-level call.
81
+ */
82
+ if (typeof history !== 'undefined' && 'scrollRestoration' in history) {
83
+ history.scrollRestoration = 'manual';
84
+ }
85
+
86
+ /**
87
+ * Holds the per-route offset map for the subtree. One provider near the app
88
+ * root is enough; the store lives for the document's lifetime so offsets
89
+ * survive navigating away and back (including browser Back/Forward).
90
+ */
91
+ export function ScrollRestorationProvider({
92
+ children,
93
+ }: ScrollRestorationProviderProps) {
94
+ const store = useMemo(() => new ScrollOffsetStore(), []);
95
+ return (
96
+ <ScrollOffsetContext.Provider value={store}>
97
+ {children}
98
+ </ScrollOffsetContext.Provider>
99
+ );
100
+ }
101
+
102
+ function useScrollOffsetStore(): ScrollOffsetStore {
103
+ const store = useContext(ScrollOffsetContext);
104
+ if (store === null) {
105
+ throw new Error(
106
+ 'useScrollRestoration must be used within a <ScrollRestorationProvider>.',
107
+ );
108
+ }
109
+ return store;
110
+ }
111
+
112
+ /**
113
+ * Preserve and restore the scroll offset of `target` across navigation, keyed
114
+ * by the active route (plus an optional `options.key` for routes that host
115
+ * multiple scrollables).
116
+ *
117
+ * Behaviour (web):
118
+ * - On every scroll while the screen is focused, the current offset is recorded
119
+ * in memory and persisted. This live stream of saves is the source of truth.
120
+ * - On focus, the saved offset is re-applied across a bounded run of animation
121
+ * frames, stopping as soon as the write sticks (the list has re-rendered its
122
+ * rows and grown tall enough) or {@link RESTORE_FRAME_CAP} is reached. A
123
+ * saved offset of 0 is a no-op (nothing to restore).
124
+ * - On blur, the LAST OBSERVED offset is persisted as a final safety net — not
125
+ * a fresh `scrollTop` read, which the navigator may already have forced to 0
126
+ * while collapsing the hidden screen.
127
+ */
128
+ export function useScrollRestoration(
129
+ target: ScrollRestorationTarget,
130
+ options?: UseScrollRestorationOptions,
131
+ ): void {
132
+ const store = useScrollOffsetStore();
133
+ const route = useRoute();
134
+ const subKey = options?.key;
135
+ const enabled = options?.enabled ?? true;
136
+
137
+ const scrollKey = deriveScrollKey(route.key, subKey);
138
+
139
+ // Keep the latest target/enabled/key in refs so the focus effect can read
140
+ // them without being re-subscribed on every render.
141
+ const targetRef = useRef(target);
142
+ targetRef.current = target;
143
+ const enabledRef = useRef(enabled);
144
+ enabledRef.current = enabled;
145
+ const scrollKeyRef = useRef(scrollKey);
146
+ scrollKeyRef.current = scrollKey;
147
+
148
+ useFocusEffect(
149
+ // The effect identity is intentionally stable across renders: it reads all
150
+ // varying inputs from refs. React Navigation re-runs it on each focus.
151
+ useCallback(
152
+ () => {
153
+ const key = scrollKeyRef.current;
154
+ if (!enabledRef.current || key === null) return undefined;
155
+
156
+ const scroller = createScroller(targetRef.current);
157
+ const element =
158
+ targetRef.current === 'window'
159
+ ? (typeof window !== 'undefined' ? window : null)
160
+ : resolveScrollEventTarget(targetRef.current);
161
+
162
+ // The last offset the live scroll listener observed for this focus
163
+ // session. This — not a blur-time `getOffset()` — is what we persist on
164
+ // blur, because by blur time the navigator may have collapsed the
165
+ // hidden screen and forced its `scrollTop` to 0 (bug A). `null` means
166
+ // the user never scrolled this session, so there is nothing newer to
167
+ // persist than what the scroll listener already saved live.
168
+ let lastObservedOffset: number | null = null;
169
+
170
+ const save = () => {
171
+ const currentKey = scrollKeyRef.current;
172
+ if (!enabledRef.current || currentKey === null) return;
173
+ const offset = scroller.getOffset();
174
+ // Ignore a spurious 0 produced by the navigator collapsing a hidden
175
+ // background screen: while collapsed the container cannot scroll, so
176
+ // its `scrollTop` is forced to 0. Persisting it would clobber the
177
+ // good offset recorded by earlier live saves (bug A). A genuine
178
+ // scroll-to-top keeps the container scrollable and is saved normally.
179
+ if (offset === 0 && !scroller.canScroll()) return;
180
+ lastObservedOffset = offset;
181
+ store.save(currentKey, offset);
182
+ };
183
+
184
+ // Restore across a bounded run of frames. A freshly re-shown
185
+ // virtualized list re-lays out its rows over several frames, so a
186
+ // single write while it is still collapsed would be clamped to 0 and
187
+ // never re-applied (bug B). We re-apply each frame until the write
188
+ // sticks or the frame cap is hit.
189
+ const targetOffset = store.read(key);
190
+ let rafId: number | null = null;
191
+
192
+ if (targetOffset > 0 && typeof requestAnimationFrame !== 'undefined') {
193
+ let framesLeft = RESTORE_FRAME_CAP;
194
+ const applyOffset = () => {
195
+ rafId = null;
196
+ scroller.setOffset(targetOffset);
197
+ framesLeft -= 1;
198
+ // Stop once the write took effect (content grew tall enough) or we
199
+ // exhaust the frame budget. `getOffset` re-reads the clamped value.
200
+ const reached =
201
+ Math.abs(scroller.getOffset() - targetOffset) <=
202
+ RESTORE_STICK_TOLERANCE_PX;
203
+ if (!reached && framesLeft > 0) {
204
+ rafId = requestAnimationFrame(applyOffset);
205
+ }
206
+ };
207
+ rafId = requestAnimationFrame(applyOffset);
208
+ }
209
+
210
+ element?.addEventListener('scroll', save, { passive: true });
211
+
212
+ return () => {
213
+ if (rafId !== null) cancelAnimationFrame(rafId);
214
+ element?.removeEventListener('scroll', save);
215
+ // Final capture on blur: persist the last offset the scroll listener
216
+ // OBSERVED, never a fresh read (which the navigator may have forced
217
+ // to 0 while collapsing the hidden screen). When the user never
218
+ // scrolled this session there is nothing newer to persist than the
219
+ // live saves already recorded.
220
+ if (lastObservedOffset !== null) {
221
+ const currentKey = scrollKeyRef.current;
222
+ if (enabledRef.current && currentKey !== null) {
223
+ store.save(currentKey, lastObservedOffset);
224
+ }
225
+ }
226
+ };
227
+ },
228
+ [store],
229
+ ),
230
+ );
231
+ }
232
+
233
+ /**
234
+ * Resolve the EventTarget to listen for `scroll` on. RNW scroll components
235
+ * expose `getScrollableNode()`; raw refs may hold the DOM node directly.
236
+ */
237
+ function resolveScrollEventTarget(
238
+ target: Exclude<ScrollRestorationTarget, 'window'>,
239
+ ): EventTarget | null {
240
+ const current = (target as { current: unknown }).current;
241
+ if (current == null) return null;
242
+ if (typeof EventTarget !== 'undefined' && current instanceof EventTarget) {
243
+ return current;
244
+ }
245
+ const handle = current as { getScrollableNode?: () => unknown };
246
+ if (typeof handle.getScrollableNode === 'function') {
247
+ const node = handle.getScrollableNode();
248
+ if (typeof EventTarget !== 'undefined' && node instanceof EventTarget) {
249
+ return node;
250
+ }
251
+ }
252
+ return null;
253
+ }
@@ -0,0 +1,92 @@
1
+ import type { ScrollableHandle, ScrollRestorationTarget } from './types';
2
+
3
+ /**
4
+ * A normalized read/write interface over whatever the caller registered, so
5
+ * the hook does not branch on target shape. All methods are safe no-ops when
6
+ * the underlying element is not yet (or no longer) attached.
7
+ */
8
+ export interface ResolvedScroller {
9
+ getOffset: () => number;
10
+ setOffset: (offset: number) => void;
11
+ /**
12
+ * Whether the scroll container can currently hold a non-zero offset, i.e.
13
+ * its content is taller than its viewport (`scrollHeight > clientHeight`).
14
+ *
15
+ * React Navigation's web stack collapses a hidden background screen so its
16
+ * content height drops to the viewport height; while collapsed the container
17
+ * cannot be scrolled and its `scrollTop` is forced to 0. The hook uses this
18
+ * to ignore a spurious 0 read coming from a collapsed container rather than
19
+ * persisting it over a previously-saved good offset. The `'window'` scroller
20
+ * is never collapsed by the navigator, so it always reports `true`.
21
+ */
22
+ canScroll: () => boolean;
23
+ }
24
+
25
+ function isElement(value: unknown): value is HTMLElement {
26
+ return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement;
27
+ }
28
+
29
+ function hasGetScrollableNode(
30
+ value: unknown,
31
+ ): value is Required<Pick<ScrollableHandle, 'getScrollableNode'>> {
32
+ return (
33
+ typeof value === 'object' &&
34
+ value !== null &&
35
+ typeof (value as ScrollableHandle).getScrollableNode === 'function'
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Resolve the live DOM element a target currently points at, or `null`.
41
+ *
42
+ * RNW scroll components expose `getScrollableNode()`; plain refs may hold the
43
+ * DOM node directly. We never cache the node because RNW can swap it across
44
+ * renders — we re-resolve on every read/write.
45
+ */
46
+ function resolveElement(target: ScrollRestorationTarget): HTMLElement | null {
47
+ if (target === 'window') return null;
48
+
49
+ const current = (target as { current: unknown }).current;
50
+ if (current == null) return null;
51
+
52
+ if (isElement(current)) return current;
53
+
54
+ if (hasGetScrollableNode(current)) {
55
+ const node = current.getScrollableNode();
56
+ if (isElement(node)) return node;
57
+ }
58
+
59
+ return null;
60
+ }
61
+
62
+ /**
63
+ * Build a {@link ResolvedScroller} for a target. The window sentinel reads and
64
+ * writes the document scroller; everything else operates on the resolved
65
+ * element's `scrollTop`.
66
+ */
67
+ export function createScroller(target: ScrollRestorationTarget): ResolvedScroller {
68
+ if (target === 'window') {
69
+ return {
70
+ getOffset: () => (typeof window === 'undefined' ? 0 : window.scrollY),
71
+ setOffset: (offset) => {
72
+ if (typeof window !== 'undefined') window.scrollTo(0, offset);
73
+ },
74
+ canScroll: () => true,
75
+ };
76
+ }
77
+
78
+ return {
79
+ getOffset: () => {
80
+ const element = resolveElement(target);
81
+ return element ? element.scrollTop : 0;
82
+ },
83
+ setOffset: (offset) => {
84
+ const element = resolveElement(target);
85
+ if (element) element.scrollTop = offset;
86
+ },
87
+ canScroll: () => {
88
+ const element = resolveElement(target);
89
+ return element ? element.scrollHeight > element.clientHeight : false;
90
+ },
91
+ };
92
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Pure, platform-agnostic core of the scroll-restoration primitive.
3
+ *
4
+ * This file deliberately contains NO React and NO DOM/native imports so the
5
+ * logic can be unit-tested in isolation and shared verbatim by the web and
6
+ * native barrels. The web barrel drives it with real scroll offsets; the
7
+ * native barrel never instantiates it (native-stack already restores scroll).
8
+ */
9
+
10
+ /**
11
+ * Separator between the navigation route key and an optional caller-supplied
12
+ * sub-key. A route may host more than one independently-scrolling list (e.g.
13
+ * a tabbed profile screen), so each list contributes its own sub-key.
14
+ *
15
+ * `\0` (NUL) can never appear in a React Navigation route key or in a
16
+ * developer-authored sub-key, so it is collision-free as a delimiter. It is
17
+ * written as an escape sequence (not a literal byte) so the source stays
18
+ * text-diffable.
19
+ */
20
+ const COMPOSITE_KEY_SEPARATOR = '\0';
21
+
22
+ /**
23
+ * Derive the storage key for a scrollable from its owning route key and an
24
+ * optional caller sub-key.
25
+ *
26
+ * - `routeKey` is React Navigation's stable per-route `route.key`.
27
+ * - `subKey` distinguishes multiple scrollables that share a single route.
28
+ *
29
+ * Returns `null` when there is no route key to anchor against (the scrollable
30
+ * is not inside a navigator), which the caller treats as "do not persist".
31
+ */
32
+ export function deriveScrollKey(
33
+ routeKey: string | undefined,
34
+ subKey?: string,
35
+ ): string | null {
36
+ if (!routeKey) return null;
37
+ if (subKey === undefined || subKey === '') return routeKey;
38
+ return `${routeKey}${COMPOSITE_KEY_SEPARATOR}${subKey}`;
39
+ }
40
+
41
+ /**
42
+ * In-memory map of `scrollKey -> last-known scroll offset`.
43
+ *
44
+ * Mirrors the semantics of Bluesky's `Map<screenKey, scrollY>`: offsets live
45
+ * only for the lifetime of the document/session. We never persist them — a
46
+ * full reload should start at the top — and we never auto-evict, because a
47
+ * route can be revisited via browser Forward/Back long after it blurred.
48
+ */
49
+ export class ScrollOffsetStore {
50
+ private readonly offsets = new Map<string, number>();
51
+
52
+ /** Persist the offset for a key. A negative offset is clamped to 0. */
53
+ save(key: string, offset: number): void {
54
+ this.offsets.set(key, offset > 0 ? offset : 0);
55
+ }
56
+
57
+ /**
58
+ * Read the saved offset for a key. Returns `0` when nothing was saved, so
59
+ * callers can restore unconditionally (an unseen list restores to the top).
60
+ */
61
+ read(key: string): number {
62
+ return this.offsets.get(key) ?? 0;
63
+ }
64
+
65
+ /** Whether an offset was ever saved for this key. */
66
+ has(key: string): boolean {
67
+ return this.offsets.has(key);
68
+ }
69
+
70
+ /** Drop a saved offset (e.g. when a route is permanently removed). */
71
+ forget(key: string): void {
72
+ this.offsets.delete(key);
73
+ }
74
+
75
+ /** Clear every saved offset. Primarily for tests and full resets. */
76
+ clear(): void {
77
+ this.offsets.clear();
78
+ }
79
+
80
+ /** Number of distinct keys currently tracked. */
81
+ get size(): number {
82
+ return this.offsets.size;
83
+ }
84
+ }
@@ -0,0 +1,48 @@
1
+ import type { ReactNode, RefObject } from 'react';
2
+
3
+ /**
4
+ * Anything `useScrollRestoration` knows how to read/write a vertical scroll
5
+ * offset from. The hook accepts a ref to one of these:
6
+ *
7
+ * - a React Native `ScrollView` / `FlatList` ref (which on web is backed by a
8
+ * DOM node and exposes `getScrollableNode()`),
9
+ * - a raw DOM element ref (when a component renders its own scroll container),
10
+ * - the literal `'window'` sentinel, for the rare layout where the list IS the
11
+ * window scroller (matches Bluesky's default).
12
+ *
13
+ * Native never reads any of these — the native hook is a no-op — so the type is
14
+ * intentionally permissive rather than coupled to a specific RN class.
15
+ */
16
+ export interface ScrollableHandle {
17
+ /** Imperative scroll API exposed by RN scrollables. */
18
+ scrollTo?: (options: { x?: number; y?: number; animated?: boolean }) => void;
19
+ /** Web/RNW path: returns the underlying DOM node. */
20
+ getScrollableNode?: () => unknown;
21
+ }
22
+
23
+ /**
24
+ * The accepted ref shapes. `'window'` is a sentinel for the document scroller.
25
+ */
26
+ export type ScrollRestorationTarget =
27
+ | RefObject<ScrollableHandle | null>
28
+ | RefObject<unknown>
29
+ | 'window';
30
+
31
+ export interface UseScrollRestorationOptions {
32
+ /**
33
+ * Sub-key to disambiguate multiple scrollables that live on the same route
34
+ * (e.g. the tabs of a profile screen). Combined with the active route key to
35
+ * form the storage key. Omit when a route has a single scrollable.
36
+ */
37
+ key?: string;
38
+ /**
39
+ * When `false`, the hook is inert (saves and restores are skipped). Useful to
40
+ * gate restoration behind a feature flag without changing call sites.
41
+ * Defaults to `true`.
42
+ */
43
+ enabled?: boolean;
44
+ }
45
+
46
+ export interface ScrollRestorationProviderProps {
47
+ children: ReactNode;
48
+ }