@r0b0t3d/react-native-collapsible 1.3.5-beta.2 → 1.3.5-beta.3
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/lib/commonjs/components/CollapsibleContainer.js +1 -2
- package/lib/commonjs/components/CollapsibleContainer.js.map +1 -1
- package/lib/commonjs/components/CollapsibleView.js +1 -1
- package/lib/commonjs/components/CollapsibleView.js.map +1 -1
- package/lib/commonjs/components/header/CollapsibleHeaderContainer.js +85 -23
- package/lib/commonjs/components/header/CollapsibleHeaderContainer.js.map +1 -1
- package/lib/commonjs/components/header/StickyView.js +30 -19
- package/lib/commonjs/components/header/StickyView.js.map +1 -1
- package/lib/commonjs/components/scrollable/useAnimatedScroll.js +2 -3
- package/lib/commonjs/components/scrollable/useAnimatedScroll.js.map +1 -1
- package/lib/commonjs/hooks/useCollapsibleHeaderContext.js.map +1 -1
- package/lib/commonjs/utils/useSharedValueRef.js +21 -0
- package/lib/commonjs/utils/useSharedValueRef.js.map +1 -0
- package/lib/commonjs/withCollapsibleContext.js +37 -92
- package/lib/commonjs/withCollapsibleContext.js.map +1 -1
- package/lib/module/components/CollapsibleContainer.js +1 -2
- package/lib/module/components/CollapsibleContainer.js.map +1 -1
- package/lib/module/components/CollapsibleView.js +1 -1
- package/lib/module/components/CollapsibleView.js.map +1 -1
- package/lib/module/components/header/CollapsibleHeaderContainer.js +87 -24
- package/lib/module/components/header/CollapsibleHeaderContainer.js.map +1 -1
- package/lib/module/components/header/StickyView.js +31 -20
- package/lib/module/components/header/StickyView.js.map +1 -1
- package/lib/module/components/scrollable/useAnimatedScroll.js +2 -3
- package/lib/module/components/scrollable/useAnimatedScroll.js.map +1 -1
- package/lib/module/hooks/useCollapsibleHeaderContext.js.map +1 -1
- package/lib/module/utils/useSharedValueRef.js +15 -0
- package/lib/module/utils/useSharedValueRef.js.map +1 -0
- package/lib/module/withCollapsibleContext.js +38 -92
- package/lib/module/withCollapsibleContext.js.map +1 -1
- package/lib/typescript/components/CollapsibleContainer.d.ts.map +1 -1
- package/lib/typescript/components/header/CollapsibleHeaderContainer.d.ts +2 -2
- package/lib/typescript/components/header/CollapsibleHeaderContainer.d.ts.map +1 -1
- package/lib/typescript/components/header/StickyView.d.ts.map +1 -1
- package/lib/typescript/components/scrollable/useAnimatedScroll.d.ts.map +1 -1
- package/lib/typescript/hooks/useCollapsibleHeaderContext.d.ts +6 -11
- package/lib/typescript/hooks/useCollapsibleHeaderContext.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +6 -6
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/useSharedValueRef.d.ts +3 -0
- package/lib/typescript/utils/useSharedValueRef.d.ts.map +1 -0
- package/lib/typescript/withCollapsibleContext.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CollapsibleContainer.tsx +0 -2
- package/src/components/CollapsibleView.tsx +1 -1
- package/src/components/header/CollapsibleHeaderContainer.tsx +145 -25
- package/src/components/header/StickyView.tsx +32 -17
- package/src/components/scrollable/useAnimatedScroll.ts +3 -9
- package/src/hooks/useCollapsibleHeaderContext.ts +6 -8
- package/src/types.ts +8 -8
- package/src/utils/useSharedValueRef.ts +22 -0
- package/src/withCollapsibleContext.tsx +46 -110
- package/lib/commonjs/components/header/CollapsibleHeaderConsumer.js +0 -59
- package/lib/commonjs/components/header/CollapsibleHeaderConsumer.js.map +0 -1
- package/lib/commonjs/components/header/CollapsibleHeaderProvider.js +0 -58
- package/lib/commonjs/components/header/CollapsibleHeaderProvider.js.map +0 -1
- package/lib/module/components/header/CollapsibleHeaderConsumer.js +0 -50
- package/lib/module/components/header/CollapsibleHeaderConsumer.js.map +0 -1
- package/lib/module/components/header/CollapsibleHeaderProvider.js +0 -49
- package/lib/module/components/header/CollapsibleHeaderProvider.js.map +0 -1
- package/lib/typescript/components/header/CollapsibleHeaderConsumer.d.ts +0 -3
- package/lib/typescript/components/header/CollapsibleHeaderConsumer.d.ts.map +0 -1
- package/lib/typescript/components/header/CollapsibleHeaderProvider.d.ts +0 -5
- package/lib/typescript/components/header/CollapsibleHeaderProvider.d.ts.map +0 -1
- package/src/components/header/CollapsibleHeaderConsumer.tsx +0 -62
- package/src/components/header/CollapsibleHeaderProvider.tsx +0 -70
|
@@ -2,112 +2,61 @@
|
|
|
2
2
|
import React, { useCallback, useMemo, useRef } from 'react';
|
|
3
3
|
import { CollapsibleContext } from './hooks/useCollapsibleContext';
|
|
4
4
|
import { InternalCollapsibleContext } from './hooks/useInternalCollapsibleContext';
|
|
5
|
-
import {
|
|
6
|
-
import { debounce } from './utils/debounce';
|
|
7
|
-
import CollapsibleHeaderProvider from './components/header/CollapsibleHeaderProvider';
|
|
5
|
+
import { useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
8
6
|
export default function withCollapsibleContext(Component) {
|
|
9
7
|
return props => {
|
|
10
8
|
const collapsibleHandlers = useRef();
|
|
11
9
|
const headerHeight = useSharedValue(0);
|
|
12
10
|
const scrollY = useSharedValue(0);
|
|
13
|
-
const stickyViewRefs = useRef({});
|
|
14
|
-
const stickyViewTops = useSharedValue({});
|
|
15
|
-
const stickyViewPositionsRef = useRef({});
|
|
16
|
-
const stickyViewPositions = useSharedValue({});
|
|
17
11
|
const fixedHeaderHeight = useSharedValue(0);
|
|
18
12
|
const containerHeight = useSharedValue(0);
|
|
19
|
-
const firstStickyViewY = useSharedValue(1000000);
|
|
20
13
|
const containerRef = useRef(null);
|
|
21
14
|
const scrollViewRef = useRef(null);
|
|
15
|
+
const headerContainerLayouts = useRef({});
|
|
16
|
+
const headerViewPositions = useSharedValue({});
|
|
22
17
|
const setCollapsibleHandlers = useCallback(handlers => {
|
|
23
18
|
collapsibleHandlers.current = handlers;
|
|
24
19
|
}, []);
|
|
25
20
|
const headerCollapsed = useDerivedValue(() => {
|
|
26
|
-
const maxY = fixedHeaderHeight.value
|
|
21
|
+
const maxY = fixedHeaderHeight.value;
|
|
27
22
|
return scrollY.value >= maxY;
|
|
28
23
|
}, []);
|
|
29
24
|
const contentMinHeight = useDerivedValue(() => {
|
|
30
25
|
return containerHeight.value + fixedHeaderHeight.value;
|
|
31
26
|
}, []);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const handleHeaderContainerLayout = useCallback((key, layout, stickyHeight) => {
|
|
28
|
+
headerContainerLayouts.current[key] = layout ? {
|
|
29
|
+
...layout,
|
|
30
|
+
stickyHeight
|
|
31
|
+
} : undefined;
|
|
32
|
+
const headerContainers = Object.keys(headerContainerLayouts.current).filter(k => !!headerContainerLayouts.current[k]);
|
|
33
|
+
// Calculate total header height
|
|
34
|
+
const totalHeight = headerContainers.reduce((acc, value) => {
|
|
35
|
+
var _headerContainerLayou;
|
|
36
|
+
return acc + (((_headerContainerLayou = headerContainerLayouts.current[value]) === null || _headerContainerLayou === void 0 ? void 0 : _headerContainerLayou.height) ?? 0);
|
|
39
37
|
}, 0);
|
|
40
|
-
|
|
41
|
-
}, (result, previous) => {
|
|
42
|
-
if (result !== previous) {
|
|
43
|
-
var _viewPositions$sorted;
|
|
44
|
-
const viewPositions = stickyViewPositions.value;
|
|
45
|
-
const sortedKeys = Object.keys(viewPositions).filter(v => !!viewPositions[v])
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
.sort((a, b) => viewPositions[a].top - viewPositions[b].top);
|
|
48
|
-
let totalTop = 0;
|
|
49
|
-
const values = {};
|
|
50
|
-
for (let i = 0; i < sortedKeys.length; i++) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
values[sortedKeys[i]] = totalTop;
|
|
53
|
-
// Try minus 1 make it filled when scrolling up.
|
|
54
|
-
// Otherwise, we can see a small space between the persits views
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
totalTop += viewPositions[sortedKeys[i]].height - 1;
|
|
57
|
-
}
|
|
58
|
-
stickyViewTops.value = values;
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
firstStickyViewY.value = ((_viewPositions$sorted = viewPositions[sortedKeys[0]]) === null || _viewPositions$sorted === void 0 ? void 0 : _viewPositions$sorted.top) || 0;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
const handleStickyViewLayout = useCallback((viewKey, viewRef) => {
|
|
64
|
-
if (viewRef && viewRef.current && containerRef.current) {
|
|
65
|
-
stickyViewRefs.current[viewKey] = viewRef;
|
|
66
|
-
viewRef.current.measureLayout(
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
containerRef.current, (left, top, width, height) => {
|
|
69
|
-
stickyViewPositionsRef.current = {
|
|
70
|
-
...stickyViewPositionsRef.current,
|
|
71
|
-
[viewKey]: {
|
|
72
|
-
left,
|
|
73
|
-
top,
|
|
74
|
-
width,
|
|
75
|
-
height
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
stickyViewPositions.value = stickyViewPositionsRef.current;
|
|
80
|
-
}, () => {});
|
|
81
|
-
} else {
|
|
82
|
-
stickyViewRefs.current = {
|
|
83
|
-
...stickyViewRefs.current,
|
|
84
|
-
[viewKey]: undefined
|
|
85
|
-
};
|
|
86
|
-
stickyViewPositionsRef.current = {
|
|
87
|
-
...stickyViewPositionsRef.current,
|
|
88
|
-
[viewKey]: undefined
|
|
89
|
-
};
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
stickyViewPositions.value = stickyViewPositionsRef.current;
|
|
92
|
-
}
|
|
93
|
-
}, []);
|
|
94
|
-
const debounceRefreshStickyPositions = useMemo(() => {
|
|
95
|
-
return debounce(() => {
|
|
96
|
-
Object.keys(stickyViewRefs.current).forEach(key => {
|
|
97
|
-
const viewRef = stickyViewRefs.current[key];
|
|
98
|
-
if (viewRef) {
|
|
99
|
-
handleStickyViewLayout(key, viewRef);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}, 200);
|
|
103
|
-
}, []);
|
|
104
|
-
const handleHeaderContainerLayout = useCallback(height => {
|
|
105
|
-
headerHeight.value = withTiming(height, {
|
|
38
|
+
headerHeight.value = withTiming(totalHeight, {
|
|
106
39
|
duration: fixedHeaderHeight.value === 0 ? 0 : 10
|
|
107
40
|
});
|
|
108
|
-
fixedHeaderHeight.value =
|
|
109
|
-
//
|
|
110
|
-
|
|
41
|
+
fixedHeaderHeight.value = totalHeight;
|
|
42
|
+
// Calculate header positions
|
|
43
|
+
const sortedHeaders = headerContainers.sort((a, b) => {
|
|
44
|
+
var _headerContainerLayou2, _headerContainerLayou3;
|
|
45
|
+
return (((_headerContainerLayou2 = headerContainerLayouts.current[a]) === null || _headerContainerLayou2 === void 0 ? void 0 : _headerContainerLayou2.y) || 0) - (((_headerContainerLayou3 = headerContainerLayouts.current[b]) === null || _headerContainerLayou3 === void 0 ? void 0 : _headerContainerLayou3.y) || 0);
|
|
46
|
+
});
|
|
47
|
+
const values = {};
|
|
48
|
+
let aStickyHeight = 0;
|
|
49
|
+
for (let index = 0; index < sortedHeaders.length; index++) {
|
|
50
|
+
var _headerContainerLayou4;
|
|
51
|
+
const headerKey = sortedHeaders[index];
|
|
52
|
+
const sHeight = ((_headerContainerLayou4 = headerContainerLayouts.current[headerKey]) === null || _headerContainerLayou4 === void 0 ? void 0 : _headerContainerLayou4.stickyHeight) ?? 0;
|
|
53
|
+
values[headerKey] = {
|
|
54
|
+
top: aStickyHeight,
|
|
55
|
+
stickyHeight: sHeight
|
|
56
|
+
};
|
|
57
|
+
aStickyHeight += sHeight;
|
|
58
|
+
}
|
|
59
|
+
headerViewPositions.value = values;
|
|
111
60
|
}, []);
|
|
112
61
|
const handleContainerHeight = useCallback(height => {
|
|
113
62
|
containerHeight.value = height;
|
|
@@ -138,21 +87,18 @@ export default function withCollapsibleContext(Component) {
|
|
|
138
87
|
const internalContext = useMemo(() => ({
|
|
139
88
|
scrollViewRef,
|
|
140
89
|
containerRef,
|
|
141
|
-
handleStickyViewLayout,
|
|
142
90
|
handleHeaderContainerLayout,
|
|
143
91
|
setCollapsibleHandlers,
|
|
144
92
|
handleContainerHeight,
|
|
145
|
-
firstStickyViewY,
|
|
146
|
-
stickyViewTops,
|
|
147
|
-
stickyViewPositions,
|
|
148
93
|
fixedHeaderHeight,
|
|
149
|
-
contentMinHeight
|
|
150
|
-
|
|
94
|
+
contentMinHeight,
|
|
95
|
+
headerViewPositions
|
|
96
|
+
}), [setCollapsibleHandlers, handleHeaderContainerLayout, handleContainerHeight, fixedHeaderHeight, contentMinHeight, headerViewPositions]);
|
|
151
97
|
return /*#__PURE__*/React.createElement(CollapsibleContext.Provider, {
|
|
152
98
|
value: context
|
|
153
99
|
}, /*#__PURE__*/React.createElement(InternalCollapsibleContext.Provider, {
|
|
154
100
|
value: internalContext
|
|
155
|
-
}, /*#__PURE__*/React.createElement(
|
|
101
|
+
}, /*#__PURE__*/React.createElement(Component, props)));
|
|
156
102
|
};
|
|
157
103
|
}
|
|
158
104
|
//# sourceMappingURL=withCollapsibleContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useCallback","useMemo","useRef","CollapsibleContext","InternalCollapsibleContext","
|
|
1
|
+
{"version":3,"names":["React","useCallback","useMemo","useRef","CollapsibleContext","InternalCollapsibleContext","useDerivedValue","useSharedValue","withTiming","withCollapsibleContext","Component","props","collapsibleHandlers","headerHeight","scrollY","fixedHeaderHeight","containerHeight","containerRef","scrollViewRef","headerContainerLayouts","headerViewPositions","setCollapsibleHandlers","handlers","current","headerCollapsed","maxY","value","contentMinHeight","handleHeaderContainerLayout","key","layout","stickyHeight","undefined","headerContainers","Object","keys","filter","k","totalHeight","reduce","acc","_headerContainerLayou","height","duration","sortedHeaders","sort","a","b","_headerContainerLayou2","_headerContainerLayou3","y","values","aStickyHeight","index","length","_headerContainerLayou4","headerKey","sHeight","top","handleContainerHeight","context","collapse","animated","_collapsibleHandlers$","expand","_collapsibleHandlers$2","scrollTo","offset","animate","_collapsibleHandlers$3","scrollToIndex","params","_collapsibleHandlers$4","internalContext","createElement","Provider"],"sourceRo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,mBAAmB,CAACW,OAAO,cAAA8C,sBAAA,uBAA3BA,sBAAA,CAA6BH,QAAQ,CAACC,MAAM,EAAEC,OAAO,CAAC;QAAA;QACxDE,aAAa,EAAGC,MAAW;UAAA,IAAAC,sBAAA;UAAA,QAAAA,sBAAA,GACzB5D,mBAAmB,CAACW,OAAO,cAAAiD,sBAAA,uBAA3BA,sBAAA,CAA6BF,aAAa,CAACC,MAAM,CAAC;QAAA;QACpD1D,YAAY;QACZC,OAAO;QACPU;MACF,CAAC;IACH,CAAC,EAAE,CAACV,OAAO,EAAED,YAAY,EAAEW,eAAe,CAAC,CAAC;IAE5C,MAAMiD,eAAe,GAAGvE,OAAO,CAC7B,OAAO;MACLgB,aAAa;MACbD,YAAY;MACZW,2BAA2B;MAC3BP,sBAAsB;MACtBsC,qBAAqB;MACrB5C,iBAAiB;MACjBY,gBAAgB;MAChBP;IACF,CAAC,CAAC,EACF,CACEC,sBAAsB,EACtBO,2BAA2B,EAC3B+B,qBAAqB,EACrB5C,iBAAiB,EACjBY,gBAAgB,EAChBP,mBAAmB,CAEvB,CAAC;IAED,oBACEpB,KAAA,CAAA0E,aAAA,CAACtE,kBAAkB,CAACuE,QAAQ;MAACjD,KAAK,EAAEkC;IAAQ,gBAC1C5D,KAAA,CAAA0E,aAAA,CAACrE,0BAA0B,CAACsE,QAAQ;MAACjD,KAAK,EAAE+C;IAAgB,gBAE1DzE,KAAA,CAAA0E,aAAA,CAAChE,SAAS,EAAKC,KAAQ,CACY,CACV,CAAC;EAElC,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollapsibleContainer.d.ts","sourceRoot":"","sources":["../../../src/components/CollapsibleContainer.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAEL,yBAAyB,EAIzB,SAAS,EACV,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"CollapsibleContainer.d.ts","sourceRoot":"","sources":["../../../src/components/CollapsibleContainer.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAEL,yBAAyB,EAIzB,SAAS,EACV,MAAM,cAAc,CAAC;AAKtB,KAAK,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,GAAG,UAAU,CAAC,GAAG;IACjD,QAAQ,EAAE,OAAO,CAAC;IAClB,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,QAAQ,EACR,yBAAyB,EACzB,aAAkB,EAClB,GAAG,KAAK,EACT,EAAE,KAAK,qBAuDP"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
type Props = {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
containerStyle?: StyleProp<ViewStyle>;
|
|
6
6
|
};
|
|
7
|
-
export default function CollapsibleHeaderContainer({ children, containerStyle, }: Props):
|
|
7
|
+
export default function CollapsibleHeaderContainer({ children, containerStyle, }: Props): React.JSX.Element;
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=CollapsibleHeaderContainer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollapsibleHeaderContainer.d.ts","sourceRoot":"","sources":["../../../../src/components/header/CollapsibleHeaderContainer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CollapsibleHeaderContainer.d.ts","sourceRoot":"","sources":["../../../../src/components/header/CollapsibleHeaderContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAmC,MAAM,OAAO,CAAC;AAC1E,OAAO,EACL,SAAS,EACT,SAAS,EAIV,MAAM,cAAc,CAAC;AAkBtB,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,SAAS,CAAC;IACpB,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACvC,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,EACjD,QAAQ,EACR,cAAc,GACf,EAAE,KAAK,qBAgIP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StickyView.d.ts","sourceRoot":"","sources":["../../../../src/components/header/StickyView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,
|
|
1
|
+
{"version":3,"file":"StickyView.d.ts","sourceRoot":"","sources":["../../../../src/components/header/StickyView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,EAGL,SAAS,EAGT,SAAS,EACV,MAAM,cAAc,CAAC;AAUtB,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,qBAyD5D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimatedScroll.d.ts","sourceRoot":"","sources":["../../../../src/components/scrollable/useAnimatedScroll.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMvD,KAAK,KAAK,GAAG;IACX,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD,aAAa,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,eAAe,EACf,QAAQ,EACR,aAAa,GACd,EAAE,KAAK;;;;
|
|
1
|
+
{"version":3,"file":"useAnimatedScroll.d.ts","sourceRoot":"","sources":["../../../../src/components/scrollable/useAnimatedScroll.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMvD,KAAK,KAAK,GAAG;IACX,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD,aAAa,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,eAAe,EACf,QAAQ,EACR,aAAa,GACd,EAAE,KAAK;;;;EA8DP"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
headers: HeaderItem[];
|
|
8
|
-
mount: (key: string, header: ReactNode) => void;
|
|
9
|
-
update: (key: string, header: ReactNode) => void;
|
|
10
|
-
unmount: (key: string) => void;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LayoutRectangle } from 'react-native';
|
|
3
|
+
import Animated from 'react-native-reanimated';
|
|
4
|
+
export type CollapsibleContextHeaderType = {
|
|
5
|
+
handleStickyViewLayout: (key: string, layout?: LayoutRectangle) => void;
|
|
6
|
+
animatedY: Animated.SharedValue<number>;
|
|
11
7
|
};
|
|
12
8
|
export declare const CollapsibleHeaderContext: import("react").Context<CollapsibleContextHeaderType>;
|
|
13
9
|
export default function useCollapsibleHeaderContext(): CollapsibleContextHeaderType;
|
|
14
|
-
export {};
|
|
15
10
|
//# sourceMappingURL=useCollapsibleHeaderContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCollapsibleHeaderContext.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCollapsibleHeaderContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCollapsibleHeaderContext.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCollapsibleHeaderContext.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAE/C,MAAM,MAAM,4BAA4B,GAAG;IACzC,sBAAsB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IACxE,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,wBAAwB,uDAEY,CAAC;AAElD,MAAM,CAAC,OAAO,UAAU,2BAA2B,iCAMlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import type { View } from 'react-native';
|
|
2
|
+
import type { LayoutRectangle, View } from 'react-native';
|
|
3
3
|
import type Animated from 'react-native-reanimated';
|
|
4
4
|
export type ScrollToIndexParams = {
|
|
5
5
|
animated?: boolean | null;
|
|
@@ -28,13 +28,13 @@ export type CollapsibleContextInternalType = {
|
|
|
28
28
|
scrollViewRef: React.RefObject<any>;
|
|
29
29
|
containerRef: React.RefObject<View>;
|
|
30
30
|
contentMinHeight: Animated.SharedValue<number>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
headerViewPositions: Animated.SharedValue<Record<string, {
|
|
32
|
+
top: number;
|
|
33
|
+
stickyHeight: number;
|
|
34
|
+
}>>;
|
|
34
35
|
fixedHeaderHeight: Animated.SharedValue<number>;
|
|
35
36
|
handleContainerHeight: (height: number) => void;
|
|
36
|
-
|
|
37
|
-
handleHeaderContainerLayout: (height: number) => void;
|
|
37
|
+
handleHeaderContainerLayout: (key: string, layout?: LayoutRectangle, stickyHeight?: number) => void;
|
|
38
38
|
setCollapsibleHandlers: (handlers: CollapsibleHandles) => void;
|
|
39
39
|
};
|
|
40
40
|
export type CollapsibleProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAEpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACtD,aAAa,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,GAAG;IACxD,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,YAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3C,eAAe,EAAE,QAA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
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSharedValueRef.d.ts","sourceRoot":"","sources":["../../../src/utils/useSharedValueRef.ts"],"names":[],"mappings":"AACA,OAAO,QAA4B,MAAM,yBAAyB,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,EACzC,YAAY,EAAE,CAAC,GACd,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAgB/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withCollapsibleContext.d.ts","sourceRoot":"","sources":["../../src/withCollapsibleContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAgC,EAAE,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"withCollapsibleContext.d.ts","sourceRoot":"","sources":["../../src/withCollapsibleContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAgC,EAAE,EAAE,MAAM,OAAO,CAAC;AAWhE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WACjD,CAAC,uBAwHjB"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
import useKeyboardShowEvent from '../hooks/useKeyboardShowEvent';
|
|
12
12
|
import useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';
|
|
13
13
|
import useCollapsibleContext from '../hooks/useCollapsibleContext';
|
|
14
|
-
import CollapsibleHeaderConsumer from './header/CollapsibleHeaderConsumer';
|
|
15
14
|
|
|
16
15
|
type Props = Omit<ViewProps, 'ref' | 'onLayout'> & {
|
|
17
16
|
children: Element;
|
|
@@ -76,7 +75,6 @@ export default function CollapsibleContainer({
|
|
|
76
75
|
collapsable={false}
|
|
77
76
|
>
|
|
78
77
|
{children}
|
|
79
|
-
<CollapsibleHeaderConsumer />
|
|
80
78
|
</View>
|
|
81
79
|
</KeyboardAvoidingView>
|
|
82
80
|
);
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import React, { ReactNode, useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleProp,
|
|
4
|
+
ViewStyle,
|
|
5
|
+
LayoutChangeEvent,
|
|
6
|
+
LayoutRectangle,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
10
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
11
|
+
import Animated, {
|
|
12
|
+
Extrapolate,
|
|
13
|
+
interpolate,
|
|
14
|
+
runOnJS,
|
|
15
|
+
useAnimatedReaction,
|
|
16
|
+
useAnimatedStyle,
|
|
17
|
+
useDerivedValue,
|
|
18
|
+
useSharedValue,
|
|
19
|
+
} from 'react-native-reanimated';
|
|
20
|
+
import {
|
|
21
|
+
CollapsibleContextHeaderType,
|
|
22
|
+
CollapsibleHeaderContext,
|
|
23
|
+
} from '../../hooks/useCollapsibleHeaderContext';
|
|
24
|
+
import useSharedValueRef from '../../utils/useSharedValueRef';
|
|
5
25
|
|
|
6
26
|
type Props = {
|
|
7
27
|
children: ReactNode;
|
|
@@ -15,7 +35,65 @@ export default function CollapsibleHeaderContainer({
|
|
|
15
35
|
containerStyle,
|
|
16
36
|
}: Props) {
|
|
17
37
|
const contentKey = useMemo(() => `collapsible-header-${key++}`, []);
|
|
18
|
-
const {
|
|
38
|
+
const { handleHeaderContainerLayout, headerViewPositions } =
|
|
39
|
+
useInternalCollapsibleContext();
|
|
40
|
+
const { scrollY } = useCollapsibleContext();
|
|
41
|
+
const currentLayout = useSharedValue<LayoutRectangle | undefined>(undefined);
|
|
42
|
+
const [stickyLayouts, setStickyLayouts] = useSharedValueRef<
|
|
43
|
+
Record<string, LayoutRectangle | undefined>
|
|
44
|
+
>({});
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
return () => {
|
|
48
|
+
handleHeaderContainerLayout(contentKey);
|
|
49
|
+
};
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
+
}, [contentKey]);
|
|
52
|
+
|
|
53
|
+
const stickyHeight = useDerivedValue(
|
|
54
|
+
() =>
|
|
55
|
+
Object.values(stickyLayouts.value).reduce(
|
|
56
|
+
(acc, value) => acc + (value?.height ?? 0),
|
|
57
|
+
0
|
|
58
|
+
),
|
|
59
|
+
[]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
useAnimatedReaction(
|
|
63
|
+
() => {
|
|
64
|
+
if (!currentLayout.value) {
|
|
65
|
+
return -1;
|
|
66
|
+
}
|
|
67
|
+
return currentLayout.value.height - stickyHeight.value;
|
|
68
|
+
},
|
|
69
|
+
(result, previous) => {
|
|
70
|
+
if (result !== -1 && result !== previous) {
|
|
71
|
+
runOnJS(handleHeaderContainerLayout)(
|
|
72
|
+
contentKey,
|
|
73
|
+
currentLayout.value,
|
|
74
|
+
stickyHeight.value
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const handleLayout = useCallback(
|
|
81
|
+
({ nativeEvent: { layout } }: LayoutChangeEvent) => {
|
|
82
|
+
currentLayout.value = layout;
|
|
83
|
+
},
|
|
84
|
+
[currentLayout]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const handleStickyViewLayout = useCallback(
|
|
88
|
+
(stickyKey: string, layout?: LayoutRectangle) => {
|
|
89
|
+
console.log('handleStickyViewLayout', stickyKey, layout);
|
|
90
|
+
|
|
91
|
+
setStickyLayouts({
|
|
92
|
+
[stickyKey]: layout,
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
[setStickyLayouts]
|
|
96
|
+
);
|
|
19
97
|
|
|
20
98
|
const internalStyle = useMemo(() => {
|
|
21
99
|
return {
|
|
@@ -23,29 +101,71 @@ export default function CollapsibleHeaderContainer({
|
|
|
23
101
|
};
|
|
24
102
|
}, []);
|
|
25
103
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [children, containerStyle]);
|
|
104
|
+
const translateY = useDerivedValue(() => {
|
|
105
|
+
const position = headerViewPositions.value[contentKey];
|
|
106
|
+
if (!currentLayout.value || !position) {
|
|
107
|
+
return scrollY.value;
|
|
108
|
+
}
|
|
109
|
+
const topPosition =
|
|
110
|
+
currentLayout.value.height +
|
|
111
|
+
currentLayout.value.y -
|
|
112
|
+
position.top -
|
|
113
|
+
position.stickyHeight;
|
|
37
114
|
|
|
38
|
-
|
|
39
|
-
|
|
115
|
+
return interpolate(
|
|
116
|
+
scrollY.value,
|
|
117
|
+
[0, topPosition, 10000],
|
|
118
|
+
[0, -topPosition, -topPosition],
|
|
119
|
+
Extrapolate.CLAMP
|
|
120
|
+
);
|
|
121
|
+
});
|
|
40
122
|
|
|
41
|
-
|
|
42
|
-
|
|
123
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
124
|
+
return {
|
|
125
|
+
transform: [
|
|
126
|
+
{
|
|
127
|
+
translateY: translateY.value,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
43
130
|
};
|
|
44
|
-
}
|
|
131
|
+
});
|
|
45
132
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
133
|
+
const animatedY = useDerivedValue(() => {
|
|
134
|
+
const position = headerViewPositions.value[contentKey];
|
|
135
|
+
if (!currentLayout.value || !position) {
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
const value = scrollY.value - currentLayout.value.y + position.top;
|
|
139
|
+
const maxV = currentLayout.value.height - stickyHeight.value;
|
|
49
140
|
|
|
50
|
-
|
|
141
|
+
return Math.max(0, Math.min(value, maxV));
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const value: CollapsibleContextHeaderType = useMemo(
|
|
145
|
+
() => ({
|
|
146
|
+
handleStickyViewLayout,
|
|
147
|
+
animatedY,
|
|
148
|
+
}),
|
|
149
|
+
[handleStickyViewLayout, animatedY]
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<CollapsibleHeaderContext.Provider value={value}>
|
|
154
|
+
<Animated.View
|
|
155
|
+
key={contentKey}
|
|
156
|
+
style={[styles.container, containerStyle, internalStyle, animatedStyle]}
|
|
157
|
+
pointerEvents="box-none"
|
|
158
|
+
onLayout={handleLayout}
|
|
159
|
+
>
|
|
160
|
+
{children}
|
|
161
|
+
</Animated.View>
|
|
162
|
+
</CollapsibleHeaderContext.Provider>
|
|
163
|
+
);
|
|
51
164
|
}
|
|
165
|
+
|
|
166
|
+
const styles = StyleSheet.create({
|
|
167
|
+
container: {
|
|
168
|
+
overflow: 'hidden',
|
|
169
|
+
backgroundColor: 'white',
|
|
170
|
+
},
|
|
171
|
+
});
|