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.
Files changed (137) hide show
  1. package/README.md +65 -528
  2. package/lib/module/components/Bridge.js +16 -0
  3. package/lib/module/components/Bridge.js.map +1 -0
  4. package/lib/module/components/FlatList.js +5 -54
  5. package/lib/module/components/FlatList.js.map +1 -1
  6. package/lib/module/components/Header.js +71 -13
  7. package/lib/module/components/Header.js.map +1 -1
  8. package/lib/module/components/HeaderDynamic.js +34 -0
  9. package/lib/module/components/HeaderDynamic.js.map +1 -0
  10. package/lib/module/components/HeaderMotion.js +14 -20
  11. package/lib/module/components/HeaderMotion.js.map +1 -1
  12. package/lib/module/components/HeaderPanBoundary.js +54 -0
  13. package/lib/module/components/HeaderPanBoundary.js.map +1 -0
  14. package/lib/module/components/NavigationBridge.js +20 -0
  15. package/lib/module/components/NavigationBridge.js.map +1 -0
  16. package/lib/module/components/ScrollManager.js +19 -7
  17. package/lib/module/components/ScrollManager.js.map +1 -1
  18. package/lib/module/components/ScrollView.js +6 -39
  19. package/lib/module/components/ScrollView.js.map +1 -1
  20. package/lib/module/components/createHeaderMotionScrollable.js +136 -0
  21. package/lib/module/components/createHeaderMotionScrollable.js.map +1 -0
  22. package/lib/module/components/index.js +3 -1
  23. package/lib/module/components/index.js.map +1 -1
  24. package/lib/module/context.js +8 -1
  25. package/lib/module/context.js.map +1 -1
  26. package/lib/module/hooks/index.js +1 -0
  27. package/lib/module/hooks/index.js.map +1 -1
  28. package/lib/module/hooks/useActiveScrollId.js +7 -6
  29. package/lib/module/hooks/useActiveScrollId.js.map +1 -1
  30. package/lib/module/hooks/useConsumerScrollHandlers.js +86 -0
  31. package/lib/module/hooks/useConsumerScrollHandlers.js.map +1 -0
  32. package/lib/module/hooks/useHeaderMotionBridge.js +14 -0
  33. package/lib/module/hooks/useHeaderMotionBridge.js.map +1 -0
  34. package/lib/module/hooks/useMotionProgress.js +12 -42
  35. package/lib/module/hooks/useMotionProgress.js.map +1 -1
  36. package/lib/module/hooks/useMotionProgress.test.js +56 -0
  37. package/lib/module/hooks/useMotionProgress.test.js.map +1 -0
  38. package/lib/module/hooks/useScrollManager.js +168 -87
  39. package/lib/module/hooks/useScrollManager.js.map +1 -1
  40. package/lib/module/index.js +21 -18
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/utils/defaults.js +2 -1
  43. package/lib/module/utils/defaults.js.map +1 -1
  44. package/lib/module/utils/header.js +24 -0
  45. package/lib/module/utils/header.js.map +1 -0
  46. package/lib/module/utils/headerOffsetStyle.js +31 -0
  47. package/lib/module/utils/headerOffsetStyle.js.map +1 -0
  48. package/lib/module/utils/index.js +2 -0
  49. package/lib/module/utils/index.js.map +1 -1
  50. package/lib/typescript/docs/docusaurus.config.d.ts +4 -0
  51. package/lib/typescript/docs/docusaurus.config.d.ts.map +1 -0
  52. package/lib/typescript/docs/sidebars.d.ts +4 -0
  53. package/lib/typescript/docs/sidebars.d.ts.map +1 -0
  54. package/lib/typescript/docs/src/pages/index.d.ts +2 -0
  55. package/lib/typescript/docs/src/pages/index.d.ts.map +1 -0
  56. package/lib/typescript/src/components/Bridge.d.ts +19 -0
  57. package/lib/typescript/src/components/Bridge.d.ts.map +1 -0
  58. package/lib/typescript/src/components/FlatList.d.ts +7 -15
  59. package/lib/typescript/src/components/FlatList.d.ts.map +1 -1
  60. package/lib/typescript/src/components/Header.d.ts +73 -12
  61. package/lib/typescript/src/components/Header.d.ts.map +1 -1
  62. package/lib/typescript/src/components/HeaderDynamic.d.ts +11 -0
  63. package/lib/typescript/src/components/HeaderDynamic.d.ts.map +1 -0
  64. package/lib/typescript/src/components/HeaderMotion.d.ts +38 -23
  65. package/lib/typescript/src/components/HeaderMotion.d.ts.map +1 -1
  66. package/lib/typescript/src/components/HeaderPanBoundary.d.ts +11 -0
  67. package/lib/typescript/src/components/HeaderPanBoundary.d.ts.map +1 -0
  68. package/lib/typescript/src/components/NavigationBridge.d.ts +19 -0
  69. package/lib/typescript/src/components/NavigationBridge.d.ts.map +1 -0
  70. package/lib/typescript/src/components/ScrollManager.d.ts +13 -9
  71. package/lib/typescript/src/components/ScrollManager.d.ts.map +1 -1
  72. package/lib/typescript/src/components/ScrollView.d.ts +7 -14
  73. package/lib/typescript/src/components/ScrollView.d.ts.map +1 -1
  74. package/lib/typescript/src/components/createHeaderMotionScrollable.d.ts +86 -0
  75. package/lib/typescript/src/components/createHeaderMotionScrollable.d.ts.map +1 -0
  76. package/lib/typescript/src/components/index.d.ts +3 -1
  77. package/lib/typescript/src/components/index.d.ts.map +1 -1
  78. package/lib/typescript/src/context.d.ts +3 -17
  79. package/lib/typescript/src/context.d.ts.map +1 -1
  80. package/lib/typescript/src/hooks/index.d.ts +1 -0
  81. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  82. package/lib/typescript/src/hooks/useActiveScrollId.d.ts +7 -6
  83. package/lib/typescript/src/hooks/useActiveScrollId.d.ts.map +1 -1
  84. package/lib/typescript/src/hooks/useConsumerScrollHandlers.d.ts +64 -0
  85. package/lib/typescript/src/hooks/useConsumerScrollHandlers.d.ts.map +1 -0
  86. package/lib/typescript/src/hooks/useHeaderMotionBridge.d.ts +10 -0
  87. package/lib/typescript/src/hooks/useHeaderMotionBridge.d.ts.map +1 -0
  88. package/lib/typescript/src/hooks/useMotionProgress.d.ts +8 -25
  89. package/lib/typescript/src/hooks/useMotionProgress.d.ts.map +1 -1
  90. package/lib/typescript/src/hooks/useMotionProgress.test.d.ts +2 -0
  91. package/lib/typescript/src/hooks/useMotionProgress.test.d.ts.map +1 -0
  92. package/lib/typescript/src/hooks/useScrollManager.d.ts +61 -29
  93. package/lib/typescript/src/hooks/useScrollManager.d.ts.map +1 -1
  94. package/lib/typescript/src/index.d.ts +56 -26
  95. package/lib/typescript/src/index.d.ts.map +1 -1
  96. package/lib/typescript/src/types.d.ts +54 -17
  97. package/lib/typescript/src/types.d.ts.map +1 -1
  98. package/lib/typescript/src/utils/defaults.d.ts +3 -2
  99. package/lib/typescript/src/utils/defaults.d.ts.map +1 -1
  100. package/lib/typescript/src/utils/header.d.ts +10 -0
  101. package/lib/typescript/src/utils/header.d.ts.map +1 -0
  102. package/lib/typescript/src/utils/headerOffsetStyle.d.ts +19 -0
  103. package/lib/typescript/src/utils/headerOffsetStyle.d.ts.map +1 -0
  104. package/lib/typescript/src/utils/index.d.ts +2 -0
  105. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  106. package/lib/typescript/src/utils/refreshControl.d.ts +12 -12
  107. package/package.json +12 -5
  108. package/src/components/Bridge.tsx +29 -0
  109. package/src/components/FlatList.tsx +18 -76
  110. package/src/components/Header.tsx +159 -23
  111. package/src/components/HeaderDynamic.tsx +45 -0
  112. package/src/components/HeaderMotion.tsx +47 -50
  113. package/src/components/HeaderPanBoundary.tsx +92 -0
  114. package/src/components/NavigationBridge.tsx +30 -0
  115. package/src/components/ScrollManager.tsx +23 -11
  116. package/src/components/ScrollView.tsx +16 -60
  117. package/src/components/createHeaderMotionScrollable.tsx +438 -0
  118. package/src/components/index.ts +3 -1
  119. package/src/context.ts +11 -24
  120. package/src/hooks/index.ts +1 -0
  121. package/src/hooks/useActiveScrollId.ts +7 -6
  122. package/src/hooks/useConsumerScrollHandlers.ts +148 -0
  123. package/src/hooks/useHeaderMotionBridge.ts +15 -0
  124. package/src/hooks/useMotionProgress.test.ts +67 -0
  125. package/src/hooks/useMotionProgress.ts +12 -45
  126. package/src/hooks/useScrollManager.ts +251 -114
  127. package/src/index.ts +82 -36
  128. package/src/types.ts +81 -29
  129. package/src/utils/defaults.ts +7 -1
  130. package/src/utils/header.tsx +52 -0
  131. package/src/utils/headerOffsetStyle.ts +40 -0
  132. package/src/utils/index.ts +2 -0
  133. package/lib/module/components/HeaderBase.js +0 -107
  134. package/lib/module/components/HeaderBase.js.map +0 -1
  135. package/lib/typescript/src/components/HeaderBase.d.ts +0 -41
  136. package/lib/typescript/src/components/HeaderBase.d.ts.map +0 -1
  137. package/src/components/HeaderBase.tsx +0 -140
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ import { forwardRef, useCallback, useLayoutEffect, useMemo, useRef } from 'react';
4
+ import Animated from 'react-native-reanimated';
5
+ import { useScrollManager } from "../hooks/index.js";
6
+ import { resolveHeaderOffsetStyle } from "../utils/index.js";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export function createHeaderMotionScrollable(ScrollableComponent, options) {
9
+ const {
10
+ isComponentAnimated = false,
11
+ contentContainerMode = 'renderScrollComponent',
12
+ displayName = `HeaderMotion(${getDisplayName(ScrollableComponent)})`
13
+ } = options || {};
14
+ const AnimatedScrollable = isComponentAnimated ? ScrollableComponent : Animated.createAnimatedComponent(ScrollableComponent);
15
+ function HeaderMotionScrollable(props) {
16
+ const {
17
+ scrollId,
18
+ animatedRef,
19
+ headerOffsetStrategy,
20
+ ensureScrollableContentMinHeight = false,
21
+ contentContainerStyle,
22
+ refreshControl,
23
+ refreshing,
24
+ onRefresh,
25
+ progressViewOffset,
26
+ onScroll,
27
+ onScrollBeginDrag,
28
+ onScrollEndDrag,
29
+ onMomentumScrollBegin,
30
+ onMomentumScrollEnd,
31
+ ...rest
32
+ } = props;
33
+ const {
34
+ scrollableProps,
35
+ headerMotionContext
36
+ } = useScrollManager(scrollId, {
37
+ refreshControl: refreshControl ?? undefined,
38
+ refreshing: refreshing ?? undefined,
39
+ onRefresh: onRefresh ?? undefined,
40
+ progressViewOffset,
41
+ onScroll,
42
+ onScrollBeginDrag,
43
+ onScrollEndDrag,
44
+ onMomentumScrollBegin,
45
+ onMomentumScrollEnd,
46
+ animatedRef,
47
+ ensureScrollableContentMinHeight
48
+ });
49
+ const {
50
+ onScroll: managedOnScroll,
51
+ onLayout: managedOnLayout,
52
+ refreshControl: managedRefreshControl,
53
+ ref,
54
+ ...scrollViewProps
55
+ } = scrollableProps;
56
+ const {
57
+ originalHeaderHeight,
58
+ contentContainerMinHeight
59
+ } = headerMotionContext;
60
+ const userOnLayoutRef = useRef(rest.onLayout);
61
+ useLayoutEffect(() => {
62
+ userOnLayoutRef.current = rest.onLayout;
63
+ });
64
+ const managedContentContainerStyle = useMemo(() => [ensureScrollableContentMinHeight && contentContainerMinHeight !== undefined ? {
65
+ minHeight: contentContainerMinHeight
66
+ } : undefined, resolveHeaderOffsetStyle(originalHeaderHeight, headerOffsetStrategy), contentContainerStyle], [contentContainerStyle, contentContainerMinHeight, ensureScrollableContentMinHeight, headerOffsetStrategy, originalHeaderHeight]);
67
+ const refreshControlProps = managedRefreshControl && {
68
+ refreshControl: managedRefreshControl
69
+ };
70
+ const handleLayout = useCallback(e => {
71
+ managedOnLayout?.(e);
72
+ userOnLayoutRef.current?.(e);
73
+ }, [managedOnLayout]);
74
+ const contentContainerProps = useContentContainerProps({
75
+ children: rest.children,
76
+ mode: contentContainerMode,
77
+ style: managedContentContainerStyle
78
+ });
79
+ return /*#__PURE__*/_jsx(AnimatedScrollable, {
80
+ ...scrollViewProps,
81
+ ...rest,
82
+ ...refreshControlProps,
83
+ ...contentContainerProps,
84
+ ref: ref,
85
+ onLayout: handleLayout,
86
+ onScroll: managedOnScroll
87
+ });
88
+ }
89
+ const TypedHeaderMotionScrollable = HeaderMotionScrollable;
90
+ TypedHeaderMotionScrollable.displayName = displayName;
91
+ return TypedHeaderMotionScrollable;
92
+ }
93
+ function useContentContainerProps({
94
+ children: rawChildren,
95
+ mode,
96
+ style
97
+ }) {
98
+ const renderScrollComponent = useCallback(props => /*#__PURE__*/_jsx(AnimatedScrollContainer, {
99
+ ...props,
100
+ contentContainerStyle: style
101
+ }), [style]);
102
+ const children = /*#__PURE__*/_jsx(Animated.View, {
103
+ style: style,
104
+ children: rawChildren
105
+ });
106
+ if (mode === 'children') {
107
+ return {
108
+ children
109
+ };
110
+ }
111
+ return {
112
+ renderScrollComponent
113
+ };
114
+ }
115
+ const AnimatedScrollContainer = /*#__PURE__*/forwardRef(({
116
+ children,
117
+ contentContainerStyle,
118
+ ...rest
119
+ }, ref) => {
120
+ return /*#__PURE__*/_jsx(Animated.ScrollView, {
121
+ ...rest,
122
+ ref: ref,
123
+ children: /*#__PURE__*/_jsx(Animated.View, {
124
+ style: contentContainerStyle,
125
+ children: children
126
+ })
127
+ });
128
+ });
129
+ function getDisplayName(ScrollableComponent) {
130
+ return ScrollableComponent.displayName ?? ScrollableComponent.name ?? 'Scrollable';
131
+ }
132
+
133
+ // TODO: From here below Codex did some absolute TypeScript magic but it seems to work
134
+ // Having limited time, I can't spend more on adjusting this to make it less convoluted
135
+ // But what matters is that it seems that for the user the types work very well
136
+ //# sourceMappingURL=createHeaderMotionScrollable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","useCallback","useLayoutEffect","useMemo","useRef","Animated","useScrollManager","resolveHeaderOffsetStyle","jsx","_jsx","createHeaderMotionScrollable","ScrollableComponent","options","isComponentAnimated","contentContainerMode","displayName","getDisplayName","AnimatedScrollable","createAnimatedComponent","HeaderMotionScrollable","props","scrollId","animatedRef","headerOffsetStrategy","ensureScrollableContentMinHeight","contentContainerStyle","refreshControl","refreshing","onRefresh","progressViewOffset","onScroll","onScrollBeginDrag","onScrollEndDrag","onMomentumScrollBegin","onMomentumScrollEnd","rest","scrollableProps","headerMotionContext","undefined","managedOnScroll","onLayout","managedOnLayout","managedRefreshControl","ref","scrollViewProps","originalHeaderHeight","contentContainerMinHeight","userOnLayoutRef","current","managedContentContainerStyle","minHeight","refreshControlProps","handleLayout","e","contentContainerProps","useContentContainerProps","children","mode","style","TypedHeaderMotionScrollable","rawChildren","renderScrollComponent","AnimatedScrollContainer","View","ScrollView","name"],"sourceRoot":"../../../src","sources":["components/createHeaderMotionScrollable.tsx"],"mappings":";;AAAA,SACEA,UAAU,EACVC,WAAW,EACXC,eAAe,EACfC,OAAO,EACPC,MAAM,QAKD,OAAO;AAEd,OAAOC,QAAQ,MAGR,yBAAyB;AAEhC,SAASC,gBAAgB,QAAsC,mBAAU;AAEzE,SAASC,wB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BA,CAAC;EAChCC,QAAQ,EAAEI,WAAW;EACrBH,IAAI;EACJC;AAKF,CAAC,EAAE;EACD,MAAMG,qBAAqB,GAAG5D,WAAW,CACtCmB,KAAsB,iBACrBX,IAAA,CAACqD,uBAAuB;IAAA,GAAK1C,KAAK;IAAEK,qBAAqB,EAAEiC;EAAM,CAAE,CACpE,EACD,CAACA,KAAK,CACR,CAAC;EAED,MAAMF,QAAQ,gBAAG/C,IAAA,CAACJ,QAAQ,CAAC0D,IAAI;IAACL,KAAK,EAAEA,KAAM;IAAAF,QAAA,EAAEI;EAAW,CAAgB,CAAC;EAE3E,IAAIH,IAAI,KAAK,UAAU,EAAE;IACvB,OAAO;MAAED;IAAS,CAAC;EACrB;EAEA,OAAO;IACLK;EACF,CAAC;AACH;AAEA,MAAMC,uBAAuB,gBAAG9D,UAAU,CAGxC,CAAC;EAAEwD,QAAQ;EAAE/B,qBAAqB;EAAE,GAAGU;AAAK,CAAC,EAAEQ,GAAG,KAAK;EACvD,oBACElC,IAAA,CAACJ,QAAQ,CAAC2D,UAAU;IAAA,GAAK7B,IAAI;IAAEQ,GAAG,EAAEA,GAAI;IAAAa,QAAA,eACtC/C,IAAA,CAACJ,QAAQ,CAAC0D,IAAI;MAACL,KAAK,EAAEjC,qBAAsB;MAAA+B,QAAA,EAAEA;IAAQ,CAAgB;EAAC,CACpD,CAAC;AAE1B,CAAC,CAAC;AAEF,SAASxC,cAAcA,CAACL,mBAGvB,EAAE;EACD,OACEA,mBAAmB,CAACI,WAAW,IAAIJ,mBAAmB,CAACsD,IAAI,IAAI,YAAY;AAE/E;;AAIA;AACA;AACA","ignoreList":[]}
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ export * from "./Bridge.js";
3
4
  export * from "./FlatList.js";
4
5
  export * from "./Header.js";
5
- export * from "./HeaderBase.js";
6
+ export * from "./NavigationBridge.js";
6
7
  export * from "./HeaderMotion.js";
7
8
  export * from "./ScrollManager.js";
8
9
  export * from "./ScrollView.js";
10
+ export * from "./createHeaderMotionScrollable.js";
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["components/index.ts"],"mappings":";;AAAA,cAAc,eAAY;AAC1B,cAAc,aAAU;AACxB,cAAc,iBAAc;AAC5B,cAAc,mBAAgB;AAC9B,cAAc,oBAAiB;AAC/B,cAAc,iBAAc","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["components/index.ts"],"mappings":";;AAAA,cAAc,aAAU;AACxB,cAAc,eAAY;AAC1B,cAAc,aAAU;AACxB,cAAc,uBAAoB;AAClC,cAAc,mBAAgB;AAC9B,cAAc,oBAAiB;AAC/B,cAAc,iBAAc;AAC5B,cAAc,mCAAgC","ignoreList":[]}
@@ -1,5 +1,12 @@
1
1
  "use strict";
2
2
 
3
- import { createContext } from 'react';
3
+ import { createContext, useContext } from 'react';
4
4
  export const HeaderMotionContext = /*#__PURE__*/createContext(null);
5
+ export function useHeaderMotionContextOrThrow(errorMessage) {
6
+ const ctxValue = useContext(HeaderMotionContext);
7
+ if (!ctxValue) {
8
+ throw new Error(errorMessage);
9
+ }
10
+ return ctxValue;
11
+ }
5
12
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createContext","HeaderMotionContext"],"sourceRoot":"../../src","sources":["context.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,OAAO;AAyBrC,OAAO,MAAMC,mBAAmB,gBAC9BD,aAAa,CAAiC,IAAI,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createContext","useContext","HeaderMotionContext","useHeaderMotionContextOrThrow","errorMessage","ctxValue","Error"],"sourceRoot":"../../src","sources":["context.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AAGjD,OAAO,MAAMC,mBAAmB,gBAC9BF,aAAa,CAAiC,IAAI,CAAC;AAErD,OAAO,SAASG,6BAA6BA,CAACC,YAAoB,EAAE;EAClE,MAAMC,QAAQ,GAAGJ,UAAU,CAACC,mBAAmB,CAAC;EAChD,IAAI,CAACG,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CAACF,YAAY,CAAC;EAC/B;EAEA,OAAOC,QAAQ;AACjB","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  export * from "./useActiveScrollId.js";
4
+ export * from "./useHeaderMotionBridge.js";
4
5
  export * from "./useMotionProgress.js";
5
6
  export * from "./useScrollManager.js";
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;AAAA,cAAc,wBAAqB;AACnC,cAAc,wBAAqB;AACnC,cAAc,uBAAoB","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;AAAA,cAAc,wBAAqB;AACnC,cAAc,4BAAyB;AACvC,cAAc,wBAAqB;AACnC,cAAc,uBAAoB","ignoreList":[]}
@@ -3,17 +3,18 @@
3
3
  import { useCallback, useMemo, useState } from 'react';
4
4
  import { useSharedValue } from 'react-native-reanimated';
5
5
  /**
6
- * Hook to manage active scroll ID for multi-scroll scenarios (e.g. tabs with different scroll views).
7
- * Returns both a state value and a shared value, along with a setter function.
6
+ * Keeps a React state value and a shared value in sync for the currently active
7
+ * scrollable.
8
8
  *
9
- * Use this when you have multiple scroll views (like in a tabbed interface) and need to
10
- * track which one is currently active. Pass the shared value to `HeaderMotion`'s `activeScrollId` prop.
9
+ * Use this when one header is shared across multiple scroll views, for example
10
+ * pager pages or tabs. Pass `values.sv` to `HeaderMotion` and use the setter
11
+ * whenever the active page changes.
11
12
  *
12
13
  * @template T - The type of the scroll ID string
13
14
  * @param initialActiveScrollId - The initial active scroll ID
14
15
  * @returns A tuple containing:
15
- * - `[0]`: Object with `state` (React state) and `sv` (shared value) for the active scroll ID
16
- * - `[1]`: Function to set the active scroll ID
16
+ * - an object with both the React `state` and shared-value `sv`
17
+ * - a setter that updates both in lockstep
17
18
  *
18
19
  * @example
19
20
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useMemo","useState","useSharedValue","useActiveScrollId","initialActiveScrollId","activeScrollIdState","setActiveScrollIdState","activeScrollIdSv","setActiveScrollId","newId","set","values","state","sv"],"sourceRoot":"../../../src","sources":["hooks/useActiveScrollId.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACtD,SAASC,cAAc,QAAQ,yBAAyB;AAGxD;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,OAAO,SAASC,iBAAiBA,CAC/BC,qBAAwB,EACyB;EACjD,MAAM,CAACC,mBAAmB,EAAEC,sBAAsB,CAAC,GAAGL,QAAQ,CAC5DG,qBACF,CAAC;EACD,MAAMG,gBAAgB,GAAGL,cAAc,CAAIE,qBAAqB,CAAC;EAEjE,MAAMI,iBAAiB,GAAGT,WAAW,CAClCU,KAAK,IAAK;IACTH,sBAAsB,CAACG,KAAK,CAAC;IAC7BF,gBAAgB,CAACG,GAAG,CAACD,KAAK,CAAC;EAC7B,CAAC,EACD,CAACH,sBAAsB,EAAEC,gBAAgB,CAC3C,CAAC;EAED,MAAMI,MAAM,GAAGX,OAAO,CACpB,OAAO;IACLY,KAAK,EAAEP,mBAAmB;IAC1BQ,EAAE,EAAEN;EACN,CAAC,CAAC,EACF,CAACF,mBAAmB,EAAEE,gBAAgB,CACxC,CAAC;EAED,OAAO,CAACI,MAAM,EAAEH,iBAAiB,CAAC;AACpC","ignoreList":[]}
1
+ {"version":3,"names":["useCallback","useMemo","useState","useSharedValue","useActiveScrollId","initialActiveScrollId","activeScrollIdState","setActiveScrollIdState","activeScrollIdSv","setActiveScrollId","newId","set","values","state","sv"],"sourceRoot":"../../../src","sources":["hooks/useActiveScrollId.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACtD,SAASC,cAAc,QAAQ,yBAAyB;AAGxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAC/BC,qBAAwB,EACyB;EACjD,MAAM,CAACC,mBAAmB,EAAEC,sBAAsB,CAAC,GAAGL,QAAQ,CAC5DG,qBACF,CAAC;EACD,MAAMG,gBAAgB,GAAGL,cAAc,CAAIE,qBAAqB,CAAC;EAEjE,MAAMI,iBAAiB,GAAGT,WAAW,CAClCU,KAAK,IAAK;IACTH,sBAAsB,CAACG,KAAK,CAAC;IAC7BF,gBAAgB,CAACG,GAAG,CAACD,KAAK,CAAC;EAC7B,CAAC,EACD,CAACH,sBAAsB,EAAEC,gBAAgB,CAC3C,CAAC;EAED,MAAMI,MAAM,GAAGX,OAAO,CACpB,OAAO;IACLY,KAAK,EAAEP,mBAAmB;IAC1BQ,EAAE,EAAEN;EACN,CAAC,CAAC,EACF,CAACF,mBAAmB,EAAEE,gBAAgB,CACxC,CAAC;EAED,OAAO,CAACI,MAAM,EAAEH,iBAAiB,CAAC;AACpC","ignoreList":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ import { useCallback } from 'react';
4
+ import { useComposedEventHandler } from 'react-native-reanimated';
5
+ import { scheduleOnRN } from 'react-native-worklets';
6
+ export function useConsumerScrollHandlers({
7
+ onScroll,
8
+ onScrollBeginDrag,
9
+ onScrollEndDrag,
10
+ onMomentumScrollBegin,
11
+ onMomentumScrollEnd
12
+ }) {
13
+ const consumerOnScroll = typeof onScroll === 'function' ? onScroll : undefined;
14
+ const consumerOnScrollBeginDrag = typeof onScrollBeginDrag === 'function' ? onScrollBeginDrag : undefined;
15
+ const consumerOnScrollEndDrag = typeof onScrollEndDrag === 'function' ? onScrollEndDrag : undefined;
16
+ const consumerOnMomentumScrollBegin = typeof onMomentumScrollBegin === 'function' ? onMomentumScrollBegin : undefined;
17
+ const consumerOnMomentumScrollEnd = typeof onMomentumScrollEnd === 'function' ? onMomentumScrollEnd : undefined;
18
+ const onScrollBridge = useCallback(event => {
19
+ 'worklet';
20
+
21
+ if (!consumerOnScroll) {
22
+ return;
23
+ }
24
+ scheduleOnRN(consumerOnScroll, {
25
+ nativeEvent: event
26
+ });
27
+ }, [consumerOnScroll]);
28
+ const onBeginDragBridge = useCallback(event => {
29
+ 'worklet';
30
+
31
+ if (!consumerOnScrollBeginDrag) {
32
+ return;
33
+ }
34
+ scheduleOnRN(consumerOnScrollBeginDrag, {
35
+ nativeEvent: event
36
+ });
37
+ }, [consumerOnScrollBeginDrag]);
38
+ const onEndDragBridge = useCallback(event => {
39
+ 'worklet';
40
+
41
+ if (!consumerOnScrollEndDrag) {
42
+ return;
43
+ }
44
+ scheduleOnRN(consumerOnScrollEndDrag, {
45
+ nativeEvent: event
46
+ });
47
+ }, [consumerOnScrollEndDrag]);
48
+ const onMomentumBeginBridge = useCallback(event => {
49
+ 'worklet';
50
+
51
+ if (!consumerOnMomentumScrollBegin) {
52
+ return;
53
+ }
54
+ scheduleOnRN(consumerOnMomentumScrollBegin, {
55
+ nativeEvent: event
56
+ });
57
+ }, [consumerOnMomentumScrollBegin]);
58
+ const onMomentumEndBridge = useCallback(event => {
59
+ 'worklet';
60
+
61
+ if (!consumerOnMomentumScrollEnd) {
62
+ return;
63
+ }
64
+ scheduleOnRN(consumerOnMomentumScrollEnd, {
65
+ nativeEvent: event
66
+ });
67
+ }, [consumerOnMomentumScrollEnd]);
68
+ return {
69
+ onScroll: onScrollBridge,
70
+ onBeginDrag: onBeginDragBridge,
71
+ onEndDrag: onEndDragBridge,
72
+ onMomentumBegin: onMomentumBeginBridge,
73
+ onMomentumEnd: onMomentumEndBridge
74
+ };
75
+ }
76
+ export function useScrollHandlerComposition(ownScrollHandler, consumerScrollHandler) {
77
+ // TODO: I guess the typing here could be more precise
78
+ const consumerWorkletHandler = isAnimatedScrollHandler(consumerScrollHandler) ? consumerScrollHandler : null;
79
+ return useComposedEventHandler([ownScrollHandler, consumerWorkletHandler]);
80
+ }
81
+ function isAnimatedScrollHandler(handler) {
82
+ // FUTURE: we could be checking just by typeof handler === 'object'?
83
+ // This seems safer for now, unless Reanimated changes this shape. Revisit
84
+ return !!handler && 'workletEventHandler' in handler;
85
+ }
86
+ //# sourceMappingURL=useConsumerScrollHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useComposedEventHandler","scheduleOnRN","useConsumerScrollHandlers","onScroll","onScrollBeginDrag","onScrollEndDrag","onMomentumScrollBegin","onMomentumScrollEnd","consumerOnScroll","undefined","consumerOnScrollBeginDrag","consumerOnScrollEndDrag","consumerOnMomentumScrollBegin","consumerOnMomentumScrollEnd","onScrollBridge","event","nativeEvent","onBeginDragBridge","onEndDragBridge","onMomentumBeginBridge","onMomentumEndBridge","onBeginDrag","onEndDrag","onMomentumBegin","onMomentumEnd","useScrollHandlerComposition","ownScrollHandler","consumerScrollHandler","consumerWorkletHandler","isAnimatedScrollHandler","handler"],"sourceRoot":"../../../src","sources":["hooks/useConsumerScrollHandlers.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,OAAO;AACnC,SACEC,uBAAuB,QAIlB,yBAAyB;AAChC,SAASC,YAAY,QAAQ,uBAAuB;AAwBpD,OAAO,SAASC,yBAAyBA,CAAC;EACxCC,QAAQ;EACRC,iBAAiB;EACjBC,eAAe;EACfC,qBAAqB;EACrBC;AAC2B,CAAC,EAAyB;EACrD,MAAMC,gBAAgB,GACpB,OAAOL,QAAQ,KAAK,UAAU,GACzBA,QAAQ,GACTM,SAAS;EACf,MAAMC,yBAAyB,GAC7B,OAAON,iBAAiB,KAAK,UAAU,GAClC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B,SAAS;;IACT,IAAI,CAACF,2BAA2B,EAAE;MAChC;IACF;IACAZ,YAAY,CAACY,2BAA2B,EAAE;MACxCG,WAAW,EAAED;IACf,CAAY,CAAC;EACf,CAAC,EACD,CAACF,2BAA2B,CAC9B,CAAC;EAED,OAAO;IACLV,QAAQ,EAAEW,cAAc;IACxBO,WAAW,EAAEJ,iBAAiB;IAC9BK,SAAS,EAAEJ,eAAe;IAC1BK,eAAe,EAAEJ,qBAAqB;IACtCK,aAAa,EAAEJ;EACjB,CAAC;AACH;AAEA,OAAO,SAASK,2BAA2BA,CACzCC,gBAA8D,EAC9DC,qBAA6D,EAC7D;EACA;EACA,MAAMC,sBAAsB,GAAGC,uBAAuB,CAACF,qBAAqB,CAAC,GACxEA,qBAAqB,GACtB,IAAI;EAER,OAAO3B,uBAAuB,CAAC,CAAC0B,gBAAgB,EAAEE,sBAAsB,CAAC,CAAC;AAC5E;AAEA,SAASC,uBAAuBA,CAC9BC,OAA+C,EACR;EACvC;EACA;EACA,OAAO,CAAC,CAACA,OAAO,IAAI,qBAAqB,IAAIA,OAAO;AACtD","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ import { useHeaderMotionContextOrThrow } from "../context.js";
4
+ /**
5
+ * Returns the full internal HeaderMotion context value.
6
+ *
7
+ * Most app code should use `useMotionProgress()` instead. Reach for this hook
8
+ * only when you need to carry HeaderMotion context across a tree boundary and
9
+ * re-provide it somewhere else.
10
+ */
11
+ export function useHeaderMotionBridge() {
12
+ return useHeaderMotionContextOrThrow('useHeaderMotionBridge must be used within <HeaderMotion />. Use it only when bridging context into a separate subtree with <HeaderMotion.Bridge /> and <HeaderMotion.NavigationBridge />.');
13
+ }
14
+ //# sourceMappingURL=useHeaderMotionBridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useHeaderMotionContextOrThrow","useHeaderMotionBridge"],"sourceRoot":"../../../src","sources":["hooks/useHeaderMotionBridge.ts"],"mappings":";;AAAA,SAASA,6BAA6B,QAAQ,eAAY;AAG1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAA,EAA4B;EAC/D,OAAOD,6BAA6B,CAClC,2LACF,CAAC;AACH","ignoreList":[]}
@@ -1,62 +1,32 @@
1
1
  "use strict";
2
2
 
3
- import { useContext } from 'react';
4
- import { HeaderMotionContext } from "../context.js";
3
+ import { useHeaderMotionContextOrThrow } from "../context.js";
5
4
  /**
6
- * Hook to access motion progress values and measuring functions for header animations.
7
- * Returns the progress value (0-1), threshold, and measurement functions.
5
+ * Returns the two shared values most header animations actually need:
6
+ * `progress` and `progressThreshold`.
8
7
  *
9
- * Must be used within a {@link HeaderMotion} component.
8
+ * Use this inside your animated header components to derive transforms,
9
+ * opacity, scale, parallax, or any other visual response to scroll.
10
10
  *
11
- * @returns Motion progress values and measuring functions:
12
- * - `progress`: Shared value from 0 to 1
13
- * - `progressThreshold`: The threshold at which animation completes
14
- * - `measureTotalHeight`: Function to measure total header height. Should be passed to the `onLayout` prop of the base of a header, to let scrollables account for the total header height
15
- * - `measureDynamic`: Function to measure a dimension of choice of the animated element of the header - should be passed to the `onLayout` prop of such. If used, can be used for dynamic calculation of the {@link progressThreshold}.
16
- *
17
- * @throws Error if used outside of a {@link HeaderMotion} component
11
+ * `progress` usually lives in the `0..1` range, where `0` is the expanded
12
+ * state and `1` is the fully collapsed state. `progressThreshold` is the pixel
13
+ * distance that corresponds to that transition.
18
14
  *
19
15
  * @example
20
16
  * ```tsx
21
17
  * function MyHeader() {
22
- * const { progress, progressThreshold, measureTotalHeight, measureDynamic } = useMotionProgress();
23
- * const dynamicStyle = useAnimatedStyle(() => {
24
- * const translateY = interpolate(
25
- * progress.value,
26
- * [0, 1],
27
- * [0, -progressThreshold],
28
- * Extrapolation.CLAMP,
29
- * )
30
- * return { transform: [{ translateY }] }
31
- * })
32
- * return (
33
- * <AnimatedHeaderBase onLayout={measureTotalHeight}>
34
- * <Animated.View onLayout={measureDynamic} style={dynamicStyle} />
35
- * </AnimatedHeaderBase>
36
- * )
18
+ * const { progress, progressThreshold } = useMotionProgress();
37
19
  * }
38
20
  * ```
39
21
  */
40
22
  export function useMotionProgress() {
41
- const ctxValue = useContext(HeaderMotionContext);
42
- if (!ctxValue) {
43
- throw new Error('useMotionProgress must be used within a <HeaderMotion /> component. If using inside a navigation header, consider using <HeaderMotion.Header /> instead to ensure context access.');
44
- }
45
23
  const {
46
24
  progress,
47
- measureTotalHeight,
48
- measureDynamic,
49
- progressThreshold,
50
- animatedHeaderBaseProps,
51
- activeScrollId
52
- } = ctxValue;
25
+ progressThreshold
26
+ } = useHeaderMotionContextOrThrow('useMotionProgress must be used within <HeaderMotion /> or <HeaderMotion.NavigationBridge />. If you are rendering inside a navigation header, bridge the context with <HeaderMotion.Bridge /> and <HeaderMotion.NavigationBridge />.');
53
27
  return {
54
28
  progress,
55
- measureTotalHeight,
56
- measureDynamic,
57
- progressThreshold,
58
- animatedHeaderBaseProps,
59
- activeScrollId
29
+ progressThreshold
60
30
  };
61
31
  }
62
32
  //# sourceMappingURL=useMotionProgress.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useContext","HeaderMotionContext","useMotionProgress","ctxValue","Error","progress","measureTotalHeight","measureDynamic","progressThreshold","animatedHeaderBaseProps","activeScrollId"],"sourceRoot":"../../../src","sources":["hooks/useMotionProgress.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,mBAAmB,QAAQ,eAAY;AAGhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAA,EAAmB;EAClD,MAAMC,QAAQ,GAAGH,UAAU,CAACC,mBAAmB,CAAC;EAChD,IAAI,CAACE,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CACb,mLACF,CAAC;EACH;EACA,MAAM;IACJC,QAAQ;IACRC,kBAAkB;IAClBC,cAAc;IACdC,iBAAiB;IACjBC,uBAAuB;IACvBC;EACF,CAAC,GAAGP,QAAQ;EAEZ,OAAO;IACLE,QAAQ;IACRC,kBAAkB;IAClBC,cAAc;IACdC,iBAAiB;IACjBC,uBAAuB;IACvBC;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["useHeaderMotionContextOrThrow","useMotionProgress","progress","progressThreshold"],"sourceRoot":"../../../src","sources":["hooks/useMotionProgress.ts"],"mappings":";;AAAA,SAASA,6BAA6B,QAAQ,eAAY;AAG1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAA,EAAmB;EAClD,MAAM;IAAEC,QAAQ;IAAEC;EAAkB,CAAC,GAAGH,6BAA6B,CACnE,sOACF,CAAC;EAED,OAAO;IACLE,QAAQ;IACRC;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ const mockUseHeaderMotionContextOrThrow = jest.fn();
4
+ jest.mock('../context', () => ({
5
+ __esModule: true,
6
+ useHeaderMotionContextOrThrow: (...args) => mockUseHeaderMotionContextOrThrow(...args)
7
+ }));
8
+ import { useHeaderMotionBridge } from "./useHeaderMotionBridge.js";
9
+ import { useMotionProgress } from "./useMotionProgress.js";
10
+ function createSharedValue(value) {
11
+ return {
12
+ get: jest.fn(() => value),
13
+ set: jest.fn(),
14
+ value
15
+ };
16
+ }
17
+ const bridgeValue = {
18
+ progress: createSharedValue(0),
19
+ progressThreshold: createSharedValue(120),
20
+ measureTotalHeight: jest.fn(),
21
+ measureDynamic: jest.fn(),
22
+ headerPanMomentumOffset: createSharedValue(null),
23
+ scrollValues: createSharedValue({}),
24
+ activeScrollId: undefined,
25
+ scrollToRef: {
26
+ current: null
27
+ },
28
+ originalHeaderHeight: 0
29
+ };
30
+ describe('motion hooks', () => {
31
+ beforeEach(() => {
32
+ mockUseHeaderMotionContextOrThrow.mockReset();
33
+ });
34
+ it('useMotionProgress returns only progress and progressThreshold', () => {
35
+ mockUseHeaderMotionContextOrThrow.mockReturnValue(bridgeValue);
36
+ expect(useMotionProgress()).toEqual({
37
+ progress: bridgeValue.progress,
38
+ progressThreshold: bridgeValue.progressThreshold
39
+ });
40
+ expect(mockUseHeaderMotionContextOrThrow).toHaveBeenCalledWith('useMotionProgress must be used within <HeaderMotion /> or <HeaderMotion.NavigationBridge />. If you are rendering inside a navigation header, bridge the context with <HeaderMotion.Bridge /> and <HeaderMotion.NavigationBridge />.');
41
+ });
42
+ it('useHeaderMotionBridge returns the full bridge value', () => {
43
+ mockUseHeaderMotionContextOrThrow.mockReturnValue(bridgeValue);
44
+ expect(useHeaderMotionBridge()).toBe(bridgeValue);
45
+ expect(mockUseHeaderMotionContextOrThrow).toHaveBeenCalledWith('useHeaderMotionBridge must be used within <HeaderMotion />. Use it only when bridging context into a separate subtree with <HeaderMotion.Bridge /> and <HeaderMotion.NavigationBridge />.');
46
+ });
47
+ it('rethrows missing-context errors from the helper hook', () => {
48
+ const error = new Error('missing context');
49
+ mockUseHeaderMotionContextOrThrow.mockImplementation(() => {
50
+ throw error;
51
+ });
52
+ expect(() => useMotionProgress()).toThrow(error);
53
+ expect(() => useHeaderMotionBridge()).toThrow(error);
54
+ });
55
+ });
56
+ //# sourceMappingURL=useMotionProgress.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mockUseHeaderMotionContextOrThrow","jest","fn","mock","__esModule","useHeaderMotionContextOrThrow","args","useHeaderMotionBridge","useMotionProgress","createSharedValue","value","get","set","bridgeValue","progress","progressThreshold","measureTotalHeight","measureDynamic","headerPanMomentumOffset","scrollValues","activeScrollId","undefined","scrollToRef","current","originalHeaderHeight","describe","beforeEach","mockReset","it","mockReturnValue","expect","toEqual","toHaveBeenCalledWith","toBe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