react-native-header-motion 1.0.0-alpha.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -528
- package/lib/module/components/Bridge.js +16 -0
- package/lib/module/components/Bridge.js.map +1 -0
- package/lib/module/components/FlatList.js +5 -54
- package/lib/module/components/FlatList.js.map +1 -1
- package/lib/module/components/Header.js +71 -13
- package/lib/module/components/Header.js.map +1 -1
- package/lib/module/components/HeaderDynamic.js +34 -0
- package/lib/module/components/HeaderDynamic.js.map +1 -0
- package/lib/module/components/HeaderMotion.js +14 -20
- package/lib/module/components/HeaderMotion.js.map +1 -1
- package/lib/module/components/HeaderPanBoundary.js +54 -0
- package/lib/module/components/HeaderPanBoundary.js.map +1 -0
- package/lib/module/components/NavigationBridge.js +20 -0
- package/lib/module/components/NavigationBridge.js.map +1 -0
- package/lib/module/components/ScrollManager.js +19 -7
- package/lib/module/components/ScrollManager.js.map +1 -1
- package/lib/module/components/ScrollView.js +6 -39
- package/lib/module/components/ScrollView.js.map +1 -1
- package/lib/module/components/createHeaderMotionScrollable.js +136 -0
- package/lib/module/components/createHeaderMotionScrollable.js.map +1 -0
- package/lib/module/components/index.js +3 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/context.js +8 -1
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useActiveScrollId.js +7 -6
- package/lib/module/hooks/useActiveScrollId.js.map +1 -1
- package/lib/module/hooks/useConsumerScrollHandlers.js +86 -0
- package/lib/module/hooks/useConsumerScrollHandlers.js.map +1 -0
- package/lib/module/hooks/useHeaderMotionBridge.js +14 -0
- package/lib/module/hooks/useHeaderMotionBridge.js.map +1 -0
- package/lib/module/hooks/useMotionProgress.js +12 -42
- package/lib/module/hooks/useMotionProgress.js.map +1 -1
- package/lib/module/hooks/useMotionProgress.test.js +56 -0
- package/lib/module/hooks/useMotionProgress.test.js.map +1 -0
- package/lib/module/hooks/useScrollManager.js +168 -87
- package/lib/module/hooks/useScrollManager.js.map +1 -1
- package/lib/module/index.js +21 -18
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/defaults.js +2 -1
- package/lib/module/utils/defaults.js.map +1 -1
- package/lib/module/utils/header.js +24 -0
- package/lib/module/utils/header.js.map +1 -0
- package/lib/module/utils/headerOffsetStyle.js +31 -0
- package/lib/module/utils/headerOffsetStyle.js.map +1 -0
- package/lib/module/utils/index.js +2 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/docs/docusaurus.config.d.ts +4 -0
- package/lib/typescript/docs/docusaurus.config.d.ts.map +1 -0
- package/lib/typescript/docs/sidebars.d.ts +4 -0
- package/lib/typescript/docs/sidebars.d.ts.map +1 -0
- package/lib/typescript/docs/src/pages/index.d.ts +2 -0
- package/lib/typescript/docs/src/pages/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Bridge.d.ts +19 -0
- package/lib/typescript/src/components/Bridge.d.ts.map +1 -0
- package/lib/typescript/src/components/FlatList.d.ts +7 -15
- package/lib/typescript/src/components/FlatList.d.ts.map +1 -1
- package/lib/typescript/src/components/Header.d.ts +73 -12
- package/lib/typescript/src/components/Header.d.ts.map +1 -1
- package/lib/typescript/src/components/HeaderDynamic.d.ts +11 -0
- package/lib/typescript/src/components/HeaderDynamic.d.ts.map +1 -0
- package/lib/typescript/src/components/HeaderMotion.d.ts +38 -23
- package/lib/typescript/src/components/HeaderMotion.d.ts.map +1 -1
- package/lib/typescript/src/components/HeaderPanBoundary.d.ts +11 -0
- package/lib/typescript/src/components/HeaderPanBoundary.d.ts.map +1 -0
- package/lib/typescript/src/components/NavigationBridge.d.ts +19 -0
- package/lib/typescript/src/components/NavigationBridge.d.ts.map +1 -0
- package/lib/typescript/src/components/ScrollManager.d.ts +13 -9
- package/lib/typescript/src/components/ScrollManager.d.ts.map +1 -1
- package/lib/typescript/src/components/ScrollView.d.ts +7 -14
- package/lib/typescript/src/components/ScrollView.d.ts.map +1 -1
- package/lib/typescript/src/components/createHeaderMotionScrollable.d.ts +86 -0
- package/lib/typescript/src/components/createHeaderMotionScrollable.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +3 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/context.d.ts +3 -17
- package/lib/typescript/src/context.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +1 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useActiveScrollId.d.ts +7 -6
- package/lib/typescript/src/hooks/useActiveScrollId.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useConsumerScrollHandlers.d.ts +64 -0
- package/lib/typescript/src/hooks/useConsumerScrollHandlers.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useHeaderMotionBridge.d.ts +10 -0
- package/lib/typescript/src/hooks/useHeaderMotionBridge.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMotionProgress.d.ts +8 -25
- package/lib/typescript/src/hooks/useMotionProgress.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMotionProgress.test.d.ts +2 -0
- package/lib/typescript/src/hooks/useMotionProgress.test.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useScrollManager.d.ts +61 -29
- package/lib/typescript/src/hooks/useScrollManager.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +56 -26
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +54 -17
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/defaults.d.ts +3 -2
- package/lib/typescript/src/utils/defaults.d.ts.map +1 -1
- package/lib/typescript/src/utils/header.d.ts +10 -0
- package/lib/typescript/src/utils/header.d.ts.map +1 -0
- package/lib/typescript/src/utils/headerOffsetStyle.d.ts +19 -0
- package/lib/typescript/src/utils/headerOffsetStyle.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +2 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/refreshControl.d.ts +12 -12
- package/package.json +12 -5
- package/src/components/Bridge.tsx +29 -0
- package/src/components/FlatList.tsx +18 -76
- package/src/components/Header.tsx +159 -23
- package/src/components/HeaderDynamic.tsx +45 -0
- package/src/components/HeaderMotion.tsx +47 -50
- package/src/components/HeaderPanBoundary.tsx +92 -0
- package/src/components/NavigationBridge.tsx +30 -0
- package/src/components/ScrollManager.tsx +23 -11
- package/src/components/ScrollView.tsx +16 -60
- package/src/components/createHeaderMotionScrollable.tsx +438 -0
- package/src/components/index.ts +3 -1
- package/src/context.ts +11 -24
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useActiveScrollId.ts +7 -6
- package/src/hooks/useConsumerScrollHandlers.ts +148 -0
- package/src/hooks/useHeaderMotionBridge.ts +15 -0
- package/src/hooks/useMotionProgress.test.ts +67 -0
- package/src/hooks/useMotionProgress.ts +12 -45
- package/src/hooks/useScrollManager.ts +251 -114
- package/src/index.ts +82 -36
- package/src/types.ts +81 -29
- package/src/utils/defaults.ts +7 -1
- package/src/utils/header.tsx +52 -0
- package/src/utils/headerOffsetStyle.ts +40 -0
- package/src/utils/index.ts +2 -0
- package/lib/module/components/HeaderBase.js +0 -107
- package/lib/module/components/HeaderBase.js.map +0 -1
- package/lib/typescript/src/components/HeaderBase.d.ts +0 -41
- package/lib/typescript/src/components/HeaderBase.d.ts.map +0 -1
- package/src/components/HeaderBase.tsx +0 -140
|
@@ -1,71 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useContext, useCallback, useEffect } from 'react';
|
|
4
|
-
import { cancelAnimation,
|
|
5
|
-
import {
|
|
3
|
+
import { useContext, useCallback, useEffect, useState } from 'react';
|
|
4
|
+
import { cancelAnimation, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useSharedValue } from 'react-native-reanimated';
|
|
5
|
+
import { scheduleOnRN, scheduleOnUI } from 'react-native-worklets';
|
|
6
6
|
import { HeaderMotionContext } from "../context.js";
|
|
7
7
|
import { resolveRefreshControl, DEFAULT_SCROLL_ID, ensureScrollValueRegistered, warnIfMissingActiveScrollId } from "../utils/index.js";
|
|
8
|
+
import { useConsumerScrollHandlers, useScrollHandlerComposition } from "./useConsumerScrollHandlers.js";
|
|
8
9
|
const SCROLL_TOLERANCE = 0.5;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Hook that manages scroll tracking and synchronization for header animations.
|
|
12
|
-
* Returns props to apply to scrollable components and additional values that help with adjusting styling of the scrollables to header's dimensions.
|
|
13
|
-
*
|
|
14
|
-
* This hook handles:
|
|
15
|
-
* - Scroll position tracking
|
|
16
|
-
* - Synchronization between multiple scroll views (when using multiple scroll IDs)
|
|
17
|
-
* - Content container minimum height calculations for cases where one of the tracked scrollables does not take enough space to reach the progress threshold/
|
|
18
|
-
*
|
|
19
|
-
* Must be used within a HeaderMotion component.
|
|
20
|
-
*
|
|
21
|
-
* @param scrollId - Optional unique identifier for the related scrollable.
|
|
22
|
-
* Use when you have multiple scrollables (e.g., in tabs).
|
|
23
|
-
* @param options - Optional configuration object.
|
|
24
|
-
* @param options.animatedRef - Optional animated ref to use instead of creating one internally.
|
|
25
|
-
* Useful when you need access to the scroll view ref from outside.
|
|
26
|
-
* @returns Configuration object containing:
|
|
27
|
-
* - `scrollableProps`: Props to apply to scrollable component (onScroll, scrollEventThrottle, ref)
|
|
28
|
-
* - `headerMotionContext`: Header context values (originalHeaderHeight, minHeightContentContainerStyle)
|
|
29
|
-
*
|
|
30
|
-
* @throws Error if used outside of a HeaderMotion component
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* function CustomScrollComponent() {
|
|
35
|
-
* const { scrollableProps, headerMotionContext } = useScrollManager('myScroll');
|
|
36
|
-
*
|
|
37
|
-
* return (
|
|
38
|
-
* <CustomScrollView {...scrollableProps}>
|
|
39
|
-
* <View style={{ paddingTop: headerMotionContext.originalHeaderHeight }}>
|
|
40
|
-
* Content
|
|
41
|
-
* </View>
|
|
42
|
-
* </CustomScrollView>
|
|
43
|
-
* );
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
export function useScrollManager(scrollId, options) {
|
|
10
|
+
function useScrollManagerContext() {
|
|
49
11
|
const ctxValue = useContext(HeaderMotionContext);
|
|
50
12
|
if (!ctxValue) {
|
|
51
13
|
throw new Error('useScrollManager must be used within a HeaderMotion component');
|
|
52
14
|
}
|
|
15
|
+
return ctxValue;
|
|
16
|
+
}
|
|
17
|
+
function useScrollManagerContentMinHeight({
|
|
18
|
+
enabled
|
|
19
|
+
}) {
|
|
20
|
+
const {
|
|
21
|
+
progressThreshold
|
|
22
|
+
} = useScrollManagerContext();
|
|
23
|
+
const preservedScrollContainerHeight = useSharedValue(0);
|
|
24
|
+
const [contentContainerMinHeight, setContentContainerMinHeight] = useState(undefined);
|
|
25
|
+
const handleLayout = useCallback(e => {
|
|
26
|
+
if (!enabled) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const nextHeight = e.nativeEvent.layout.height;
|
|
30
|
+
scheduleOnUI(height => {
|
|
31
|
+
'worklet';
|
|
32
|
+
|
|
33
|
+
preservedScrollContainerHeight.set(height);
|
|
34
|
+
const nextMinHeight = height + progressThreshold.get();
|
|
35
|
+
scheduleOnRN(setContentContainerMinHeight, nextMinHeight);
|
|
36
|
+
}, nextHeight);
|
|
37
|
+
}, [enabled, preservedScrollContainerHeight, progressThreshold]);
|
|
38
|
+
useAnimatedReaction(() => progressThreshold.get(), (threshold, previousThreshold) => {
|
|
39
|
+
if (!enabled || previousThreshold === null || previousThreshold === threshold) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const currentHeight = preservedScrollContainerHeight.get();
|
|
43
|
+
if (currentHeight <= 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const nextMinHeight = currentHeight + threshold;
|
|
47
|
+
scheduleOnRN(setContentContainerMinHeight, nextMinHeight);
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
contentContainerMinHeight,
|
|
51
|
+
handleLayout: enabled ? handleLayout : undefined
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function useScrollManagerSynchronization({
|
|
55
|
+
animatedRef,
|
|
56
|
+
id
|
|
57
|
+
}) {
|
|
53
58
|
const {
|
|
54
|
-
scrollValues,
|
|
55
|
-
progress,
|
|
56
59
|
activeScrollId,
|
|
60
|
+
progress,
|
|
57
61
|
progressThreshold,
|
|
58
|
-
originalHeaderHeight,
|
|
59
62
|
scrollToRef,
|
|
60
|
-
|
|
61
|
-
} =
|
|
62
|
-
const id = scrollId ?? DEFAULT_SCROLL_ID;
|
|
63
|
-
const localRef = useAnimatedRef();
|
|
64
|
-
const animatedRef = options?.animatedRef ?? localRef;
|
|
65
|
-
const refreshControl = options?.refreshControl;
|
|
66
|
-
const refreshing = options?.refreshing;
|
|
67
|
-
const onRefresh = options?.onRefresh;
|
|
68
|
-
const progressViewOffset = options?.progressViewOffset ?? originalHeaderHeight;
|
|
63
|
+
scrollValues
|
|
64
|
+
} = useScrollManagerContext();
|
|
69
65
|
useAnimatedReaction(() => activeScrollId?.get(), activeId => {
|
|
70
66
|
const currentValues = ensureScrollValueRegistered(scrollValues, id);
|
|
71
67
|
warnIfMissingActiveScrollId(currentValues, id, activeId);
|
|
@@ -94,10 +90,8 @@ export function useScrollManager(scrollId, options) {
|
|
|
94
90
|
});
|
|
95
91
|
}, id);
|
|
96
92
|
};
|
|
97
|
-
}, [
|
|
93
|
+
}, [id, scrollValues]);
|
|
98
94
|
useAnimatedReaction(() => progress.value, (newProgress, oldProgress) => {
|
|
99
|
-
// FUTURE: If really needed for, can use other scroll handlers to only do this either on scroll end or between scroll end and momentum end in onScroll (keep context in shared value)
|
|
100
|
-
// Only sync inactive scroll views when we have multiple tabs being tracked
|
|
101
95
|
const currentActiveScrollId = activeScrollId?.get();
|
|
102
96
|
if (!currentActiveScrollId || id === currentActiveScrollId || oldProgress === null) {
|
|
103
97
|
return;
|
|
@@ -121,9 +115,28 @@ export function useScrollManager(scrollId, options) {
|
|
|
121
115
|
scrollTo(animatedRef, 0, newCur, false);
|
|
122
116
|
}
|
|
123
117
|
});
|
|
124
|
-
|
|
118
|
+
}
|
|
119
|
+
function useScrollManagerHandlers({
|
|
120
|
+
consumerHandlers,
|
|
121
|
+
id
|
|
122
|
+
}) {
|
|
123
|
+
const {
|
|
124
|
+
activeScrollId,
|
|
125
|
+
headerPanMomentumOffset,
|
|
126
|
+
progressThreshold,
|
|
127
|
+
scrollValues
|
|
128
|
+
} = useScrollManagerContext();
|
|
129
|
+
const {
|
|
130
|
+
onScroll,
|
|
131
|
+
onBeginDrag,
|
|
132
|
+
onEndDrag,
|
|
133
|
+
onMomentumBegin,
|
|
134
|
+
onMomentumEnd
|
|
135
|
+
} = useConsumerScrollHandlers(consumerHandlers);
|
|
136
|
+
const handleScroll = useCallback((e, ctx) => {
|
|
125
137
|
'worklet';
|
|
126
138
|
|
|
139
|
+
onScroll?.(e);
|
|
127
140
|
const newCurrent = e.contentOffset.y;
|
|
128
141
|
if (ctx.lastOffset !== undefined && Math.abs(ctx.lastOffset - newCurrent) < SCROLL_TOLERANCE) {
|
|
129
142
|
return;
|
|
@@ -142,14 +155,6 @@ export function useScrollManager(scrollId, options) {
|
|
|
142
155
|
const oldCurrent = scrollValue.current;
|
|
143
156
|
const oldMin = scrollValue.min;
|
|
144
157
|
const isCollapsed = oldCurrent >= oldMin + threshold - 0.001;
|
|
145
|
-
|
|
146
|
-
// When the header is fully collapsed and the user is scrolled past the
|
|
147
|
-
// threshold, progress is mathematically guaranteed to stay at 1:
|
|
148
|
-
// min = newCurrent - threshold → (newCurrent - min) / threshold = 1
|
|
149
|
-
// In this case we update the values directly via .get() instead of
|
|
150
|
-
// .modify(), which avoids triggering the reactive cascade (progress
|
|
151
|
-
// re-derivation, animated reactions, animated styles). The values are
|
|
152
|
-
// still updated in-place for tab synchronization correctness.
|
|
153
158
|
if (isCollapsed && newCurrent >= threshold) {
|
|
154
159
|
scrollValue.current = newCurrent;
|
|
155
160
|
scrollValue.min = newCurrent - threshold;
|
|
@@ -165,32 +170,108 @@ export function useScrollManager(scrollId, options) {
|
|
|
165
170
|
}
|
|
166
171
|
return value;
|
|
167
172
|
});
|
|
168
|
-
}, [
|
|
169
|
-
const
|
|
173
|
+
}, [activeScrollId, id, onScroll, progressThreshold, scrollValues]);
|
|
174
|
+
const handleBeginDrag = useCallback(e => {
|
|
170
175
|
'worklet';
|
|
171
176
|
|
|
177
|
+
onBeginDrag?.(e);
|
|
172
178
|
if (headerPanMomentumOffset.get() === null) {
|
|
173
179
|
return;
|
|
174
180
|
}
|
|
175
181
|
cancelAnimation(headerPanMomentumOffset);
|
|
176
182
|
headerPanMomentumOffset.set(null);
|
|
177
|
-
}, [headerPanMomentumOffset]);
|
|
178
|
-
|
|
179
|
-
onBeginDrag,
|
|
180
|
-
onScroll
|
|
183
|
+
}, [headerPanMomentumOffset, onBeginDrag]);
|
|
184
|
+
return useAnimatedScrollHandler({
|
|
185
|
+
onBeginDrag: handleBeginDrag,
|
|
186
|
+
onScroll: handleScroll,
|
|
187
|
+
onEndDrag,
|
|
188
|
+
onMomentumBegin,
|
|
189
|
+
onMomentumEnd
|
|
181
190
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Wires a custom scrollable into HeaderMotion.
|
|
194
|
+
*
|
|
195
|
+
* Most code should not use this hook directly.
|
|
196
|
+
*
|
|
197
|
+
* **Prefer `createHeaderMotionScrollable()` whenever possible.** It gives
|
|
198
|
+
* you the same integration in a reusable component wrapper with less manual
|
|
199
|
+
* wiring. Reach for `useScrollManager()` only in more complex cases where the
|
|
200
|
+
* factory API is not enough, for example when a third-party scrollable needs
|
|
201
|
+
* highly custom composition.
|
|
202
|
+
*
|
|
203
|
+
* It returns two things:
|
|
204
|
+
* - `scrollableProps`: the event handlers / ref / refresh-control props that
|
|
205
|
+
* should go on the scrollable itself
|
|
206
|
+
* - `headerMotionContext`: layout values you can use to offset the content
|
|
207
|
+
* below the measured header
|
|
208
|
+
*
|
|
209
|
+
* In multi-scroll setups, pass a unique `scrollId` for each scrollable.
|
|
210
|
+
* In single-scroll setups, you usually do not need one.
|
|
211
|
+
*
|
|
212
|
+
* If you need the same fallback behavior but prefer render-prop composition
|
|
213
|
+
* over a hook, use `HeaderMotion.ScrollManager`.
|
|
214
|
+
*
|
|
215
|
+
* @param scrollId Optional unique identifier for the managed scrollable.
|
|
216
|
+
* @param options Optional configuration for refs, refresh handling, user
|
|
217
|
+
* scroll callbacks, and short-content fallback behavior.
|
|
218
|
+
* @returns Object containing:
|
|
219
|
+
* - `scrollableProps`: props to spread onto the scrollable (`ref`, managed
|
|
220
|
+
* `onScroll`, optional `onLayout`, and resolved `refreshControl`)
|
|
221
|
+
* - `headerMotionContext`: layout values for offsetting the content container
|
|
222
|
+
* (`originalHeaderHeight` and optional `contentContainerMinHeight`)
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```tsx
|
|
226
|
+
* function CustomScrollComponent() {
|
|
227
|
+
* const { scrollableProps, headerMotionContext } = useScrollManager('myScroll');
|
|
228
|
+
*
|
|
229
|
+
* return (
|
|
230
|
+
* <CustomScrollView {...scrollableProps}>
|
|
231
|
+
* <View
|
|
232
|
+
* style={{
|
|
233
|
+
* paddingTop: headerMotionContext.originalHeaderHeight,
|
|
234
|
+
* minHeight: headerMotionContext.contentContainerMinHeight,
|
|
235
|
+
* }}
|
|
236
|
+
* >
|
|
237
|
+
* Content
|
|
238
|
+
* </View>
|
|
239
|
+
* </CustomScrollView>
|
|
240
|
+
* );
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export function useScrollManager(scrollId, options) {
|
|
245
|
+
const {
|
|
246
|
+
originalHeaderHeight
|
|
247
|
+
} = useScrollManagerContext();
|
|
248
|
+
const id = scrollId ?? DEFAULT_SCROLL_ID;
|
|
249
|
+
const ensureScrollableContentMinHeight = options?.ensureScrollableContentMinHeight ?? false;
|
|
250
|
+
const refreshControl = options?.refreshControl;
|
|
251
|
+
const refreshing = options?.refreshing;
|
|
252
|
+
const onRefresh = options?.onRefresh;
|
|
253
|
+
const progressViewOffset = options?.progressViewOffset ?? originalHeaderHeight;
|
|
254
|
+
const localRef = useAnimatedRef();
|
|
255
|
+
const animatedRef = options?.animatedRef ?? localRef;
|
|
256
|
+
const {
|
|
257
|
+
contentContainerMinHeight,
|
|
258
|
+
handleLayout
|
|
259
|
+
} = useScrollManagerContentMinHeight({
|
|
260
|
+
enabled: ensureScrollableContentMinHeight
|
|
261
|
+
});
|
|
262
|
+
useScrollManagerSynchronization({
|
|
263
|
+
id,
|
|
264
|
+
animatedRef
|
|
265
|
+
});
|
|
266
|
+
const animatedOnScroll = useScrollManagerHandlers({
|
|
267
|
+
id,
|
|
268
|
+
consumerHandlers: {
|
|
269
|
+
onScroll: options?.onScroll,
|
|
270
|
+
onScrollBeginDrag: options?.onScrollBeginDrag,
|
|
271
|
+
onScrollEndDrag: options?.onScrollEndDrag,
|
|
272
|
+
onMomentumScrollBegin: options?.onMomentumScrollBegin,
|
|
273
|
+
onMomentumScrollEnd: options?.onMomentumScrollEnd
|
|
190
274
|
}
|
|
191
|
-
return {
|
|
192
|
-
minHeight: measurement.height + threshold
|
|
193
|
-
};
|
|
194
275
|
});
|
|
195
276
|
const resolvedRefreshControl = resolveRefreshControl({
|
|
196
277
|
refreshControl,
|
|
@@ -199,14 +280,14 @@ export function useScrollManager(scrollId, options) {
|
|
|
199
280
|
progressViewOffset
|
|
200
281
|
});
|
|
201
282
|
const scrollableProps = {
|
|
202
|
-
onScroll: animatedOnScroll,
|
|
203
|
-
|
|
283
|
+
onScroll: useScrollHandlerComposition(animatedOnScroll, options?.onScroll),
|
|
284
|
+
onLayout: handleLayout,
|
|
204
285
|
ref: animatedRef,
|
|
205
286
|
refreshControl: resolvedRefreshControl
|
|
206
287
|
};
|
|
207
288
|
const headerMotionContext = {
|
|
208
289
|
originalHeaderHeight,
|
|
209
|
-
|
|
290
|
+
contentContainerMinHeight
|
|
210
291
|
};
|
|
211
292
|
return {
|
|
212
293
|
scrollableProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useContext","useCallback","useEffect","
|
|
1
|
+
{"version":3,"names":["useContext","useCallback","useEffect","useState","cancelAnimation","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedScrollHandler","useSharedValue","scheduleOnRN","scheduleOnUI","HeaderMotionContext","resolveRefreshControl","DEFAULT_SCROLL_ID","ensureScrollValueRegistered","warnIfMissingActiveScrollId","useConsumerScrollHandlers","useScrollHandlerComposition","SCROLL_TOLERANCE","useScrollManagerContext","ctxValue","Error","useScrollManagerContentMinHeight","enabled","progressThreshold","preservedScrollContainerHeight","contentContainerMinHeight","setContentContainerMinHeight","undefined","handleLayout","e","nextHeight","nativeEvent","layout","height","set","nextMinHeight","get","threshold","previousThreshold","currentHeight","useScrollManagerSynchronization","animatedRef","id","activeScrollId","progress","scrollToRef","scrollValues","activeId","currentValues","current","y","scrollOptions","isValueDelta","animated","newY","scrollIdToDelete","modify","value","newProgress","oldProgress","currentActiveScrollId","newCur","scrollValue","progressDiff","newMin","min","useScrollManagerHandlers","consumerHandlers","headerPanMomentumOffset","onScroll","onBeginDrag","onEndDrag","onMomentumBegin","onMomentumEnd","handleScroll","ctx","newCurrent","contentOffset","lastOffset","Math","abs","values","activeScrollIdValue","oldCurrent","oldMin","isCollapsed","max","handleBeginDrag","useScrollManager","scrollId","options","originalHeaderHeight","ensureScrollableContentMinHeight","refreshControl","refreshing","onRefresh","progressViewOffset","localRef","animatedOnScroll","onScrollBeginDrag","onScrollEndDrag","onMomentumScrollBegin","onMomentumScrollEnd","resolvedRefreshControl","scrollableProps","onLayout","ref","headerMotionContext"],"sourceRoot":"../../../src","sources":["hooks/useScrollManager.ts"],"mappings":";;AAAA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,QAAQ,QAEH,OAAO;AACd,SACEC,eAAe,EACfC,QAAQ,EACRC,mBAAmB,EACnBC,cAAc,EACdC,wBAAwB,EACxBC,cAAc,QAGT,yBAAyB;AAChC,SAASC,YAAY,EAAEC,YAAY,QAAQ,uBAAuB;AAClE,SAASC,mBAAmB,QAAQ,eAAY;AAGhD,SACEC,qBAAqB,EACrBC,iBAAiB,EACjBC,2BAA2B,EAC3BC,2BAA2B,QAEtB,mBAAU;AAEjB,SACEC,yBAAyB,EACzBC,2BAA2B,QAEtB,gCAA6B;AAEpC,MAAMC,gBAAgB,GAAG,GAAG;AAoB5B,SAASC,uBAAuBA,CAAA,EAA8B;EAC5D,MAAMC,QAAQ,GAAGrB,UAAU,CAACY,mBAAmB,CAAC;EAChD,IAAI,CAACS,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CACb,+DACF,CAAC;EACH;EAEA,OAAOD,QAAQ;AACjB;AAEA,SAASE,gCAAgCA,CAAC;EAAEC;AAA0B,CAAC,EAAE;EACvE,MAAM;IAAEC;EAAkB,CAAC,GAAGL,uBAAuB,CAAC,CAAC;EACvD,MAAMM,8BAA8B,GAAGjB,cAAc,CAAC,CAAC,CAAC;EACxD,MAAM,CAACkB,yBAAyB,EAAEC,4BAA4B,CAAC,GAAGzB,QAAQ,CAExE0B,SAAS,CAAC;EAEZ,MAAMC,YAAY,GAAG7B,WAAW,CAC7B8B,CAAoB,IAAK;IACxB,IAAI,CAACP,OAAO,EAAE;MACZ;IACF;IAEA,MAAMQ,UAAU,GAAGD,CAAC,CAACE,WAAW,CAACC,MAAM,CAACC,MAAM;IAC9CxB,YAAY,CAAEwB,MAAc,IAAK;MAC/B,SAAS;;MACTT,8BAA8B,CA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9BE,EAAE;IACFD;EACF,CAAC,CAAC;EAEF,MAAMyD,gBAAgB,GAAGhC,wBAAwB,CAAC;IAChDxB,EAAE;IACFyB,gBAAgB,EAAE;MAChBE,QAAQ,EAAEqB,OAAO,EAAErB,QAAQ;MAC3B8B,iBAAiB,EAAET,OAAO,EAAES,iBAAiB;MAC7CC,eAAe,EAAEV,OAAO,EAAEU,eAAe;MACzCC,qBAAqB,EAAEX,OAAO,EAAEW,qBAAqB;MACrDC,mBAAmB,EAAEZ,OAAO,EAAEY;IAChC;EACF,CAAC,CAAC;EAEF,MAAMC,sBAAsB,GAAG5F,qBAAqB,CAAC;IACnDkF,cAAc;IACdC,UAAU;IACVC,SAAS;IACTC;EACF,CAAC,CAAC;EAEF,MAAMQ,eAAe,GAAG;IACtBnC,QAAQ,EAAErD,2BAA2B,CAACkF,gBAAgB,EAAER,OAAO,EAAErB,QAAQ,CAAC;IAC1EoC,QAAQ,EAAE7E,YAAY;IACtB8E,GAAG,EAAEjE,WAAW;IAChBoD,cAAc,EAAEU;EAClB,CAAC;EACD,MAAMI,mBAAmB,GAAG;IAC1BhB,oBAAoB;IACpBlE;EACF,CAAC;EAED,OAAO;IAAE+E,eAAe;IAAEG;EAAoB,CAAC;AACjD","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Compound component type for HeaderMotion.
|
|
7
|
-
* Provides the main context provider and sub-components for building collapsible headers.
|
|
8
|
-
*/
|
|
9
|
-
|
|
3
|
+
import { createHeaderMotionScrollable, Bridge, HeaderMotionContextProvider, FlatList, Header, NavigationBridge, ScrollManager, ScrollView } from "./components/index.js";
|
|
10
4
|
/**
|
|
11
5
|
* Main HeaderMotion component.
|
|
12
|
-
*
|
|
6
|
+
* Root provider and compound entrypoint for the library.
|
|
7
|
+
*
|
|
8
|
+
* It tracks header measurements, derives the shared `progress` value, and
|
|
9
|
+
* exposes the pre-wired subcomponents used to connect headers and scrollables.
|
|
13
10
|
*
|
|
14
11
|
* @example
|
|
15
12
|
* ```tsx
|
|
16
13
|
* <HeaderMotion>
|
|
17
|
-
* <HeaderMotion.
|
|
18
|
-
* {(
|
|
14
|
+
* <HeaderMotion.Bridge>
|
|
15
|
+
* {(value) => (
|
|
19
16
|
* <Stack.Screen
|
|
20
17
|
* options={{
|
|
21
18
|
* header: () => (
|
|
22
|
-
* <
|
|
19
|
+
* <HeaderMotion.NavigationBridge value={value}>
|
|
20
|
+
* <MyAnimatedHeader />
|
|
21
|
+
* </HeaderMotion.NavigationBridge>
|
|
23
22
|
* ),
|
|
24
23
|
* }}
|
|
25
24
|
* />
|
|
26
25
|
* )}
|
|
27
|
-
* </HeaderMotion.
|
|
26
|
+
* </HeaderMotion.Bridge>
|
|
28
27
|
* <HeaderMotion.ScrollView>
|
|
29
28
|
* <MyScrollableContent />
|
|
30
29
|
* </HeaderMotion.ScrollView>
|
|
31
30
|
* </HeaderMotion>
|
|
32
31
|
* ```
|
|
33
32
|
*/
|
|
34
|
-
const HeaderMotion = HeaderMotionContextProvider
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const HeaderMotion = Object.assign(HeaderMotionContextProvider, {
|
|
34
|
+
Header,
|
|
35
|
+
Bridge,
|
|
36
|
+
NavigationBridge,
|
|
37
|
+
ScrollManager,
|
|
38
|
+
ScrollView,
|
|
39
|
+
FlatList
|
|
40
|
+
});
|
|
39
41
|
export default HeaderMotion;
|
|
40
42
|
export * from "./hooks/index.js";
|
|
41
|
-
export {
|
|
43
|
+
export { createHeaderMotionScrollable };
|
|
44
|
+
export { Bridge, Header, NavigationBridge };
|
|
42
45
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHeaderMotionScrollable","Bridge","HeaderMotionContextProvider","FlatList","Header","NavigationBridge","ScrollManager","ScrollView","HeaderMotion","Object","assign"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SACEA,4BAA4B,EAC5BC,MAAM,EACNC,2BAA2B,EAC3BC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,QAUL,uBAAc;AA8CrB;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,MAAMC,YAAkC,GAAGC,MAAM,CAACC,MAAM,CACtDR,2BAA2B,EAC3B;EACEE,MAAM;EACNH,MAAM;EACNI,gBAAgB;EAChBC,aAAa;EACbC,UAAU;EACVJ;AACF,CACF,CAAC;AAED,eAAeK,YAAY;AAC3B,cAAc,kBAAS;AAEvB,SAASR,4BAA4B;AACrC,SAASC,MAAM,EAAEG,MAAM,EAAEC,gBAAgB","ignoreList":[]}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const DEFAULT_PROGRESS_THRESHOLD = measuredHeaderValue => measuredHeaderValue;
|
|
4
4
|
const DEFAULT_MEASURE_DYNAMIC = e => e.nativeEvent.layout.height;
|
|
5
|
+
const DEFAULT_HEADER_OFFSET_STRATEGY = 'padding';
|
|
5
6
|
|
|
6
7
|
// Symbol doesn't work?
|
|
7
8
|
// const DEFAULT_SCROLL_ID = Symbol("HEADER_MOTION_DEFAULT_SCROLL_ID");
|
|
8
9
|
const DEFAULT_SCROLL_ID = '__HEADER_MOTION_DEFAULT_SCROLL_ID__';
|
|
9
|
-
export { DEFAULT_MEASURE_DYNAMIC, DEFAULT_PROGRESS_THRESHOLD, DEFAULT_SCROLL_ID };
|
|
10
|
+
export { DEFAULT_HEADER_OFFSET_STRATEGY, DEFAULT_MEASURE_DYNAMIC, DEFAULT_PROGRESS_THRESHOLD, DEFAULT_SCROLL_ID };
|
|
10
11
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_PROGRESS_THRESHOLD","measuredHeaderValue","DEFAULT_MEASURE_DYNAMIC","e","nativeEvent","layout","height","DEFAULT_SCROLL_ID"],"sourceRoot":"../../../src","sources":["utils/defaults.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["DEFAULT_PROGRESS_THRESHOLD","measuredHeaderValue","DEFAULT_MEASURE_DYNAMIC","e","nativeEvent","layout","height","DEFAULT_HEADER_OFFSET_STRATEGY","DEFAULT_SCROLL_ID"],"sourceRoot":"../../../src","sources":["utils/defaults.ts"],"mappings":";;AAMA,MAAMA,0BAA6C,GAAIC,mBAAmB,IACxEA,mBAAmB;AACrB,MAAMC,uBAA8C,GAAIC,CAAC,IACvDA,CAAC,CAACC,WAAW,CAACC,MAAM,CAACC,MAAM;AAC7B,MAAMC,8BAA0D,GAAG,SAAS;;AAE5E;AACA;AACA,MAAMC,iBAAiB,GAAG,qCAAqC;AAE/D,SACED,8BAA8B,EAC9BL,uBAAuB,EACvBF,0BAA0B,EAC1BQ,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Fragment, cloneElement, isValidElement } from 'react';
|
|
4
|
+
export function composeOnLayoutHandlers(userHandler, internalHandler) {
|
|
5
|
+
return e => {
|
|
6
|
+
internalHandler?.(e);
|
|
7
|
+
userHandler?.(e);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function resolveSlottableChild(componentName, child) {
|
|
11
|
+
if (! /*#__PURE__*/isValidElement(child) || child.type === Fragment) {
|
|
12
|
+
throw new Error(`${componentName} with \`asChild\` expects a single valid React element child that accepts \`onLayout\`.`);
|
|
13
|
+
}
|
|
14
|
+
return child;
|
|
15
|
+
}
|
|
16
|
+
export function cloneWithOnLayout(child, onLayout, componentName) {
|
|
17
|
+
if (! /*#__PURE__*/isValidElement(child)) {
|
|
18
|
+
throw new Error(`${componentName} with \`asChild\` expects a valid React element child.`);
|
|
19
|
+
}
|
|
20
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
21
|
+
onLayout: composeOnLayoutHandlers(child.props.onLayout, onLayout)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Fragment","cloneElement","isValidElement","composeOnLayoutHandlers","userHandler","internalHandler","e","resolveSlottableChild","componentName","child","type","Error","cloneWithOnLayout","onLayout","props"],"sourceRoot":"../../../src","sources":["utils/header.tsx"],"mappings":";;AAAA,SACEA,QAAQ,EACRC,YAAY,EACZC,cAAc,QAET,OAAO;AASd,OAAO,SAASC,uBAAuBA,CACrCC,WAAkC,EAClCC,eAAsC,EACtC;EACA,OAAQC,CAAoD,IAAK;IAC/DD,eAAe,GAAGC,CAAC,CAAC;IACpBF,WAAW,GAAGE,CAAC,CAAC;EAClB,CAAC;AACH;AAEA,OAAO,SAASC,qBAAqBA,CACnCC,aAAqB,EACrBC,KAAmB,EACnB;EACA,IAAI,eAACP,cAAc,CAACO,KAAK,CAAC,IAAIA,KAAK,CAACC,IAAI,KAAKV,QAAQ,EAAE;IACrD,MAAM,IAAIW,KAAK,CACb,GAAGH,aAAa,yFAClB,CAAC;EACH;EAEA,OAAOC,KAAK;AACd;AAEA,OAAO,SAASG,iBAAiBA,CAC/BH,KAAuB,EACvBI,QAA+B,EAC/BL,aAAqB,EACrB;EACA,IAAI,eAACN,cAAc,CAACO,KAAK,CAAC,EAAE;IAC1B,MAAM,IAAIE,KAAK,CACb,GAAGH,aAAa,wDAClB,CAAC;EACH;EAEA,oBAAOP,YAAY,CAACQ,KAAK,EAAE;IACzBI,QAAQ,EAAEV,uBAAuB,CAACM,KAAK,CAACK,KAAK,CAACD,QAAQ,EAAEA,QAAQ;EAClE,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_HEADER_OFFSET_STRATEGY } from "./defaults.js";
|
|
4
|
+
export function resolveHeaderOffsetStyle(originalHeaderHeight, headerOffsetStrategy = DEFAULT_HEADER_OFFSET_STRATEGY) {
|
|
5
|
+
switch (headerOffsetStrategy) {
|
|
6
|
+
case 'none':
|
|
7
|
+
return undefined;
|
|
8
|
+
case 'margin':
|
|
9
|
+
return {
|
|
10
|
+
marginTop: originalHeaderHeight
|
|
11
|
+
};
|
|
12
|
+
case 'top':
|
|
13
|
+
return {
|
|
14
|
+
top: originalHeaderHeight,
|
|
15
|
+
paddingBottom: originalHeaderHeight
|
|
16
|
+
};
|
|
17
|
+
case 'translate':
|
|
18
|
+
return {
|
|
19
|
+
transform: [{
|
|
20
|
+
translateY: originalHeaderHeight
|
|
21
|
+
}],
|
|
22
|
+
paddingBottom: originalHeaderHeight
|
|
23
|
+
};
|
|
24
|
+
case 'padding':
|
|
25
|
+
default:
|
|
26
|
+
return {
|
|
27
|
+
paddingTop: originalHeaderHeight
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=headerOffsetStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_HEADER_OFFSET_STRATEGY","resolveHeaderOffsetStyle","originalHeaderHeight","headerOffsetStrategy","undefined","marginTop","top","paddingBottom","transform","translateY","paddingTop"],"sourceRoot":"../../../src","sources":["utils/headerOffsetStyle.ts"],"mappings":";;AAEA,SAASA,8BAA8B,QAAQ,eAAY;AAc3D,OAAO,SAASC,wBAAwBA,CACtCC,oBAAuC,EACvCC,oBAAgD,GAAGH,8BAA8B,EAC9D;EACnB,QAAQG,oBAAoB;IAC1B,KAAK,MAAM;MACT,OAAOC,SAAS;IAClB,KAAK,QAAQ;MACX,OAAO;QAAEC,SAAS,EAAEH;MAAqB,CAAC;IAC5C,KAAK,KAAK;MACR,OAAO;QACLI,GAAG,EAAEJ,oBAAoB;QACzBK,aAAa,EAAEL;MACjB,CAAC;IACH,KAAK,WAAW;MACd,OAAO;QACLM,SAAS,EAAE,CAAC;UAAEC,UAAU,EAAEP;QAAqB,CAAC,CAAC;QACjDK,aAAa,EAAEL;MACjB,CAAC;IACH,KAAK,SAAS;IACd;MACE,OAAO;QAAEQ,UAAU,EAAER;MAAqB,CAAC;EAC/C;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;AAAA,cAAc,eAAY;AAC1B,cAAc,aAAU;AACxB,cAAc,qBAAkB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;AAAA,cAAc,eAAY;AAC1B,cAAc,aAAU;AACxB,cAAc,wBAAqB;AACnC,cAAc,aAAU;AACxB,cAAc,qBAAkB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docusaurus.config.d.ts","sourceRoot":"","sources":["../../../docs/docusaurus.config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD,QAAA,MAAM,MAAM,EAAE,MAwIb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidebars.d.ts","sourceRoot":"","sources":["../../../docs/sidebars.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,QAAA,MAAM,QAAQ,EAAE,cA8Ef,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../docs/src/pages/index.tsx"],"names":[],"mappings":"AA0LA,MAAM,CAAC,OAAO,UAAU,IAAI,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAUhD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { HeaderMotionBridgeValue } from '../types';
|
|
3
|
+
type HeaderRenderChildren = (value: HeaderMotionBridgeValue) => ReactNode;
|
|
4
|
+
export interface HeaderMotionBridgeProps {
|
|
5
|
+
/**
|
|
6
|
+
* Render function that receives the current HeaderMotion context value.
|
|
7
|
+
*
|
|
8
|
+
* Use this when you need to pass the library's context across a React tree
|
|
9
|
+
* boundary, most commonly into a navigation-rendered header.
|
|
10
|
+
*/
|
|
11
|
+
children: HeaderRenderChildren;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads the current HeaderMotion context and exposes it through a render
|
|
15
|
+
* function so it can be forwarded into another subtree.
|
|
16
|
+
*/
|
|
17
|
+
export declare function Bridge({ children }: HeaderMotionBridgeProps): ReactNode;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=Bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bridge.d.ts","sourceRoot":"","sources":["../../../../src/components/Bridge.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,uBAAuB,KAAK,SAAS,CAAC;AAE1E,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,QAAQ,EAAE,oBAAoB,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,uBAAuB,aAQ3D"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Animated, { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Use this when you have multiple scroll views (e.g. in tabs) to track them separately.
|
|
7
|
-
*/
|
|
8
|
-
scrollId?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Optional animated ref to use for the flat list.
|
|
11
|
-
* When provided, the scroll manager will use this ref instead of creating its own.
|
|
12
|
-
*/
|
|
13
|
-
animatedRef?: AnimatedRef<Animated.FlatList<T>> | AnimatedRef;
|
|
14
|
-
};
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import Animated, { type FlatListPropsWithLayout } from 'react-native-reanimated';
|
|
3
|
+
import { type HeaderMotionScrollableOwnProps } from './createHeaderMotionScrollable';
|
|
4
|
+
export type HeaderMotionFlatListProps<T = any> = FlatListPropsWithLayout<T> & HeaderMotionScrollableOwnProps<Animated.FlatList<T>>;
|
|
5
|
+
type FlatListComponent = <T = any>(props: HeaderMotionFlatListProps<T>) => ReactElement | null;
|
|
15
6
|
/**
|
|
16
7
|
* Animated FlatList component that integrates with HeaderMotion.
|
|
17
8
|
* Automatically handles scroll tracking and header animation synchronization.
|
|
@@ -29,5 +20,6 @@ export type HeaderMotionFlatListProps<T = any> = ComponentProps<typeof Animated.
|
|
|
29
20
|
* </HeaderMotion>
|
|
30
21
|
* ```
|
|
31
22
|
*/
|
|
32
|
-
export declare
|
|
23
|
+
export declare const FlatList: FlatListComponent;
|
|
24
|
+
export {};
|
|
33
25
|
//# sourceMappingURL=FlatList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlatList.d.ts","sourceRoot":"","sources":["../../../../src/components/FlatList.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FlatList.d.ts","sourceRoot":"","sources":["../../../../src/components/FlatList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,QAAQ,EAAE,EACf,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,uBAAuB,CAAC,CAAC,CAAC,GACzE,8BAA8B,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvD,KAAK,iBAAiB,GAAG,CAAC,CAAC,GAAG,GAAG,EAC/B,KAAK,EAAE,yBAAyB,CAAC,CAAC,CAAC,KAChC,YAAY,GAAG,IAAI,CAAC;AAEzB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,EAIf,iBAAiB,CAAC"}
|