@r0b0t3d/react-native-collapsible 1.2.0-alpha.0 → 1.2.0-alpha.1
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 +45 -2
- package/lib/commonjs/components/CollapsibleContainer.js.map +1 -1
- package/lib/commonjs/components/scrollable/CollapsibleFlatList.js +6 -6
- package/lib/commonjs/components/scrollable/CollapsibleFlatList.js.map +1 -1
- package/lib/commonjs/components/scrollable/CollapsibleScrollView.js +5 -6
- package/lib/commonjs/components/scrollable/CollapsibleScrollView.js.map +1 -1
- package/lib/commonjs/hooks/useKeyboardShowEvent.js +29 -0
- package/lib/commonjs/hooks/useKeyboardShowEvent.js.map +1 -0
- package/lib/commonjs/{types.d.js → types.js} +1 -1
- package/lib/commonjs/{types.d.js.map → types.js.map} +0 -0
- package/lib/commonjs/withCollapsibleContext.js +2 -0
- package/lib/commonjs/withCollapsibleContext.js.map +1 -1
- package/lib/module/components/CollapsibleContainer.js +45 -4
- package/lib/module/components/CollapsibleContainer.js.map +1 -1
- package/lib/module/components/scrollable/CollapsibleFlatList.js +7 -6
- package/lib/module/components/scrollable/CollapsibleFlatList.js.map +1 -1
- package/lib/module/components/scrollable/CollapsibleScrollView.js +7 -7
- package/lib/module/components/scrollable/CollapsibleScrollView.js.map +1 -1
- package/lib/module/hooks/useKeyboardShowEvent.js +19 -0
- package/lib/module/hooks/useKeyboardShowEvent.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/{types.d.js.map → types.js.map} +0 -0
- package/lib/module/withCollapsibleContext.js +2 -0
- package/lib/module/withCollapsibleContext.js.map +1 -1
- package/lib/typescript/components/CollapsibleContainer.d.ts +4 -2
- package/lib/typescript/hooks/useKeyboardShowEvent.d.ts +1 -0
- package/lib/typescript/types.d.ts +40 -0
- package/package.json +1 -1
- package/src/components/CollapsibleContainer.tsx +63 -10
- package/src/components/scrollable/CollapsibleFlatList.tsx +9 -12
- package/src/components/scrollable/CollapsibleScrollView.tsx +5 -6
- package/src/hooks/useKeyboardShowEvent.ts +22 -0
- package/src/{types.d.ts → types.ts} +1 -1
- package/src/withCollapsibleContext.tsx +2 -0
- package/lib/module/types.d.js +0 -2
|
@@ -9,8 +9,12 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
|
+
var _useKeyboardShowEvent = _interopRequireDefault(require("../hooks/useKeyboardShowEvent"));
|
|
13
|
+
|
|
12
14
|
var _useInternalCollapsibleContext = _interopRequireDefault(require("../hooks/useInternalCollapsibleContext"));
|
|
13
15
|
|
|
16
|
+
var _useCollapsibleContext = _interopRequireDefault(require("../hooks/useCollapsibleContext"));
|
|
17
|
+
|
|
14
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
19
|
|
|
16
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -21,21 +25,60 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
21
25
|
|
|
22
26
|
function CollapsibleContainer({
|
|
23
27
|
children,
|
|
28
|
+
keyboardAvoidingViewProps,
|
|
29
|
+
textInputRefs = [],
|
|
24
30
|
...props
|
|
25
31
|
}) {
|
|
26
32
|
const {
|
|
27
33
|
containerRef,
|
|
28
34
|
handleContainerHeight
|
|
29
35
|
} = (0, _useInternalCollapsibleContext.default)();
|
|
36
|
+
const {
|
|
37
|
+
scrollY,
|
|
38
|
+
scrollTo
|
|
39
|
+
} = (0, _useCollapsibleContext.default)();
|
|
40
|
+
const containerHeight = (0, _react.useRef)(0);
|
|
41
|
+
(0, _useKeyboardShowEvent.default)(() => {
|
|
42
|
+
textInputRefs.some(ref => {
|
|
43
|
+
const isFocusedFunc = ref.current.isFocused;
|
|
44
|
+
const isFocused = isFocusedFunc && typeof isFocusedFunc === 'function' ? isFocusedFunc() : isFocusedFunc;
|
|
45
|
+
|
|
46
|
+
if (isFocused) {
|
|
47
|
+
ref.current.measureLayout( // @ts-ignore
|
|
48
|
+
containerRef.current, (left, top, width, height) => {
|
|
49
|
+
console.log({
|
|
50
|
+
left,
|
|
51
|
+
top,
|
|
52
|
+
width,
|
|
53
|
+
height
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (top + height - scrollY.value > containerHeight.current) {
|
|
57
|
+
var _keyboardAvoidingView;
|
|
58
|
+
|
|
59
|
+
console.log('need to scroll');
|
|
60
|
+
const extraOffset = (_keyboardAvoidingView = keyboardAvoidingViewProps === null || keyboardAvoidingViewProps === void 0 ? void 0 : keyboardAvoidingViewProps.keyboardVerticalOffset) !== null && _keyboardAvoidingView !== void 0 ? _keyboardAvoidingView : 20;
|
|
61
|
+
scrollTo(top + height + extraOffset - containerHeight.current);
|
|
62
|
+
}
|
|
63
|
+
}, () => {});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return isFocused;
|
|
67
|
+
});
|
|
68
|
+
});
|
|
30
69
|
const handleContainerLayout = (0, _react.useCallback)(layout => {
|
|
31
70
|
const height = layout.nativeEvent.layout.height;
|
|
71
|
+
containerHeight.current = height;
|
|
32
72
|
handleContainerHeight(height);
|
|
33
73
|
}, [handleContainerHeight]);
|
|
34
|
-
return /*#__PURE__*/_react.default.createElement(_reactNative.
|
|
74
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.KeyboardAvoidingView, _extends({
|
|
75
|
+
style: styles.container,
|
|
76
|
+
behavior: "padding"
|
|
77
|
+
}, keyboardAvoidingViewProps), /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({}, props, {
|
|
35
78
|
ref: containerRef,
|
|
36
79
|
style: [styles.container, props.style],
|
|
37
80
|
onLayout: handleContainerLayout
|
|
38
|
-
}), children);
|
|
81
|
+
}), children));
|
|
39
82
|
}
|
|
40
83
|
|
|
41
84
|
const styles = _reactNative.StyleSheet.create({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CollapsibleContainer.tsx"],"names":["CollapsibleContainer","children","props","containerRef","handleContainerHeight","
|
|
1
|
+
{"version":3,"sources":["CollapsibleContainer.tsx"],"names":["CollapsibleContainer","children","keyboardAvoidingViewProps","textInputRefs","props","containerRef","handleContainerHeight","scrollY","scrollTo","containerHeight","some","ref","isFocusedFunc","current","isFocused","measureLayout","left","top","width","height","console","log","value","extraOffset","keyboardVerticalOffset","handleContainerLayout","layout","nativeEvent","styles","container","style","StyleSheet","create","flex","overflow"],"mappings":";;;;;;;AAAA;;AACA;;AAQA;;AACA;;AACA;;;;;;;;;;AAQe,SAASA,oBAAT,CAA8B;AAC3CC,EAAAA,QAD2C;AAE3CC,EAAAA,yBAF2C;AAG3CC,EAAAA,aAAa,GAAG,EAH2B;AAI3C,KAAGC;AAJwC,CAA9B,EAKL;AACR,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MACJ,6CADF;AAEA,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAwB,qCAA9B;AAEA,QAAMC,eAAe,GAAG,mBAAO,CAAP,CAAxB;AAEA,qCAAqB,MAAM;AACzBN,IAAAA,aAAa,CAACO,IAAd,CAAoBC,GAAD,IAAS;AAC1B,YAAMC,aAAa,GAAGD,GAAG,CAACE,OAAJ,CAAYC,SAAlC;AACA,YAAMA,SAAS,GACbF,aAAa,IAAI,OAAOA,aAAP,KAAyB,UAA1C,GACIA,aAAa,EADjB,GAEIA,aAHN;;AAIA,UAAIE,SAAJ,EAAe;AACbH,QAAAA,GAAG,CAACE,OAAJ,CAAYE,aAAZ,EACE;AACAV,QAAAA,YAAY,CAACQ,OAFf,EAGE,CAACG,IAAD,EAAeC,GAAf,EAA4BC,KAA5B,EAA2CC,MAA3C,KAA8D;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,IAAAA,IAAI,EAAE,CADG;AAETC,IAAAA,QAAQ,EAAE;AAFD;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback, useRef } from 'react';\nimport {\n KeyboardAvoidingView,\n KeyboardAvoidingViewProps,\n LayoutChangeEvent,\n StyleSheet,\n View,\n ViewProps,\n} from 'react-native';\nimport useKeyboardShowEvent from '../hooks/useKeyboardShowEvent';\nimport useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';\nimport useCollapsibleContext from '../hooks/useCollapsibleContext';\n\ntype Props = Omit<ViewProps, 'ref' | 'onLayout'> & {\n children: Element;\n keyboardAvoidingViewProps?: KeyboardAvoidingViewProps;\n textInputRefs?: any[];\n};\n\nexport default function CollapsibleContainer({\n children,\n keyboardAvoidingViewProps,\n textInputRefs = [],\n ...props\n}: Props) {\n const { containerRef, handleContainerHeight } =\n useInternalCollapsibleContext();\n const { scrollY, scrollTo } = useCollapsibleContext();\n\n const containerHeight = useRef(0);\n\n useKeyboardShowEvent(() => {\n textInputRefs.some((ref) => {\n const isFocusedFunc = ref.current.isFocused;\n const isFocused =\n isFocusedFunc && typeof isFocusedFunc === 'function'\n ? isFocusedFunc()\n : isFocusedFunc;\n if (isFocused) {\n ref.current.measureLayout(\n // @ts-ignore\n containerRef.current,\n (left: number, top: number, width: number, height: number) => {\n console.log({ left, top, width, height });\n if (top + height - scrollY.value > containerHeight.current) {\n console.log('need to scroll');\n const extraOffset =\n keyboardAvoidingViewProps?.keyboardVerticalOffset ?? 20;\n scrollTo(top + height + extraOffset - containerHeight.current);\n }\n },\n () => {}\n );\n }\n return isFocused;\n });\n });\n\n const handleContainerLayout = useCallback(\n (layout: LayoutChangeEvent) => {\n const height = layout.nativeEvent.layout.height;\n containerHeight.current = height;\n handleContainerHeight(height);\n },\n [handleContainerHeight]\n );\n\n return (\n <KeyboardAvoidingView\n style={styles.container}\n behavior=\"padding\"\n {...keyboardAvoidingViewProps}\n >\n <View\n {...props}\n ref={containerRef}\n style={[styles.container, props.style]}\n onLayout={handleContainerLayout}\n >\n {children}\n </View>\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"]}
|
|
@@ -40,9 +40,9 @@ function CollapsibleFlatList({
|
|
|
40
40
|
scrollY
|
|
41
41
|
} = (0, _useCollapsibleContext.default)();
|
|
42
42
|
const {
|
|
43
|
-
contentMinHeight
|
|
43
|
+
contentMinHeight,
|
|
44
|
+
scrollViewRef
|
|
44
45
|
} = (0, _useInternalCollapsibleContext.default)();
|
|
45
|
-
const scrollRef = (0, _react.useRef)(null);
|
|
46
46
|
const mounted = (0, _react.useRef)(true);
|
|
47
47
|
const contentHeight = (0, _react.useRef)(0);
|
|
48
48
|
(0, _react.useEffect)(() => {
|
|
@@ -51,13 +51,13 @@ function CollapsibleFlatList({
|
|
|
51
51
|
};
|
|
52
52
|
}, []);
|
|
53
53
|
const scrollTo = (0, _react.useCallback)((yValue, animated = true) => {
|
|
54
|
-
var
|
|
54
|
+
var _scrollViewRef$curren;
|
|
55
55
|
|
|
56
|
-
(
|
|
56
|
+
(_scrollViewRef$curren = scrollViewRef.current) === null || _scrollViewRef$curren === void 0 ? void 0 : _scrollViewRef$curren.scrollToOffset({
|
|
57
57
|
offset: yValue,
|
|
58
58
|
animated
|
|
59
59
|
});
|
|
60
|
-
}, [
|
|
60
|
+
}, []);
|
|
61
61
|
const handleInternalContentHeight = (0, _react.useCallback)(value => {
|
|
62
62
|
if (mounted.current) {
|
|
63
63
|
setInternalContentMinHeight(value);
|
|
@@ -93,7 +93,7 @@ function CollapsibleFlatList({
|
|
|
93
93
|
return /*#__PURE__*/_react.default.createElement(_PullToRefreshContainer.default, {
|
|
94
94
|
scrollY: scrollY
|
|
95
95
|
}, /*#__PURE__*/_react.default.createElement(AnimatedFlatList, _extends({
|
|
96
|
-
ref:
|
|
96
|
+
ref: scrollViewRef,
|
|
97
97
|
bounces: false,
|
|
98
98
|
keyboardDismissMode: "on-drag",
|
|
99
99
|
keyboardShouldPersistTaps: "handled",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CollapsibleFlatList.tsx"],"names":["AnimatedFlatList","Animated","createAnimatedComponent","FlatList","CollapsibleFlatList","headerSnappable","props","headerHeight","scrollY","contentMinHeight","
|
|
1
|
+
{"version":3,"sources":["CollapsibleFlatList.tsx"],"names":["AnimatedFlatList","Animated","createAnimatedComponent","FlatList","CollapsibleFlatList","headerSnappable","props","headerHeight","scrollY","contentMinHeight","scrollViewRef","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","StyleSheet","create","absoluteFillObject","flexGrow","topView","position","top","left","right"],"mappings":";;;;;;;AACA;;AAOA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;AAEA,MAAMA,gBAAgB,GAAGC,+BAASC,uBAAT,CAAiCC,qBAAjC,CAAzB;;AAKe,SAASC,mBAAT,CAAmC;AAChDC,EAAAA,eAAe,GAAG,IAD8B;AAEhD,KAAGC;AAF6C,CAAnC,EAGC;AACd,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA4B,qCAAlC;AACA,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MAAsC,6CAA5C;AACA,QAAMC,OAAO,GAAG,mBAAO,IAAP,CAAhB;AACA,QAAMC,aAAa,GAAG,mBAAO,CAAP,CAAtB;AAEA,wBAAU,MAAM;AACd,WAAO,MAAM;AACXD,MAAAA,OAAO,CAACE,OAAR,GAAkB,KAAlB;AACD,KAFD;AAGD,GAJD,EAIG,EAJH;AAMA,QAAMC,QAAQ,GAAG,wBAAY,CAACC,MAAD,EAAiBC,QAAQ,GAAG,IAA5B,KAAqC;AAAA;;AAChE,6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B,6BAAC,iBAAD,qBACE,6BAAC,wBAAD;AAAiB,IAAA,MAAM,EAAE1B;AAAzB,IADF,EAEGD,KAAK,CAAC4B,mBAFT,CADF;;AAOA,sBACE,6BAAC,+BAAD;AAAwB,IAAA,OAAO,EAAE1B;AAAjC,kBAEE,6BAAC,gBAAD;AACE,IAAA,GAAG,EAAEE,aADP;AAEE,IAAA,OAAO,EAAE,KAFX;AAGE,IAAA,mBAAmB,EAAC,SAHtB;AAIE,IAAA,yBAAyB,EAAC,SAJ5B;AAKE,IAAA,mBAAmB,EAAE;AALvB,KAMMJ,KANN;AAOE,IAAA,KAAK,EAAE,CAACqB,MAAM,CAACQ,SAAR,EAAmB7B,KAAK,CAAC8B,KAAzB,CAPT;AAQE,IAAA,qBAAqB,EAAEV,qBARzB;AASE,IAAA,QAAQ,EAAEJ,aATZ;AAUE,IAAA,mBAAmB,EAAEW,gBAAgB,EAVvC;AAWE,IAAA,mBAAmB,EAAEH;AAXvB,KAFF,CADF;AAkBD;;AAED,MAAMH,MAAM,GAAGU,wBAAWC,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE,EACT,GAAGE,wBAAWE;AADL,GADoB;AAI/BX,EAAAA,gBAAgB,EAAE;AAChBY,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":["/* eslint-disable react-hooks/exhaustive-deps */\nimport React, {\n useCallback,\n useEffect,\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, scrollViewRef } = useInternalCollapsibleContext();\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((yValue: number, animated = true) => {\n scrollViewRef.current?.scrollToOffset({\n offset: yValue,\n animated,\n });\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={scrollViewRef}\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"]}
|
|
@@ -32,18 +32,17 @@ function CollapsibleScrollView({
|
|
|
32
32
|
children,
|
|
33
33
|
...props
|
|
34
34
|
}) {
|
|
35
|
-
const scrollView = (0, _react.useRef)(null);
|
|
36
35
|
const {
|
|
37
|
-
contentMinHeight
|
|
36
|
+
contentMinHeight,
|
|
37
|
+
scrollViewRef
|
|
38
38
|
} = (0, _useInternalCollapsibleContext.default)();
|
|
39
39
|
const {
|
|
40
40
|
headerHeight
|
|
41
41
|
} = (0, _useCollapsibleContext.default)();
|
|
42
42
|
const scrollTo = (0, _react.useCallback)((yValue, animated = true) => {
|
|
43
|
-
var
|
|
43
|
+
var _scrollViewRef$curren;
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
(_scrollView$current = scrollView.current) === null || _scrollView$current === void 0 ? void 0 : _scrollView$current.scrollTo({
|
|
45
|
+
(_scrollViewRef$curren = scrollViewRef.current) === null || _scrollViewRef$curren === void 0 ? void 0 : _scrollViewRef$curren.scrollTo({
|
|
47
46
|
y: yValue,
|
|
48
47
|
animated
|
|
49
48
|
});
|
|
@@ -61,7 +60,7 @@ function CollapsibleScrollView({
|
|
|
61
60
|
}, []);
|
|
62
61
|
const contentContainerStyle = (0, _react.useMemo)(() => [styles.contentContainer, props.contentContainerStyle], [props.contentContainerStyle]);
|
|
63
62
|
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.ScrollView, _extends({
|
|
64
|
-
ref:
|
|
63
|
+
ref: scrollViewRef,
|
|
65
64
|
bounces: false
|
|
66
65
|
}, props, {
|
|
67
66
|
style: [styles.container, props.style],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CollapsibleScrollView.tsx"],"names":["CollapsibleScrollView","headerSnappable","children","props","
|
|
1
|
+
{"version":3,"sources":["CollapsibleScrollView.tsx"],"names":["CollapsibleScrollView","headerSnappable","children","props","contentMinHeight","scrollViewRef","headerHeight","scrollTo","yValue","animated","current","y","scrollHandler","animatedStyle","minHeight","value","contentContainerStyle","styles","contentContainer","container","style","StyleSheet","create","absoluteFillObject","flexGrow","topView","position","top","left","right"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;;;AAOe,SAASA,qBAAT,CAA+B;AAC5CC,EAAAA,eAAe,GAAG,IAD0B;AAE5CC,EAAAA,QAF4C;AAG5C,KAAGC;AAHyC,CAA/B,EAIL;AACR,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MAAsC,6CAA5C;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAmB,qCAAzB;AAEA,QAAMC,QAAQ,GAAG,wBAAY,CAACC,MAAD,EAAiBC,QAAQ,GAAG,IAA5B,KAAqC;AAAA;;AAChE,6BAAAJ,aAAa,CAACK,OAAd,gFAAuBH,QAAvB,CAAgC;AAAEI,MAAAA,CAAC,EAAEH,MAAL;AAAaC,MAAAA;AAAb,KAAhC;AACD,GAFgB,EAEd,EAFc,CAAjB;AAIA,QAAM;AAAEG,IAAAA;AAAF,MAAoB,gCAAkB;AAC1CX,IAAAA,eAD0C;AAE1CM,IAAAA;AAF0C,GAAlB,CAA1B;AAKA,QAAMM,aAAa,GAAG,6CAAiB,MAAM;AAC3C,WAAO;AACLC,MAAAA,SAAS,EAAEV,gBAAgB,CAACW;AADvB,KAAP;AAGD,GAJqB,EAInB,EAJmB,CAAtB;AAMA,QAAMC,qBAAqB,GAAG,oBAC5B,MAAM,CAACC,MAAM,CAACC,gBAAR,EAA0Bf,KAAK,CAACa,qBAAhC,CADsB,EAE5B,CAACb,KAAK,CAACa,qBAAP,CAF4B,CAA9B;AAKA,sBACE,6BAAC,8BAAD,CAAU,UAAV;AACE,IAAA,GAAG,EAAEX,aADP;AAEE,IAAA,OAAO,EAAE;AAFX,KAGMF,KAHN;AAIE,IAAA,KAAK,EAAE,CAACc,MAAM,CAACE,SAAR,EAAmBhB,KAAK,CAACiB,KAAzB,CAJT;AAKE,IAAA,qBAAqB,EAAEJ,qBALzB;AAME,IAAA,QAAQ,EAAEJ,aANZ;AAOE,IAAA,mBAAmB,EAAC,SAPtB;AAQE,IAAA,yBAAyB,EAAC,SAR5B;AASE,IAAA,mBAAmB,EAAE;AATvB,mBAWE,6BAAC,8BAAD,CAAU,IAAV;AAAe,IAAA,KAAK,EAAEC;AAAtB,kBACE,6BAAC,wBAAD;AAAiB,IAAA,MAAM,EAAEP;AAAzB,IADF,EAEGJ,QAFH,CAXF,CADF;AAkBD;;AAED,MAAMe,MAAM,GAAGI,wBAAWC,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE,EACT,GAAGE,wBAAWE;AADL,GADoB;AAI/BL,EAAAA,gBAAgB,EAAE;AAChBM,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":["/* eslint-disable react-hooks/exhaustive-deps */\nimport AnimatedTopView from '../header/AnimatedTopView';\nimport useAnimatedScroll from './useAnimatedScroll';\nimport React, { ReactNode, useCallback, useMemo } 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 { contentMinHeight, scrollViewRef } = useInternalCollapsibleContext();\n const { headerHeight } = useCollapsibleContext();\n\n const scrollTo = useCallback((yValue: number, animated = true) => {\n scrollViewRef.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={scrollViewRef}\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"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useKeyboardShowEvent;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
function useKeyboardShowEvent(callback) {
|
|
13
|
+
const savedCallback = (0, _react.useRef)(callback);
|
|
14
|
+
(0, _react.useEffect)(() => {
|
|
15
|
+
savedCallback.current = callback;
|
|
16
|
+
}, [callback]);
|
|
17
|
+
(0, _react.useEffect)(() => {
|
|
18
|
+
const subscription = _reactNative.Keyboard.addListener('keyboardDidShow', () => {
|
|
19
|
+
if (savedCallback.current) {
|
|
20
|
+
savedCallback.current();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
subscription.remove();
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=useKeyboardShowEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useKeyboardShowEvent.ts"],"names":["useKeyboardShowEvent","callback","savedCallback","current","subscription","Keyboard","addListener","remove"],"mappings":";;;;;;;AAAA;;AACA;;AAEe,SAASA,oBAAT,CAA8BC,QAA9B,EAAoD;AACjE,QAAMC,aAAa,GAAG,mBAAOD,QAAP,CAAtB;AAEA,wBAAU,MAAM;AACdC,IAAAA,aAAa,CAACC,OAAd,GAAwBF,QAAxB;AACD,GAFD,EAEG,CAACA,QAAD,CAFH;AAIA,wBAAU,MAAM;AACd,UAAMG,YAAY,GAAGC,sBAASC,WAAT,CAAqB,iBAArB,EAAwC,MAAM;AACjE,UAAIJ,aAAa,CAACC,OAAlB,EAA2B;AACzBD,QAAAA,aAAa,CAACC,OAAd;AACD;AACF,KAJoB,CAArB;;AAMA,WAAO,MAAM;AACXC,MAAAA,YAAY,CAACG,MAAb;AACD,KAFD;AAGD,GAVD,EAUG,EAVH;AAWD","sourcesContent":["import { useEffect, useRef } from 'react';\nimport { Keyboard } from 'react-native';\n\nexport default function useKeyboardShowEvent(callback: () => void) {\n const savedCallback = useRef(callback);\n\n useEffect(() => {\n savedCallback.current = callback;\n }, [callback]);\n\n useEffect(() => {\n const subscription = Keyboard.addListener('keyboardDidShow', () => {\n if (savedCallback.current) {\n savedCallback.current();\n }\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n}\n"]}
|
|
File without changes
|
|
@@ -41,6 +41,7 @@ function withCollapsibleContext(Component) {
|
|
|
41
41
|
const firstStickyViewY = (0, _reactNativeReanimated.useSharedValue)(1000000);
|
|
42
42
|
const headerContainersHeight = (0, _react.useRef)({});
|
|
43
43
|
const containerRef = (0, _react.useRef)(null);
|
|
44
|
+
const scrollViewRef = (0, _react.useRef)(null);
|
|
44
45
|
const setCollapsibleHandlers = (0, _react.useCallback)(handlers => {
|
|
45
46
|
collapsibleHandlers.current = handlers;
|
|
46
47
|
}, []);
|
|
@@ -161,6 +162,7 @@ function withCollapsibleContext(Component) {
|
|
|
161
162
|
};
|
|
162
163
|
}, [scrollY, headerHeight, headerCollapsed]);
|
|
163
164
|
const internalContext = (0, _react.useMemo)(() => ({
|
|
165
|
+
scrollViewRef,
|
|
164
166
|
containerRef,
|
|
165
167
|
handleStickyViewLayout,
|
|
166
168
|
handleHeaderContainerLayout,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["withCollapsibleContext.tsx"],"names":["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":";;;;;;;AAEA;;AAEA;;AACA;;AACA;;AAOA;;AACA;;;;;;;;AAdA;;AACA;AAee,SAASA,sBAAT,CAAmCC,SAAnC,EAAqD;AA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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"]}
|
|
1
|
+
{"version":3,"sources":["withCollapsibleContext.tsx"],"names":["withCollapsibleContext","Component","props","collapsibleHandlers","headerHeight","scrollY","stickyViewRefs","stickyViewTops","stickyViewPositionsRef","stickyViewPositions","fixedHeaderHeight","stickyHeaderHeight","containerHeight","firstStickyViewY","headerContainersHeight","containerRef","scrollViewRef","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":";;;;;;;AAEA;;AAEA;;AACA;;AACA;;AAOA;;AACA;;;;;;;;AAdA;;AACA;AAee,SAASA,sBAAT,CAAmCC,SAAnC,EAAqD;AAClE,SAAQC,KAAD,IAAc;AACnB,UAAMC,mBAAmB,GAAG,oBAA5B;AACA,UAAMC,YAAY,GAAG,2CAAe,CAAf,CAArB;AACA,UAAMC,OAAO,GAAG,2CAAe,CAAf,CAAhB;AACA,UAAMC,cAAc,GAAG,mBAA8C,EAA9C,CAAvB;AACA,UAAMC,cAAc,GAAG,2CAAuC,EAAvC,CAAvB;AACA,UAAMC,sBAAsB,GAAG,mBAAqC,EAArC,CAA/B;AACA,UAAMC,mBAAmB,GAAG,2CAC1B,EAD0B,CAA5B;AAGA,UAAMC,iBAAiB,GAAG,2CAAe,CAAf,CAA1B;AACA,UAAMC,kBAAkB,GAAG,2CAAe,CAAf,CAA3B;AACA,UAAMC,eAAe,GAAG,2CAAe,CAAf,CAAxB;AACA,UAAMC,gBAAgB,GAAG,2CAAe,OAAf,CAAzB;AACA,UAAMC,sBAAsB,GAAG,mBAA+B,EAA/B,CAA/B;AACA,UAAMC,YAAY,GAAG,mBAAa,IAAb,CAArB;AACA,UAAMC,aAAa,GAAG,mBAAa,IAAb,CAAtB;AAEA,UAAMC,sBAAsB,GAAG,wBAAaC,QAAD,IAAc;AACvDf,MAAAA,mBAAmB,CAACgB,OAApB,GAA8BD,QAA9B;AACD,KAF8B,EAE5B,EAF4B,CAA/B;AAIA,UAAME,eAAe,GAAG,4CAAgB,MAAM;AAC5C,YAAMC,IAAI,GAAGX,iBAAiB,CAACY,KAAlB,GAA0BT,gBAAgB,CAACS,KAAxD;AACA,aAAOjB,OAAO,CAACiB,KAAR,IAAiBD,IAAxB;AACD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,CACEN,sBADF,EAEE8B,sBAFF,EAGEQ,2BAHF,EAIEE,qBAJF,EAKE5C,gBALF,EAMEN,cANF,EAOEE,mBAPF,EAQEC,iBARF,EASEa,gBATF,CAdsB,CAAxB;AA2BA,wBACE,6BAAC,yCAAD,CAAoB,QAApB;AAA6B,MAAA,KAAK,EAAEmC;AAApC,oBACE,6BAAC,yDAAD,CAA4B,QAA5B;AAAqC,MAAA,KAAK,EAAEM;AAA5C,oBACE,6BAAC,8BAAD,qBACE,6BAAC,SAAD,EAAe9D,KAAf,CADF,CADF,CADF,CADF;AASD,GAxLD;AAyLD","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 const scrollViewRef = 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 scrollViewRef,\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"]}
|
|
@@ -1,25 +1,66 @@
|
|
|
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 React, { useCallback } from 'react';
|
|
4
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import React, { useCallback, useRef } from 'react';
|
|
4
|
+
import { KeyboardAvoidingView, StyleSheet, View } from 'react-native';
|
|
5
|
+
import useKeyboardShowEvent from '../hooks/useKeyboardShowEvent';
|
|
5
6
|
import useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';
|
|
7
|
+
import useCollapsibleContext from '../hooks/useCollapsibleContext';
|
|
6
8
|
export default function CollapsibleContainer({
|
|
7
9
|
children,
|
|
10
|
+
keyboardAvoidingViewProps,
|
|
11
|
+
textInputRefs = [],
|
|
8
12
|
...props
|
|
9
13
|
}) {
|
|
10
14
|
const {
|
|
11
15
|
containerRef,
|
|
12
16
|
handleContainerHeight
|
|
13
17
|
} = useInternalCollapsibleContext();
|
|
18
|
+
const {
|
|
19
|
+
scrollY,
|
|
20
|
+
scrollTo
|
|
21
|
+
} = useCollapsibleContext();
|
|
22
|
+
const containerHeight = useRef(0);
|
|
23
|
+
useKeyboardShowEvent(() => {
|
|
24
|
+
textInputRefs.some(ref => {
|
|
25
|
+
const isFocusedFunc = ref.current.isFocused;
|
|
26
|
+
const isFocused = isFocusedFunc && typeof isFocusedFunc === 'function' ? isFocusedFunc() : isFocusedFunc;
|
|
27
|
+
|
|
28
|
+
if (isFocused) {
|
|
29
|
+
ref.current.measureLayout( // @ts-ignore
|
|
30
|
+
containerRef.current, (left, top, width, height) => {
|
|
31
|
+
console.log({
|
|
32
|
+
left,
|
|
33
|
+
top,
|
|
34
|
+
width,
|
|
35
|
+
height
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (top + height - scrollY.value > containerHeight.current) {
|
|
39
|
+
var _keyboardAvoidingView;
|
|
40
|
+
|
|
41
|
+
console.log('need to scroll');
|
|
42
|
+
const extraOffset = (_keyboardAvoidingView = keyboardAvoidingViewProps === null || keyboardAvoidingViewProps === void 0 ? void 0 : keyboardAvoidingViewProps.keyboardVerticalOffset) !== null && _keyboardAvoidingView !== void 0 ? _keyboardAvoidingView : 20;
|
|
43
|
+
scrollTo(top + height + extraOffset - containerHeight.current);
|
|
44
|
+
}
|
|
45
|
+
}, () => {});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return isFocused;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
14
51
|
const handleContainerLayout = useCallback(layout => {
|
|
15
52
|
const height = layout.nativeEvent.layout.height;
|
|
53
|
+
containerHeight.current = height;
|
|
16
54
|
handleContainerHeight(height);
|
|
17
55
|
}, [handleContainerHeight]);
|
|
18
|
-
return /*#__PURE__*/React.createElement(
|
|
56
|
+
return /*#__PURE__*/React.createElement(KeyboardAvoidingView, _extends({
|
|
57
|
+
style: styles.container,
|
|
58
|
+
behavior: "padding"
|
|
59
|
+
}, keyboardAvoidingViewProps), /*#__PURE__*/React.createElement(View, _extends({}, props, {
|
|
19
60
|
ref: containerRef,
|
|
20
61
|
style: [styles.container, props.style],
|
|
21
62
|
onLayout: handleContainerLayout
|
|
22
|
-
}), children);
|
|
63
|
+
}), children));
|
|
23
64
|
}
|
|
24
65
|
const styles = StyleSheet.create({
|
|
25
66
|
container: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CollapsibleContainer.tsx"],"names":["React","useCallback","StyleSheet","View","useInternalCollapsibleContext","CollapsibleContainer","children","props","containerRef","handleContainerHeight","
|
|
1
|
+
{"version":3,"sources":["CollapsibleContainer.tsx"],"names":["React","useCallback","useRef","KeyboardAvoidingView","StyleSheet","View","useKeyboardShowEvent","useInternalCollapsibleContext","useCollapsibleContext","CollapsibleContainer","children","keyboardAvoidingViewProps","textInputRefs","props","containerRef","handleContainerHeight","scrollY","scrollTo","containerHeight","some","ref","isFocusedFunc","current","isFocused","measureLayout","left","top","width","height","console","log","value","extraOffset","keyboardVerticalOffset","handleContainerLayout","layout","nativeEvent","styles","container","style","create","flex","overflow"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,MAA7B,QAA2C,OAA3C;AACA,SACEC,oBADF,EAIEC,UAJF,EAKEC,IALF,QAOO,cAPP;AAQA,OAAOC,oBAAP,MAAiC,+BAAjC;AACA,OAAOC,6BAAP,MAA0C,wCAA1C;AACA,OAAOC,qBAAP,MAAkC,gCAAlC;AAQA,eAAe,SAASC,oBAAT,CAA8B;AAC3CC,EAAAA,QAD2C;AAE3CC,EAAAA,yBAF2C;AAG3CC,EAAAA,aAAa,GAAG,EAH2B;AAI3C,KAAGC;AAJwC,CAA9B,EAKL;AACR,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MACJR,6BAA6B,EAD/B;AAEA,QAAM;AAAES,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAwBT,qBAAqB,EAAnD;AAEA,QAAMU,eAAe,GAAGhB,MAAM,CAAC,CAAD,CAA9B;AAEAI,EAAAA,oBAAoB,CAAC,MAAM;AACzBM,IAAAA,aAAa,CAACO,IAAd,CAAoBC,GAAD,IAAS;AAC1B,YAAMC,aAAa,GAAGD,GAAG,CAACE,OAAJ,CAAYC,SAAlC;AACA,YAAMA,SAAS,GACbF,aAAa,IAAI,OAAOA,aAAP,KAAyB,UAA1C,GACIA,aAAa,EADjB,GAEIA,aAHN;;AAIA,UAAIE,SAAJ,EAAe;AACbH,QAAAA,GAAG,CAACE,OAAJ,CAAYE,aAAZ,EACE;AACAV,QAAAA,YAAY,CAACQ,OAFf,EAGE,CAACG,IAAD,EAAeC,GAAf,EAA4BC,KAA5B,EAA2CC,MAA3C,KAA8D;AAC5DC,UAAAA,OA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AAAA,IAAI,EAAE,CADG;AAETC,IAAAA,QAAQ,EAAE;AAFD;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback, useRef } from 'react';\nimport {\n KeyboardAvoidingView,\n KeyboardAvoidingViewProps,\n LayoutChangeEvent,\n StyleSheet,\n View,\n ViewProps,\n} from 'react-native';\nimport useKeyboardShowEvent from '../hooks/useKeyboardShowEvent';\nimport useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';\nimport useCollapsibleContext from '../hooks/useCollapsibleContext';\n\ntype Props = Omit<ViewProps, 'ref' | 'onLayout'> & {\n children: Element;\n keyboardAvoidingViewProps?: KeyboardAvoidingViewProps;\n textInputRefs?: any[];\n};\n\nexport default function CollapsibleContainer({\n children,\n keyboardAvoidingViewProps,\n textInputRefs = [],\n ...props\n}: Props) {\n const { containerRef, handleContainerHeight } =\n useInternalCollapsibleContext();\n const { scrollY, scrollTo } = useCollapsibleContext();\n\n const containerHeight = useRef(0);\n\n useKeyboardShowEvent(() => {\n textInputRefs.some((ref) => {\n const isFocusedFunc = ref.current.isFocused;\n const isFocused =\n isFocusedFunc && typeof isFocusedFunc === 'function'\n ? isFocusedFunc()\n : isFocusedFunc;\n if (isFocused) {\n ref.current.measureLayout(\n // @ts-ignore\n containerRef.current,\n (left: number, top: number, width: number, height: number) => {\n console.log({ left, top, width, height });\n if (top + height - scrollY.value > containerHeight.current) {\n console.log('need to scroll');\n const extraOffset =\n keyboardAvoidingViewProps?.keyboardVerticalOffset ?? 20;\n scrollTo(top + height + extraOffset - containerHeight.current);\n }\n },\n () => {}\n );\n }\n return isFocused;\n });\n });\n\n const handleContainerLayout = useCallback(\n (layout: LayoutChangeEvent) => {\n const height = layout.nativeEvent.layout.height;\n containerHeight.current = height;\n handleContainerHeight(height);\n },\n [handleContainerHeight]\n );\n\n return (\n <KeyboardAvoidingView\n style={styles.container}\n behavior=\"padding\"\n {...keyboardAvoidingViewProps}\n >\n <View\n {...props}\n ref={containerRef}\n style={[styles.container, props.style]}\n onLayout={handleContainerLayout}\n >\n {children}\n </View>\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
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
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
3
4
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
5
|
import { View, StyleSheet, FlatList } from 'react-native';
|
|
5
6
|
import Animated, { runOnJS, useAnimatedReaction } from 'react-native-reanimated';
|
|
@@ -18,9 +19,9 @@ export default function CollapsibleFlatList({
|
|
|
18
19
|
scrollY
|
|
19
20
|
} = useCollapsibleContext();
|
|
20
21
|
const {
|
|
21
|
-
contentMinHeight
|
|
22
|
+
contentMinHeight,
|
|
23
|
+
scrollViewRef
|
|
22
24
|
} = useInternalCollapsibleContext();
|
|
23
|
-
const scrollRef = useRef(null);
|
|
24
25
|
const mounted = useRef(true);
|
|
25
26
|
const contentHeight = useRef(0);
|
|
26
27
|
useEffect(() => {
|
|
@@ -29,13 +30,13 @@ export default function CollapsibleFlatList({
|
|
|
29
30
|
};
|
|
30
31
|
}, []);
|
|
31
32
|
const scrollTo = useCallback((yValue, animated = true) => {
|
|
32
|
-
var
|
|
33
|
+
var _scrollViewRef$curren;
|
|
33
34
|
|
|
34
|
-
(
|
|
35
|
+
(_scrollViewRef$curren = scrollViewRef.current) === null || _scrollViewRef$curren === void 0 ? void 0 : _scrollViewRef$curren.scrollToOffset({
|
|
35
36
|
offset: yValue,
|
|
36
37
|
animated
|
|
37
38
|
});
|
|
38
|
-
}, [
|
|
39
|
+
}, []);
|
|
39
40
|
const handleInternalContentHeight = useCallback(value => {
|
|
40
41
|
if (mounted.current) {
|
|
41
42
|
setInternalContentMinHeight(value);
|
|
@@ -71,7 +72,7 @@ export default function CollapsibleFlatList({
|
|
|
71
72
|
return /*#__PURE__*/React.createElement(PullToRefreshContainer, {
|
|
72
73
|
scrollY: scrollY
|
|
73
74
|
}, /*#__PURE__*/React.createElement(AnimatedFlatList, _extends({
|
|
74
|
-
ref:
|
|
75
|
+
ref: scrollViewRef,
|
|
75
76
|
bounces: false,
|
|
76
77
|
keyboardDismissMode: "on-drag",
|
|
77
78
|
keyboardShouldPersistTaps: "handled",
|
|
@@ -1 +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","
|
|
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","scrollViewRef","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;AACA,OAAOA,KAAP,IACEC,WADF,EAEEC,SAFF,EAGEC,OAHF,EAIEC,MAJF,EAKEC,QALF,QAMO,OANP;AAOA,SAAwBC,IAAxB,EAA8BC,U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ACE,IAAA,GAAG,EAAEE,aADP;AAEE,IAAA,OAAO,EAAE,KAFX;AAGE,IAAA,mBAAmB,EAAC,SAHtB;AAIE,IAAA,yBAAyB,EAAC,SAJ5B;AAKE,IAAA,mBAAmB,EAAE;AALvB,KAMMJ,KANN;AAOE,IAAA,KAAK,EAAE,CAACqB,MAAM,CAACQ,SAAR,EAAmB7B,KAAK,CAAC8B,KAAzB,CAPT;AAQE,IAAA,qBAAqB,EAAEV,qBARzB;AASE,IAAA,QAAQ,EAAEJ,aATZ;AAUE,IAAA,mBAAmB,EAAEW,gBAAgB,EAVvC;AAWE,IAAA,mBAAmB,EAAEH;AAXvB,KAFF,CADF;AAkBD;AAED,MAAMH,MAAM,GAAGnC,UAAU,CAAC6C,MAAX,CAAkB;AAC/BF,EAAAA,SAAS,EAAE,EACT,GAAG3C,UAAU,CAAC8C;AADL,GADoB;AAI/BV,EAAAA,gBAAgB,EAAE;AAChBW,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":["/* eslint-disable react-hooks/exhaustive-deps */\nimport React, {\n useCallback,\n useEffect,\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, scrollViewRef } = useInternalCollapsibleContext();\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((yValue: number, animated = true) => {\n scrollViewRef.current?.scrollToOffset({\n offset: yValue,\n animated,\n });\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={scrollViewRef}\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"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
3
4
|
import AnimatedTopView from '../header/AnimatedTopView';
|
|
4
5
|
import useAnimatedScroll from './useAnimatedScroll';
|
|
5
|
-
import React, { useCallback, useMemo
|
|
6
|
+
import React, { useCallback, useMemo } from 'react';
|
|
6
7
|
import { StyleSheet } from 'react-native';
|
|
7
8
|
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
8
9
|
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
@@ -12,18 +13,17 @@ export default function CollapsibleScrollView({
|
|
|
12
13
|
children,
|
|
13
14
|
...props
|
|
14
15
|
}) {
|
|
15
|
-
const scrollView = useRef(null);
|
|
16
16
|
const {
|
|
17
|
-
contentMinHeight
|
|
17
|
+
contentMinHeight,
|
|
18
|
+
scrollViewRef
|
|
18
19
|
} = useInternalCollapsibleContext();
|
|
19
20
|
const {
|
|
20
21
|
headerHeight
|
|
21
22
|
} = useCollapsibleContext();
|
|
22
23
|
const scrollTo = useCallback((yValue, animated = true) => {
|
|
23
|
-
var
|
|
24
|
+
var _scrollViewRef$curren;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
(_scrollView$current = scrollView.current) === null || _scrollView$current === void 0 ? void 0 : _scrollView$current.scrollTo({
|
|
26
|
+
(_scrollViewRef$curren = scrollViewRef.current) === null || _scrollViewRef$curren === void 0 ? void 0 : _scrollViewRef$curren.scrollTo({
|
|
27
27
|
y: yValue,
|
|
28
28
|
animated
|
|
29
29
|
});
|
|
@@ -41,7 +41,7 @@ export default function CollapsibleScrollView({
|
|
|
41
41
|
}, []);
|
|
42
42
|
const contentContainerStyle = useMemo(() => [styles.contentContainer, props.contentContainerStyle], [props.contentContainerStyle]);
|
|
43
43
|
return /*#__PURE__*/React.createElement(Animated.ScrollView, _extends({
|
|
44
|
-
ref:
|
|
44
|
+
ref: scrollViewRef,
|
|
45
45
|
bounces: false
|
|
46
46
|
}, props, {
|
|
47
47
|
style: [styles.container, props.style],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CollapsibleScrollView.tsx"],"names":["AnimatedTopView","useAnimatedScroll","React","useCallback","useMemo","
|
|
1
|
+
{"version":3,"sources":["CollapsibleScrollView.tsx"],"names":["AnimatedTopView","useAnimatedScroll","React","useCallback","useMemo","StyleSheet","Animated","useAnimatedStyle","useCollapsibleContext","useInternalCollapsibleContext","CollapsibleScrollView","headerSnappable","children","props","contentMinHeight","scrollViewRef","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;AACA,OAAOA,eAAP,MAA4B,2BAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,KAAP,IAA2BC,WAA3B,EAAwCC,OAAxC,QAAuD,OAAvD;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,QAAM;AAAEC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AAAiB,IAAA,MAAM,EAAEP;AAAzB,IADF,EAEGJ,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":["/* eslint-disable react-hooks/exhaustive-deps */\nimport AnimatedTopView from '../header/AnimatedTopView';\nimport useAnimatedScroll from './useAnimatedScroll';\nimport React, { ReactNode, useCallback, useMemo } 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 { contentMinHeight, scrollViewRef } = useInternalCollapsibleContext();\n const { headerHeight } = useCollapsibleContext();\n\n const scrollTo = useCallback((yValue: number, animated = true) => {\n scrollViewRef.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={scrollViewRef}\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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { Keyboard } from 'react-native';
|
|
3
|
+
export default function useKeyboardShowEvent(callback) {
|
|
4
|
+
const savedCallback = useRef(callback);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
savedCallback.current = callback;
|
|
7
|
+
}, [callback]);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const subscription = Keyboard.addListener('keyboardDidShow', () => {
|
|
10
|
+
if (savedCallback.current) {
|
|
11
|
+
savedCallback.current();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return () => {
|
|
15
|
+
subscription.remove();
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=useKeyboardShowEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useKeyboardShowEvent.ts"],"names":["useEffect","useRef","Keyboard","useKeyboardShowEvent","callback","savedCallback","current","subscription","addListener","remove"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,eAAe,SAASC,oBAAT,CAA8BC,QAA9B,EAAoD;AACjE,QAAMC,aAAa,GAAGJ,MAAM,CAACG,QAAD,CAA5B;AAEAJ,EAAAA,SAAS,CAAC,MAAM;AACdK,IAAAA,aAAa,CAACC,OAAd,GAAwBF,QAAxB;AACD,GAFQ,EAEN,CAACA,QAAD,CAFM,CAAT;AAIAJ,EAAAA,SAAS,CAAC,MAAM;AACd,UAAMO,YAAY,GAAGL,QAAQ,CAACM,WAAT,CAAqB,iBAArB,EAAwC,MAAM;AACjE,UAAIH,aAAa,CAACC,OAAlB,EAA2B;AACzBD,QAAAA,aAAa,CAACC,OAAd;AACD;AACF,KAJoB,CAArB;AAMA,WAAO,MAAM;AACXC,MAAAA,YAAY,CAACE,MAAb;AACD,KAFD;AAGD,GAVQ,EAUN,EAVM,CAAT;AAWD","sourcesContent":["import { useEffect, useRef } from 'react';\nimport { Keyboard } from 'react-native';\n\nexport default function useKeyboardShowEvent(callback: () => void) {\n const savedCallback = useRef(callback);\n\n useEffect(() => {\n savedCallback.current = callback;\n }, [callback]);\n\n useEffect(() => {\n const subscription = Keyboard.addListener('keyboardDidShow', () => {\n if (savedCallback.current) {\n savedCallback.current();\n }\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n}\n"]}
|
|
File without changes
|
|
@@ -22,6 +22,7 @@ export default function withCollapsibleContext(Component) {
|
|
|
22
22
|
const firstStickyViewY = useSharedValue(1000000);
|
|
23
23
|
const headerContainersHeight = useRef({});
|
|
24
24
|
const containerRef = useRef(null);
|
|
25
|
+
const scrollViewRef = useRef(null);
|
|
25
26
|
const setCollapsibleHandlers = useCallback(handlers => {
|
|
26
27
|
collapsibleHandlers.current = handlers;
|
|
27
28
|
}, []);
|
|
@@ -142,6 +143,7 @@ export default function withCollapsibleContext(Component) {
|
|
|
142
143
|
};
|
|
143
144
|
}, [scrollY, headerHeight, headerCollapsed]);
|
|
144
145
|
const internalContext = useMemo(() => ({
|
|
146
|
+
scrollViewRef,
|
|
145
147
|
containerRef,
|
|
146
148
|
handleStickyViewLayout,
|
|
147
149
|
handleHeaderContainerLayout,
|
|
@@ -1 +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":"AAAA;;AACA;AACA,OAAOA,KAAP,IAAoBC,WAApB,EAAiCC,OAAjC,EAA0CC,MAA1C,QAAwD,OAAxD;AAEA,SAASC,kBAAT,QAAmC,+BAAnC;AACA,SAASC,0BAAT,QAA2C,uCAA3C;AACA,SACEC,mBADF,EAEEC,eAFF,EAGEC,cAHF,EAIEC,UAJF,QAKO,yBALP;AAOA,SAASC,QAAT,QAAyB,kBAAzB;AACA,OAAOC,qBAAP,MAAkC,kDAAlC;AAEA,eAAe,SAASC,sBAAT,CAAmCC,SAAnC,EAAqD;AAClE,SAAQC,KAAD,IAAc;AACnB,UAAMC,mBAAmB,GAAGZ,MAAM,EAAlC;AACA,UAAMa,YAAY,GAAGR,cAAc,CAAC,CAAD,CAAnC;AACA,UAAMS,OAAO,GAAGT,cAAc,CAAC,CAAD,CAA9B;AACA,UAAMU,cAAc,GAAGf,MAAM,CAAwC,EAAxC,CAA7B;AACA,UAAMgB,cAAc,GAAGX,cAAc,CAAyB,EAAzB,CAArC;AACA,UAAMY,sBAAsB,GAAGjB,MAAM,CAA+B,EAA/B,CAArC;AACA,UAAMkB,mBAAmB,GAAGb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AmB,CAACe,OAA1B,0DAAM,sBAA6BwC,QAA7B,EAAN;AAAA,SADL;AAELC,QAAAA,MAAM,EAAE;AAAA;;AAAA,2CAAMxD,mBAAmB,CAACe,OAA1B,2DAAM,uBAA6ByC,MAA7B,EAAN;AAAA,SAFH;AAGLC,QAAAA,QAAQ,EAAE,CAACC,MAAD,EAAiBC,OAAjB;AAAA;;AAAA,2CACR3D,mBAAmB,CAACe,OADZ,2DACR,uBAA6B0C,QAA7B,CAAsCC,MAAtC,EAA8CC,OAA9C,CADQ;AAAA,SAHL;AAKL1D,QAAAA,YALK;AAMLC,QAAAA,OANK;AAOLc,QAAAA;AAPK,OAAP;AASD,KAVsB,EAUpB,CAACd,OAAD,EAAUD,YAAV,EAAwBe,eAAxB,CAVoB,CAAvB;AAYA,UAAM4C,eAAe,GAAGzE,OAAO,CAC7B,OAAO;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"]}
|
|
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","scrollViewRef","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":"AAAA;;AACA;AACA,OAAOA,KAAP,IAAoBC,WAApB,EAAiCC,OAAjC,EAA0CC,MAA1C,QAAwD,OAAxD;AAEA,SAASC,kBAAT,QAAmC,+BAAnC;AACA,SAASC,0BAAT,QAA2C,uCAA3C;AACA,SACEC,mBADF,EAEEC,eAFF,EAGEC,cAHF,EAIEC,UAJF,QAKO,yBALP;AAOA,SAASC,QAAT,QAAyB,kBAAzB;AACA,OAAOC,qBAAP,MAAkC,kDAAlC;AAEA,eAAe,SAASC,sBAAT,CAAmCC,SAAnC,EAAqD;AAClE,SAAQC,KAAD,IAAc;AACnB,UAAMC,mBAAmB,GAAGZ,MAAM,EAAlC;AACA,UAAMa,YAAY,GAAGR,cAAc,CAAC,CAAD,CAAnC;AACA,UAAMS,OAAO,GAAGT,cAAc,CAAC,CAAD,CAA9B;AACA,UAAMU,cAAc,GAAGf,MAAM,CAAwC,EAAxC,CAA7B;AACA,UAAMgB,cAAc,GAAGX,cAAc,CAAyB,EAAzB,CAArC;AACA,UAAMY,sBAAsB,GAAGjB,MAAM,CAA+B,EAA/B,CAArC;AACA,UAAMkB,mBAAmB,GAAGb,cAAc,CACxC,EADwC,CAA1C;AAGA,UAAMc,iBAAiB,GAAGd,cAAc,CAAC,CAAD,CAAxC;AACA,UAAMe,kBAAkB,GAAGf,cAAc,CAAC,CAAD,CAAzC;AACA,UAAMgB,eAAe,GAAGhB,cAAc,CAAC,CAAD,CAAtC;AACA,UAAMiB,gBAAgB,GAAGjB,cAAc,CAAC,OAAD,CAAvC;AACA,UAAMkB,sBAAsB,GAAGvB,MAAM,CAAyB,EAAzB,CAArC;AACA,UAAMwB,YAAY,GAAGxB,MAAM,CAAO,IAAP,CAA3B;AACA,UAAMyB,aAAa,GAAGzB,MAAM,CAAO,IAAP,CAA5B;AAE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D,QAAAA,YALK;AAMLC,QAAAA,OANK;AAOLe,QAAAA;AAPK,OAAP;AASD,KAVsB,EAUpB,CAACf,OAAD,EAAUD,YAAV,EAAwBgB,eAAxB,CAVoB,CAAvB;AAYA,UAAM4C,eAAe,GAAG1E,OAAO,CAC7B,OAAO;AACL0B,MAAAA,aADK;AAELD,MAAAA,YAFK;AAGLgC,MAAAA,sBAHK;AAILQ,MAAAA,2BAJK;AAKLtC,MAAAA,sBALK;AAMLwC,MAAAA,qBANK;AAOL5C,MAAAA,gBAPK;AAQLN,MAAAA,cARK;AASLE,MAAAA,mBATK;AAULC,MAAAA,iBAVK;AAWLa,MAAAA;AAXK,KAAP,CAD6B,EAc7B,CACEN,sBADF,EAEE8B,sBAFF,EAGEQ,2BAHF,EAIEE,qBAJF,EAKE5C,gBALF,EAMEN,cANF,EAOEE,mBAPF,EAQEC,iBARF,EASEa,gBATF,CAd6B,CAA/B;AA2BA,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,EAAe9D,KAAf,CADF,CADF,CADF,CADF;AASD,GAxLD;AAyLD","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 const scrollViewRef = 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 scrollViewRef,\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"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ViewProps } from 'react-native';
|
|
1
|
+
import { KeyboardAvoidingViewProps, ViewProps } from 'react-native';
|
|
2
2
|
declare type Props = Omit<ViewProps, 'ref' | 'onLayout'> & {
|
|
3
3
|
children: Element;
|
|
4
|
+
keyboardAvoidingViewProps?: KeyboardAvoidingViewProps;
|
|
5
|
+
textInputRefs?: any[];
|
|
4
6
|
};
|
|
5
|
-
export default function CollapsibleContainer({ children, ...props }: Props): JSX.Element;
|
|
7
|
+
export default function CollapsibleContainer({ children, keyboardAvoidingViewProps, textInputRefs, ...props }: Props): JSX.Element;
|
|
6
8
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useKeyboardShowEvent(callback: () => void): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { View } from 'react-native';
|
|
3
|
+
import type Animated from 'react-native-reanimated';
|
|
4
|
+
export declare type CollapsibleHandles = {
|
|
5
|
+
collapse: () => void;
|
|
6
|
+
expand: () => void;
|
|
7
|
+
scrollTo: (offset: number, animate?: boolean) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare type CollapsibleContextType = CollapsibleHandles & {
|
|
10
|
+
scrollY: Animated.SharedValue<number>;
|
|
11
|
+
headerHeight: Animated.SharedValue<number>;
|
|
12
|
+
headerCollapsed: Animated.SharedValue<boolean>;
|
|
13
|
+
};
|
|
14
|
+
export declare type LayoutParams = {
|
|
15
|
+
top: number;
|
|
16
|
+
left: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
export declare type CollapsibleContextInternalType = {
|
|
21
|
+
scrollViewRef: React.RefObject<any>;
|
|
22
|
+
containerRef: React.RefObject<View>;
|
|
23
|
+
contentMinHeight: Animated.SharedValue<number>;
|
|
24
|
+
firstStickyViewY: Animated.SharedValue<number>;
|
|
25
|
+
stickyViewPositions: Animated.SharedValue<Record<string, LayoutParams>>;
|
|
26
|
+
stickyViewTops: Animated.SharedValue<Record<string, number>>;
|
|
27
|
+
fixedHeaderHeight: Animated.SharedValue<number>;
|
|
28
|
+
handleContainerHeight: (height: number) => void;
|
|
29
|
+
handleStickyViewLayout: (viewKey: string, viewRef?: React.RefObject<View>) => void;
|
|
30
|
+
handleHeaderContainerLayout: (viewKey: string, height?: number) => void;
|
|
31
|
+
setCollapsibleHandlers: (handlers: CollapsibleHandles) => void;
|
|
32
|
+
};
|
|
33
|
+
export declare type CollapsibleProps = {
|
|
34
|
+
headerSnappable?: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare type PullToRefreshContextType = {
|
|
37
|
+
refreshValue: Animated.SharedValue<number>;
|
|
38
|
+
internalRefreshing: Animated.SharedValue<boolean>;
|
|
39
|
+
internalHeight: Animated.SharedValue<number>;
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,32 +1,85 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useCallback, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
KeyboardAvoidingView,
|
|
4
|
+
KeyboardAvoidingViewProps,
|
|
5
|
+
LayoutChangeEvent,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
View,
|
|
8
|
+
ViewProps,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import useKeyboardShowEvent from '../hooks/useKeyboardShowEvent';
|
|
3
11
|
import useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';
|
|
12
|
+
import useCollapsibleContext from '../hooks/useCollapsibleContext';
|
|
4
13
|
|
|
5
14
|
type Props = Omit<ViewProps, 'ref' | 'onLayout'> & {
|
|
6
15
|
children: Element;
|
|
16
|
+
keyboardAvoidingViewProps?: KeyboardAvoidingViewProps;
|
|
17
|
+
textInputRefs?: any[];
|
|
7
18
|
};
|
|
8
19
|
|
|
9
|
-
export default function CollapsibleContainer({
|
|
20
|
+
export default function CollapsibleContainer({
|
|
21
|
+
children,
|
|
22
|
+
keyboardAvoidingViewProps,
|
|
23
|
+
textInputRefs = [],
|
|
24
|
+
...props
|
|
25
|
+
}: Props) {
|
|
10
26
|
const { containerRef, handleContainerHeight } =
|
|
11
27
|
useInternalCollapsibleContext();
|
|
28
|
+
const { scrollY, scrollTo } = useCollapsibleContext();
|
|
29
|
+
|
|
30
|
+
const containerHeight = useRef(0);
|
|
31
|
+
|
|
32
|
+
useKeyboardShowEvent(() => {
|
|
33
|
+
textInputRefs.some((ref) => {
|
|
34
|
+
const isFocusedFunc = ref.current.isFocused;
|
|
35
|
+
const isFocused =
|
|
36
|
+
isFocusedFunc && typeof isFocusedFunc === 'function'
|
|
37
|
+
? isFocusedFunc()
|
|
38
|
+
: isFocusedFunc;
|
|
39
|
+
if (isFocused) {
|
|
40
|
+
ref.current.measureLayout(
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
containerRef.current,
|
|
43
|
+
(left: number, top: number, width: number, height: number) => {
|
|
44
|
+
console.log({ left, top, width, height });
|
|
45
|
+
if (top + height - scrollY.value > containerHeight.current) {
|
|
46
|
+
console.log('need to scroll');
|
|
47
|
+
const extraOffset =
|
|
48
|
+
keyboardAvoidingViewProps?.keyboardVerticalOffset ?? 20;
|
|
49
|
+
scrollTo(top + height + extraOffset - containerHeight.current);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
() => {}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return isFocused;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
12
58
|
|
|
13
59
|
const handleContainerLayout = useCallback(
|
|
14
60
|
(layout: LayoutChangeEvent) => {
|
|
15
61
|
const height = layout.nativeEvent.layout.height;
|
|
62
|
+
containerHeight.current = height;
|
|
16
63
|
handleContainerHeight(height);
|
|
17
64
|
},
|
|
18
65
|
[handleContainerHeight]
|
|
19
66
|
);
|
|
20
67
|
|
|
21
68
|
return (
|
|
22
|
-
<
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
onLayout={handleContainerLayout}
|
|
69
|
+
<KeyboardAvoidingView
|
|
70
|
+
style={styles.container}
|
|
71
|
+
behavior="padding"
|
|
72
|
+
{...keyboardAvoidingViewProps}
|
|
27
73
|
>
|
|
28
|
-
|
|
29
|
-
|
|
74
|
+
<View
|
|
75
|
+
{...props}
|
|
76
|
+
ref={containerRef}
|
|
77
|
+
style={[styles.container, props.style]}
|
|
78
|
+
onLayout={handleContainerLayout}
|
|
79
|
+
>
|
|
80
|
+
{children}
|
|
81
|
+
</View>
|
|
82
|
+
</KeyboardAvoidingView>
|
|
30
83
|
);
|
|
31
84
|
}
|
|
32
85
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1
2
|
import React, {
|
|
2
3
|
useCallback,
|
|
3
4
|
useEffect,
|
|
@@ -27,8 +28,7 @@ export default function CollapsibleFlatList<Data>({
|
|
|
27
28
|
...props
|
|
28
29
|
}: Props<Data>) {
|
|
29
30
|
const { headerHeight, scrollY } = useCollapsibleContext();
|
|
30
|
-
const { contentMinHeight } = useInternalCollapsibleContext();
|
|
31
|
-
const scrollRef = useRef<any>(null);
|
|
31
|
+
const { contentMinHeight, scrollViewRef } = useInternalCollapsibleContext();
|
|
32
32
|
const mounted = useRef(true);
|
|
33
33
|
const contentHeight = useRef(0);
|
|
34
34
|
|
|
@@ -38,15 +38,12 @@ export default function CollapsibleFlatList<Data>({
|
|
|
38
38
|
};
|
|
39
39
|
}, []);
|
|
40
40
|
|
|
41
|
-
const scrollTo = useCallback(
|
|
42
|
-
(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
[scrollRef]
|
|
49
|
-
);
|
|
41
|
+
const scrollTo = useCallback((yValue: number, animated = true) => {
|
|
42
|
+
scrollViewRef.current?.scrollToOffset({
|
|
43
|
+
offset: yValue,
|
|
44
|
+
animated,
|
|
45
|
+
});
|
|
46
|
+
}, []);
|
|
50
47
|
|
|
51
48
|
const handleInternalContentHeight = useCallback((value: number) => {
|
|
52
49
|
if (mounted.current) {
|
|
@@ -103,7 +100,7 @@ export default function CollapsibleFlatList<Data>({
|
|
|
103
100
|
<PullToRefreshContainer scrollY={scrollY}>
|
|
104
101
|
{/* @ts-ignore */}
|
|
105
102
|
<AnimatedFlatList
|
|
106
|
-
ref={
|
|
103
|
+
ref={scrollViewRef}
|
|
107
104
|
bounces={false}
|
|
108
105
|
keyboardDismissMode="on-drag"
|
|
109
106
|
keyboardShouldPersistTaps="handled"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1
2
|
import AnimatedTopView from '../header/AnimatedTopView';
|
|
2
3
|
import useAnimatedScroll from './useAnimatedScroll';
|
|
3
|
-
import React, { ReactNode, useCallback, useMemo
|
|
4
|
+
import React, { ReactNode, useCallback, useMemo } from 'react';
|
|
4
5
|
import { ScrollViewProps, StyleSheet } from 'react-native';
|
|
5
6
|
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
6
7
|
import type { CollapsibleProps } from '../../types';
|
|
@@ -17,13 +18,11 @@ export default function CollapsibleScrollView({
|
|
|
17
18
|
children,
|
|
18
19
|
...props
|
|
19
20
|
}: Props) {
|
|
20
|
-
const
|
|
21
|
-
const { contentMinHeight } = useInternalCollapsibleContext();
|
|
21
|
+
const { contentMinHeight, scrollViewRef } = useInternalCollapsibleContext();
|
|
22
22
|
const { headerHeight } = useCollapsibleContext();
|
|
23
23
|
|
|
24
24
|
const scrollTo = useCallback((yValue: number, animated = true) => {
|
|
25
|
-
|
|
26
|
-
scrollView.current?.scrollTo({ y: yValue, animated });
|
|
25
|
+
scrollViewRef.current?.scrollTo({ y: yValue, animated });
|
|
27
26
|
}, []);
|
|
28
27
|
|
|
29
28
|
const { scrollHandler } = useAnimatedScroll({
|
|
@@ -44,7 +43,7 @@ export default function CollapsibleScrollView({
|
|
|
44
43
|
|
|
45
44
|
return (
|
|
46
45
|
<Animated.ScrollView
|
|
47
|
-
ref={
|
|
46
|
+
ref={scrollViewRef}
|
|
48
47
|
bounces={false}
|
|
49
48
|
{...props}
|
|
50
49
|
style={[styles.container, props.style]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { Keyboard } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export default function useKeyboardShowEvent(callback: () => void) {
|
|
5
|
+
const savedCallback = useRef(callback);
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
savedCallback.current = callback;
|
|
9
|
+
}, [callback]);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const subscription = Keyboard.addListener('keyboardDidShow', () => {
|
|
13
|
+
if (savedCallback.current) {
|
|
14
|
+
savedCallback.current();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
subscription.remove();
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RefObject } from 'react';
|
|
2
1
|
import type React from 'react';
|
|
3
2
|
import type { View } from 'react-native';
|
|
4
3
|
import type Animated from 'react-native-reanimated';
|
|
@@ -23,6 +22,7 @@ export type LayoutParams = {
|
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
export type CollapsibleContextInternalType = {
|
|
25
|
+
scrollViewRef: React.RefObject<any>;
|
|
26
26
|
containerRef: React.RefObject<View>;
|
|
27
27
|
contentMinHeight: Animated.SharedValue<number>;
|
|
28
28
|
firstStickyViewY: Animated.SharedValue<number>;
|
|
@@ -31,6 +31,7 @@ export default function withCollapsibleContext<T>(Component: FC<T>) {
|
|
|
31
31
|
const firstStickyViewY = useSharedValue(1000000);
|
|
32
32
|
const headerContainersHeight = useRef<Record<string, number>>({});
|
|
33
33
|
const containerRef = useRef<View>(null);
|
|
34
|
+
const scrollViewRef = useRef<View>(null);
|
|
34
35
|
|
|
35
36
|
const setCollapsibleHandlers = useCallback((handlers) => {
|
|
36
37
|
collapsibleHandlers.current = handlers;
|
|
@@ -164,6 +165,7 @@ export default function withCollapsibleContext<T>(Component: FC<T>) {
|
|
|
164
165
|
|
|
165
166
|
const internalContext = useMemo(
|
|
166
167
|
() => ({
|
|
168
|
+
scrollViewRef,
|
|
167
169
|
containerRef,
|
|
168
170
|
handleStickyViewLayout,
|
|
169
171
|
handleHeaderContainerLayout,
|
package/lib/module/types.d.js
DELETED