@symbiote-native/react 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/build/components/activity-indicator-props.d.ts +4 -0
- package/build/components/{button.d.ts → button-props.d.ts} +0 -2
- package/build/components/button-props.js +1 -0
- package/build/components/flat-list/index.js +3 -3
- package/build/components/image/image-props.d.ts +4 -0
- package/build/components/image/image-props.js +1 -0
- package/build/components/image-background-props.d.ts +9 -0
- package/build/components/image-background-props.js +1 -0
- package/build/components/input-accessory-view-props.d.ts +10 -0
- package/build/components/input-accessory-view-props.js +1 -0
- package/build/components/keyboard-avoiding-view/index.js +10 -5
- package/build/components/modal/index.js +3 -3
- package/build/components/pressable/{index.d.ts → pressable-props.d.ts} +6 -5
- package/build/components/pressable/pressable-props.js +1 -0
- package/build/components/{refresh-control/index.d.ts → refresh-control-props.d.ts} +3 -3
- package/build/components/refresh-control-props.js +1 -0
- package/build/components/safe-area-view-props.d.ts +11 -0
- package/build/components/safe-area-view-props.js +1 -0
- package/build/components/scroll-view/{shared.d.ts → scroll-view-props.d.ts} +4 -26
- package/build/components/scroll-view/scroll-view-props.js +1 -0
- package/build/components/switch/switch-props.d.ts +4 -0
- package/build/components/switch/switch-props.js +1 -0
- package/build/components/text-input/text-input-props.d.ts +4 -0
- package/build/components/text-input/text-input-props.js +1 -0
- package/build/components/touchable/touchable-props.d.ts +19 -0
- package/build/components/touchable/touchable-props.js +1 -0
- package/build/components/touchable-native-feedback/touchable-native-feedback-props.d.ts +9 -0
- package/build/components/touchable-native-feedback/touchable-native-feedback-props.js +1 -0
- package/build/components/touchable-without-feedback/touchable-without-feedback-props.d.ts +7 -0
- package/build/components/touchable-without-feedback/touchable-without-feedback-props.js +1 -0
- package/build/components/virtualized-list/index.js +90 -41
- package/build/components.d.ts +1 -2
- package/build/components.js +5 -19
- package/build/create-portal/index.js +1 -1
- package/build/create-tunnel/index.js +1 -1
- package/build/descriptor-to-react/index.js +1 -1
- package/build/host-config.js +23 -12
- package/build/index.d.ts +23 -28
- package/build/index.js +14 -14
- package/build/jsx-dev-runtime.d.ts +3 -0
- package/build/jsx-dev-runtime.js +10 -0
- package/build/jsx-namespace.type-check.d.ts +1 -0
- package/build/jsx-namespace.type-check.js +7 -0
- package/build/jsx-runtime.d.ts +62 -0
- package/build/jsx-runtime.js +1 -0
- package/build/modules/animated/index.d.ts +29 -20
- package/build/modules/animated/index.js +16 -22
- package/build/modules/image/index.d.ts +3 -0
- package/build/modules/image/index.js +14 -0
- package/build/register.d.ts +1 -0
- package/build/register.js +15 -0
- package/metro-css-parser.cjs +2 -1
- package/package.json +12 -8
- package/build/components/activity-indicator/index.android.d.ts +0 -3
- package/build/components/activity-indicator/index.android.js +0 -17
- package/build/components/activity-indicator/index.d.ts +0 -1
- package/build/components/activity-indicator/index.ios.d.ts +0 -3
- package/build/components/activity-indicator/index.ios.js +0 -16
- package/build/components/activity-indicator/index.js +0 -4
- package/build/components/activity-indicator/shared.d.ts +0 -6
- package/build/components/activity-indicator/shared.js +0 -22
- package/build/components/button.js +0 -42
- package/build/components/image/index.d.ts +0 -9
- package/build/components/image/index.js +0 -28
- package/build/components/image-background/index.d.ts +0 -10
- package/build/components/image-background/index.js +0 -46
- package/build/components/input-accessory-view/index.d.ts +0 -11
- package/build/components/input-accessory-view/index.js +0 -19
- package/build/components/pressable/index.js +0 -112
- package/build/components/refresh-control/index.js +0 -21
- package/build/components/safe-area-view/index.d.ts +0 -12
- package/build/components/safe-area-view/index.js +0 -18
- package/build/components/scroll-view/index.android.d.ts +0 -3
- package/build/components/scroll-view/index.android.js +0 -61
- package/build/components/scroll-view/index.d.ts +0 -1
- package/build/components/scroll-view/index.ios.d.ts +0 -3
- package/build/components/scroll-view/index.ios.js +0 -29
- package/build/components/scroll-view/index.js +0 -4
- package/build/components/scroll-view/shared.js +0 -240
- package/build/components/scroll-view/sticky-header.d.ts +0 -18
- package/build/components/scroll-view/sticky-header.js +0 -227
- package/build/components/switch/index.android.d.ts +0 -3
- package/build/components/switch/index.android.js +0 -18
- package/build/components/switch/index.d.ts +0 -1
- package/build/components/switch/index.ios.d.ts +0 -3
- package/build/components/switch/index.ios.js +0 -16
- package/build/components/switch/index.js +0 -6
- package/build/components/switch/shared.d.ts +0 -9
- package/build/components/switch/shared.js +0 -60
- package/build/components/text-input/index.d.ts +0 -50
- package/build/components/text-input/index.js +0 -180
- package/build/components/touchable/index.d.ts +0 -22
- package/build/components/touchable/index.js +0 -165
- package/build/components/touchable-native-feedback/index.d.ts +0 -18
- package/build/components/touchable-native-feedback/index.js +0 -32
- package/build/jsx.d.ts +0 -18
- package/build/state-style.d.ts +0 -1
- package/build/state-style.js +0 -13
- /package/build/{jsx.js → components/activity-indicator-props.js} +0 -0
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type FC, type ReactNode } from 'react';
|
|
2
|
-
import { type ISymbioteEvent } from '@symbiote-native/engine';
|
|
3
|
-
import { type IAccessibilityProps, type IAriaProps } from '@symbiote-native/components';
|
|
4
|
-
import type { IStyleProp, IViewStyle } from '../../utils/styles';
|
|
5
|
-
export interface ISafeAreaViewProps extends IAccessibilityProps, IAriaProps {
|
|
6
|
-
style?: IStyleProp<IViewStyle>;
|
|
7
|
-
id?: string;
|
|
8
|
-
className?: string;
|
|
9
|
-
children?: ReactNode;
|
|
10
|
-
onLayout?: (event: ISymbioteEvent) => void;
|
|
11
|
-
}
|
|
12
|
-
export declare const SafeAreaView: FC<ISafeAreaViewProps>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// SafeAreaView primitive. A plain view whose native side insets its children to
|
|
2
|
-
// the safe area (notch, rounded corners, system bars). There is no JS-side
|
|
3
|
-
// translation; RN just renders the native RCTSafeAreaView and lets the host do
|
|
4
|
-
// the inset math, so this maps style + children straight onto the intrinsic.
|
|
5
|
-
import { createElement } from 'react';
|
|
6
|
-
import { dlog } from '@symbiote-native/engine';
|
|
7
|
-
import { resolveAccessibilityProps, } from '@symbiote-native/components';
|
|
8
|
-
export const SafeAreaView = rawProps => {
|
|
9
|
-
// Owns its host element (symbiote-safe-area-view), so it folds aria/role here;
|
|
10
|
-
// the resolved accessibility* surface rides the node via `...accessibilityRest`.
|
|
11
|
-
const props = resolveAccessibilityProps(rawProps);
|
|
12
|
-
const { style, children, onLayout, ...accessibilityRest } = props;
|
|
13
|
-
dlog('SafeAreaView -> SafeAreaView');
|
|
14
|
-
const nodeProps = { ...accessibilityRest, style };
|
|
15
|
-
if (onLayout !== undefined)
|
|
16
|
-
nodeProps.onLayout = onLayout;
|
|
17
|
-
return createElement('symbiote-safe-area-view', nodeProps, children);
|
|
18
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type IScrollViewHandle, type IScrollViewProps } from './shared';
|
|
2
|
-
export type { IScrollViewProps, IScrollViewHandle } from './shared';
|
|
3
|
-
export declare const ScrollView: import("react").ForwardRefExoticComponent<IScrollViewProps & import("react").RefAttributes<IScrollViewHandle>>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// ScrollView on Android: an Android ScrollView accepts only ONE child, so a RefreshControl
|
|
2
|
-
// can't be a sibling of the content the way iOS allows ("addViewAt: failed to insert view
|
|
3
|
-
// ... at index 1"). Instead the RefreshControl (AndroidSwipeRefreshLayout) WRAPS the
|
|
4
|
-
// scroll view, with the scroll view nested inside and nestedScrollEnabled so the inner
|
|
5
|
-
// scroll handles the gesture before the refresh parent, which mirrors RN's ScrollView.js
|
|
6
|
-
// android branch (cloneElement(refreshControl, {style}, <ScrollView nestedScrollEnabled
|
|
7
|
-
// style={flex:1}>{content}</ScrollView>)). Metro picks this on an Android host; no
|
|
8
|
-
// Platform.OS read.
|
|
9
|
-
import { cloneElement, createElement, forwardRef, useImperativeHandle, useRef, } from 'react';
|
|
10
|
-
import { dlog } from '@symbiote-native/engine';
|
|
11
|
-
import { buildScrollViewHandle, splitLayoutProps, } from '@symbiote-native/components';
|
|
12
|
-
import { usePreparedScrollView, useNativeStickyScrollAttach, } from './shared.js';
|
|
13
|
-
export const ScrollView = forwardRef((props, forwardedRef) => {
|
|
14
|
-
const { scrollViewIntrinsic, scrollViewBaseStyle, outerProps, style, layoutSplitStyle, content, refreshControl, scrollAnimatedValue, nativeStickyAvailable, } = usePreparedScrollView(props);
|
|
15
|
-
// The node ref backs the imperative handle; it attaches to the inner scroll-view element
|
|
16
|
-
// (the wrap shape leaves the scroll view as the command target, not the RefreshControl).
|
|
17
|
-
const ref = useRef(null);
|
|
18
|
-
// Lazy getter, not the ref itself: the node is null until the element commits, so the handle
|
|
19
|
-
// must read ref.current on each command, an eager capture would freeze null.
|
|
20
|
-
useImperativeHandle(forwardedRef, () => buildScrollViewHandle(() => ref.current), []);
|
|
21
|
-
// Drive the sticky scroll value on the native UI thread (RN attachNativeEvent). No-op on a
|
|
22
|
-
// host without the native animated module. The JS sticky path stays in effect.
|
|
23
|
-
useNativeStickyScrollAttach(ref, scrollAnimatedValue, nativeStickyAvailable);
|
|
24
|
-
dlog('ScrollView.ANDROID refreshControl=' +
|
|
25
|
-
(refreshControl === undefined ? 'NONE(1child)' : 'WRAP'));
|
|
26
|
-
if (refreshControl === undefined) {
|
|
27
|
-
// Base style (flexDirection: row for horizontal) under user style; undefined base
|
|
28
|
-
// (vertical) passes the user style through unchanged.
|
|
29
|
-
const scrollStyle = scrollViewBaseStyle
|
|
30
|
-
? [scrollViewBaseStyle, style]
|
|
31
|
-
: style;
|
|
32
|
-
return createElement(scrollViewIntrinsic, { ...outerProps, style: scrollStyle, ref }, content);
|
|
33
|
-
}
|
|
34
|
-
// RN splits the flattened style across the two boxes (ScrollView.js android branch):
|
|
35
|
-
// LAYOUT props (margin/flex/size/position/transform/gap/…) drive the outer
|
|
36
|
-
// AndroidSwipeRefreshLayout frame; VISUAL props (background/padding/border/opacity/…) paint
|
|
37
|
-
// the inner scroll view. So the wrapper carries `outer`, and the inner scroll view its base
|
|
38
|
-
// (flexDirection/overflow) plus the visual `inner` composed over it, NOT a hardcoded flex:1
|
|
39
|
-
// that would override an explicit user height/width.
|
|
40
|
-
//
|
|
41
|
-
// layoutSplitStyle (not style): a class-only layout prop (flex/height/gap/…) is invisible to
|
|
42
|
-
// `style` (it never carries the resolved `className` value), so splitting on `style` alone
|
|
43
|
-
// starves the wrapper of its layout style and it collapses to nothing. layoutSplitStyle is
|
|
44
|
-
// `style` merged with the resolved className style (see usePreparedScrollView).
|
|
45
|
-
const { outer: outerStyle, inner: innerStyle } = splitLayoutProps(layoutSplitStyle);
|
|
46
|
-
const scrollStyle = scrollViewBaseStyle
|
|
47
|
-
? [scrollViewBaseStyle, innerStyle]
|
|
48
|
-
: innerStyle;
|
|
49
|
-
// className is stripped from the spread here: layoutSplitStyle already folded its resolved
|
|
50
|
-
// value into `outer`/`inner` above, so forwarding the raw prop too would re-apply its LAYOUT
|
|
51
|
-
// half onto the inner scroll view a second time (on top of the outer wrapper).
|
|
52
|
-
const { className: _classNameAppliedViaSplit, ...innerOuterProps } = outerProps;
|
|
53
|
-
const scrollView = createElement(scrollViewIntrinsic, {
|
|
54
|
-
...innerOuterProps,
|
|
55
|
-
style: scrollStyle,
|
|
56
|
-
nestedScrollEnabled: true,
|
|
57
|
-
ref,
|
|
58
|
-
}, content);
|
|
59
|
-
return cloneElement(refreshControl, { style: outerStyle }, scrollView);
|
|
60
|
-
});
|
|
61
|
-
ScrollView.displayName = 'ScrollView';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './index.ios';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type IScrollViewHandle, type IScrollViewProps } from './shared';
|
|
2
|
-
export type { IScrollViewProps, IScrollViewHandle } from './shared';
|
|
3
|
-
export declare const ScrollView: import("react").ForwardRefExoticComponent<IScrollViewProps & import("react").RefAttributes<IScrollViewHandle>>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// ScrollView (iOS): RefreshControl renders as a sibling BEFORE the content container, matching
|
|
2
|
-
// RN's ScrollView.js ({refreshControl}{contentContainer}). Also the base export
|
|
3
|
-
// (scroll-view.ts re-exports it) for headless / web.
|
|
4
|
-
import { createElement, forwardRef, useImperativeHandle, useRef } from 'react';
|
|
5
|
-
import { buildScrollViewHandle } from '@symbiote-native/components';
|
|
6
|
-
import { usePreparedScrollView, useNativeStickyScrollAttach, } from './shared.js';
|
|
7
|
-
export const ScrollView = forwardRef((props, forwardedRef) => {
|
|
8
|
-
const { scrollViewIntrinsic, scrollViewBaseStyle, outerProps, style, content, refreshControl, scrollAnimatedValue, nativeStickyAvailable, } = usePreparedScrollView(props);
|
|
9
|
-
// Backs the imperative handle; passing `ref` through createElement props binds it to the
|
|
10
|
-
// SymbioteNode below, as TextInput does.
|
|
11
|
-
const ref = useRef(null);
|
|
12
|
-
// Lazy getter: the node is null until commit, so the handle reads ref.current per call
|
|
13
|
-
// instead of capturing eagerly, which would freeze null.
|
|
14
|
-
useImperativeHandle(forwardedRef, () => buildScrollViewHandle(() => ref.current), []);
|
|
15
|
-
// Drives sticky scroll on the native UI thread (RN attachNativeEvent); no-ops without the
|
|
16
|
-
// native animated module, falling back to the JS sticky path.
|
|
17
|
-
useNativeStickyScrollAttach(ref, scrollAnimatedValue, nativeStickyAvailable);
|
|
18
|
-
// Base style stays under user style so an explicit value wins; undefined base (vertical)
|
|
19
|
-
// passes the user style through unchanged.
|
|
20
|
-
const scrollStyle = scrollViewBaseStyle
|
|
21
|
-
? [scrollViewBaseStyle, style]
|
|
22
|
-
: style;
|
|
23
|
-
const scrollProps = { ...outerProps, style: scrollStyle, ref };
|
|
24
|
-
if (refreshControl === undefined) {
|
|
25
|
-
return createElement(scrollViewIntrinsic, scrollProps, content);
|
|
26
|
-
}
|
|
27
|
-
return createElement(scrollViewIntrinsic, scrollProps, refreshControl, content);
|
|
28
|
-
});
|
|
29
|
-
ScrollView.displayName = 'ScrollView';
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// Base / default ScrollView: re-exports the iOS build. Metro overrides this with
|
|
2
|
-
// scroll-view.ios.ts / .android.ts on a real host; under tsx / tsc / web the host config
|
|
3
|
-
// resolves here. Filename is the selector, no Platform.OS read.
|
|
4
|
-
export * from './index.ios.js';
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// ScrollView: shared core. The Fabric tree is nested: the scroll view wraps a content
|
|
2
|
-
// view that holds the children (RN's own ScrollView.js shape). Building that content
|
|
3
|
-
// node, resolving decelerationRate, and the prop plumbing are platform-invariant and
|
|
4
|
-
// live here. What diverges is how a RefreshControl integrates: on iOS it is a
|
|
5
|
-
// CHILD of the scroll view (sibling of the content), on Android it WRAPS the scroll view
|
|
6
|
-
// (AndroidSwipeRefreshLayout is the parent, ScrollView nested inside). So the .ios/.android
|
|
7
|
-
// files assemble the final element; the filename selects, no Platform.OS read.
|
|
8
|
-
//
|
|
9
|
-
// The framework-agnostic pieces (decelerationRate, the per-axis intrinsics/base style, the
|
|
10
|
-
// content-size dedupe, the imperative handle, splitLayoutProps, the sticky math, the native
|
|
11
|
-
// scroll-attach) live in @symbiote-native/components; this file holds only the React
|
|
12
|
-
// lifecycle (refs/state/effects) and the element assembly that consumes them.
|
|
13
|
-
import { createElement, useEffect, useRef, useState, } from 'react';
|
|
14
|
-
import { AnimatedValue, dlog, event as animatedEvent, isClassNameValue, isNativeAnimatedAvailable, resolveClassName, } from '@symbiote-native/engine';
|
|
15
|
-
import { attachStickyScroll, didContentSizeChange, forwardScrollEvent, readLayoutDimension, resolveDecelerationRate, resolveScrollForwarding, selectScrollIntrinsics, } from '@symbiote-native/components';
|
|
16
|
-
import { resolveAccessibilityProps, } from '@symbiote-native/components';
|
|
17
|
-
import { wrapStickyHeaders, } from './sticky-header.js';
|
|
18
|
-
export function usePreparedScrollView(rawProps) {
|
|
19
|
-
// ScrollView forwards its outer props straight to the native scroll view (not a View
|
|
20
|
-
// wrapper), so it folds aria/role into accessibility* here before forwarding.
|
|
21
|
-
const props = resolveAccessibilityProps(rawProps);
|
|
22
|
-
const { style, className, contentContainerStyle, horizontal, decelerationRate, refreshControl, children, onContentSizeChange, stickyHeaderIndices, invertStickyHeaders, StickyHeaderComponent, onLayout, onScroll, scrollEventThrottle, ...outer } = props;
|
|
23
|
-
const isHorizontal = horizontal === true;
|
|
24
|
-
const hasStickyHeaders = stickyHeaderIndices !== undefined && stickyHeaderIndices.length > 0;
|
|
25
|
-
// A single AnimatedValue tracks the scroll offset and drives every sticky header's
|
|
26
|
-
// translateY (RN's _scrollAnimatedValue). Stable across renders via a ref so the headers'
|
|
27
|
-
// bindings survive re-renders. Allocated even when no sticky headers are present (hooks
|
|
28
|
-
// run unconditionally: usePreparedScrollView is always called at the top of the render body).
|
|
29
|
-
const scrollAnimatedValueRef = useRef(null);
|
|
30
|
-
if (scrollAnimatedValueRef.current === null)
|
|
31
|
-
scrollAnimatedValueRef.current = new AnimatedValue(0);
|
|
32
|
-
const scrollAnimatedValue = scrollAnimatedValueRef.current;
|
|
33
|
-
// Inverted sticky headers stick to the BOTTOM, so they need the viewport height (RN reads
|
|
34
|
-
// it in _handleLayout). Tracked here and fed back into the wrapped headers.
|
|
35
|
-
const [viewportHeight, setViewportHeight] = useState(undefined);
|
|
36
|
-
// Sticky-header cross-talk (RN ScrollView.js _headerLayoutYs, line 754): a child-index→measured-y
|
|
37
|
-
// map the parent keeps so each header can learn where the NEXT sticky header starts (its push-off
|
|
38
|
-
// collision point). The map lives in a ref (mutated imperatively from each header's onLayout, like
|
|
39
|
-
// RN's _onStickyHeaderLayout), and a state bump forces the re-render that feeds the freshly-recorded
|
|
40
|
-
// y forward into the previous header's nextHeaderLayoutY prop.
|
|
41
|
-
const headerLayoutYsRef = useRef(null);
|
|
42
|
-
if (headerLayoutYsRef.current === null)
|
|
43
|
-
headerLayoutYsRef.current = new Map();
|
|
44
|
-
const headerLayoutYs = headerLayoutYsRef.current;
|
|
45
|
-
// The mounted headers by child index (RN's _stickyHeaderRefs, ScrollView.js:750), so a fresh
|
|
46
|
-
// measurement reaches its predecessor directly.
|
|
47
|
-
const stickyHeaderRefsRef = useRef(null);
|
|
48
|
-
if (stickyHeaderRefsRef.current === null)
|
|
49
|
-
stickyHeaderRefsRef.current = new Map();
|
|
50
|
-
const stickyHeaderRefs = stickyHeaderRefsRef.current;
|
|
51
|
-
const onHeaderRef = (index, handle) => {
|
|
52
|
-
if (handle === null)
|
|
53
|
-
stickyHeaderRefs.delete(index);
|
|
54
|
-
else
|
|
55
|
-
stickyHeaderRefs.set(index, handle);
|
|
56
|
-
};
|
|
57
|
-
// Measurements waiting to be handed to their predecessors, flushed together (see below).
|
|
58
|
-
const pendingHeaderYsRef = useRef(null);
|
|
59
|
-
if (pendingHeaderYsRef.current === null)
|
|
60
|
-
pendingHeaderYsRef.current = new Map();
|
|
61
|
-
const pendingHeaderYs = pendingHeaderYsRef.current;
|
|
62
|
-
const flushScheduledRef = useRef(false);
|
|
63
|
-
const flushHeaderYs = () => {
|
|
64
|
-
flushScheduledRef.current = false;
|
|
65
|
-
if (stickyHeaderIndices === undefined)
|
|
66
|
-
return;
|
|
67
|
-
for (const [index, y] of pendingHeaderYs) {
|
|
68
|
-
const previousIndex = stickyHeaderIndices[stickyHeaderIndices.indexOf(index) - 1];
|
|
69
|
-
if (previousIndex === undefined)
|
|
70
|
-
continue;
|
|
71
|
-
stickyHeaderRefs.get(previousIndex)?.setNextHeaderY(y);
|
|
72
|
-
}
|
|
73
|
-
pendingHeaderYs.clear();
|
|
74
|
-
};
|
|
75
|
-
// RN _onStickyHeaderLayout (ScrollView.js:1136): record this header's y, then hand it to the
|
|
76
|
-
// PREVIOUS sticky header as its push-off collision point.
|
|
77
|
-
//
|
|
78
|
-
// The handoff is COALESCED rather than immediate, and that is the point. Cross-talk runs BACKWARDS
|
|
79
|
-
// (a header learns its collision point from the one after it), so a mount measures every header
|
|
80
|
-
// and walks the chain end to start. Pushing each value the moment it arrives makes every link its
|
|
81
|
-
// own update generation - a setState on the predecessor, whose effect setStates again - and React
|
|
82
|
-
// caps nested updates at 50: three headers go unnoticed, two hundred abort the app with "Maximum
|
|
83
|
-
// update depth exceeded", which reads like an infinite loop but is really depth. Draining on a
|
|
84
|
-
// microtask puts one burst of layouts into ONE render pass, so depth stops tracking header count.
|
|
85
|
-
const onHeaderLayoutY = (index, y) => {
|
|
86
|
-
if (headerLayoutYs.get(index) === y)
|
|
87
|
-
return;
|
|
88
|
-
headerLayoutYs.set(index, y);
|
|
89
|
-
dlog(`ScrollView sticky-header layoutY index=${index} y=${y}`);
|
|
90
|
-
pendingHeaderYs.set(index, y);
|
|
91
|
-
if (flushScheduledRef.current)
|
|
92
|
-
return;
|
|
93
|
-
flushScheduledRef.current = true;
|
|
94
|
-
void Promise.resolve().then(flushHeaderYs);
|
|
95
|
-
};
|
|
96
|
-
// A class-name string resolves through the shared registry before it reaches the
|
|
97
|
-
// framework-agnostic selector below, which only understands style objects/arrays.
|
|
98
|
-
const resolvedContentContainerStyle = typeof contentContainerStyle === 'string'
|
|
99
|
-
? resolveClassName(contentContainerStyle)
|
|
100
|
-
: contentContainerStyle;
|
|
101
|
-
// The per-axis intrinsics, base style, and content style come from the shared selector
|
|
102
|
-
// (@symbiote-native/components): on Android horizontal resolves to its own ViewManager, on iOS both
|
|
103
|
-
// map back to RCTScrollView; here we only pass the axis.
|
|
104
|
-
const { scrollViewIntrinsic, contentIntrinsic, scrollViewBaseStyle, contentStyle, } = selectScrollIntrinsics(isHorizontal, resolvedContentContainerStyle);
|
|
105
|
-
const outerProps = { ...outer };
|
|
106
|
-
// className is pulled out above (unlike the rest of `...outer`) so `layoutSplitStyle` below can
|
|
107
|
-
// resolve it eagerly; re-added here so the simple single-node paths (iOS, Android with no
|
|
108
|
-
// refreshControl) keep forwarding it raw, exactly as it did when it flowed through `...outer`.
|
|
109
|
-
if (className !== undefined)
|
|
110
|
-
outerProps.className = className;
|
|
111
|
-
// RN defaults nested scrolling ON (ScrollView.js:1862 `nestedScrollEnabled ?? true`).
|
|
112
|
-
// Android needs the flag to scroll a scrollable nested inside another scroll view
|
|
113
|
-
// independently; without it the inner one stays put. iOS handles nesting natively, so
|
|
114
|
-
// it is a no-op there. Default to true so nested lists scroll out of the box, like RN.
|
|
115
|
-
outerProps.nestedScrollEnabled = props.nestedScrollEnabled ?? true;
|
|
116
|
-
// iOS needs `horizontal` to flip RCTScrollView's axis; Android's dedicated horizontal
|
|
117
|
-
// manager ignores it. Harmless on Android, load-bearing on iOS, so always forward it.
|
|
118
|
-
if (horizontal !== undefined)
|
|
119
|
-
outerProps.horizontal = horizontal;
|
|
120
|
-
if (decelerationRate !== undefined) {
|
|
121
|
-
outerProps.decelerationRate = resolveDecelerationRate(decelerationRate);
|
|
122
|
-
}
|
|
123
|
-
// The scroll-forwarding DECISIONS (which onScroll path, the 1/16 throttle defaults, whether to
|
|
124
|
-
// capture the viewport height for inverted sticky, whether to keep cells un-flattened) are folded
|
|
125
|
-
// out to the shared resolveScrollForwarding; here React only EXECUTES them with its own primitives.
|
|
126
|
-
const nativeStickyAvailable = hasStickyHeaders && isNativeAnimatedAvailable();
|
|
127
|
-
const forwarding = resolveScrollForwarding({
|
|
128
|
-
hasStickyHeaders,
|
|
129
|
-
nativeStickyAvailable,
|
|
130
|
-
invertStickyHeaders,
|
|
131
|
-
scrollEventThrottle,
|
|
132
|
-
maintainVisibleContentPosition: props.maintainVisibleContentPosition,
|
|
133
|
-
snapToAlignment: props.snapToAlignment,
|
|
134
|
-
});
|
|
135
|
-
// onScroll: the JS-fallback path wraps the user's handler in Animated.event so the offset drives
|
|
136
|
-
// the AnimatedValue each frame (RN _scrollAnimatedValueAttachment); the native + plain paths
|
|
137
|
-
// forward the user's handler as-is (the native driver attaches the value on the UI thread).
|
|
138
|
-
if (forwarding.mode === 'sticky-js') {
|
|
139
|
-
outerProps.onScroll = animatedEvent([{ nativeEvent: { contentOffset: { y: scrollAnimatedValue } } }], onScroll === undefined
|
|
140
|
-
? undefined
|
|
141
|
-
: { listener: (...args) => forwardScrollEvent(onScroll, args) });
|
|
142
|
-
}
|
|
143
|
-
else if (onScroll !== undefined) {
|
|
144
|
-
outerProps.onScroll = onScroll;
|
|
145
|
-
}
|
|
146
|
-
if (forwarding.scrollEventThrottle !== undefined) {
|
|
147
|
-
outerProps.scrollEventThrottle = forwarding.scrollEventThrottle;
|
|
148
|
-
}
|
|
149
|
-
// onLayout on the scroll-view node: capture the viewport height for inverted sticky headers
|
|
150
|
-
// (RN _handleLayout), then call the user's handler. Pass through unchanged otherwise.
|
|
151
|
-
if (forwarding.capturesViewportHeight) {
|
|
152
|
-
outerProps.onLayout = (layoutEvent) => {
|
|
153
|
-
const height = readLayoutDimension(layoutEvent, 'height');
|
|
154
|
-
if (height !== undefined)
|
|
155
|
-
setViewportHeight(height);
|
|
156
|
-
onLayout?.(layoutEvent);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
else if (onLayout !== undefined) {
|
|
160
|
-
outerProps.onLayout = onLayout;
|
|
161
|
-
}
|
|
162
|
-
dlog(`ScrollView -> ${scrollViewIntrinsic} (horizontal=${isHorizontal} sticky=${hasStickyHeaders})`);
|
|
163
|
-
// onContentSizeChange is synthesized from the content view's own onLayout (RN
|
|
164
|
-
// _handleContentOnLayout): read width/height off nativeEvent.layout and fire only when the
|
|
165
|
-
// size actually changed (dedupe via a ref, like RN). Composed with any content onLayout.
|
|
166
|
-
const lastContentSizeRef = useRef(null);
|
|
167
|
-
const contentProps = {
|
|
168
|
-
style: contentStyle,
|
|
169
|
-
collapsable: false,
|
|
170
|
-
};
|
|
171
|
-
// maintainVisibleContentPosition (and Android snapToAlignment) anchor against the metrics
|
|
172
|
-
// of MOUNTED cell views. Android Fabric view-flattens layout-only cells away, so the native
|
|
173
|
-
// MaintainVisibleScrollPositionHelper has nothing to anchor to and the list jumps on prepend.
|
|
174
|
-
// RN keeps the cells as real views via collapsableChildren={false} on the content container
|
|
175
|
-
// (ScrollView.js:1731-1748 `preserveChildren`). iOS never flattens, so it is a no-op there.
|
|
176
|
-
if (forwarding.collapsableChildren) {
|
|
177
|
-
contentProps.collapsableChildren = false;
|
|
178
|
-
}
|
|
179
|
-
if (onContentSizeChange !== undefined) {
|
|
180
|
-
contentProps.onLayout = (layoutEvent) => {
|
|
181
|
-
const width = readLayoutDimension(layoutEvent, 'width');
|
|
182
|
-
const height = readLayoutDimension(layoutEvent, 'height');
|
|
183
|
-
if (width === undefined || height === undefined)
|
|
184
|
-
return;
|
|
185
|
-
const last = lastContentSizeRef.current;
|
|
186
|
-
if (!didContentSizeChange(last, { width, height }))
|
|
187
|
-
return;
|
|
188
|
-
lastContentSizeRef.current = { width, height };
|
|
189
|
-
dlog(`ScrollView onContentSizeChange ${width}x${height}`);
|
|
190
|
-
onContentSizeChange(width, height);
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
// Wrap the flagged children so they pin to the scroll offset (see the sticky-headers note
|
|
194
|
-
// above); no-op when none are flagged.
|
|
195
|
-
const contentChildren = hasStickyHeaders
|
|
196
|
-
? wrapStickyHeaders(children, stickyHeaderIndices, scrollAnimatedValue, invertStickyHeaders, viewportHeight, StickyHeaderComponent, { headerLayoutYs, onHeaderLayoutY, onHeaderRef })
|
|
197
|
-
: children;
|
|
198
|
-
// `collapsable: false` is load-bearing on Android. The content container is a
|
|
199
|
-
// layout-only View, which Android Fabric view-flattens away, hoisting the cells
|
|
200
|
-
// up as DIRECT children of the scroll view, which strictly hosts exactly one
|
|
201
|
-
// child ("ScrollView can host only one direct child" → addViewAt crash). RN pins
|
|
202
|
-
// its own NativeScrollContentView the same way (ScrollView.js, collapsable={false};
|
|
203
|
-
// ReactScrollView.java: "the 'content' View … non-collapsable so it will never be
|
|
204
|
-
// View-flattened away"). iOS doesn't flatten, so this is a no-op there.
|
|
205
|
-
const content = createElement(contentIntrinsic, contentProps, contentChildren);
|
|
206
|
-
// resolveClassName(undefined) is a cheap {} no-op, so this is safe with no className too.
|
|
207
|
-
const resolvedClassName = isClassNameValue(className) ? className : undefined;
|
|
208
|
-
const layoutSplitStyle = [
|
|
209
|
-
resolveClassName(resolvedClassName),
|
|
210
|
-
style,
|
|
211
|
-
];
|
|
212
|
-
return {
|
|
213
|
-
scrollViewIntrinsic,
|
|
214
|
-
scrollViewBaseStyle,
|
|
215
|
-
outerProps,
|
|
216
|
-
style,
|
|
217
|
-
layoutSplitStyle,
|
|
218
|
-
content,
|
|
219
|
-
refreshControl,
|
|
220
|
-
scrollAnimatedValue,
|
|
221
|
-
nativeStickyAvailable,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
// Attach the scroll event to the scroll-offset value on the NATIVE driver, RN's
|
|
225
|
-
// _updateAnimatedNodeAttachment / AnimatedImplementation.attachNativeEvent (ScrollView.js:1087).
|
|
226
|
-
// Called by each platform ScrollView with its committed scroll-node ref; the value then tracks
|
|
227
|
-
// scroll on the UI thread and the sticky-header interpolations ride it natively (no JS jitter).
|
|
228
|
-
// No-op when native sticky is unavailable or the node hasn't committed. Detaches on unmount.
|
|
229
|
-
// The attach/detach itself lives in @symbiote-native/components (attachStickyScroll); this is the React
|
|
230
|
-
// effect that drives it.
|
|
231
|
-
export function useNativeStickyScrollAttach(scrollNodeRef, scrollAnimatedValue, enabled) {
|
|
232
|
-
useEffect(() => {
|
|
233
|
-
if (!enabled)
|
|
234
|
-
return;
|
|
235
|
-
const node = scrollNodeRef.current;
|
|
236
|
-
if (node === null)
|
|
237
|
-
return;
|
|
238
|
-
return attachStickyScroll(node, scrollAnimatedValue);
|
|
239
|
-
}, [scrollNodeRef, scrollAnimatedValue, enabled]);
|
|
240
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type ComponentType, type ReactNode, type Ref } from 'react';
|
|
2
|
-
import { AnimatedValue } from '@symbiote-native/engine';
|
|
3
|
-
import { type IStickyHeaderProps } from '@symbiote-native/components';
|
|
4
|
-
export type IStickyHeaderHandle = {
|
|
5
|
-
setNextHeaderY: (y: number) => void;
|
|
6
|
-
};
|
|
7
|
-
export type IStickyCrossTalk = {
|
|
8
|
-
headerLayoutYs: ReadonlyMap<number, number>;
|
|
9
|
-
onHeaderLayoutY: (index: number, y: number) => void;
|
|
10
|
-
onHeaderRef: (index: number, handle: IStickyHeaderHandle | null) => void;
|
|
11
|
-
};
|
|
12
|
-
export type IStickyHeaderComponentProps = IStickyHeaderProps & {
|
|
13
|
-
children?: ReactNode;
|
|
14
|
-
ref?: Ref<IStickyHeaderHandle>;
|
|
15
|
-
};
|
|
16
|
-
export type IStickyHeaderComponentType = ComponentType<IStickyHeaderComponentProps>;
|
|
17
|
-
export declare const ScrollViewStickyHeader: IStickyHeaderComponentType;
|
|
18
|
-
export declare function wrapStickyHeaders(children: ReactNode, stickyHeaderIndices: number[] | undefined, scrollAnimatedValue: AnimatedValue, invertStickyHeaders: boolean | undefined, scrollViewHeight: number | undefined, StickyHeaderComponent: IStickyHeaderComponentType | undefined, crossTalk: IStickyCrossTalk): ReactNode;
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
// Sticky headers: the JS layer RN implements in ScrollView.js / ScrollViewStickyHeader.js.
|
|
2
|
-
//
|
|
3
|
-
// RN does stickiness purely in JS: ScrollView.js (~line 1690) wraps each flagged child in a
|
|
4
|
-
// ScrollViewStickyHeader, fed by a single `_scrollAnimatedValue` that Animated.event drives
|
|
5
|
-
// from `onScroll` (~line 1095). The native Fabric scroll view does not honor the index array,
|
|
6
|
-
// so forwarding `stickyHeaderIndices` to native would be a silent no-op - we replicate the JS
|
|
7
|
-
// layer instead. The interpolation mirrors ScrollViewStickyHeader.js and now lives,
|
|
8
|
-
// framework-agnostic, in @symbiote-native/components (computeStickyInterpolation); this file
|
|
9
|
-
// holds only the React component shell, layout state, and child-wrapping.
|
|
10
|
-
import { Children, createElement, isValidElement, useCallback, useEffect, useImperativeHandle, useReducer, useRef, useState, } from 'react';
|
|
11
|
-
import { AnimatedInterpolation, AnimatedValue, Platform, dlog, } from '@symbiote-native/engine';
|
|
12
|
-
import { createInitialStickyState, nextStickyHeaderY, readLayoutNumber, reduceSticky, STICKY_HEADER_Z_INDEX, } from '@symbiote-native/components';
|
|
13
|
-
import { Animated } from '../../modules/animated/index.js';
|
|
14
|
-
function readChildOnLayout(child) {
|
|
15
|
-
const childProps = child.props;
|
|
16
|
-
if (typeof childProps !== 'object' || childProps === null)
|
|
17
|
-
return undefined;
|
|
18
|
-
const handler = Reflect.get(childProps, 'onLayout');
|
|
19
|
-
return typeof handler === 'function' ? handler : undefined;
|
|
20
|
-
}
|
|
21
|
-
function firstChild(children) {
|
|
22
|
-
const first = Children.toArray(children)[0];
|
|
23
|
-
return isValidElement(first) ? first : undefined;
|
|
24
|
-
}
|
|
25
|
-
// One sticky header. Measures its own y/height via onLayout, interpolates the shared scroll
|
|
26
|
-
// offset into a translateY that keeps it pinned to the top (or bottom, inverted) until the next
|
|
27
|
-
// header collides with it, and drives that translate through the native driver when available so
|
|
28
|
-
// the pin tracks scroll on the UI thread (no JS jitter). The DECISIONS — the zero-swallow gate, the
|
|
29
|
-
// debounce delay, the rebuild-on-input-change ranges — live in `reduceSticky`
|
|
30
|
-
// (@symbiote-native/components); this component supplies only the React lifecycle: the ONE folded
|
|
31
|
-
// state cell, the interpolation-node + listener wiring, the debounce setTimeout, and the re-render.
|
|
32
|
-
export const ScrollViewStickyHeader = props => {
|
|
33
|
-
const { inverted, scrollViewHeight, scrollAnimatedValue, nextHeaderLayoutY, children, ref, } = props;
|
|
34
|
-
// The next header's y lives HERE, not in a prop the parent re-renders to update (RN keeps it in
|
|
35
|
-
// the child too, ScrollViewStickyHeader.js:65). The prop only seeds the first render; afterwards
|
|
36
|
-
// the ScrollView pushes updates through setNextHeaderY. That keeps the cost linear - a
|
|
37
|
-
// parent-state round trip re-renders every child on every header's layout, so N headers cost N
|
|
38
|
-
// re-renders of N children. At N=200 it churned enough native animated nodes to trip Fabric's view
|
|
39
|
-
// registry ("Attempt to dequeue already registered component") seconds after mount.
|
|
40
|
-
const [nextHeaderY, setNextHeaderY] = useState(nextHeaderLayoutY);
|
|
41
|
-
useImperativeHandle(ref, () => ({ setNextHeaderY }), []);
|
|
42
|
-
// The imperative push is a fast path, not the source of truth. When the parent DOES re-render
|
|
43
|
-
// with a different value the prop wins, because the successor may be gone: a VirtualizedList
|
|
44
|
-
// unmounts headers as they scroll out, and a value pushed in earlier would otherwise stick
|
|
45
|
-
// around as a collision point that no longer exists.
|
|
46
|
-
const lastNextHeaderProp = useRef(nextHeaderLayoutY);
|
|
47
|
-
if (lastNextHeaderProp.current !== nextHeaderLayoutY) {
|
|
48
|
-
lastNextHeaderProp.current = nextHeaderLayoutY;
|
|
49
|
-
setNextHeaderY(nextHeaderLayoutY);
|
|
50
|
-
}
|
|
51
|
-
// The one folded state cell (RN's scattered useState/useRef collapsed into IStickyHeaderState),
|
|
52
|
-
// mutated in place by reduceSticky. Lazily created once.
|
|
53
|
-
const stateRef = useRef(null);
|
|
54
|
-
const state = (stateRef.current ??= createInitialStickyState());
|
|
55
|
-
const [, forceRender] = useReducer((tick) => tick + 1, 0);
|
|
56
|
-
// The animated node that drives the transform (RN's animatedTranslateY), rebuilt by the
|
|
57
|
-
// rebuild-interpolation effect. When the scroll value is native, this interpolation runs on the
|
|
58
|
-
// UI thread: the smooth pin.
|
|
59
|
-
const [animatedTranslateY, setAnimatedTranslateY] = useState(() => scrollAnimatedValue.interpolate({
|
|
60
|
-
inputRange: [-1, 0],
|
|
61
|
-
outputRange: [0, 0],
|
|
62
|
-
}));
|
|
63
|
-
const debounceTimer = useRef(null);
|
|
64
|
-
// The current interpolation node + its settled-value listener id, held so the next rebuild can
|
|
65
|
-
// detach the old listener (engine calls the reducer does NOT own) and unmount can clean up.
|
|
66
|
-
const interpolationRef = useRef(null);
|
|
67
|
-
const listenerIdRef = useRef(null);
|
|
68
|
-
const inputsRef = useRef({
|
|
69
|
-
os: Platform.OS,
|
|
70
|
-
inverted,
|
|
71
|
-
scrollViewHeight,
|
|
72
|
-
nextHeaderLayoutY: nextHeaderY,
|
|
73
|
-
});
|
|
74
|
-
inputsRef.current = {
|
|
75
|
-
os: Platform.OS,
|
|
76
|
-
inverted,
|
|
77
|
-
scrollViewHeight,
|
|
78
|
-
nextHeaderLayoutY: nextHeaderY,
|
|
79
|
-
};
|
|
80
|
-
// dispatch reaches through a ref because the effect executors dispatch follow-up actions
|
|
81
|
-
// (the listener -> animated-tick, the debounce timer -> debounce-fired).
|
|
82
|
-
const dispatchRef = useRef(() => { });
|
|
83
|
-
const runEffects = useCallback((effects) => {
|
|
84
|
-
for (const effect of effects) {
|
|
85
|
-
switch (effect.kind) {
|
|
86
|
-
case 'rebuild-interpolation': {
|
|
87
|
-
// Detach the old listener, build a fresh interpolation onto the shared scroll value, and
|
|
88
|
-
// wire the settled-value listener (symbiote is always Fabric; RN attaches it only there).
|
|
89
|
-
const previous = interpolationRef.current;
|
|
90
|
-
if (previous !== null && listenerIdRef.current !== null) {
|
|
91
|
-
previous.removeListener(listenerIdRef.current);
|
|
92
|
-
listenerIdRef.current = null;
|
|
93
|
-
}
|
|
94
|
-
const next = scrollAnimatedValue.interpolate({
|
|
95
|
-
inputRange: effect.inputRange,
|
|
96
|
-
outputRange: effect.outputRange,
|
|
97
|
-
});
|
|
98
|
-
listenerIdRef.current = next.addListener(({ value }) => {
|
|
99
|
-
if (typeof value === 'number')
|
|
100
|
-
dispatchRef.current({ kind: 'animated-tick', value });
|
|
101
|
-
});
|
|
102
|
-
interpolationRef.current = next;
|
|
103
|
-
setAnimatedTranslateY(next);
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case 'schedule-debounce': {
|
|
107
|
-
// The animated value updates several times per frame; debounce the settled value into the
|
|
108
|
-
// committed transform so hit detection stays current (a Fabric issue, worse on Android).
|
|
109
|
-
if (debounceTimer.current !== null)
|
|
110
|
-
clearTimeout(debounceTimer.current);
|
|
111
|
-
debounceTimer.current = setTimeout(() => {
|
|
112
|
-
debounceTimer.current = null;
|
|
113
|
-
dispatchRef.current({
|
|
114
|
-
kind: 'debounce-fired',
|
|
115
|
-
value: effect.value,
|
|
116
|
-
});
|
|
117
|
-
}, effect.delay);
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
case 'apply-passthrough':
|
|
121
|
-
forceRender();
|
|
122
|
-
break;
|
|
123
|
-
case 'record-header-y':
|
|
124
|
-
// React records through the wrapper's onLayout closure (props.onLayout, below), which
|
|
125
|
-
// honors the public IStickyHeaderProps contract; the reducer emits no index for it.
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [scrollAnimatedValue]);
|
|
130
|
-
const dispatch = useCallback((action) => {
|
|
131
|
-
const current = stateRef.current;
|
|
132
|
-
if (current === null)
|
|
133
|
-
return;
|
|
134
|
-
runEffects(reduceSticky(current, action, inputsRef.current).effects);
|
|
135
|
-
}, [runEffects]);
|
|
136
|
-
dispatchRef.current = dispatch;
|
|
137
|
-
// Rebuild when the collision/viewport inputs change (RN effect deps minus the layout state, which
|
|
138
|
-
// dispatches 'layout' itself); also does the initial identity build on mount.
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
dispatchRef.current({ kind: 'inputs-changed' });
|
|
141
|
-
}, [inverted, scrollViewHeight, nextHeaderY, scrollAnimatedValue]);
|
|
142
|
-
// Detach the listener + clear the debounce on unmount.
|
|
143
|
-
useEffect(() => () => {
|
|
144
|
-
const previous = interpolationRef.current;
|
|
145
|
-
if (previous !== null && listenerIdRef.current !== null)
|
|
146
|
-
previous.removeListener(listenerIdRef.current);
|
|
147
|
-
if (debounceTimer.current !== null)
|
|
148
|
-
clearTimeout(debounceTimer.current);
|
|
149
|
-
}, []);
|
|
150
|
-
const onLayout = (event) => {
|
|
151
|
-
const y = readLayoutNumber(event, 'y');
|
|
152
|
-
const height = readLayoutNumber(event, 'height');
|
|
153
|
-
// Keep the previous value when a field is absent (RN sets state only on a defined read).
|
|
154
|
-
dispatch({
|
|
155
|
-
kind: 'layout',
|
|
156
|
-
y: y ?? state.layoutY,
|
|
157
|
-
height: height ?? state.layoutHeight,
|
|
158
|
-
});
|
|
159
|
-
props.onLayout(event);
|
|
160
|
-
const child = firstChild(children);
|
|
161
|
-
const childOnLayout = child === undefined ? undefined : readChildOnLayout(child);
|
|
162
|
-
childOnLayout?.(event);
|
|
163
|
-
};
|
|
164
|
-
// The EXPLICIT debounced translateY overrides the committed transform for hit-testing, while
|
|
165
|
-
// `animatedTranslateY` does the smooth (native-driven) pin, per RN ScrollViewStickyHeader.js.
|
|
166
|
-
const passthroughAnimatedPropExplicitValues = state.translateY !== null
|
|
167
|
-
? { style: { transform: [{ translateY: state.translateY }] } }
|
|
168
|
-
: null;
|
|
169
|
-
// collapsable:false keeps the wrapper a real Yoga node; zIndex makes the pinned header paint
|
|
170
|
-
// OVER the rows scrolling under it. `style` is `unknown` on Animated.View, so the interpolation
|
|
171
|
-
// transform passes with no cast.
|
|
172
|
-
return createElement(Animated.View, {
|
|
173
|
-
style: {
|
|
174
|
-
transform: [{ translateY: animatedTranslateY }],
|
|
175
|
-
zIndex: STICKY_HEADER_Z_INDEX,
|
|
176
|
-
},
|
|
177
|
-
onLayout,
|
|
178
|
-
collapsable: false,
|
|
179
|
-
passthroughAnimatedPropExplicitValues,
|
|
180
|
-
}, children);
|
|
181
|
-
};
|
|
182
|
-
ScrollViewStickyHeader.displayName = 'ScrollViewStickyHeader';
|
|
183
|
-
// Wrap each child flagged by `stickyHeaderIndices` in the sticky header component, fed by the
|
|
184
|
-
// shared scroll AnimatedValue. Mirrors ScrollView.js's render-time children.map (~line 1690).
|
|
185
|
-
// Returns the children unchanged when no indices are flagged.
|
|
186
|
-
//
|
|
187
|
-
// Cross-talk plumbing (RN's _headerLayoutYs + _onStickyHeaderLayout, ScrollView.js:1115-1143):
|
|
188
|
-
// `headerLayoutYs` is a child-index→measured-y map the parent keeps; each header reports its own
|
|
189
|
-
// y through `onHeaderLayoutY` as it measures, and we feed every header the y of the NEXT flagged
|
|
190
|
-
// header (the collision point past which it scrolls off) by looking up its successor's index in
|
|
191
|
-
// `stickyHeaderIndices`. The LAST flagged header has no successor, so its `nextHeaderLayoutY`
|
|
192
|
-
// stays undefined and it sticks indefinitely (correct).
|
|
193
|
-
export function wrapStickyHeaders(children, stickyHeaderIndices, scrollAnimatedValue, invertStickyHeaders, scrollViewHeight, StickyHeaderComponent, crossTalk) {
|
|
194
|
-
const { headerLayoutYs, onHeaderLayoutY, onHeaderRef } = crossTalk;
|
|
195
|
-
if (stickyHeaderIndices === undefined || stickyHeaderIndices.length === 0)
|
|
196
|
-
return children;
|
|
197
|
-
const Wrapper = StickyHeaderComponent ?? ScrollViewStickyHeader;
|
|
198
|
-
return Children.toArray(children).map((child, index) => {
|
|
199
|
-
const indexOfIndex = stickyHeaderIndices.indexOf(index);
|
|
200
|
-
if (indexOfIndex === -1 || !isValidElement(child))
|
|
201
|
-
return child;
|
|
202
|
-
// The next flagged header's measured y, by index order in stickyHeaderIndices (RN
|
|
203
|
-
// ScrollView.js:1695 nextIndex). undefined until that header has measured (or for the last).
|
|
204
|
-
const nextIndex = stickyHeaderIndices[indexOfIndex + 1];
|
|
205
|
-
const nextHeaderLayoutY = nextStickyHeaderY(stickyHeaderIndices, indexOfIndex, headerLayoutYs);
|
|
206
|
-
dlog(`ScrollView sticky-header wrap index=${index} next=${nextIndex} nextY=${nextHeaderLayoutY}`);
|
|
207
|
-
return createElement(Wrapper, {
|
|
208
|
-
key: child.key ?? `sticky-${index}`,
|
|
209
|
-
// Registers this header so the ScrollView can push the NEXT header's y straight in
|
|
210
|
-
// (RN ScrollView.js:1109). Without it a measurement would have to travel through parent
|
|
211
|
-
// state, re-rendering every child.
|
|
212
|
-
ref: (handle) => onHeaderRef(index, handle),
|
|
213
|
-
nextHeaderLayoutY,
|
|
214
|
-
// RN _onStickyHeaderLayout: record this header's own y, then push it to the previous
|
|
215
|
-
// header as its nextHeaderLayoutY. We record into the parent map; the lookup above feeds
|
|
216
|
-
// it forward on the resulting re-render.
|
|
217
|
-
onLayout: (event) => {
|
|
218
|
-
const y = readLayoutNumber(event, 'y');
|
|
219
|
-
if (y !== undefined)
|
|
220
|
-
onHeaderLayoutY(index, y);
|
|
221
|
-
},
|
|
222
|
-
scrollAnimatedValue,
|
|
223
|
-
inverted: invertStickyHeaders,
|
|
224
|
-
scrollViewHeight,
|
|
225
|
-
}, child);
|
|
226
|
-
});
|
|
227
|
-
}
|