@r0b0t3d/react-native-collapsible 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/CollapsibleContainer.js +5 -2
- package/lib/commonjs/components/CollapsibleContainer.js.map +1 -1
- package/lib/commonjs/components/header/CollapsibleHeaderConsumer.js +67 -0
- package/lib/commonjs/components/header/CollapsibleHeaderConsumer.js.map +1 -0
- package/lib/commonjs/components/header/CollapsibleHeaderContainer.js +15 -62
- package/lib/commonjs/components/header/CollapsibleHeaderContainer.js.map +1 -1
- package/lib/commonjs/components/header/CollapsibleHeaderProvider.js +62 -0
- package/lib/commonjs/components/header/CollapsibleHeaderProvider.js.map +1 -0
- package/lib/commonjs/hooks/useCollapsibleHeaderContext.js +26 -0
- package/lib/commonjs/hooks/useCollapsibleHeaderContext.js.map +1 -0
- package/lib/commonjs/withCollapsibleContext.js +6 -15
- package/lib/commonjs/withCollapsibleContext.js.map +1 -1
- package/lib/module/components/CollapsibleContainer.js +4 -2
- package/lib/module/components/CollapsibleContainer.js.map +1 -1
- package/lib/module/components/header/CollapsibleHeaderConsumer.js +47 -0
- package/lib/module/components/header/CollapsibleHeaderConsumer.js.map +1 -0
- package/lib/module/components/header/CollapsibleHeaderContainer.js +15 -54
- package/lib/module/components/header/CollapsibleHeaderContainer.js.map +1 -1
- package/lib/module/components/header/CollapsibleHeaderProvider.js +49 -0
- package/lib/module/components/header/CollapsibleHeaderProvider.js.map +1 -0
- package/lib/module/hooks/useCollapsibleHeaderContext.js +15 -0
- package/lib/module/hooks/useCollapsibleHeaderContext.js.map +1 -0
- package/lib/module/withCollapsibleContext.js +5 -15
- package/lib/module/withCollapsibleContext.js.map +1 -1
- package/lib/typescript/components/header/CollapsibleHeaderConsumer.d.ts +1 -0
- package/lib/typescript/components/header/CollapsibleHeaderContainer.d.ts +2 -2
- package/lib/typescript/components/header/CollapsibleHeaderProvider.d.ts +4 -0
- package/lib/typescript/hooks/useCollapsibleHeaderContext.d.ts +14 -0
- package/lib/typescript/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/CollapsibleContainer.tsx +3 -0
- package/src/components/header/CollapsibleHeaderConsumer.tsx +61 -0
- package/src/components/header/CollapsibleHeaderContainer.tsx +13 -82
- package/src/components/header/CollapsibleHeaderProvider.tsx +70 -0
- package/src/hooks/useCollapsibleHeaderContext.ts +22 -0
- package/src/types.ts +1 -1
- package/src/withCollapsibleContext.tsx +15 -26
|
@@ -15,6 +15,8 @@ var _useInternalCollapsibleContext = _interopRequireDefault(require("../hooks/us
|
|
|
15
15
|
|
|
16
16
|
var _useCollapsibleContext = _interopRequireDefault(require("../hooks/useCollapsibleContext"));
|
|
17
17
|
|
|
18
|
+
var _CollapsibleHeaderConsumer = _interopRequireDefault(require("./header/CollapsibleHeaderConsumer"));
|
|
19
|
+
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
22
|
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); }
|
|
@@ -69,8 +71,9 @@ function CollapsibleContainer({
|
|
|
69
71
|
}, keyboardAvoidingViewProps), /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({}, props, {
|
|
70
72
|
ref: containerRef,
|
|
71
73
|
style: [styles.container, props.style],
|
|
72
|
-
onLayout: handleContainerLayout
|
|
73
|
-
|
|
74
|
+
onLayout: handleContainerLayout,
|
|
75
|
+
collapsable: false
|
|
76
|
+
}), children, /*#__PURE__*/_react.default.createElement(_CollapsibleHeaderConsumer.default, null)));
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
const styles = _reactNative.StyleSheet.create({
|
|
@@ -1 +1 @@
|
|
|
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","value","extraOffset","keyboardVerticalOffset","handleContainerLayout","layout","nativeEvent","styles","container","style","StyleSheet","create","flex","overflow"],"mappings":";;;;;;;AACA;;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,KAAD,EAAgBC,GAAhB,EAA6BC,MAA7B,EAA6CC,MAA7C,KAAgE;AAC9D,cAAIF,GAAG,GAAGE,MAAN,GAAeZ,OAAO,CAACa,KAAvB,GAA+BX,eAAe,CAACI,OAAnD,EAA4D;AAAA;;AAC1D,kBAAMQ,WAAW,4BACfnB,yBADe,aACfA,yBADe,uBACfA,yBAAyB,CAAEoB,sBADZ,yEACsC,EADvD;AAEAd,YAAAA,QAAQ,CAACS,GAAG,GAAGE,MAAN,GAAeE,WAAf,GAA6BZ,eAAe,CAACI,OAA9C,CAAR;AACD;AACF,SATH,EAUE,MAAM,CAAE,CAVV;AAYD;;AACD,aAAOC,SAAP;AACD,KArBD;AAsBD,GAvBD;AAyBA,QAAMS,qBAAqB,GAAG,wBAAaC,MAAD,IAA+B;AACvE,UAAML,MAAM,GAAGK,MAAM,CAACC,WAAP,CAAmBD,MAAnB,CAA0BL,MAAzC;AACAV,IAAAA,eAAe,CAACI,OAAhB,GAA0BM,MAA1B;AACAb,IAAAA,qBAAqB,CAACa,MAAD,CAArB;AACD,GAJ6B,EAI3B,EAJ2B,CAA9B;AAMA,sBACE,6BAAC,iCAAD;AACE,IAAA,KAAK,EAAEO,MAAM,CAACC,SADhB;AAEE,IAAA,QAAQ,EAAC;AAFX,KAGMzB,yBAHN,gBAKE,6BAAC,iBAAD,eACME,KADN;AAEE,IAAA,GAAG,EAAEC,YAFP;AAGE,IAAA,KAAK,EAAE,CAACqB,MAAM,CAACC,SAAR,EAAmBvB,KAAK,CAACwB,KAAzB,CAHT;AAIE,IAAA,QAAQ,EAAEL;
|
|
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","value","extraOffset","keyboardVerticalOffset","handleContainerLayout","layout","nativeEvent","styles","container","style","StyleSheet","create","flex","overflow"],"mappings":";;;;;;;AACA;;AACA;;AAQA;;AACA;;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,QAA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AQ,EAAC;AAFX,KAGMzB,yBAHN,gBAKE,6BAAC,iBAAD,eACME,KADN;AAEE,IAAA,GAAG,EAAEC,YAFP;AAGE,IAAA,KAAK,EAAE,CAACqB,MAAM,CAACC,SAAR,EAAmBvB,KAAK,CAACwB,KAAzB,CAHT;AAIE,IAAA,QAAQ,EAAEL,qBAJZ;AAKE,IAAA,WAAW,EAAE;AALf,MAOGtB,QAPH,eAQE,6BAAC,kCAAD,OARF,CALF,CADF;AAkBD;;AAED,MAAMyB,MAAM,GAAGG,wBAAWC,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AACTI,IAAAA,IAAI,EAAE,CADG;AAETC,IAAAA,QAAQ,EAAE;AAFD;AADoB,CAAlB,CAAf","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport 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';\nimport CollapsibleHeaderConsumer from './header/CollapsibleHeaderConsumer';\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 if (top + height - scrollY.value > containerHeight.current) {\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((layout: LayoutChangeEvent) => {\n const height = layout.nativeEvent.layout.height;\n containerHeight.current = height;\n handleContainerHeight(height);\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 collapsable={false}\n >\n {children}\n <CollapsibleHeaderConsumer />\n </View>\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = CollapsibleHeaderConsumer;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _useInternalCollapsibleContext = _interopRequireDefault(require("../../hooks/useInternalCollapsibleContext"));
|
|
11
|
+
|
|
12
|
+
var _useCollapsibleHeaderContext = _interopRequireDefault(require("../../hooks/useCollapsibleHeaderContext"));
|
|
13
|
+
|
|
14
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
15
|
+
|
|
16
|
+
var _useCollapsibleContext = _interopRequireDefault(require("../../hooks/useCollapsibleContext"));
|
|
17
|
+
|
|
18
|
+
var _reactNative = require("react-native");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
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); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
26
|
+
function CollapsibleHeaderConsumer() {
|
|
27
|
+
const {
|
|
28
|
+
headers
|
|
29
|
+
} = (0, _useCollapsibleHeaderContext.default)();
|
|
30
|
+
const {
|
|
31
|
+
handleHeaderContainerLayout
|
|
32
|
+
} = (0, _useInternalCollapsibleContext.default)();
|
|
33
|
+
const {
|
|
34
|
+
scrollY,
|
|
35
|
+
headerHeight
|
|
36
|
+
} = (0, _useCollapsibleContext.default)();
|
|
37
|
+
const headerTranslate = (0, _reactNativeReanimated.useDerivedValue)(() => (0, _reactNativeReanimated.interpolate)(scrollY.value, // FIXME: can improve by geting maxY value of header and sticky views
|
|
38
|
+
[-250, 0, 100000], [250, 0, -100000], _reactNativeReanimated.default.Extrapolate.CLAMP), []);
|
|
39
|
+
const headerStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
40
|
+
return {
|
|
41
|
+
transform: [{
|
|
42
|
+
translateY: headerTranslate.value
|
|
43
|
+
}]
|
|
44
|
+
};
|
|
45
|
+
}, [headerHeight, headerTranslate]);
|
|
46
|
+
const handleHeaderLayout = (0, _react.useCallback)(({
|
|
47
|
+
nativeEvent: {
|
|
48
|
+
layout: {
|
|
49
|
+
height
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}) => {
|
|
53
|
+
handleHeaderContainerLayout(height);
|
|
54
|
+
}, [handleHeaderContainerLayout]);
|
|
55
|
+
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
56
|
+
onLayout: handleHeaderLayout,
|
|
57
|
+
style: [styles.container, headerStyle],
|
|
58
|
+
pointerEvents: "box-none"
|
|
59
|
+
}, headers.map(item => item.children));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const styles = _reactNative.StyleSheet.create({
|
|
63
|
+
container: {
|
|
64
|
+
backgroundColor: 'white'
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=CollapsibleHeaderConsumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["CollapsibleHeaderConsumer.tsx"],"names":["CollapsibleHeaderConsumer","headers","handleHeaderContainerLayout","scrollY","headerHeight","headerTranslate","value","Animated","Extrapolate","CLAMP","headerStyle","transform","translateY","handleHeaderLayout","nativeEvent","layout","height","styles","container","map","item","children","StyleSheet","create","backgroundColor"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;;;;;AAEe,SAASA,yBAAT,GAAqC;AAClD,QAAM;AAAEC,IAAAA;AAAF,MAAc,2CAApB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAkC,6CAAxC;AACA,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAA4B,qCAAlC;AAEA,QAAMC,eAAe,GAAG,4CACtB,MACE,wCACEF,OAAO,CAACG,KADV,EAEE;AACA,GAAC,CAAC,GAAF,EAAO,CAAP,EAAU,MAAV,CAHF,EAIE,CAAC,GAAD,EAAM,CAAN,EAAS,CAAC,MAAV,CAJF,EAKEC,+BAASC,WAAT,CAAqBC,KALvB,CAFoB,EAStB,EATsB,CAAxB;AAYA,QAAMC,WAAW,GAAG,6CAAiB,MAAM;AACzC,WAAO;AACLC,MAAAA,SAAS,EAAE,CAAC;AAAEC,QAAAA,UAAU,EAAEP,eAAe,CAACC;AAA9B,OAAD;AADN,KAAP;AAGD,GAJmB,EAIjB,CAACF,YAAD,EAAeC,eAAf,CAJiB,CAApB;AAMA,QAAMQ,kBAAkB,GAAG,wBACzB,CAAC;AACCC,IAAAA,WAAW,EAAE;AACXC,MAAAA,MAAM,EAAE;AAAEC,QAAAA;AAAF;AADG;AADd,GAAD,KAIyB;AACvBd,IAAAA,2BAA2B,CAACc,MAAD,CAA3B;AACD,GAPwB,EAQzB,CAACd,2BAAD,CARyB,CAA3B;AAWA,sBACE,6BAAC,8BAAD,CAAU,IAAV;AACE,IAAA,QAAQ,EAAEW,kBADZ;AAEE,IAAA,KAAK,EAAE,CAACI,MAAM,CAACC,SAAR,EAAmBR,WAAnB,CAFT;AAGE,IAAA,aAAa,EAAC;AAHhB,KAKGT,OAAO,CAACkB,GAAR,CAAaC,IAAD,IAAUA,IAAI,CAACC,QAA3B,CALH,CADF;AASD;;AAED,MAAMJ,MAAM,GAAGK,wBAAWC,MAAX,CAAkB;AAC/BL,EAAAA,SAAS,EAAE;AACTM,IAAAA,eAAe,EAAE;AADR;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback } from 'react';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\nimport useCollapsibleHeaderContext from '../../hooks/useCollapsibleHeaderContext';\nimport Animated, {\n interpolate,\n useAnimatedStyle,\n useDerivedValue,\n} from 'react-native-reanimated';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport { LayoutChangeEvent, StyleSheet } from 'react-native';\n\nexport default function CollapsibleHeaderConsumer() {\n const { headers } = useCollapsibleHeaderContext();\n const { handleHeaderContainerLayout } = useInternalCollapsibleContext();\n const { scrollY, headerHeight } = useCollapsibleContext();\n\n const headerTranslate = useDerivedValue(\n () =>\n interpolate(\n scrollY.value,\n // FIXME: can improve by geting maxY value of header and sticky views\n [-250, 0, 100000],\n [250, 0, -100000],\n Animated.Extrapolate.CLAMP\n ),\n []\n );\n\n const headerStyle = useAnimatedStyle(() => {\n return {\n transform: [{ translateY: headerTranslate.value }],\n };\n }, [headerHeight, headerTranslate]);\n\n const handleHeaderLayout = useCallback(\n ({\n nativeEvent: {\n layout: { height },\n },\n }: LayoutChangeEvent) => {\n handleHeaderContainerLayout(height);\n },\n [handleHeaderContainerLayout]\n );\n\n return (\n <Animated.View\n onLayout={handleHeaderLayout}\n style={[styles.container, headerStyle]}\n pointerEvents=\"box-none\"\n >\n {headers.map((item) => item.children)}\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: 'white',\n },\n});\n"]}
|
|
@@ -5,19 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = CollapsibleHeaderContainer;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _reactNative = require("react-native");
|
|
13
|
-
|
|
14
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
15
|
-
|
|
16
|
-
var _useCollapsibleContext = _interopRequireDefault(require("../../hooks/useCollapsibleContext"));
|
|
17
|
-
|
|
18
|
-
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); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
var _useCollapsibleHeaderContext = _interopRequireDefault(require("../../hooks/useCollapsibleHeaderContext"));
|
|
21
11
|
|
|
22
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
13
|
|
|
@@ -25,60 +15,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
15
|
let key = 0;
|
|
26
16
|
|
|
27
17
|
function CollapsibleHeaderContainer({
|
|
28
|
-
children
|
|
29
|
-
containerStyle
|
|
18
|
+
children
|
|
30
19
|
}) {
|
|
31
20
|
const contentKey = (0, _react.useMemo)(() => `collapsible-header-${key++}`, []);
|
|
32
21
|
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} = (0, _useInternalCollapsibleContext.default)();
|
|
38
|
-
const headerHeight = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
22
|
+
mount,
|
|
23
|
+
unmount,
|
|
24
|
+
update
|
|
25
|
+
} = (0, _useCollapsibleHeaderContext.default)();
|
|
39
26
|
(0, _react.useEffect)(() => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
nativeEvent: {
|
|
44
|
-
layout: {
|
|
45
|
-
height
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}) => {
|
|
49
|
-
headerHeight.value = height;
|
|
50
|
-
handleHeaderContainerLayout(contentKey, height);
|
|
51
|
-
}, [contentKey]);
|
|
52
|
-
const headerTranslate = (0, _reactNativeReanimated.useDerivedValue)(() => (0, _reactNativeReanimated.interpolate)(scrollY.value, // FIXME: can improve by geting maxY value of header and sticky views
|
|
53
|
-
[-250, 0, 100000], [250, 0, -100000], _reactNativeReanimated.default.Extrapolate.CLAMP), []);
|
|
54
|
-
const headerStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
55
|
-
return {
|
|
56
|
-
transform: [{
|
|
57
|
-
translateY: headerTranslate.value
|
|
58
|
-
}],
|
|
59
|
-
minHeight: headerHeight.value
|
|
60
|
-
};
|
|
61
|
-
}, [headerHeight, headerTranslate]);
|
|
62
|
-
const internalStyle = (0, _react.useMemo)(() => {
|
|
63
|
-
return {
|
|
64
|
-
zIndex: 100000 - key
|
|
27
|
+
mount(contentKey, children);
|
|
28
|
+
return () => {
|
|
29
|
+
unmount(contentKey);
|
|
65
30
|
};
|
|
66
|
-
}, []);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
key: contentKey,
|
|
72
|
-
onLayout: handleHeaderLayout,
|
|
73
|
-
pointerEvents: "box-none",
|
|
74
|
-
style: [styles.container, containerStyle]
|
|
75
|
-
}, children));
|
|
31
|
+
}, [contentKey]);
|
|
32
|
+
(0, _react.useEffect)(() => {
|
|
33
|
+
update(contentKey, children);
|
|
34
|
+
}, [children]);
|
|
35
|
+
return null;
|
|
76
36
|
}
|
|
77
|
-
|
|
78
|
-
const styles = _reactNative.StyleSheet.create({
|
|
79
|
-
container: {
|
|
80
|
-
backgroundColor: 'white',
|
|
81
|
-
marginTop: _reactNative.Platform.OS === 'android' ? -1 : 0
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
37
|
//# sourceMappingURL=CollapsibleHeaderContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CollapsibleHeaderContainer.tsx"],"names":["key","CollapsibleHeaderContainer","children","
|
|
1
|
+
{"version":3,"sources":["CollapsibleHeaderContainer.tsx"],"names":["key","CollapsibleHeaderContainer","children","contentKey","mount","unmount","update"],"mappings":";;;;;;;AACA;;AAEA;;;;AAHA;AAUA,IAAIA,GAAG,GAAG,CAAV;;AAEe,SAASC,0BAAT,CAAoC;AAAEC,EAAAA;AAAF,CAApC,EAAyD;AACtE,QAAMC,UAAU,GAAG,oBAAQ,MAAO,sBAAqBH,GAAG,EAAG,EAA1C,EAA6C,EAA7C,CAAnB;AACA,QAAM;AAAEI,IAAAA,KAAF;AAASC,IAAAA,OAAT;AAAkBC,IAAAA;AAAlB,MAA6B,2CAAnC;AAEA,wBAAU,MAAM;AACdF,IAAAA,KAAK,CAACD,UAAD,EAAaD,QAAb,CAAL;AAEA,WAAO,MAAM;AACXG,MAAAA,OAAO,CAACF,UAAD,CAAP;AACD,KAFD;AAGD,GAND,EAMG,CAACA,UAAD,CANH;AAQA,wBAAU,MAAM;AACdG,IAAAA,MAAM,CAACH,UAAD,EAAaD,QAAb,CAAN;AACD,GAFD,EAEG,CAACA,QAAD,CAFH;AAIA,SAAO,IAAP;AACD","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport { ReactNode, useEffect, useMemo } from 'react';\nimport type { StyleProp, ViewStyle } from 'react-native';\nimport useCollapsibleHeaderContext from '../../hooks/useCollapsibleHeaderContext';\n\ntype Props = {\n children: ReactNode;\n containerStyle?: StyleProp<ViewStyle>;\n};\n\nlet key = 0;\n\nexport default function CollapsibleHeaderContainer({ children }: Props) {\n const contentKey = useMemo(() => `collapsible-header-${key++}`, []);\n const { mount, unmount, update } = useCollapsibleHeaderContext();\n\n useEffect(() => {\n mount(contentKey, children);\n\n return () => {\n unmount(contentKey);\n };\n }, [contentKey]);\n\n useEffect(() => {\n update(contentKey, children);\n }, [children]);\n\n return null;\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = CollapsibleHeaderProvider;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _useCollapsibleHeaderContext = require("../../hooks/useCollapsibleHeaderContext");
|
|
11
|
+
|
|
12
|
+
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); }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
|
|
16
|
+
/* eslint-disable no-shadow */
|
|
17
|
+
function CollapsibleHeaderProvider({
|
|
18
|
+
children
|
|
19
|
+
}) {
|
|
20
|
+
const [headers, setHeaders] = (0, _react.useState)([]);
|
|
21
|
+
const mounted = (0, _react.useRef)(false);
|
|
22
|
+
(0, _react.useEffect)(() => {
|
|
23
|
+
mounted.current = true;
|
|
24
|
+
return () => {
|
|
25
|
+
mounted.current = false;
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
const mount = (0, _react.useCallback)((key, children) => {
|
|
29
|
+
setHeaders(prev => [...prev, {
|
|
30
|
+
key,
|
|
31
|
+
children
|
|
32
|
+
}]);
|
|
33
|
+
}, []);
|
|
34
|
+
const unmount = (0, _react.useCallback)(key => {
|
|
35
|
+
setHeaders(prev => prev.filter(h => h.key !== key));
|
|
36
|
+
}, []);
|
|
37
|
+
const update = (0, _react.useCallback)((key, children) => {
|
|
38
|
+
if (!mounted.current) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setHeaders(prev => prev.map(item => {
|
|
43
|
+
if (item.key === key) {
|
|
44
|
+
return { ...item,
|
|
45
|
+
children
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return item;
|
|
50
|
+
}));
|
|
51
|
+
}, []);
|
|
52
|
+
const context = (0, _react.useMemo)(() => ({
|
|
53
|
+
headers,
|
|
54
|
+
mount,
|
|
55
|
+
unmount,
|
|
56
|
+
update
|
|
57
|
+
}), [headers, mount, unmount, update]);
|
|
58
|
+
return /*#__PURE__*/_react.default.createElement(_useCollapsibleHeaderContext.CollapsibleHeaderContext.Provider, {
|
|
59
|
+
value: context
|
|
60
|
+
}, children);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=CollapsibleHeaderProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["CollapsibleHeaderProvider.tsx"],"names":["CollapsibleHeaderProvider","children","headers","setHeaders","mounted","current","mount","key","prev","unmount","filter","h","update","map","item","context"],"mappings":";;;;;;;AACA;;AAQA;;;;;;AATA;AAce,SAASA,yBAAT,CAAmC;AAChDC,EAAAA;AADgD,CAAnC,EAIZ;AACD,QAAM,CAACC,OAAD,EAAUC,UAAV,IAAwB,qBAAuB,EAAvB,CAA9B;AACA,QAAMC,OAAO,GAAG,mBAAO,KAAP,CAAhB;AAEA,wBAAU,MAAM;AACdA,IAAAA,OAAO,CAACC,OAAR,GAAkB,IAAlB;AACA,WAAO,MAAM;AACXD,MAAAA,OAAO,CAACC,OAAR,GAAkB,KAAlB;AACD,KAFD;AAGD,GALD,EAKG,EALH;AAOA,QAAMC,KAAK,GAAG,wBAAY,CAACC,GAAD,EAAcN,QAAd,KAAsC;AAC9DE,IAAAA,UAAU,CAAEK,IAAD,IAAU,CAAC,GAAGA,IAAJ,EAAU;AAAED,MAAAA,GAAF;AAAON,MAAAA;AAAP,KAAV,CAAX,CAAV;AACD,GAFa,EAEX,EAFW,CAAd;AAIA,QAAMQ,OAAO,GAAG,wBAAaF,GAAD,IAAiB;AAC3CJ,IAAAA,UAAU,CAAEK,IAAD,IAAUA,IAAI,CAACE,MAAL,CAAaC,CAAD,IAAOA,CAAC,CAACJ,GAAF,KAAUA,GAA7B,CAAX,CAAV;AACD,GAFe,EAEb,EAFa,CAAhB;AAIA,QAAMK,MAAM,GAAG,wBAAY,CAACL,GAAD,EAAcN,QAAd,KAAsC;AAC/D,QAAI,CAACG,OAAO,CAACC,OAAb,EAAsB;AACpB;AACD;;AACDF,IAAAA,UAAU,CAAEK,IAAD,IACTA,IAAI,CAACK,GAAL,CAAUC,IAAD,IAAU;AACjB,UAAIA,IAAI,CAACP,GAAL,KAAaA,GAAjB,EAAsB;AACpB,eAAO,EACL,GAAGO,IADE;AAELb,UAAAA;AAFK,SAAP;AAID;;AACD,aAAOa,IAAP;AACD,KARD,CADQ,CAAV;AAWD,GAfc,EAeZ,EAfY,CAAf;AAiBA,QAAMC,OAAO,GAAG,oBACd,OAAO;AACLb,IAAAA,OADK;AAELI,IAAAA,KAFK;AAGLG,IAAAA,OAHK;AAILG,IAAAA;AAJK,GAAP,CADc,EAOd,CAACV,OAAD,EAAUI,KAAV,EAAiBG,OAAjB,EAA0BG,MAA1B,CAPc,CAAhB;AAUA,sBACE,6BAAC,qDAAD,CAA0B,QAA1B;AAAmC,IAAA,KAAK,EAAEG;AAA1C,KACGd,QADH,CADF;AAKD","sourcesContent":["/* eslint-disable no-shadow */\nimport React, {\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n CollapsibleHeaderContext,\n HeaderItem,\n} from '../../hooks/useCollapsibleHeaderContext';\n\nexport default function CollapsibleHeaderProvider({\n children,\n}: {\n children: ReactNode;\n}) {\n const [headers, setHeaders] = useState<HeaderItem[]>([]);\n const mounted = useRef(false);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const mount = useCallback((key: string, children: ReactNode) => {\n setHeaders((prev) => [...prev, { key, children }]);\n }, []);\n\n const unmount = useCallback((key: string) => {\n setHeaders((prev) => prev.filter((h) => h.key !== key));\n }, []);\n\n const update = useCallback((key: string, children: ReactNode) => {\n if (!mounted.current) {\n return;\n }\n setHeaders((prev) =>\n prev.map((item) => {\n if (item.key === key) {\n return {\n ...item,\n children,\n };\n }\n return item;\n })\n );\n }, []);\n\n const context = useMemo(\n () => ({\n headers,\n mount,\n unmount,\n update,\n }),\n [headers, mount, unmount, update]\n );\n\n return (\n <CollapsibleHeaderContext.Provider value={context}>\n {children}\n </CollapsibleHeaderContext.Provider>\n );\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useCollapsibleHeaderContext;
|
|
7
|
+
exports.CollapsibleHeaderContext = void 0;
|
|
8
|
+
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
|
|
11
|
+
const CollapsibleHeaderContext =
|
|
12
|
+
/*#__PURE__*/
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
(0, _react.createContext)({});
|
|
15
|
+
exports.CollapsibleHeaderContext = CollapsibleHeaderContext;
|
|
16
|
+
|
|
17
|
+
function useCollapsibleHeaderContext() {
|
|
18
|
+
const ctx = (0, _react.useContext)(CollapsibleHeaderContext);
|
|
19
|
+
|
|
20
|
+
if (!ctx) {
|
|
21
|
+
throw new Error('Component should be wrapped CollapsibleHeaderProvider');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return ctx;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=useCollapsibleHeaderContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useCollapsibleHeaderContext.ts"],"names":["CollapsibleHeaderContext","useCollapsibleHeaderContext","ctx","Error"],"mappings":";;;;;;;;AAAA;;AAWO,MAAMA,wBAAwB;AAAA;AACnC;AACA,0BAA4C,EAA5C,CAFK;;;AAIQ,SAASC,2BAAT,GAAuC;AACpD,QAAMC,GAAG,GAAG,uBAAWF,wBAAX,CAAZ;;AACA,MAAI,CAACE,GAAL,EAAU;AACR,UAAM,IAAIC,KAAJ,CAAU,uDAAV,CAAN;AACD;;AACD,SAAOD,GAAP;AACD","sourcesContent":["import { createContext, ReactNode, useContext } from 'react';\n\nexport type HeaderItem = { key: string; children: ReactNode };\n\ntype CollapsibleContextHeaderType = {\n headers: HeaderItem[];\n mount: (key: string, header: ReactNode) => void;\n update: (key: string, header: ReactNode) => void;\n unmount: (key: string) => void;\n};\n\nexport const CollapsibleHeaderContext =\n // @ts-ignore\n createContext<CollapsibleContextHeaderType>({});\n\nexport default function useCollapsibleHeaderContext() {\n const ctx = useContext(CollapsibleHeaderContext);\n if (!ctx) {\n throw new Error('Component should be wrapped CollapsibleHeaderProvider');\n }\n return ctx;\n}\n"]}
|
|
@@ -17,6 +17,8 @@ var _debounce = require("./utils/debounce");
|
|
|
17
17
|
|
|
18
18
|
var _PullToRefreshProvider = _interopRequireDefault(require("./components/pullToRefresh/PullToRefreshProvider"));
|
|
19
19
|
|
|
20
|
+
var _CollapsibleHeaderProvider = _interopRequireDefault(require("./components/header/CollapsibleHeaderProvider"));
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
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); }
|
|
@@ -39,13 +41,9 @@ function withCollapsibleContext(Component) {
|
|
|
39
41
|
const stickyHeaderHeight = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
40
42
|
const containerHeight = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
41
43
|
const firstStickyViewY = (0, _reactNativeReanimated.useSharedValue)(1000000);
|
|
42
|
-
const headerContainersHeight = (0, _react.useRef)({});
|
|
43
44
|
const containerRef = (0, _react.useRef)(null);
|
|
44
45
|
const scrollViewRef = (0, _react.useRef)(null);
|
|
45
46
|
const setCollapsibleHandlers = (0, _react.useCallback)(handlers => {
|
|
46
|
-
console.log({
|
|
47
|
-
handlers
|
|
48
|
-
});
|
|
49
47
|
collapsibleHandlers.current = handlers;
|
|
50
48
|
}, []);
|
|
51
49
|
const headerCollapsed = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
@@ -124,18 +122,11 @@ function withCollapsibleContext(Component) {
|
|
|
124
122
|
});
|
|
125
123
|
}, 200);
|
|
126
124
|
}, []);
|
|
127
|
-
const handleHeaderContainerLayout = (0, _react.useCallback)(
|
|
128
|
-
|
|
129
|
-
delete headerContainersHeight.current[viewKey];
|
|
130
|
-
} else {
|
|
131
|
-
headerContainersHeight.current[viewKey] = height;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const totalHeight = Object.keys(headerContainersHeight.current).reduce((acc, key) => headerContainersHeight.current[key] + acc, 0);
|
|
135
|
-
headerHeight.value = (0, _reactNativeReanimated.withTiming)(totalHeight, {
|
|
125
|
+
const handleHeaderContainerLayout = (0, _react.useCallback)(height => {
|
|
126
|
+
headerHeight.value = (0, _reactNativeReanimated.withTiming)(height, {
|
|
136
127
|
duration: fixedHeaderHeight.value === 0 ? 0 : 10
|
|
137
128
|
});
|
|
138
|
-
fixedHeaderHeight.value =
|
|
129
|
+
fixedHeaderHeight.value = height; // Try refresh sticky positions
|
|
139
130
|
|
|
140
131
|
debounceRefreshStickyPositions();
|
|
141
132
|
}, []);
|
|
@@ -186,7 +177,7 @@ function withCollapsibleContext(Component) {
|
|
|
186
177
|
value: context
|
|
187
178
|
}, /*#__PURE__*/_react.default.createElement(_useInternalCollapsibleContext.InternalCollapsibleContext.Provider, {
|
|
188
179
|
value: internalContext
|
|
189
|
-
}, /*#__PURE__*/_react.default.createElement(_PullToRefreshProvider.default, null, /*#__PURE__*/_react.default.createElement(Component, props))));
|
|
180
|
+
}, /*#__PURE__*/_react.default.createElement(_CollapsibleHeaderProvider.default, null, /*#__PURE__*/_react.default.createElement(_PullToRefreshProvider.default, null, /*#__PURE__*/_react.default.createElement(Component, props)))));
|
|
190
181
|
};
|
|
191
182
|
}
|
|
192
183
|
//# sourceMappingURL=withCollapsibleContext.js.map
|
|
@@ -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","scrollViewRef","setCollapsibleHandlers","handlers","console","log","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","animated","expand","scrollTo","offset","animate","scrollToIndex","params","internalContext"],"mappings":";;;;;;;AAEA;;AAEA;;AACA;;AACA;;AAOA;;AACA;;;;;;;;AAdA;;AACA;AAee,SAASA,sBAAT,CAAmCC,SAAnC,EAAqD;AAClE,SAAQC,KAAD,IAAc;AACnB,UAAMC,mBAAmB,GAAG,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,iBARF,EASEe,gBATF,CAdsB,CAAxB;AA2BA,wBACE,6BAAC,yCAAD,CAAoB,QAApB;AAA6B,MAAA,KAAK,EAAEmC;AAApC,oBACE,6BAAC,yDAAD,CAA4B,QAA5B;AAAqC,MAAA,KAAK,EAAES;AAA5C,oBACE,6BAAC,8BAAD,qBACE,6BAAC,SAAD,EAAenE,KAAf,CADF,CADF,CADF,CADF;AASD,GA7LD;AA8LD","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 console.log({ handlers });\n\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 : 10,\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: (animated?: boolean) =>\n collapsibleHandlers.current?.collapse(animated),\n expand: () => collapsibleHandlers.current?.expand(),\n scrollTo: (offset: number, animate?: boolean) =>\n collapsibleHandlers.current?.scrollTo(offset, animate),\n scrollToIndex: (params: any) =>\n collapsibleHandlers.current?.scrollToIndex(params),\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
|
+
{"version":3,"sources":["withCollapsibleContext.tsx"],"names":["withCollapsibleContext","Component","props","collapsibleHandlers","headerHeight","scrollY","stickyViewRefs","stickyViewTops","stickyViewPositionsRef","stickyViewPositions","fixedHeaderHeight","stickyHeaderHeight","containerHeight","firstStickyViewY","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","animated","expand","scrollTo","offset","animate","scrollToIndex","params","internalContext"],"mappings":";;;;;;;AAEA;;AAEA;;AACA;;AACA;;AAOA;;AACA;;AACA;;;;;;;;AAfA;;AACA;AAgBe,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,YAAY,GAAG,mBAAa,IAAb,CAArB;AACA,UAAMC,aAAa,GAAG,mBAAa,IAAb,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VK;AAWLY,MAAAA;AAXK,KAAP,CADsB,EActB,CACEN,sBADF,EAEE8B,sBAFF,EAGEQ,2BAHF,EAIEE,qBAJF,EAKE3C,gBALF,EAMEN,cANF,EAOEE,mBAPF,EAQEC,iBARF,EASEY,gBATF,CAdsB,CAAxB;AA2BA,wBACE,6BAAC,yCAAD,CAAoB,QAApB;AAA6B,MAAA,KAAK,EAAEmC;AAApC,oBACE,6BAAC,yDAAD,CAA4B,QAA5B;AAAqC,MAAA,KAAK,EAAES;AAA5C,oBACE,6BAAC,kCAAD,qBACE,6BAAC,8BAAD,qBAEE,6BAAC,SAAD,EAAehE,KAAf,CAFF,CADF,CADF,CADF,CADF;AAYD,GAjLD;AAkLD","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';\nimport CollapsibleHeaderProvider from './components/header/CollapsibleHeaderProvider';\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 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((height: number) => {\n headerHeight.value = withTiming(height, {\n duration: fixedHeaderHeight.value === 0 ? 0 : 10,\n });\n fixedHeaderHeight.value = height;\n // Try refresh sticky positions\n debounceRefreshStickyPositions();\n }, []);\n\n const handleContainerHeight = useCallback((height: number) => {\n containerHeight.value = height;\n }, []);\n\n const context = useMemo(() => {\n return {\n collapse: (animated?: boolean) =>\n collapsibleHandlers.current?.collapse(animated),\n expand: () => collapsibleHandlers.current?.expand(),\n scrollTo: (offset: number, animate?: boolean) =>\n collapsibleHandlers.current?.scrollTo(offset, animate),\n scrollToIndex: (params: any) =>\n collapsibleHandlers.current?.scrollToIndex(params),\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 <CollapsibleHeaderProvider>\n <PullToRefreshProvider>\n {/** @ts-ignore */}\n <Component {...props} />\n </PullToRefreshProvider>\n </CollapsibleHeaderProvider>\n </InternalCollapsibleContext.Provider>\n </CollapsibleContext.Provider>\n );\n };\n}\n"]}
|
|
@@ -6,6 +6,7 @@ import { KeyboardAvoidingView, StyleSheet, View } from 'react-native';
|
|
|
6
6
|
import useKeyboardShowEvent from '../hooks/useKeyboardShowEvent';
|
|
7
7
|
import useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';
|
|
8
8
|
import useCollapsibleContext from '../hooks/useCollapsibleContext';
|
|
9
|
+
import CollapsibleHeaderConsumer from './header/CollapsibleHeaderConsumer';
|
|
9
10
|
export default function CollapsibleContainer({
|
|
10
11
|
children,
|
|
11
12
|
keyboardAvoidingViewProps,
|
|
@@ -52,8 +53,9 @@ export default function CollapsibleContainer({
|
|
|
52
53
|
}, keyboardAvoidingViewProps), /*#__PURE__*/React.createElement(View, _extends({}, props, {
|
|
53
54
|
ref: containerRef,
|
|
54
55
|
style: [styles.container, props.style],
|
|
55
|
-
onLayout: handleContainerLayout
|
|
56
|
-
|
|
56
|
+
onLayout: handleContainerLayout,
|
|
57
|
+
collapsable: false
|
|
58
|
+
}), children, /*#__PURE__*/React.createElement(CollapsibleHeaderConsumer, null)));
|
|
57
59
|
}
|
|
58
60
|
const styles = StyleSheet.create({
|
|
59
61
|
container: {
|
|
@@ -1 +1 @@
|
|
|
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","value","extraOffset","keyboardVerticalOffset","handleContainerLayout","layout","nativeEvent","styles","container","style","create","flex","overflow"],"mappings":";;AAAA;AACA,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,
|
|
1
|
+
{"version":3,"sources":["CollapsibleContainer.tsx"],"names":["React","useCallback","useRef","KeyboardAvoidingView","StyleSheet","View","useKeyboardShowEvent","useInternalCollapsibleContext","useCollapsibleContext","CollapsibleHeaderConsumer","CollapsibleContainer","children","keyboardAvoidingViewProps","textInputRefs","props","containerRef","handleContainerHeight","scrollY","scrollTo","containerHeight","some","ref","isFocusedFunc","current","isFocused","measureLayout","_left","top","_width","height","value","extraOffset","keyboardVerticalOffset","handleContainerLayout","layout","nativeEvent","styles","container","style","create","flex","overflow"],"mappings":";;AAAA;AACA,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;AACA,OAAOC,yBAAP,MAAsC,oCAAtC;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,MACJT,6BAA6B,EAD/B;AAEA,QAAM;AAAEU,IAAAA,OAAF;AAAWC,IAAAA;AAA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AAQ,EAAC;AAFX,KAGMzB,yBAHN,gBAKE,oBAAC,IAAD,eACME,KADN;AAEE,IAAA,GAAG,EAAEC,YAFP;AAGE,IAAA,KAAK,EAAE,CAACqB,MAAM,CAACC,SAAR,EAAmBvB,KAAK,CAACwB,KAAzB,CAHT;AAIE,IAAA,QAAQ,EAAEL,qBAJZ;AAKE,IAAA,WAAW,EAAE;AALf,MAOGtB,QAPH,eAQE,oBAAC,yBAAD,OARF,CALF,CADF;AAkBD;AAED,MAAMyB,MAAM,GAAGhC,UAAU,CAACmC,MAAX,CAAkB;AAC/BF,EAAAA,SAAS,EAAE;AACTG,IAAAA,IAAI,EAAE,CADG;AAETC,IAAAA,QAAQ,EAAE;AAFD;AADoB,CAAlB,CAAf","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport 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';\nimport CollapsibleHeaderConsumer from './header/CollapsibleHeaderConsumer';\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 if (top + height - scrollY.value > containerHeight.current) {\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((layout: LayoutChangeEvent) => {\n const height = layout.nativeEvent.layout.height;\n containerHeight.current = height;\n handleContainerHeight(height);\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 collapsable={false}\n >\n {children}\n <CollapsibleHeaderConsumer />\n </View>\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
|
|
3
|
+
import useCollapsibleHeaderContext from '../../hooks/useCollapsibleHeaderContext';
|
|
4
|
+
import Animated, { interpolate, useAnimatedStyle, useDerivedValue } from 'react-native-reanimated';
|
|
5
|
+
import useCollapsibleContext from '../../hooks/useCollapsibleContext';
|
|
6
|
+
import { StyleSheet } from 'react-native';
|
|
7
|
+
export default function CollapsibleHeaderConsumer() {
|
|
8
|
+
const {
|
|
9
|
+
headers
|
|
10
|
+
} = useCollapsibleHeaderContext();
|
|
11
|
+
const {
|
|
12
|
+
handleHeaderContainerLayout
|
|
13
|
+
} = useInternalCollapsibleContext();
|
|
14
|
+
const {
|
|
15
|
+
scrollY,
|
|
16
|
+
headerHeight
|
|
17
|
+
} = useCollapsibleContext();
|
|
18
|
+
const headerTranslate = useDerivedValue(() => interpolate(scrollY.value, // FIXME: can improve by geting maxY value of header and sticky views
|
|
19
|
+
[-250, 0, 100000], [250, 0, -100000], Animated.Extrapolate.CLAMP), []);
|
|
20
|
+
const headerStyle = useAnimatedStyle(() => {
|
|
21
|
+
return {
|
|
22
|
+
transform: [{
|
|
23
|
+
translateY: headerTranslate.value
|
|
24
|
+
}]
|
|
25
|
+
};
|
|
26
|
+
}, [headerHeight, headerTranslate]);
|
|
27
|
+
const handleHeaderLayout = useCallback(({
|
|
28
|
+
nativeEvent: {
|
|
29
|
+
layout: {
|
|
30
|
+
height
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}) => {
|
|
34
|
+
handleHeaderContainerLayout(height);
|
|
35
|
+
}, [handleHeaderContainerLayout]);
|
|
36
|
+
return /*#__PURE__*/React.createElement(Animated.View, {
|
|
37
|
+
onLayout: handleHeaderLayout,
|
|
38
|
+
style: [styles.container, headerStyle],
|
|
39
|
+
pointerEvents: "box-none"
|
|
40
|
+
}, headers.map(item => item.children));
|
|
41
|
+
}
|
|
42
|
+
const styles = StyleSheet.create({
|
|
43
|
+
container: {
|
|
44
|
+
backgroundColor: 'white'
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=CollapsibleHeaderConsumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["CollapsibleHeaderConsumer.tsx"],"names":["React","useCallback","useInternalCollapsibleContext","useCollapsibleHeaderContext","Animated","interpolate","useAnimatedStyle","useDerivedValue","useCollapsibleContext","StyleSheet","CollapsibleHeaderConsumer","headers","handleHeaderContainerLayout","scrollY","headerHeight","headerTranslate","value","Extrapolate","CLAMP","headerStyle","transform","translateY","handleHeaderLayout","nativeEvent","layout","height","styles","container","map","item","children","create","backgroundColor"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,OAAOC,6BAAP,MAA0C,2CAA1C;AACA,OAAOC,2BAAP,MAAwC,yCAAxC;AACA,OAAOC,QAAP,IACEC,WADF,EAEEC,gBAFF,EAGEC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AACC,QAA3B,CALH,CADF;AASD;AAED,MAAMJ,MAAM,GAAGjB,UAAU,CAACsB,MAAX,CAAkB;AAC/BJ,EAAAA,SAAS,EAAE;AACTK,IAAAA,eAAe,EAAE;AADR;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback } from 'react';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\nimport useCollapsibleHeaderContext from '../../hooks/useCollapsibleHeaderContext';\nimport Animated, {\n interpolate,\n useAnimatedStyle,\n useDerivedValue,\n} from 'react-native-reanimated';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport { LayoutChangeEvent, StyleSheet } from 'react-native';\n\nexport default function CollapsibleHeaderConsumer() {\n const { headers } = useCollapsibleHeaderContext();\n const { handleHeaderContainerLayout } = useInternalCollapsibleContext();\n const { scrollY, headerHeight } = useCollapsibleContext();\n\n const headerTranslate = useDerivedValue(\n () =>\n interpolate(\n scrollY.value,\n // FIXME: can improve by geting maxY value of header and sticky views\n [-250, 0, 100000],\n [250, 0, -100000],\n Animated.Extrapolate.CLAMP\n ),\n []\n );\n\n const headerStyle = useAnimatedStyle(() => {\n return {\n transform: [{ translateY: headerTranslate.value }],\n };\n }, [headerHeight, headerTranslate]);\n\n const handleHeaderLayout = useCallback(\n ({\n nativeEvent: {\n layout: { height },\n },\n }: LayoutChangeEvent) => {\n handleHeaderContainerLayout(height);\n },\n [handleHeaderContainerLayout]\n );\n\n return (\n <Animated.View\n onLayout={handleHeaderLayout}\n style={[styles.container, headerStyle]}\n pointerEvents=\"box-none\"\n >\n {headers.map((item) => item.children)}\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: 'white',\n },\n});\n"]}
|