@r0b0t3d/react-native-collapsible 1.1.2 → 1.2.0-alpha.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/lib/commonjs/components/CollapsibleContainer.js +4 -2
- package/lib/commonjs/components/CollapsibleContainer.js.map +1 -1
- package/lib/commonjs/components/{AnimatedTopView.js → header/AnimatedTopView.js} +0 -0
- package/lib/commonjs/components/{AnimatedTopView.js.map → header/AnimatedTopView.js.map} +0 -0
- package/lib/commonjs/components/{CollapsibleHeaderContainer.js → header/CollapsibleHeaderContainer.js} +5 -5
- package/lib/commonjs/components/header/CollapsibleHeaderContainer.js.map +1 -0
- package/lib/commonjs/components/{StickyView.js → header/StickyView.js} +4 -4
- package/lib/commonjs/components/header/StickyView.js.map +1 -0
- package/lib/commonjs/components/pullToRefresh/PullToRefreshContainer.js +75 -0
- package/lib/commonjs/components/pullToRefresh/PullToRefreshContainer.js.map +1 -0
- package/lib/commonjs/components/pullToRefresh/PullToRefreshProvider.js +35 -0
- package/lib/commonjs/components/pullToRefresh/PullToRefreshProvider.js.map +1 -0
- package/lib/commonjs/components/pullToRefresh/RefreshControl.js +73 -0
- package/lib/commonjs/components/pullToRefresh/RefreshControl.js.map +1 -0
- package/lib/commonjs/components/pullToRefresh/usePullToRefreshContext.js +24 -0
- package/lib/commonjs/components/pullToRefresh/usePullToRefreshContext.js.map +1 -0
- package/lib/commonjs/components/pullToRefresh/utils.js +59 -0
- package/lib/commonjs/components/pullToRefresh/utils.js.map +1 -0
- package/lib/commonjs/components/{CollapsibleFlatList.js → scrollable/CollapsibleFlatList.js} +28 -27
- package/lib/commonjs/components/scrollable/CollapsibleFlatList.js.map +1 -0
- package/lib/commonjs/components/{CollapsibleScrollView.js → scrollable/CollapsibleScrollView.js} +6 -6
- package/lib/commonjs/components/scrollable/CollapsibleScrollView.js.map +1 -0
- package/lib/commonjs/{hooks → components/scrollable}/useAnimatedScroll.js +3 -3
- package/lib/commonjs/{hooks → components/scrollable}/useAnimatedScroll.js.map +1 -1
- package/lib/commonjs/hooks/useInternalCollapsibleContext.js +1 -1
- package/lib/commonjs/hooks/useInternalCollapsibleContext.js.map +1 -1
- package/lib/commonjs/index.js +21 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/{types.js → types.d.js} +1 -1
- package/lib/commonjs/{types.js.map → types.d.js.map} +0 -0
- package/lib/commonjs/{hooks/withCollapsibleContext.js → withCollapsibleContext.js} +8 -4
- package/lib/commonjs/{hooks/withCollapsibleContext.js.map → withCollapsibleContext.js.map} +1 -1
- package/lib/module/components/CollapsibleContainer.js +1 -1
- package/lib/module/components/CollapsibleContainer.js.map +1 -1
- package/lib/module/components/{AnimatedTopView.js → header/AnimatedTopView.js} +0 -0
- package/lib/module/components/{AnimatedTopView.js.map → header/AnimatedTopView.js.map} +0 -0
- package/lib/module/components/{CollapsibleHeaderContainer.js → header/CollapsibleHeaderContainer.js} +2 -2
- package/lib/module/components/{CollapsibleHeaderContainer.js.map → header/CollapsibleHeaderContainer.js.map} +1 -1
- package/lib/module/components/{StickyView.js → header/StickyView.js} +2 -2
- package/lib/module/components/header/StickyView.js.map +1 -0
- package/lib/module/components/pullToRefresh/PullToRefreshContainer.js +56 -0
- package/lib/module/components/pullToRefresh/PullToRefreshContainer.js.map +1 -0
- package/lib/module/components/pullToRefresh/PullToRefreshProvider.js +21 -0
- package/lib/module/components/pullToRefresh/PullToRefreshProvider.js.map +1 -0
- package/lib/module/components/pullToRefresh/RefreshControl.js +55 -0
- package/lib/module/components/pullToRefresh/RefreshControl.js.map +1 -0
- package/lib/module/components/pullToRefresh/usePullToRefreshContext.js +13 -0
- package/lib/module/components/pullToRefresh/usePullToRefreshContext.js.map +1 -0
- package/lib/module/components/pullToRefresh/utils.js +42 -0
- package/lib/module/components/pullToRefresh/utils.js.map +1 -0
- package/lib/module/components/{CollapsibleFlatList.js → scrollable/CollapsibleFlatList.js} +27 -27
- package/lib/module/components/scrollable/CollapsibleFlatList.js.map +1 -0
- package/lib/module/components/{CollapsibleScrollView.js → scrollable/CollapsibleScrollView.js} +5 -5
- package/lib/module/components/scrollable/CollapsibleScrollView.js.map +1 -0
- package/lib/module/{hooks → components/scrollable}/useAnimatedScroll.js +2 -2
- package/lib/module/{hooks → components/scrollable}/useAnimatedScroll.js.map +1 -1
- package/lib/module/hooks/useInternalCollapsibleContext.js +1 -1
- package/lib/module/hooks/useInternalCollapsibleContext.js.map +1 -1
- package/lib/module/index.js +6 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.d.js +2 -0
- package/lib/module/{types.js.map → types.d.js.map} +0 -0
- package/lib/module/{hooks/withCollapsibleContext.js → withCollapsibleContext.js} +5 -4
- package/lib/module/withCollapsibleContext.js.map +1 -0
- package/lib/typescript/components/{AnimatedTopView.d.ts → header/AnimatedTopView.d.ts} +0 -0
- package/lib/typescript/components/{CollapsibleHeaderContainer.d.ts → header/CollapsibleHeaderContainer.d.ts} +0 -0
- package/lib/typescript/components/{StickyView.d.ts → header/StickyView.d.ts} +0 -0
- package/lib/typescript/components/pullToRefresh/PullToRefreshContainer.d.ts +8 -0
- package/lib/typescript/components/pullToRefresh/PullToRefreshProvider.d.ts +6 -0
- package/lib/typescript/components/pullToRefresh/RefreshControl.d.ts +9 -0
- package/lib/typescript/components/pullToRefresh/usePullToRefreshContext.d.ts +4 -0
- package/lib/typescript/components/pullToRefresh/utils.d.ts +20 -0
- package/lib/typescript/components/{CollapsibleFlatList.d.ts → scrollable/CollapsibleFlatList.d.ts} +1 -1
- package/lib/typescript/components/{CollapsibleScrollView.d.ts → scrollable/CollapsibleScrollView.d.ts} +1 -1
- package/lib/typescript/{hooks → components/scrollable}/useAnimatedScroll.d.ts +0 -0
- package/lib/typescript/hooks/useInternalCollapsibleContext.d.ts +1 -1
- package/lib/typescript/index.d.ts +6 -5
- package/lib/typescript/{hooks/withCollapsibleContext.d.ts → withCollapsibleContext.d.ts} +0 -0
- package/package.json +4 -2
- package/src/components/CollapsibleContainer.tsx +1 -1
- package/src/components/{AnimatedTopView.tsx → header/AnimatedTopView.tsx} +0 -0
- package/src/components/{CollapsibleHeaderContainer.tsx → header/CollapsibleHeaderContainer.tsx} +3 -3
- package/src/components/{StickyView.tsx → header/StickyView.tsx} +2 -2
- package/src/components/pullToRefresh/PullToRefreshContainer.tsx +65 -0
- package/src/components/pullToRefresh/PullToRefreshProvider.tsx +27 -0
- package/src/components/pullToRefresh/RefreshControl.tsx +80 -0
- package/src/components/pullToRefresh/usePullToRefreshContext.ts +13 -0
- package/src/components/pullToRefresh/utils.ts +49 -0
- package/src/components/{CollapsibleFlatList.tsx → scrollable/CollapsibleFlatList.tsx} +34 -28
- package/src/components/{CollapsibleScrollView.tsx → scrollable/CollapsibleScrollView.tsx} +6 -6
- package/src/{hooks → components/scrollable}/useAnimatedScroll.ts +2 -2
- package/src/hooks/useInternalCollapsibleContext.ts +1 -1
- package/src/index.tsx +6 -5
- package/src/{types.ts → types.d.ts} +7 -0
- package/src/{hooks/withCollapsibleContext.tsx → withCollapsibleContext.tsx} +8 -5
- package/lib/commonjs/components/CollapsibleFlatList.js.map +0 -1
- package/lib/commonjs/components/CollapsibleHeaderContainer.js.map +0 -1
- package/lib/commonjs/components/CollapsibleScrollView.js.map +0 -1
- package/lib/commonjs/components/StickyView.js.map +0 -1
- package/lib/module/components/CollapsibleFlatList.js.map +0 -1
- package/lib/module/components/CollapsibleScrollView.js.map +0 -1
- package/lib/module/components/StickyView.js.map +0 -1
- package/lib/module/hooks/withCollapsibleContext.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/typescript/types.d.ts +0 -34
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { View, StyleSheet, FlatList } from 'react-native';
|
|
5
5
|
import Animated, { runOnJS, useAnimatedReaction } from 'react-native-reanimated';
|
|
6
|
-
import AnimatedTopView from '
|
|
7
|
-
import useAnimatedScroll from '
|
|
8
|
-
import useCollapsibleContext from '
|
|
9
|
-
import
|
|
6
|
+
import AnimatedTopView from '../header/AnimatedTopView';
|
|
7
|
+
import useAnimatedScroll from './useAnimatedScroll';
|
|
8
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
9
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
10
|
+
import PullToRefreshContainer from '../pullToRefresh/PullToRefreshContainer';
|
|
10
11
|
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
|
11
12
|
export default function CollapsibleFlatList({
|
|
12
13
|
headerSnappable = true,
|
|
13
14
|
...props
|
|
14
15
|
}) {
|
|
15
|
-
const scrollView = useRef(null);
|
|
16
16
|
const {
|
|
17
|
-
headerHeight
|
|
17
|
+
headerHeight,
|
|
18
|
+
scrollY
|
|
18
19
|
} = useCollapsibleContext();
|
|
19
20
|
const {
|
|
20
21
|
contentMinHeight
|
|
21
22
|
} = useInternalCollapsibleContext();
|
|
23
|
+
const scrollRef = useRef(null);
|
|
22
24
|
const mounted = useRef(true);
|
|
23
25
|
const contentHeight = useRef(0);
|
|
24
26
|
useEffect(() => {
|
|
@@ -27,13 +29,13 @@ export default function CollapsibleFlatList({
|
|
|
27
29
|
};
|
|
28
30
|
}, []);
|
|
29
31
|
const scrollTo = useCallback((yValue, animated = true) => {
|
|
30
|
-
var
|
|
32
|
+
var _scrollRef$current;
|
|
31
33
|
|
|
32
|
-
(
|
|
34
|
+
(_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 ? void 0 : _scrollRef$current.scrollToOffset({
|
|
33
35
|
offset: yValue,
|
|
34
36
|
animated
|
|
35
37
|
});
|
|
36
|
-
}, []);
|
|
38
|
+
}, [scrollRef]);
|
|
37
39
|
const handleInternalContentHeight = useCallback(value => {
|
|
38
40
|
if (mounted.current) {
|
|
39
41
|
setInternalContentMinHeight(value);
|
|
@@ -66,23 +68,21 @@ export default function CollapsibleFlatList({
|
|
|
66
68
|
height: headerHeight
|
|
67
69
|
}), props.ListHeaderComponent);
|
|
68
70
|
|
|
69
|
-
return (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}))
|
|
85
|
-
);
|
|
71
|
+
return /*#__PURE__*/React.createElement(PullToRefreshContainer, {
|
|
72
|
+
scrollY: scrollY
|
|
73
|
+
}, /*#__PURE__*/React.createElement(AnimatedFlatList, _extends({
|
|
74
|
+
ref: scrollRef,
|
|
75
|
+
bounces: false,
|
|
76
|
+
keyboardDismissMode: "on-drag",
|
|
77
|
+
keyboardShouldPersistTaps: "handled",
|
|
78
|
+
scrollEventThrottle: 1
|
|
79
|
+
}, props, {
|
|
80
|
+
style: [styles.container, props.style],
|
|
81
|
+
contentContainerStyle: contentContainerStyle,
|
|
82
|
+
onScroll: scrollHandler,
|
|
83
|
+
ListHeaderComponent: renderListHeader(),
|
|
84
|
+
onContentSizeChange: handleContentSizeChange
|
|
85
|
+
})));
|
|
86
86
|
}
|
|
87
87
|
const styles = StyleSheet.create({
|
|
88
88
|
container: { ...StyleSheet.absoluteFillObject
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["CollapsibleFlatList.tsx"],"names":["React","useCallback","useEffect","useMemo","useRef","useState","View","StyleSheet","FlatList","Animated","runOnJS","useAnimatedReaction","AnimatedTopView","useAnimatedScroll","useCollapsibleContext","useInternalCollapsibleContext","PullToRefreshContainer","AnimatedFlatList","createAnimatedComponent","CollapsibleFlatList","headerSnappable","props","headerHeight","scrollY","contentMinHeight","scrollRef","mounted","contentHeight","current","scrollTo","yValue","animated","scrollToOffset","offset","handleInternalContentHeight","value","setInternalContentMinHeight","scrollHandler","internalContentMinHeight","result","previous","contentContainerStyle","styles","contentContainer","minHeight","handleContentSizeChange","_","height","renderListHeader","ListHeaderComponent","container","style","create","absoluteFillObject","flexGrow","topView","position","top","left","right"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,WADF,EAEEC,SAFF,EAGEC,OAHF,EAIEC,MAJF,EAKEC,QALF,QAMO,OANP;AAOA,SAAwBC,IAAxB,EAA8BC,UAA9B,EAA0CC,QAA1C,QAA0D,cAA1D;AACA,OAAOC,QAAP,IACEC,OADF,EAEEC,mBAFF,QAGO,yBAHP;AAIA,OAAOC,eAAP,MAA4B,2BAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,qBAAP,MAAkC,mCAAlC;AACA,OAAOC,6BAAP,MAA0C,2CAA1C;AAEA,OAAOC,sBAAP,MAAmC,yCAAnC;AAEA,MAAMC,gBAAgB,GAAGR,QAAQ,CAACS,uBAAT,CAAiCV,QAAjC,CAAzB;AAKA,eAAe,SAASW,mBAAT,CAAmC;AAChDC,EAAAA,eAAe,GAAG,IAD8B;AAEhD,KAAGC;AAF6C,CAAnC,EAGC;AACd,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA4BT,qBAAqB,EAAvD;AACA,QAAM;AAAEU,IAAAA;AAAF,MAAuBT,6BAA6B,EAA1D;AACA,QAAMU,SAAS,GAAGrB,MAAM,CAAM,IAAN,CAAxB;AACA,QAAMsB,OAAO,GAAGtB,MAAM,CAAC,IAAD,CAAtB;AACA,QAAMuB,aAAa,GAAGvB,MAAM,CAAC,CAAD,CAA5B;AAEAF,EAAAA,SAAS,CAAC,MAAM;AACd,WAAO,MAAM;AACXwB,MAAAA,OAAO,CAACE,OAAR,GAAkB,KAAlB;AACD,KAFD;AAGD,GAJQ,EAIN,EA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,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { FlatListProps, View, StyleSheet, FlatList } from 'react-native';\nimport Animated, {\n runOnJS,\n useAnimatedReaction,\n} from 'react-native-reanimated';\nimport AnimatedTopView from '../header/AnimatedTopView';\nimport useAnimatedScroll from './useAnimatedScroll';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\nimport type { CollapsibleProps } from '../../types';\nimport PullToRefreshContainer from '../pullToRefresh/PullToRefreshContainer';\n\nconst AnimatedFlatList = Animated.createAnimatedComponent(FlatList);\n\ntype Props<Data> = Omit<FlatListProps<Data>, 'scrollEnabled'> &\n CollapsibleProps;\n\nexport default function CollapsibleFlatList<Data>({\n headerSnappable = true,\n ...props\n}: Props<Data>) {\n const { headerHeight, scrollY } = useCollapsibleContext();\n const { contentMinHeight } = useInternalCollapsibleContext();\n const scrollRef = useRef<any>(null);\n const mounted = useRef(true);\n const contentHeight = useRef(0);\n\n useEffect(() => {\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const scrollTo = useCallback(\n (yValue: number, animated = true) => {\n scrollRef.current?.scrollToOffset({\n offset: yValue,\n animated,\n });\n },\n [scrollRef]\n );\n\n const handleInternalContentHeight = useCallback((value: number) => {\n if (mounted.current) {\n setInternalContentMinHeight(value);\n }\n }, []);\n\n const { scrollHandler } = useAnimatedScroll({\n headerSnappable,\n scrollTo,\n });\n\n const [internalContentMinHeight, setInternalContentMinHeight] = useState(\n contentMinHeight.value\n );\n\n useAnimatedReaction(\n () => {\n return contentMinHeight.value;\n },\n (result, previous) => {\n if (result !== previous) {\n if (\n contentHeight.current < contentMinHeight.value &&\n internalContentMinHeight !== contentMinHeight.value\n ) {\n runOnJS(handleInternalContentHeight)(contentMinHeight.value);\n }\n }\n }\n );\n\n const contentContainerStyle = useMemo(\n () => [\n styles.contentContainer,\n { minHeight: internalContentMinHeight },\n props.contentContainerStyle,\n ],\n [props.contentContainerStyle, internalContentMinHeight]\n );\n\n const handleContentSizeChange = useCallback((_, height) => {\n contentHeight.current = height;\n }, []);\n\n const renderListHeader = () => (\n <View>\n <AnimatedTopView height={headerHeight} />\n {props.ListHeaderComponent}\n </View>\n );\n\n return (\n <PullToRefreshContainer scrollY={scrollY}>\n {/* @ts-ignore */}\n <AnimatedFlatList\n ref={scrollRef}\n bounces={false}\n keyboardDismissMode=\"on-drag\"\n keyboardShouldPersistTaps=\"handled\"\n scrollEventThrottle={1}\n {...props}\n style={[styles.container, props.style]}\n contentContainerStyle={contentContainerStyle}\n onScroll={scrollHandler}\n ListHeaderComponent={renderListHeader()}\n onContentSizeChange={handleContentSizeChange}\n />\n </PullToRefreshContainer>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n ...StyleSheet.absoluteFillObject,\n },\n contentContainer: {\n flexGrow: 1,\n },\n topView: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n },\n});\n"]}
|
package/lib/module/components/{CollapsibleScrollView.js → scrollable/CollapsibleScrollView.js}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import AnimatedTopView from '
|
|
4
|
-
import useAnimatedScroll from '
|
|
3
|
+
import AnimatedTopView from '../header/AnimatedTopView';
|
|
4
|
+
import useAnimatedScroll from './useAnimatedScroll';
|
|
5
5
|
import React, { useCallback, useMemo, useRef } from 'react';
|
|
6
6
|
import { StyleSheet } from 'react-native';
|
|
7
7
|
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
8
|
-
import useCollapsibleContext from '
|
|
9
|
-
import
|
|
8
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
9
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
10
10
|
export default function CollapsibleScrollView({
|
|
11
11
|
headerSnappable = true,
|
|
12
12
|
children,
|
|
@@ -49,7 +49,7 @@ export default function CollapsibleScrollView({
|
|
|
49
49
|
onScroll: scrollHandler,
|
|
50
50
|
keyboardDismissMode: "on-drag",
|
|
51
51
|
keyboardShouldPersistTaps: "handled",
|
|
52
|
-
scrollEventThrottle:
|
|
52
|
+
scrollEventThrottle: 1
|
|
53
53
|
}), /*#__PURE__*/React.createElement(Animated.View, {
|
|
54
54
|
style: animatedStyle
|
|
55
55
|
}, /*#__PURE__*/React.createElement(AnimatedTopView, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["CollapsibleScrollView.tsx"],"names":["AnimatedTopView","useAnimatedScroll","React","useCallback","useMemo","useRef","StyleSheet","Animated","useAnimatedStyle","useCollapsibleContext","useInternalCollapsibleContext","CollapsibleScrollView","headerSnappable","children","props","scrollView","contentMinHeight","headerHeight","scrollTo","yValue","animated","current","y","scrollHandler","animatedStyle","minHeight","value","contentContainerStyle","styles","contentContainer","container","style","create","absoluteFillObject","flexGrow","topView","position","top","left","right"],"mappings":";;AAAA,OAAOA,eAAP,MAA4B,2BAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,KAAP,IAA2BC,WAA3B,EAAwCC,OAAxC,EAAiDC,MAAjD,QAA+D,OAA/D;AACA,SAA0BC,UAA1B,QAA4C,cAA5C;AACA,OAAOC,QAAP,IAAmBC,gBAAnB,QAA2C,yBAA3C;AAEA,OAAOC,qBAAP,MAAkC,mCAAlC;AACA,OAAOC,6BAAP,MAA0C,2CAA1C;AAOA,eAAe,SAASC,qBAAT,CAA+B;AAC5CC,EAAAA,eAAe,GAAG,IAD0B;AAE5CC,EAAAA,QAF4C;AAG5C,KAAGC;AAHyC,CAA/B,EAIL;AACR,QAAMC,UAAU,GAAGV,MAAM,CAAsB,IAAtB,CAAzB;AACA,QAAM;AAAEW,IAAAA;AAAF,MAAuB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AEGJ,QAFH,CAXF,CADF;AAkBD;AAED,MAAMe,MAAM,GAAGtB,UAAU,CAAC0B,MAAX,CAAkB;AAC/BF,EAAAA,SAAS,EAAE,EACT,GAAGxB,UAAU,CAAC2B;AADL,GADoB;AAI/BJ,EAAAA,gBAAgB,EAAE;AAChBK,IAAAA,QAAQ,EAAE;AADM,GAJa;AAO/BC,EAAAA,OAAO,EAAE;AACPC,IAAAA,QAAQ,EAAE,UADH;AAEPC,IAAAA,GAAG,EAAE,CAFE;AAGPC,IAAAA,IAAI,EAAE,CAHC;AAIPC,IAAAA,KAAK,EAAE;AAJA;AAPsB,CAAlB,CAAf","sourcesContent":["import AnimatedTopView from '../header/AnimatedTopView';\nimport useAnimatedScroll from './useAnimatedScroll';\nimport React, { ReactNode, useCallback, useMemo, useRef } from 'react';\nimport { ScrollViewProps, StyleSheet } from 'react-native';\nimport Animated, { useAnimatedStyle } from 'react-native-reanimated';\nimport type { CollapsibleProps } from '../../types';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\n\ntype Props = ScrollViewProps &\n CollapsibleProps & {\n children?: ReactNode;\n };\n\nexport default function CollapsibleScrollView({\n headerSnappable = true,\n children,\n ...props\n}: Props) {\n const scrollView = useRef<Animated.ScrollView>(null);\n const { contentMinHeight } = useInternalCollapsibleContext();\n const { headerHeight } = useCollapsibleContext();\n\n const scrollTo = useCallback((yValue: number, animated = true) => {\n // @ts-ignore\n scrollView.current?.scrollTo({ y: yValue, animated });\n }, []);\n\n const { scrollHandler } = useAnimatedScroll({\n headerSnappable,\n scrollTo,\n });\n\n const animatedStyle = useAnimatedStyle(() => {\n return {\n minHeight: contentMinHeight.value,\n };\n }, []);\n\n const contentContainerStyle = useMemo(\n () => [styles.contentContainer, props.contentContainerStyle],\n [props.contentContainerStyle]\n );\n\n return (\n <Animated.ScrollView\n ref={scrollView}\n bounces={false}\n {...props}\n style={[styles.container, props.style]}\n contentContainerStyle={contentContainerStyle}\n onScroll={scrollHandler}\n keyboardDismissMode=\"on-drag\"\n keyboardShouldPersistTaps=\"handled\"\n scrollEventThrottle={1}\n >\n <Animated.View style={animatedStyle}>\n <AnimatedTopView height={headerHeight} />\n {children}\n </Animated.View>\n </Animated.ScrollView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n ...StyleSheet.absoluteFillObject,\n },\n contentContainer: {\n flexGrow: 1,\n },\n topView: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n },\n});\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { useCallback, useEffect } from 'react';
|
|
3
3
|
import { Dimensions } from 'react-native';
|
|
4
4
|
import { runOnJS, useAnimatedScrollHandler, useSharedValue } from 'react-native-reanimated';
|
|
5
|
-
import useCollapsibleContext from '
|
|
6
|
-
import
|
|
5
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
6
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
7
7
|
const {
|
|
8
8
|
height: wHeight
|
|
9
9
|
} = Dimensions.get('window');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useAnimatedScroll.ts"],"names":["useCallback","useEffect","Dimensions","runOnJS","useAnimatedScrollHandler","useSharedValue","useCollapsibleContext","useInternalCollapsibleContext","height","wHeight","get","useAnimatedScroll","headerSnappable","scrollTo","scrollDirection","scrollY","setCollapsibleHandlers","firstStickyViewY","fixedHeaderHeight","value","requestAnimationFrame","collapse","Math","min","expand","scrollHandler","onScroll","event","offset","contentOffset","y","diff","onEndDrag","maxY","delta","abs","yValue"],"mappings":"AAAA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,OAAvC;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,SACEC,OADF,EAEEC,wBAFF,EAGEC,cAHF,QAIO,yBAJP;AAKA,OAAOC,qBAAP,MAAkC,
|
|
1
|
+
{"version":3,"sources":["useAnimatedScroll.ts"],"names":["useCallback","useEffect","Dimensions","runOnJS","useAnimatedScrollHandler","useSharedValue","useCollapsibleContext","useInternalCollapsibleContext","height","wHeight","get","useAnimatedScroll","headerSnappable","scrollTo","scrollDirection","scrollY","setCollapsibleHandlers","firstStickyViewY","fixedHeaderHeight","value","requestAnimationFrame","collapse","Math","min","expand","scrollHandler","onScroll","event","offset","contentOffset","y","diff","onEndDrag","maxY","delta","abs","yValue"],"mappings":"AAAA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,OAAvC;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,SACEC,OADF,EAEEC,wBAFF,EAGEC,cAHF,QAIO,yBAJP;AAKA,OAAOC,qBAAP,MAAkC,mCAAlC;AACA,OAAOC,6BAAP,MAA0C,2CAA1C;AAEA,MAAM;AAAEC,EAAAA,MAAM,EAAEC;AAAV,IAAsBP,UAAU,CAACQ,GAAX,CAAe,QAAf,CAA5B;AAOA,eAAe,SAASC,iBAAT,CAA2B;AACxCC,EAAAA,eADwC;AAExCC,EAAAA;AAFwC,CAA3B,EAGL;AACR,QAAMC,eAAe,GAAGT,cAAc,CAAC,SAAD,CAAtC;AACA,QAAM;AAAEU,IAAAA;AAAF,MAAcT,qBAAqB,EAAzC;AACA,QAAM;AAAEU,IAAAA,sBAAF;AAA0BC,IAAAA,gBAA1B;AAA4CC,IAAAA;AAA5C,MACJX,6BAA6B,EAD/B;AAGAN,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIc,OAAO,CAACI,KAAR,GAAgB,CAApB,EAAuB;AACrBC,MAAAA,qBAAqB,CAAC,MAAMP,QAAQ,CAACE,OAAO,CAACI,KAAT,EAAgB,KAAhB,CAAf,CAArB;AACD;AACF,GAJQ,EAIN,EAJM,CAAT;AAMA,QAAME,QAAQ,GAAGrB,WAAW,CAAC,MAAM;AACjCa,IAAAA,QAAQ,CACNS,IAAI,CAACC,GAAL,CAASL,iBAAiB,CAACC,KAAlB,IAA2B,CAApC,EAAuCF,gBAA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AyB;AACvB,cAAI2B,MAAM,GAAG,CAAb;;AACA,cAAItB,eAAe,CAACK,KAAhB,KAA0B,IAA9B,EAAoC;AAClCiB,YAAAA,MAAM,GAAGH,IAAT;AACD;;AACD9B,UAAAA,OAAO,CAACU,QAAD,CAAP,CAAkBuB,MAAlB;AACD;AACF;AACF;AAxBH,GAD4C,EA2B5C,CAACvB,QAAD,CA3B4C,CAA9C;AA8BA,SAAO;AACLY,IAAAA,aADK;AAELJ,IAAAA,QAFK;AAGLG,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport { useCallback, useEffect } from 'react';\nimport { Dimensions } from 'react-native';\nimport {\n runOnJS,\n useAnimatedScrollHandler,\n useSharedValue,\n} from 'react-native-reanimated';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\n\nconst { height: wHeight } = Dimensions.get('window');\n\ntype Props = {\n headerSnappable: boolean;\n scrollTo: (yValue: number, animated?: boolean) => void;\n};\n\nexport default function useAnimatedScroll({\n headerSnappable,\n scrollTo,\n}: Props) {\n const scrollDirection = useSharedValue('unknown');\n const { scrollY } = useCollapsibleContext();\n const { setCollapsibleHandlers, firstStickyViewY, fixedHeaderHeight } =\n useInternalCollapsibleContext();\n\n useEffect(() => {\n if (scrollY.value > 0) {\n requestAnimationFrame(() => scrollTo(scrollY.value, false));\n }\n }, []);\n\n const collapse = useCallback(() => {\n scrollTo(\n Math.min(fixedHeaderHeight.value || 0, firstStickyViewY.value || 0)\n );\n }, [scrollTo]);\n\n const expand = useCallback(() => scrollTo(0), [scrollTo]);\n\n useEffect(() => {\n setCollapsibleHandlers({\n collapse,\n expand,\n scrollTo,\n });\n }, [setCollapsibleHandlers, collapse, expand, scrollTo]);\n\n const scrollHandler = useAnimatedScrollHandler(\n {\n onScroll: (event) => {\n const offset = event.contentOffset.y;\n const diff = scrollY.value - offset;\n scrollDirection.value = diff > 0 ? 'down' : diff < 0 ? 'up' : 'unknown';\n scrollY.value = offset;\n },\n onEndDrag: () => {\n if (!headerSnappable) return;\n const maxY =\n firstStickyViewY.value && firstStickyViewY.value > 0\n ? firstStickyViewY.value\n : fixedHeaderHeight.value || 0;\n\n if (scrollY.value < maxY) {\n const delta = Math.abs(scrollY.value - maxY);\n if (delta < wHeight / 2) {\n let yValue = 0;\n if (scrollDirection.value === 'up') {\n yValue = maxY;\n }\n runOnJS(scrollTo)(yValue);\n }\n }\n },\n },\n [scrollTo]\n );\n\n return {\n scrollHandler,\n collapse,\n expand,\n };\n}\n"]}
|
|
@@ -3,7 +3,7 @@ export const InternalCollapsibleContext =
|
|
|
3
3
|
/*#__PURE__*/
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
createContext();
|
|
6
|
-
export function useInternalCollapsibleContext() {
|
|
6
|
+
export default function useInternalCollapsibleContext() {
|
|
7
7
|
const ctx = useContext(InternalCollapsibleContext);
|
|
8
8
|
|
|
9
9
|
if (!ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useInternalCollapsibleContext.ts"],"names":["createContext","useContext","InternalCollapsibleContext","useInternalCollapsibleContext","ctx","Error"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAGA,OAAO,MAAMC,0BAA0B;AAAA;AACrC;AACAF,aAAa,EAFR;AAIP,
|
|
1
|
+
{"version":3,"sources":["useInternalCollapsibleContext.ts"],"names":["createContext","useContext","InternalCollapsibleContext","useInternalCollapsibleContext","ctx","Error"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAGA,OAAO,MAAMC,0BAA0B;AAAA;AACrC;AACAF,aAAa,EAFR;AAIP,eAAe,SAASG,6BAAT,GAAyC;AACtD,QAAMC,GAAG,GAAGH,UAAU,CAACC,0BAAD,CAAtB;;AACA,MAAI,CAACE,GAAL,EAAU;AACR,UAAM,IAAIC,KAAJ,CAAU,yDAAV,CAAN;AACD;;AACD,SAAOD,GAAP;AACD","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { CollapsibleContextInternalType } from '../types';\n\nexport const InternalCollapsibleContext =\n // @ts-ignore\n createContext<CollapsibleContextInternalType>();\n\nexport default function useInternalCollapsibleContext() {\n const ctx = useContext(InternalCollapsibleContext);\n if (!ctx) {\n throw new Error('Component should be wrapped with withCollapsibleContext');\n }\n return ctx;\n}\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { default as withCollapsibleContext } from './
|
|
1
|
+
export { default as withCollapsibleContext } from './withCollapsibleContext';
|
|
2
2
|
export { default as useCollapsibleContext } from './hooks/useCollapsibleContext';
|
|
3
3
|
export { default as CollapsibleContainer } from './components/CollapsibleContainer';
|
|
4
|
-
export { default as CollapsibleFlatList } from './components/CollapsibleFlatList';
|
|
5
|
-
export { default as CollapsibleScrollView } from './components/CollapsibleScrollView';
|
|
6
|
-
export { default as CollapsibleHeaderContainer } from './components/CollapsibleHeaderContainer';
|
|
4
|
+
export { default as CollapsibleFlatList } from './components/scrollable/CollapsibleFlatList';
|
|
5
|
+
export { default as CollapsibleScrollView } from './components/scrollable/CollapsibleScrollView';
|
|
6
|
+
export { default as CollapsibleHeaderContainer } from './components/header/CollapsibleHeaderContainer';
|
|
7
|
+
export { default as StickyView } from './components/header/StickyView';
|
|
8
|
+
export { default as RefreshControl } from './components/pullToRefresh/RefreshControl';
|
|
7
9
|
export { default as CollapsibleView } from './components/CollapsibleView';
|
|
8
|
-
export { default as StickyView } from './components/StickyView';
|
|
9
10
|
export * from './components/CollapsibleView';
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["default","withCollapsibleContext","useCollapsibleContext","CollapsibleContainer","CollapsibleFlatList","CollapsibleScrollView","CollapsibleHeaderContainer","
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["default","withCollapsibleContext","useCollapsibleContext","CollapsibleContainer","CollapsibleFlatList","CollapsibleScrollView","CollapsibleHeaderContainer","StickyView","RefreshControl","CollapsibleView"],"mappings":"AAAA,SAASA,OAAO,IAAIC,sBAApB,QAAkD,0BAAlD;AACA,SAASD,OAAO,IAAIE,qBAApB,QAAiD,+BAAjD;AAEA,SAASF,OAAO,IAAIG,oBAApB,QAAgD,mCAAhD;AACA,SAASH,OAAO,IAAII,mBAApB,QAA+C,6CAA/C;AACA,SAASJ,OAAO,IAAIK,qBAApB,QAAiD,+CAAjD;AACA,SAASL,OAAO,IAAIM,0BAApB,QAAsD,gDAAtD;AACA,SAASN,OAAO,IAAIO,UAApB,QAAsC,gCAAtC;AACA,SAASP,OAAO,IAAIQ,cAApB,QAA0C,2CAA1C;AACA,SAASR,OAAO,IAAIS,eAApB,QAA2C,8BAA3C;AACA,cAAc,8BAAd","sourcesContent":["export { default as withCollapsibleContext } from './withCollapsibleContext';\nexport { default as useCollapsibleContext } from './hooks/useCollapsibleContext';\n\nexport { default as CollapsibleContainer } from './components/CollapsibleContainer';\nexport { default as CollapsibleFlatList } from './components/scrollable/CollapsibleFlatList';\nexport { default as CollapsibleScrollView } from './components/scrollable/CollapsibleScrollView';\nexport { default as CollapsibleHeaderContainer } from './components/header/CollapsibleHeaderContainer';\nexport { default as StickyView } from './components/header/StickyView';\nexport { default as RefreshControl } from './components/pullToRefresh/RefreshControl';\nexport { default as CollapsibleView } from './components/CollapsibleView';\nexport * from './components/CollapsibleView';\n"]}
|
|
File without changes
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
4
4
|
import React, { useCallback, useMemo, useRef } from 'react';
|
|
5
|
-
import { CollapsibleContext } from './useCollapsibleContext';
|
|
6
|
-
import { InternalCollapsibleContext } from './useInternalCollapsibleContext';
|
|
5
|
+
import { CollapsibleContext } from './hooks/useCollapsibleContext';
|
|
6
|
+
import { InternalCollapsibleContext } from './hooks/useInternalCollapsibleContext';
|
|
7
7
|
import { useAnimatedReaction, useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
8
|
-
import { debounce } from '
|
|
8
|
+
import { debounce } from './utils/debounce';
|
|
9
|
+
import PullToRefreshProvider from './components/pullToRefresh/PullToRefreshProvider';
|
|
9
10
|
export default function withCollapsibleContext(Component) {
|
|
10
11
|
return props => {
|
|
11
12
|
const collapsibleHandlers = useRef();
|
|
@@ -156,7 +157,7 @@ export default function withCollapsibleContext(Component) {
|
|
|
156
157
|
value: context
|
|
157
158
|
}, /*#__PURE__*/React.createElement(InternalCollapsibleContext.Provider, {
|
|
158
159
|
value: internalContext
|
|
159
|
-
}, /*#__PURE__*/React.createElement(Component, props)));
|
|
160
|
+
}, /*#__PURE__*/React.createElement(PullToRefreshProvider, null, /*#__PURE__*/React.createElement(Component, props))));
|
|
160
161
|
};
|
|
161
162
|
}
|
|
162
163
|
//# sourceMappingURL=withCollapsibleContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["withCollapsibleContext.tsx"],"names":["React","useCallback","useMemo","useRef","CollapsibleContext","InternalCollapsibleContext","useAnimatedReaction","useDerivedValue","useSharedValue","withTiming","debounce","PullToRefreshProvider","withCollapsibleContext","Component","props","collapsibleHandlers","headerHeight","scrollY","stickyViewRefs","stickyViewTops","stickyViewPositionsRef","stickyViewPositions","fixedHeaderHeight","stickyHeaderHeight","containerHeight","firstStickyViewY","headerContainersHeight","containerRef","setCollapsibleHandlers","handlers","current","headerCollapsed","maxY","value","contentMinHeight","totalHeight","Object","keys","reduce","acc","item","top","result","previous","viewPositions","sortedKeys","sort","a","b","totalTop","values","i","length","height","stickyHeader","key","data","isInsideHeader","handleStickyViewLayout","viewKey","viewRef","measureLayout","left","width","debounceRefreshStickyPositions","forEach","handleHeaderContainerLayout","duration","handleContainerHeight","context","collapse","expand","scrollTo","offset","animate","internalContext"],"mappings":"A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O;AACLyB,MAAAA,YADK;AAEL+B,MAAAA,sBAFK;AAGLQ,MAAAA,2BAHK;AAILtC,MAAAA,sBAJK;AAKLwC,MAAAA,qBALK;AAML3C,MAAAA,gBANK;AAOLN,MAAAA,cAPK;AAQLE,MAAAA,mBARK;AASLC,MAAAA,iBATK;AAULY,MAAAA;AAVK,KAAP,CAD6B,EAa7B,CACEN,sBADF,EAEE8B,sBAFF,EAGEQ,2BAHF,EAIEE,qBAJF,EAKE3C,gBALF,EAMEN,cANF,EAOEE,mBAPF,EAQEC,iBARF,EASEY,gBATF,CAb6B,CAA/B;AA0BA,wBACE,oBAAC,kBAAD,CAAoB,QAApB;AAA6B,MAAA,KAAK,EAAEmC;AAApC,oBACE,oBAAC,0BAAD,CAA4B,QAA5B;AAAqC,MAAA,KAAK,EAAEM;AAA5C,oBACE,oBAAC,qBAAD,qBACE,oBAAC,SAAD,EAAe7D,KAAf,CADF,CADF,CADF,CADF;AASD,GAtLD;AAuLD","sourcesContent":["/* eslint-disable no-shadow */\n/* eslint-disable react-hooks/exhaustive-deps */\nimport React, { FC, useCallback, useMemo, useRef } from 'react';\nimport type { CollapsibleHandles, LayoutParams } from './types';\nimport { CollapsibleContext } from './hooks/useCollapsibleContext';\nimport { InternalCollapsibleContext } from './hooks/useInternalCollapsibleContext';\nimport {\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport type { View } from 'react-native';\nimport { debounce } from './utils/debounce';\nimport PullToRefreshProvider from './components/pullToRefresh/PullToRefreshProvider';\n\nexport default function withCollapsibleContext<T>(Component: FC<T>) {\n return (props: T) => {\n const collapsibleHandlers = useRef<CollapsibleHandles>();\n const headerHeight = useSharedValue(0);\n const scrollY = useSharedValue(0);\n const stickyViewRefs = useRef<Record<string, React.RefObject<View>>>({});\n const stickyViewTops = useSharedValue<Record<string, number>>({});\n const stickyViewPositionsRef = useRef<Record<string, LayoutParams>>({});\n const stickyViewPositions = useSharedValue<Record<string, LayoutParams>>(\n {}\n );\n const fixedHeaderHeight = useSharedValue(0);\n const stickyHeaderHeight = useSharedValue(0);\n const containerHeight = useSharedValue(0);\n const firstStickyViewY = useSharedValue(1000000);\n const headerContainersHeight = useRef<Record<string, number>>({});\n const containerRef = useRef<View>(null);\n\n const setCollapsibleHandlers = useCallback((handlers) => {\n collapsibleHandlers.current = handlers;\n }, []);\n\n const headerCollapsed = useDerivedValue(() => {\n const maxY = fixedHeaderHeight.value - firstStickyViewY.value;\n return scrollY.value >= maxY;\n }, []);\n\n const contentMinHeight = useDerivedValue(() => {\n return (\n containerHeight.value +\n fixedHeaderHeight.value -\n stickyHeaderHeight.value\n );\n }, []);\n\n useAnimatedReaction(\n () => {\n const totalHeight = Object.keys(stickyViewPositions.value).reduce(\n (acc, item) => {\n return acc + stickyViewPositions.value[item].top;\n },\n 0\n );\n return totalHeight - fixedHeaderHeight.value;\n },\n (result, previous) => {\n if (result !== previous) {\n const viewPositions = stickyViewPositions.value;\n const headerHeight = fixedHeaderHeight.value;\n const sortedKeys = Object.keys(viewPositions).sort(\n (a, b) => viewPositions[a].top - viewPositions[b].top\n );\n let totalTop = 0;\n const values: any = {};\n for (let i = 0; i < sortedKeys.length; i++) {\n values[sortedKeys[i]] = totalTop;\n // Try minus 1 make it filled when scrolling up.\n // Otherwise, we can see a small space between the persits views\n totalTop += viewPositions[sortedKeys[i]].height - 1;\n }\n stickyViewTops.value = values;\n firstStickyViewY.value = viewPositions[sortedKeys[0]]?.top || 0;\n const stickyHeader = sortedKeys.reduce((acc, key) => {\n const data = viewPositions[key];\n const isInsideHeader = data.top < headerHeight;\n if (isInsideHeader) {\n return acc + data.height;\n }\n return acc;\n }, 0);\n stickyHeaderHeight.value = stickyHeader;\n }\n }\n );\n\n const handleStickyViewLayout = useCallback(\n (viewKey: string, viewRef?: React.RefObject<View>) => {\n if (viewRef && viewRef.current && containerRef.current) {\n stickyViewRefs.current[viewKey] = viewRef;\n viewRef.current.measureLayout(\n // @ts-ignore\n containerRef.current,\n (left, top, width, height) => {\n stickyViewPositionsRef.current = {\n ...stickyViewPositionsRef.current,\n [viewKey]: { left, top, width, height },\n };\n stickyViewPositions.value = stickyViewPositionsRef.current;\n },\n () => {}\n );\n } else {\n delete stickyViewRefs.current[viewKey];\n delete stickyViewPositionsRef.current[viewKey];\n stickyViewPositions.value = stickyViewPositionsRef.current;\n }\n },\n []\n );\n\n const debounceRefreshStickyPositions = useMemo(() => {\n return debounce(() => {\n Object.keys(stickyViewRefs.current).forEach((key) => {\n const viewRef = stickyViewRefs.current[key];\n if (viewRef) {\n handleStickyViewLayout(key, viewRef);\n }\n });\n }, 200);\n }, []);\n\n const handleHeaderContainerLayout = useCallback(\n (viewKey: string, height?: number) => {\n if (!height) {\n delete headerContainersHeight.current[viewKey];\n } else {\n headerContainersHeight.current[viewKey] = height;\n }\n const totalHeight = Object.keys(headerContainersHeight.current).reduce(\n (acc, key) => headerContainersHeight.current[key] + acc,\n 0\n );\n headerHeight.value = withTiming(totalHeight, {\n duration: fixedHeaderHeight.value === 0 ? 0 : 200,\n });\n fixedHeaderHeight.value = totalHeight;\n // Try refresh sticky positions\n debounceRefreshStickyPositions();\n },\n []\n );\n\n const handleContainerHeight = useCallback((height: number) => {\n containerHeight.value = height;\n }, []);\n\n const context = useMemo(() => {\n return {\n collapse: () => collapsibleHandlers.current?.collapse(),\n expand: () => collapsibleHandlers.current?.expand(),\n scrollTo: (offset: number, animate?: boolean) =>\n collapsibleHandlers.current?.scrollTo(offset, animate),\n headerHeight,\n scrollY,\n headerCollapsed,\n };\n }, [scrollY, headerHeight, headerCollapsed]);\n\n const internalContext = useMemo(\n () => ({\n containerRef,\n handleStickyViewLayout,\n handleHeaderContainerLayout,\n setCollapsibleHandlers,\n handleContainerHeight,\n firstStickyViewY,\n stickyViewTops,\n stickyViewPositions,\n fixedHeaderHeight,\n contentMinHeight,\n }),\n [\n setCollapsibleHandlers,\n handleStickyViewLayout,\n handleHeaderContainerLayout,\n handleContainerHeight,\n firstStickyViewY,\n stickyViewTops,\n stickyViewPositions,\n fixedHeaderHeight,\n contentMinHeight,\n ]\n );\n\n return (\n <CollapsibleContext.Provider value={context}>\n <InternalCollapsibleContext.Provider value={internalContext}>\n <PullToRefreshProvider>\n <Component {...props} />\n </PullToRefreshProvider>\n </InternalCollapsibleContext.Provider>\n </CollapsibleContext.Provider>\n );\n };\n}\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Animated from 'react-native-reanimated';
|
|
3
|
+
declare type Props = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
scrollY: Animated.SharedValue<number>;
|
|
6
|
+
};
|
|
7
|
+
export default function PullToRefreshContainer({ children, scrollY }: Props): JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type Props = {
|
|
3
|
+
height?: number;
|
|
4
|
+
refreshing: boolean;
|
|
5
|
+
onRefresh: () => void;
|
|
6
|
+
renderAnimation: (animatedProps: any) => React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export default function RefreshControl({ height, refreshing, onRefresh, renderAnimation, }: Props): JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const springConfig: (velocity: number) => {
|
|
2
|
+
stiffness: number;
|
|
3
|
+
damping: number;
|
|
4
|
+
mass: number;
|
|
5
|
+
overshootClamping: boolean;
|
|
6
|
+
restDisplacementThreshold: number;
|
|
7
|
+
restSpeedThreshold: number;
|
|
8
|
+
velocity: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function clamp(value: number, lowerbound: number, upperbound: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* calculates rubber value
|
|
13
|
+
*
|
|
14
|
+
* @param x distance from the edge
|
|
15
|
+
* @param dim dimension, either width or height
|
|
16
|
+
* @param coeff constant value, UIScrollView uses 0.55
|
|
17
|
+
* @returns rubber = (1.0 – (1.0 / ((x * coeff / dim) + 1.0))) * dim
|
|
18
|
+
*/
|
|
19
|
+
export declare const rubberBandClamp: (x: number, dim: number, coeff: number) => number;
|
|
20
|
+
export declare const rubberClamp: (y: number, topBound: number, bottomBound: number, coeff?: number) => number;
|
package/lib/typescript/components/{CollapsibleFlatList.d.ts → scrollable/CollapsibleFlatList.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FlatListProps } from 'react-native';
|
|
2
|
-
import type { CollapsibleProps } from '
|
|
2
|
+
import type { CollapsibleProps } from '../../types';
|
|
3
3
|
declare type Props<Data> = Omit<FlatListProps<Data>, 'scrollEnabled'> & CollapsibleProps;
|
|
4
4
|
export default function CollapsibleFlatList<Data>({ headerSnappable, ...props }: Props<Data>): JSX.Element;
|
|
5
5
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { ScrollViewProps } from 'react-native';
|
|
3
|
-
import type { CollapsibleProps } from '
|
|
3
|
+
import type { CollapsibleProps } from '../../types';
|
|
4
4
|
declare type Props = ScrollViewProps & CollapsibleProps & {
|
|
5
5
|
children?: ReactNode;
|
|
6
6
|
};
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { CollapsibleContextInternalType } from '../types';
|
|
3
3
|
export declare const InternalCollapsibleContext: import("react").Context<CollapsibleContextInternalType>;
|
|
4
|
-
export
|
|
4
|
+
export default function useInternalCollapsibleContext(): CollapsibleContextInternalType;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { default as withCollapsibleContext } from './
|
|
1
|
+
export { default as withCollapsibleContext } from './withCollapsibleContext';
|
|
2
2
|
export { default as useCollapsibleContext } from './hooks/useCollapsibleContext';
|
|
3
3
|
export { default as CollapsibleContainer } from './components/CollapsibleContainer';
|
|
4
|
-
export { default as CollapsibleFlatList } from './components/CollapsibleFlatList';
|
|
5
|
-
export { default as CollapsibleScrollView } from './components/CollapsibleScrollView';
|
|
6
|
-
export { default as CollapsibleHeaderContainer } from './components/CollapsibleHeaderContainer';
|
|
4
|
+
export { default as CollapsibleFlatList } from './components/scrollable/CollapsibleFlatList';
|
|
5
|
+
export { default as CollapsibleScrollView } from './components/scrollable/CollapsibleScrollView';
|
|
6
|
+
export { default as CollapsibleHeaderContainer } from './components/header/CollapsibleHeaderContainer';
|
|
7
|
+
export { default as StickyView } from './components/header/StickyView';
|
|
8
|
+
export { default as RefreshControl } from './components/pullToRefresh/RefreshControl';
|
|
7
9
|
export { default as CollapsibleView } from './components/CollapsibleView';
|
|
8
|
-
export { default as StickyView } from './components/StickyView';
|
|
9
10
|
export * from './components/CollapsibleView';
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r0b0t3d/react-native-collapsible",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.0",
|
|
4
4
|
"description": "Fully customizable collapsible views",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"react": "16.13.1",
|
|
65
65
|
"react-native": "0.63.4",
|
|
66
66
|
"react-native-builder-bob": "^0.18.0",
|
|
67
|
+
"react-native-gesture-handler": "^1.10.3",
|
|
67
68
|
"react-native-reanimated": "^2.2.0",
|
|
68
69
|
"release-it": "^14.11.5",
|
|
69
70
|
"typescript": "^4.1.3"
|
|
@@ -71,7 +72,8 @@
|
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"react": "*",
|
|
73
74
|
"react-native": "*",
|
|
74
|
-
"react-native-
|
|
75
|
+
"react-native-gesture-handler": "*",
|
|
76
|
+
"react-native-reanimated": ">=2.2.0"
|
|
75
77
|
},
|
|
76
78
|
"jest": {
|
|
77
79
|
"preset": "react-native",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { LayoutChangeEvent, StyleSheet, View, ViewProps } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
import useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';
|
|
4
4
|
|
|
5
5
|
type Props = Omit<ViewProps, 'ref' | 'onLayout'> & {
|
|
6
6
|
children: Element;
|
|
File without changes
|
package/src/components/{CollapsibleHeaderContainer.tsx → header/CollapsibleHeaderContainer.tsx}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
-
import
|
|
2
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
3
3
|
import React, { ReactNode, useCallback, useEffect, useMemo } from 'react';
|
|
4
4
|
import {
|
|
5
5
|
LayoutChangeEvent,
|
|
@@ -16,7 +16,7 @@ import Animated, {
|
|
|
16
16
|
useSharedValue,
|
|
17
17
|
withTiming,
|
|
18
18
|
} from 'react-native-reanimated';
|
|
19
|
-
import useCollapsibleContext from '
|
|
19
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
20
20
|
|
|
21
21
|
type Props = {
|
|
22
22
|
children: ReactNode;
|
|
@@ -97,6 +97,6 @@ export default function CollapsibleHeaderContainer({
|
|
|
97
97
|
const styles = StyleSheet.create({
|
|
98
98
|
container: {
|
|
99
99
|
backgroundColor: 'white',
|
|
100
|
-
marginTop: Platform.OS === 'android' ? -1 : 0
|
|
100
|
+
marginTop: Platform.OS === 'android' ? -1 : 0,
|
|
101
101
|
},
|
|
102
102
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
-
import { useInternalCollapsibleContext } from '../hooks/useInternalCollapsibleContext';
|
|
3
2
|
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
4
3
|
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
|
5
|
-
import useCollapsibleContext from '
|
|
4
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
5
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
6
6
|
import Animated, {
|
|
7
7
|
Extrapolate,
|
|
8
8
|
interpolate,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NativeViewGestureHandler,
|
|
3
|
+
PanGestureHandler,
|
|
4
|
+
} from 'react-native-gesture-handler';
|
|
5
|
+
import React, { useRef } from 'react';
|
|
6
|
+
import Animated, {
|
|
7
|
+
useAnimatedGestureHandler,
|
|
8
|
+
withTiming,
|
|
9
|
+
} from 'react-native-reanimated';
|
|
10
|
+
import usePullToRefreshContext from './usePullToRefreshContext';
|
|
11
|
+
import { StyleSheet } from 'react-native';
|
|
12
|
+
import { rubberClamp } from './utils';
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
scrollY: Animated.SharedValue<number>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function PullToRefreshContainer({ children, scrollY }: Props) {
|
|
20
|
+
const scrollRef = useRef();
|
|
21
|
+
const panRef = useRef();
|
|
22
|
+
const { refreshValue, internalRefreshing, internalHeight } =
|
|
23
|
+
usePullToRefreshContext();
|
|
24
|
+
|
|
25
|
+
const gestureHandler = useAnimatedGestureHandler({
|
|
26
|
+
onStart: (_, ctx: any) => {
|
|
27
|
+
ctx.startY = internalRefreshing.value ? refreshValue.value : 0;
|
|
28
|
+
},
|
|
29
|
+
onActive: (event, ctx: any) => {
|
|
30
|
+
if (scrollY.value <= 1) {
|
|
31
|
+
const tranY = event.translationY + ctx.startY;
|
|
32
|
+
const clampedValue = rubberClamp(tranY, 0, internalHeight.value);
|
|
33
|
+
refreshValue.value = clampedValue;
|
|
34
|
+
if (clampedValue > internalHeight.value) {
|
|
35
|
+
internalRefreshing.value = true;
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
refreshValue.value = 0;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onEnd: () => {
|
|
42
|
+
if (refreshValue.value > 0) {
|
|
43
|
+
const value = internalRefreshing.value ? internalHeight.value : 0;
|
|
44
|
+
refreshValue.value = withTiming(value);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<PanGestureHandler
|
|
51
|
+
ref={panRef}
|
|
52
|
+
simultaneousHandlers={scrollRef}
|
|
53
|
+
onGestureEvent={gestureHandler}
|
|
54
|
+
shouldCancelWhenOutside={false}
|
|
55
|
+
enableTrackpadTwoFingerGesture
|
|
56
|
+
maxPointers={1}
|
|
57
|
+
>
|
|
58
|
+
<Animated.View style={StyleSheet.absoluteFill}>
|
|
59
|
+
<NativeViewGestureHandler ref={scrollRef} simultaneousHandlers={panRef}>
|
|
60
|
+
{children}
|
|
61
|
+
</NativeViewGestureHandler>
|
|
62
|
+
</Animated.View>
|
|
63
|
+
</PanGestureHandler>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
3
|
+
import { PullToRefreshContext } from './usePullToRefreshContext';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function PullToRefreshProvider({ children }: Props) {
|
|
10
|
+
const refreshValue = useSharedValue(0);
|
|
11
|
+
const internalRefreshing = useSharedValue(false);
|
|
12
|
+
const internalHeight = useSharedValue(0);
|
|
13
|
+
|
|
14
|
+
const context = useMemo(() => {
|
|
15
|
+
return {
|
|
16
|
+
refreshValue: refreshValue,
|
|
17
|
+
internalRefreshing,
|
|
18
|
+
internalHeight,
|
|
19
|
+
};
|
|
20
|
+
}, [refreshValue, internalRefreshing, internalHeight]);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<PullToRefreshContext.Provider value={context}>
|
|
24
|
+
{children}
|
|
25
|
+
</PullToRefreshContext.Provider>
|
|
26
|
+
);
|
|
27
|
+
}
|