@r0b0t3d/react-native-collapsible 1.0.1 → 1.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/lib/commonjs/components/CollapsibleContainer.js +4 -2
  2. package/lib/commonjs/components/CollapsibleContainer.js.map +1 -1
  3. package/lib/commonjs/components/CollapsibleView.js +4 -3
  4. package/lib/commonjs/components/CollapsibleView.js.map +1 -1
  5. package/lib/commonjs/components/{AnimatedTopView.js → header/AnimatedTopView.js} +0 -0
  6. package/lib/commonjs/components/{AnimatedTopView.js.map → header/AnimatedTopView.js.map} +0 -0
  7. package/lib/commonjs/components/{CollapsibleHeaderContainer.js → header/CollapsibleHeaderContainer.js} +9 -8
  8. package/lib/commonjs/components/header/CollapsibleHeaderContainer.js.map +1 -0
  9. package/lib/commonjs/components/{StickyView.js → header/StickyView.js} +18 -31
  10. package/lib/commonjs/components/header/StickyView.js.map +1 -0
  11. package/lib/commonjs/components/pullToRefresh/PullToRefreshContainer.js +75 -0
  12. package/lib/commonjs/components/pullToRefresh/PullToRefreshContainer.js.map +1 -0
  13. package/lib/commonjs/components/pullToRefresh/PullToRefreshProvider.js +35 -0
  14. package/lib/commonjs/components/pullToRefresh/PullToRefreshProvider.js.map +1 -0
  15. package/lib/commonjs/components/pullToRefresh/RefreshControl.js +73 -0
  16. package/lib/commonjs/components/pullToRefresh/RefreshControl.js.map +1 -0
  17. package/lib/commonjs/components/pullToRefresh/usePullToRefreshContext.js +24 -0
  18. package/lib/commonjs/components/pullToRefresh/usePullToRefreshContext.js.map +1 -0
  19. package/lib/commonjs/components/pullToRefresh/utils.js +59 -0
  20. package/lib/commonjs/components/pullToRefresh/utils.js.map +1 -0
  21. package/lib/commonjs/components/{CollapsibleFlatList.js → scrollable/CollapsibleFlatList.js} +36 -31
  22. package/lib/commonjs/components/scrollable/CollapsibleFlatList.js.map +1 -0
  23. package/lib/commonjs/components/{CollapsibleScrollView.js → scrollable/CollapsibleScrollView.js} +6 -6
  24. package/lib/commonjs/components/scrollable/CollapsibleScrollView.js.map +1 -0
  25. package/lib/commonjs/{hooks → components/scrollable}/useAnimatedScroll.js +7 -7
  26. package/lib/commonjs/components/scrollable/useAnimatedScroll.js.map +1 -0
  27. package/lib/commonjs/hooks/useInternalCollapsibleContext.js +1 -1
  28. package/lib/commonjs/hooks/useInternalCollapsibleContext.js.map +1 -1
  29. package/lib/commonjs/index.js +21 -12
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/{types.js → types.d.js} +1 -1
  32. package/lib/commonjs/{types.js.map → types.d.js.map} +0 -0
  33. package/lib/commonjs/utils/debounce.js +20 -0
  34. package/lib/commonjs/utils/debounce.js.map +1 -0
  35. package/lib/commonjs/{hooks/withCollapsibleContext.js → withCollapsibleContext.js} +95 -64
  36. package/lib/commonjs/withCollapsibleContext.js.map +1 -0
  37. package/lib/module/components/CollapsibleContainer.js +1 -1
  38. package/lib/module/components/CollapsibleContainer.js.map +1 -1
  39. package/lib/module/components/CollapsibleView.js +4 -3
  40. package/lib/module/components/CollapsibleView.js.map +1 -1
  41. package/lib/module/components/{AnimatedTopView.js → header/AnimatedTopView.js} +0 -0
  42. package/lib/module/components/{AnimatedTopView.js.map → header/AnimatedTopView.js.map} +0 -0
  43. package/lib/module/components/{CollapsibleHeaderContainer.js → header/CollapsibleHeaderContainer.js} +7 -6
  44. package/lib/module/components/header/CollapsibleHeaderContainer.js.map +1 -0
  45. package/lib/module/components/{StickyView.js → header/StickyView.js} +17 -30
  46. package/lib/module/components/header/StickyView.js.map +1 -0
  47. package/lib/module/components/pullToRefresh/PullToRefreshContainer.js +56 -0
  48. package/lib/module/components/pullToRefresh/PullToRefreshContainer.js.map +1 -0
  49. package/lib/module/components/pullToRefresh/PullToRefreshProvider.js +21 -0
  50. package/lib/module/components/pullToRefresh/PullToRefreshProvider.js.map +1 -0
  51. package/lib/module/components/pullToRefresh/RefreshControl.js +55 -0
  52. package/lib/module/components/pullToRefresh/RefreshControl.js.map +1 -0
  53. package/lib/module/components/pullToRefresh/usePullToRefreshContext.js +13 -0
  54. package/lib/module/components/pullToRefresh/usePullToRefreshContext.js.map +1 -0
  55. package/lib/module/components/pullToRefresh/utils.js +42 -0
  56. package/lib/module/components/pullToRefresh/utils.js.map +1 -0
  57. package/lib/module/components/{CollapsibleFlatList.js → scrollable/CollapsibleFlatList.js} +36 -32
  58. package/lib/module/components/scrollable/CollapsibleFlatList.js.map +1 -0
  59. package/lib/module/components/{CollapsibleScrollView.js → scrollable/CollapsibleScrollView.js} +5 -5
  60. package/lib/module/components/scrollable/CollapsibleScrollView.js.map +1 -0
  61. package/lib/module/{hooks → components/scrollable}/useAnimatedScroll.js +6 -6
  62. package/lib/module/components/scrollable/useAnimatedScroll.js.map +1 -0
  63. package/lib/module/hooks/useInternalCollapsibleContext.js +1 -1
  64. package/lib/module/hooks/useInternalCollapsibleContext.js.map +1 -1
  65. package/lib/module/index.js +6 -5
  66. package/lib/module/index.js.map +1 -1
  67. package/lib/module/types.d.js +2 -0
  68. package/lib/module/{types.js.map → types.d.js.map} +0 -0
  69. package/lib/module/utils/debounce.js +13 -0
  70. package/lib/module/utils/debounce.js.map +1 -0
  71. package/lib/module/withCollapsibleContext.js +163 -0
  72. package/lib/module/withCollapsibleContext.js.map +1 -0
  73. package/lib/typescript/components/CollapsibleView.d.ts +1 -1
  74. package/lib/typescript/components/{AnimatedTopView.d.ts → header/AnimatedTopView.d.ts} +0 -0
  75. package/lib/typescript/components/{CollapsibleHeaderContainer.d.ts → header/CollapsibleHeaderContainer.d.ts} +0 -0
  76. package/lib/typescript/components/{StickyView.d.ts → header/StickyView.d.ts} +0 -0
  77. package/lib/typescript/components/pullToRefresh/PullToRefreshContainer.d.ts +8 -0
  78. package/lib/typescript/components/pullToRefresh/PullToRefreshProvider.d.ts +6 -0
  79. package/lib/typescript/components/pullToRefresh/RefreshControl.d.ts +9 -0
  80. package/lib/typescript/components/pullToRefresh/usePullToRefreshContext.d.ts +4 -0
  81. package/lib/typescript/components/pullToRefresh/utils.d.ts +20 -0
  82. package/lib/typescript/components/{CollapsibleFlatList.d.ts → scrollable/CollapsibleFlatList.d.ts} +1 -1
  83. package/lib/typescript/components/{CollapsibleScrollView.d.ts → scrollable/CollapsibleScrollView.d.ts} +1 -1
  84. package/lib/typescript/{hooks → components/scrollable}/useAnimatedScroll.d.ts +0 -0
  85. package/lib/typescript/hooks/useInternalCollapsibleContext.d.ts +1 -1
  86. package/lib/typescript/index.d.ts +6 -5
  87. package/lib/typescript/utils/debounce.d.ts +1 -0
  88. package/lib/typescript/{hooks/withCollapsibleContext.d.ts → withCollapsibleContext.d.ts} +0 -0
  89. package/package.json +4 -2
  90. package/src/components/CollapsibleContainer.tsx +1 -1
  91. package/src/components/CollapsibleView.tsx +4 -3
  92. package/src/components/{AnimatedTopView.tsx → header/AnimatedTopView.tsx} +0 -0
  93. package/src/components/{CollapsibleHeaderContainer.tsx → header/CollapsibleHeaderContainer.tsx} +6 -4
  94. package/src/components/{StickyView.tsx → header/StickyView.tsx} +15 -22
  95. package/src/components/pullToRefresh/PullToRefreshContainer.tsx +65 -0
  96. package/src/components/pullToRefresh/PullToRefreshProvider.tsx +27 -0
  97. package/src/components/pullToRefresh/RefreshControl.tsx +80 -0
  98. package/src/components/pullToRefresh/usePullToRefreshContext.ts +13 -0
  99. package/src/components/pullToRefresh/utils.ts +49 -0
  100. package/src/components/scrollable/CollapsibleFlatList.tsx +135 -0
  101. package/src/components/{CollapsibleScrollView.tsx → scrollable/CollapsibleScrollView.tsx} +6 -6
  102. package/src/{hooks → components/scrollable}/useAnimatedScroll.ts +8 -8
  103. package/src/hooks/useInternalCollapsibleContext.ts +1 -1
  104. package/src/index.tsx +6 -5
  105. package/src/{types.ts → types.d.ts} +14 -3
  106. package/src/utils/debounce.ts +10 -0
  107. package/src/withCollapsibleContext.tsx +201 -0
  108. package/lib/commonjs/components/CollapsibleFlatList.js.map +0 -1
  109. package/lib/commonjs/components/CollapsibleHeaderContainer.js.map +0 -1
  110. package/lib/commonjs/components/CollapsibleScrollView.js.map +0 -1
  111. package/lib/commonjs/components/StickyView.js.map +0 -1
  112. package/lib/commonjs/hooks/useAnimatedScroll.js.map +0 -1
  113. package/lib/commonjs/hooks/withCollapsibleContext.js.map +0 -1
  114. package/lib/module/components/CollapsibleFlatList.js.map +0 -1
  115. package/lib/module/components/CollapsibleHeaderContainer.js.map +0 -1
  116. package/lib/module/components/CollapsibleScrollView.js.map +0 -1
  117. package/lib/module/components/StickyView.js.map +0 -1
  118. package/lib/module/hooks/useAnimatedScroll.js.map +0 -1
  119. package/lib/module/hooks/withCollapsibleContext.js +0 -136
  120. package/lib/module/hooks/withCollapsibleContext.js.map +0 -1
  121. package/lib/module/types.js +0 -2
  122. package/lib/typescript/types.d.ts +0 -33
  123. package/src/components/CollapsibleFlatList.tsx +0 -119
  124. package/src/hooks/withCollapsibleContext.tsx +0 -164
@@ -11,13 +11,15 @@ var _reactNative = require("react-native");
11
11
 
12
12
  var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
13
13
 
14
- var _AnimatedTopView = _interopRequireDefault(require("./AnimatedTopView"));
14
+ var _AnimatedTopView = _interopRequireDefault(require("../header/AnimatedTopView"));
15
15
 
16
- var _useAnimatedScroll = _interopRequireDefault(require("../hooks/useAnimatedScroll"));
16
+ var _useAnimatedScroll = _interopRequireDefault(require("./useAnimatedScroll"));
17
17
 
18
- var _useCollapsibleContext = _interopRequireDefault(require("../hooks/useCollapsibleContext"));
18
+ var _useCollapsibleContext = _interopRequireDefault(require("../../hooks/useCollapsibleContext"));
19
19
 
20
- var _useInternalCollapsibleContext = require("../hooks/useInternalCollapsibleContext");
20
+ var _useInternalCollapsibleContext = _interopRequireDefault(require("../../hooks/useInternalCollapsibleContext"));
21
+
22
+ var _PullToRefreshContainer = _interopRequireDefault(require("../pullToRefresh/PullToRefreshContainer"));
21
23
 
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
@@ -33,13 +35,14 @@ function CollapsibleFlatList({
33
35
  headerSnappable = true,
34
36
  ...props
35
37
  }) {
36
- const scrollView = (0, _react.useRef)(null);
37
38
  const {
38
- headerHeight
39
+ headerHeight,
40
+ scrollY
39
41
  } = (0, _useCollapsibleContext.default)();
40
42
  const {
41
43
  contentMinHeight
42
- } = (0, _useInternalCollapsibleContext.useInternalCollapsibleContext)();
44
+ } = (0, _useInternalCollapsibleContext.default)();
45
+ const scrollRef = (0, _react.useRef)(null);
43
46
  const mounted = (0, _react.useRef)(true);
44
47
  const contentHeight = (0, _react.useRef)(0);
45
48
  (0, _react.useEffect)(() => {
@@ -48,13 +51,13 @@ function CollapsibleFlatList({
48
51
  };
49
52
  }, []);
50
53
  const scrollTo = (0, _react.useCallback)((yValue, animated = true) => {
51
- var _scrollView$current;
54
+ var _scrollRef$current;
52
55
 
53
- (_scrollView$current = scrollView.current) === null || _scrollView$current === void 0 ? void 0 : _scrollView$current.scrollToOffset({
56
+ (_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 ? void 0 : _scrollRef$current.scrollToOffset({
54
57
  offset: yValue,
55
58
  animated
56
59
  });
57
- }, []);
60
+ }, [scrollRef]);
58
61
  const handleInternalContentHeight = (0, _react.useCallback)(value => {
59
62
  if (mounted.current) {
60
63
  setInternalContentMinHeight(value);
@@ -67,11 +70,15 @@ function CollapsibleFlatList({
67
70
  scrollTo
68
71
  });
69
72
  const [internalContentMinHeight, setInternalContentMinHeight] = (0, _react.useState)(contentMinHeight.value);
70
- (0, _reactNativeReanimated.useDerivedValue)(() => {
71
- if (contentHeight.current < contentMinHeight.value && contentMinHeight.value !== internalContentMinHeight) {
72
- (0, _reactNativeReanimated.runOnJS)(handleInternalContentHeight)(contentMinHeight.value);
73
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => {
74
+ return contentMinHeight.value;
75
+ }, (result, previous) => {
76
+ if (result !== previous) {
77
+ if (contentHeight.current < contentMinHeight.value && internalContentMinHeight !== contentMinHeight.value) {
78
+ (0, _reactNativeReanimated.runOnJS)(handleInternalContentHeight)(contentMinHeight.value);
79
+ }
73
80
  }
74
- }, [internalContentMinHeight, contentHeight.current]);
81
+ });
75
82
  const contentContainerStyle = (0, _react.useMemo)(() => [styles.contentContainer, {
76
83
  minHeight: internalContentMinHeight
77
84
  }, props.contentContainerStyle], [props.contentContainerStyle, internalContentMinHeight]);
@@ -83,23 +90,21 @@ function CollapsibleFlatList({
83
90
  height: headerHeight
84
91
  }), props.ListHeaderComponent);
85
92
 
86
- return (
87
- /*#__PURE__*/
88
- // @ts-ignore
89
- _react.default.createElement(AnimatedFlatList, _extends({
90
- ref: scrollView,
91
- bounces: false,
92
- keyboardDismissMode: "on-drag",
93
- keyboardShouldPersistTaps: "handled",
94
- scrollEventThrottle: 16
95
- }, props, {
96
- style: [styles.container, props.style],
97
- contentContainerStyle: contentContainerStyle,
98
- onScroll: scrollHandler,
99
- ListHeaderComponent: renderListHeader(),
100
- onContentSizeChange: handleContentSizeChange
101
- }))
102
- );
93
+ return /*#__PURE__*/_react.default.createElement(_PullToRefreshContainer.default, {
94
+ scrollY: scrollY
95
+ }, /*#__PURE__*/_react.default.createElement(AnimatedFlatList, _extends({
96
+ ref: scrollRef,
97
+ bounces: false,
98
+ keyboardDismissMode: "on-drag",
99
+ keyboardShouldPersistTaps: "handled",
100
+ scrollEventThrottle: 1
101
+ }, props, {
102
+ style: [styles.container, props.style],
103
+ contentContainerStyle: contentContainerStyle,
104
+ onScroll: scrollHandler,
105
+ ListHeaderComponent: renderListHeader(),
106
+ onContentSizeChange: handleContentSizeChange
107
+ })));
103
108
  }
104
109
 
105
110
  const styles = _reactNative.StyleSheet.create({
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["CollapsibleFlatList.tsx"],"names":["AnimatedFlatList","Animated","createAnimatedComponent","FlatList","CollapsibleFlatList","headerSnappable","props","headerHeight","scrollY","contentMinHeight","scrollRef","mounted","contentHeight","current","scrollTo","yValue","animated","scrollToOffset","offset","handleInternalContentHeight","value","setInternalContentMinHeight","scrollHandler","internalContentMinHeight","result","previous","contentContainerStyle","styles","contentContainer","minHeight","handleContentSizeChange","_","height","renderListHeader","ListHeaderComponent","container","style","StyleSheet","create","absoluteFillObject","flexGrow","topView","position","top","left","right"],"mappings":"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","sourcesContent":["import 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 } = useInternalCollapsibleContext();\n const scrollRef = useRef<any>(null);\n const mounted = useRef(true);\n const contentHeight = useRef(0);\n\n useEffect(() => {\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const scrollTo = useCallback(\n (yValue: number, animated = true) => {\n scrollRef.current?.scrollToOffset({\n offset: yValue,\n animated,\n });\n },\n [scrollRef]\n );\n\n const handleInternalContentHeight = useCallback((value: number) => {\n if (mounted.current) {\n setInternalContentMinHeight(value);\n }\n }, []);\n\n const { scrollHandler } = useAnimatedScroll({\n headerSnappable,\n scrollTo,\n });\n\n const [internalContentMinHeight, setInternalContentMinHeight] = useState(\n contentMinHeight.value\n );\n\n useAnimatedReaction(\n () => {\n return contentMinHeight.value;\n },\n (result, previous) => {\n if (result !== previous) {\n if (\n contentHeight.current < contentMinHeight.value &&\n internalContentMinHeight !== contentMinHeight.value\n ) {\n runOnJS(handleInternalContentHeight)(contentMinHeight.value);\n }\n }\n }\n );\n\n const contentContainerStyle = useMemo(\n () => [\n styles.contentContainer,\n { minHeight: internalContentMinHeight },\n props.contentContainerStyle,\n ],\n [props.contentContainerStyle, internalContentMinHeight]\n );\n\n const handleContentSizeChange = useCallback((_, height) => {\n contentHeight.current = height;\n }, []);\n\n const renderListHeader = () => (\n <View>\n <AnimatedTopView height={headerHeight} />\n {props.ListHeaderComponent}\n </View>\n );\n\n return (\n <PullToRefreshContainer scrollY={scrollY}>\n {/* @ts-ignore */}\n <AnimatedFlatList\n ref={scrollRef}\n bounces={false}\n keyboardDismissMode=\"on-drag\"\n keyboardShouldPersistTaps=\"handled\"\n scrollEventThrottle={1}\n {...props}\n style={[styles.container, props.style]}\n contentContainerStyle={contentContainerStyle}\n onScroll={scrollHandler}\n ListHeaderComponent={renderListHeader()}\n onContentSizeChange={handleContentSizeChange}\n />\n </PullToRefreshContainer>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n ...StyleSheet.absoluteFillObject,\n },\n contentContainer: {\n flexGrow: 1,\n },\n topView: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n },\n});\n"]}
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = CollapsibleScrollView;
7
7
 
8
- var _AnimatedTopView = _interopRequireDefault(require("./AnimatedTopView"));
8
+ var _AnimatedTopView = _interopRequireDefault(require("../header/AnimatedTopView"));
9
9
 
10
- var _useAnimatedScroll = _interopRequireDefault(require("../hooks/useAnimatedScroll"));
10
+ var _useAnimatedScroll = _interopRequireDefault(require("./useAnimatedScroll"));
11
11
 
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
 
@@ -15,9 +15,9 @@ var _reactNative = require("react-native");
15
15
 
16
16
  var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
17
17
 
18
- var _useCollapsibleContext = _interopRequireDefault(require("../hooks/useCollapsibleContext"));
18
+ var _useCollapsibleContext = _interopRequireDefault(require("../../hooks/useCollapsibleContext"));
19
19
 
20
- var _useInternalCollapsibleContext = require("../hooks/useInternalCollapsibleContext");
20
+ var _useInternalCollapsibleContext = _interopRequireDefault(require("../../hooks/useInternalCollapsibleContext"));
21
21
 
22
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
23
 
@@ -35,7 +35,7 @@ function CollapsibleScrollView({
35
35
  const scrollView = (0, _react.useRef)(null);
36
36
  const {
37
37
  contentMinHeight
38
- } = (0, _useInternalCollapsibleContext.useInternalCollapsibleContext)();
38
+ } = (0, _useInternalCollapsibleContext.default)();
39
39
  const {
40
40
  headerHeight
41
41
  } = (0, _useCollapsibleContext.default)();
@@ -69,7 +69,7 @@ function CollapsibleScrollView({
69
69
  onScroll: scrollHandler,
70
70
  keyboardDismissMode: "on-drag",
71
71
  keyboardShouldPersistTaps: "handled",
72
- scrollEventThrottle: 16
72
+ scrollEventThrottle: 1
73
73
  }), /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
74
74
  style: animatedStyle
75
75
  }, /*#__PURE__*/_react.default.createElement(_AnimatedTopView.default, {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["CollapsibleScrollView.tsx"],"names":["CollapsibleScrollView","headerSnappable","children","props","scrollView","contentMinHeight","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":";;;;;;;AAAA;;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,QAAMC,UAAU,GAAG,mBAA4B,IAA5B,CAAnB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,6CAA7B;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAmB,qCAAzB;AAEA,QAAMC,QAAQ,GAAG,wBAAY,CAACC,MAAD,EAAiBC,QAAQ,GAAG,IAA5B,KAAqC;AAAA;;AAChE;AACA,2BAAAL,UAAU,CAACM,OAAX,4EAAoBH,QAApB,CAA6B;AAAEI,MAAAA,CAAC,EAAEH,MAAL;AAAaC,MAAAA;AAAb,KAA7B;AACD,GAHgB,EAGd,EAHc,CAAjB;AAKA,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,EAAET,gBAAgB,CAACU;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,EAAEZ,UADP;AAEE,IAAA,OAAO,EAAE;AAFX,KAGMD,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":["import AnimatedTopView from '../header/AnimatedTopView';\nimport useAnimatedScroll from './useAnimatedScroll';\nimport React, { ReactNode, useCallback, useMemo, useRef } from 'react';\nimport { ScrollViewProps, StyleSheet } from 'react-native';\nimport Animated, { useAnimatedStyle } from 'react-native-reanimated';\nimport type { CollapsibleProps } from '../../types';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\n\ntype Props = ScrollViewProps &\n CollapsibleProps & {\n children?: ReactNode;\n };\n\nexport default function CollapsibleScrollView({\n headerSnappable = true,\n children,\n ...props\n}: Props) {\n const scrollView = useRef<Animated.ScrollView>(null);\n const { contentMinHeight } = useInternalCollapsibleContext();\n const { headerHeight } = useCollapsibleContext();\n\n const scrollTo = useCallback((yValue: number, animated = true) => {\n // @ts-ignore\n scrollView.current?.scrollTo({ y: yValue, animated });\n }, []);\n\n const { scrollHandler } = useAnimatedScroll({\n headerSnappable,\n scrollTo,\n });\n\n const animatedStyle = useAnimatedStyle(() => {\n return {\n minHeight: contentMinHeight.value,\n };\n }, []);\n\n const contentContainerStyle = useMemo(\n () => [styles.contentContainer, props.contentContainerStyle],\n [props.contentContainerStyle]\n );\n\n return (\n <Animated.ScrollView\n ref={scrollView}\n bounces={false}\n {...props}\n style={[styles.container, props.style]}\n contentContainerStyle={contentContainerStyle}\n onScroll={scrollHandler}\n keyboardDismissMode=\"on-drag\"\n keyboardShouldPersistTaps=\"handled\"\n scrollEventThrottle={1}\n >\n <Animated.View style={animatedStyle}>\n <AnimatedTopView height={headerHeight} />\n {children}\n </Animated.View>\n </Animated.ScrollView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n ...StyleSheet.absoluteFillObject,\n },\n contentContainer: {\n flexGrow: 1,\n },\n topView: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n },\n});\n"]}
@@ -11,9 +11,9 @@ var _reactNative = require("react-native");
11
11
 
12
12
  var _reactNativeReanimated = require("react-native-reanimated");
13
13
 
14
- var _useCollapsibleContext = _interopRequireDefault(require("./useCollapsibleContext"));
14
+ var _useCollapsibleContext = _interopRequireDefault(require("../../hooks/useCollapsibleContext"));
15
15
 
16
- var _useInternalCollapsibleContext = require("./useInternalCollapsibleContext");
16
+ var _useInternalCollapsibleContext = _interopRequireDefault(require("../../hooks/useInternalCollapsibleContext"));
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
@@ -34,15 +34,15 @@ function useAnimatedScroll({
34
34
  setCollapsibleHandlers,
35
35
  firstStickyViewY,
36
36
  fixedHeaderHeight
37
- } = (0, _useInternalCollapsibleContext.useInternalCollapsibleContext)();
37
+ } = (0, _useInternalCollapsibleContext.default)();
38
38
  (0, _react.useEffect)(() => {
39
39
  if (scrollY.value > 0) {
40
40
  requestAnimationFrame(() => scrollTo(scrollY.value, false));
41
41
  }
42
42
  }, []);
43
43
  const collapse = (0, _react.useCallback)(() => {
44
- scrollTo(Math.min(fixedHeaderHeight.current || 0, firstStickyViewY.current || 0));
45
- }, [scrollTo, fixedHeaderHeight.current, firstStickyViewY.current]);
44
+ scrollTo(Math.min(fixedHeaderHeight.value || 0, firstStickyViewY.value || 0));
45
+ }, [scrollTo]);
46
46
  const expand = (0, _react.useCallback)(() => scrollTo(0), [scrollTo]);
47
47
  (0, _react.useEffect)(() => {
48
48
  setCollapsibleHandlers({
@@ -60,7 +60,7 @@ function useAnimatedScroll({
60
60
  },
61
61
  onEndDrag: () => {
62
62
  if (!headerSnappable) return;
63
- const maxY = firstStickyViewY.current && firstStickyViewY.current > 0 ? firstStickyViewY.current : fixedHeaderHeight.current || 0;
63
+ const maxY = firstStickyViewY.value && firstStickyViewY.value > 0 ? firstStickyViewY.value : fixedHeaderHeight.value || 0;
64
64
 
65
65
  if (scrollY.value < maxY) {
66
66
  const delta = Math.abs(scrollY.value - maxY);
@@ -76,7 +76,7 @@ function useAnimatedScroll({
76
76
  }
77
77
  }
78
78
  }
79
- }, [firstStickyViewY.current, fixedHeaderHeight.current]);
79
+ }, [scrollTo]);
80
80
  return {
81
81
  scrollHandler,
82
82
  collapse,
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useAnimatedScroll.ts"],"names":["height","wHeight","Dimensions","get","useAnimatedScroll","headerSnappable","scrollTo","scrollDirection","scrollY","setCollapsibleHandlers","firstStickyViewY","fixedHeaderHeight","value","requestAnimationFrame","collapse","Math","min","expand","scrollHandler","onScroll","event","offset","contentOffset","y","diff","onEndDrag","maxY","delta","abs","yValue"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;AATA;AAWA,MAAM;AAAEA,EAAAA,MAAM,EAAEC;AAAV,IAAsBC,wBAAWC,GAAX,CAAe,QAAf,CAA5B;;AAOe,SAASC,iBAAT,CAA2B;AACxCC,EAAAA,eADwC;AAExCC,EAAAA;AAFwC,CAA3B,EAGL;AACR,QAAMC,eAAe,GAAG,2CAAe,SAAf,CAAxB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAc,qCAApB;AACA,QAAM;AAAEC,IAAAA,sBAAF;AAA0BC,IAAAA,gBAA1B;AAA4CC,IAAAA;AAA5C,MACJ,6CADF;AAGA,wBAAU,MAAM;AACd,QAAIH,OAAO,CAACI,KAAR,GAAgB,CAApB,EAAuB;AACrBC,MAAAA,qBAAqB,CAAC,MAAMP,QAAQ,CAACE,OAAO,CAACI,KAAT,EAAgB,KAAhB,CAAf,CAArB;AACD;AACF,GAJD,EAIG,EAJH;AAMA,QAAME,QAAQ,GAAG,wBAAY,MAAM;AACjCR,IAAAA,QAAQ,CACNS,IAAI,CAACC,GAAL,CAASL,iBAAiB,CAACC,KAAlB,IAA2B,CAApC,EAAuCF,gBAAgB,CAACE,KAAjB,IAA0B,CAAjE,CADM,CAAR;AAGD,GAJgB,EAId,CAACN,QAAD,CAJc,CAAjB;AAMA,QAAMW,MAAM,GAAG,wBAAY,MAAMX,QAAQ,CAAC,CAAD,CAA1B,EAA+B,CAACA,QAAD,CAA/B,CAAf;AAEA,wBAAU,MAAM;AACdG,IAAAA,sBAAsB,CAAC;AACrBK,MAAAA,QADqB;AAErBG,MAAAA,MAFqB;AAGrBX,MAAAA;AAHqB,KAAD,CAAtB;AAKD,GAND,EAMG,CAACG,sBAAD,EAAyBK,QAAzB,EAAmCG,MAAnC,EAA2CX,QAA3C,CANH;AAQA,QAAMY,aAAa,GAAG,qDACpB;AACEC,IAAAA,QAAQ,EAAGC,KAAD,IAAW;AACnB,YAAMC,MAAM,GAAGD,KAAK,CAACE,aAAN,CAAoBC,CAAnC;AACA,YAAMC,IAAI,GAAGhB,OAAO,CAACI,KAAR,GAAgBS,MAA7B;AACAd,MAAAA,eAAe,CAACK,KAAhB,GAAwBY,IAAI,GAAG,CAAP,GAAW,MAAX,GAAoBA,IAAI,GAAG,CAAP,GAAW,IAAX,GAAkB,SAA9D;AACAhB,MAAAA,OAAO,CAACI,KAAR,GAAgBS,MAAhB;AACD,KANH;AAOEI,IAAAA,SAAS,EAAE,MAAM;AACf,UAAI,CAACpB,eAAL,EAAsB;AACtB,YAAMqB,IAAI,GACRhB,gBAAgB,CAACE,KAAjB,IAA0BF,gBAAgB,CAACE,KAAjB,GAAyB,CAAnD,GACIF,gBAAgB,CAACE,KADrB,GAEID,iBAAiB,CAACC,KAAlB,IAA2B,CAHjC;;AAKA,UAAIJ,OAAO,CAACI,KAAR,GAAgBc,IAApB,EAA0B;AACxB,cAAMC,KAAK,GAAGZ,IAAI,CAACa,GAAL,CAASpB,OAAO,CAACI,KAAR,GAAgBc,IAAzB,CAAd;;AACA,YAAIC,KAAK,GAAG1B,OAAO,GAAG,CAAtB,EAAyB;AACvB,cAAI4B,MAAM,GAAG,CAAb;;AACA,cAAItB,eAAe,CAACK,KAAhB,KAA0B,IAA9B,EAAoC;AAClCiB,YAAAA,MAAM,GAAGH,IAAT;AACD;;AACD,8CAAQpB,QAAR,EAAkBuB,MAAlB;AACD;AACF;AACF;AAxBH,GADoB,EA2BpB,CAACvB,QAAD,CA3BoB,CAAtB;AA8BA,SAAO;AACLY,IAAAA,aADK;AAELJ,IAAAA,QAFK;AAGLG,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport { useCallback, useEffect } from 'react';\nimport { Dimensions } from 'react-native';\nimport {\n runOnJS,\n useAnimatedScrollHandler,\n useSharedValue,\n} from 'react-native-reanimated';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\n\nconst { height: wHeight } = Dimensions.get('window');\n\ntype Props = {\n headerSnappable: boolean;\n scrollTo: (yValue: number, animated?: boolean) => void;\n};\n\nexport default function useAnimatedScroll({\n headerSnappable,\n scrollTo,\n}: Props) {\n const scrollDirection = useSharedValue('unknown');\n const { scrollY } = useCollapsibleContext();\n const { setCollapsibleHandlers, firstStickyViewY, fixedHeaderHeight } =\n useInternalCollapsibleContext();\n\n useEffect(() => {\n if (scrollY.value > 0) {\n requestAnimationFrame(() => scrollTo(scrollY.value, false));\n }\n }, []);\n\n const collapse = useCallback(() => {\n scrollTo(\n Math.min(fixedHeaderHeight.value || 0, firstStickyViewY.value || 0)\n );\n }, [scrollTo]);\n\n const expand = useCallback(() => scrollTo(0), [scrollTo]);\n\n useEffect(() => {\n setCollapsibleHandlers({\n collapse,\n expand,\n scrollTo,\n });\n }, [setCollapsibleHandlers, collapse, expand, scrollTo]);\n\n const scrollHandler = useAnimatedScrollHandler(\n {\n onScroll: (event) => {\n const offset = event.contentOffset.y;\n const diff = scrollY.value - offset;\n scrollDirection.value = diff > 0 ? 'down' : diff < 0 ? 'up' : 'unknown';\n scrollY.value = offset;\n },\n onEndDrag: () => {\n if (!headerSnappable) return;\n const maxY =\n firstStickyViewY.value && firstStickyViewY.value > 0\n ? firstStickyViewY.value\n : fixedHeaderHeight.value || 0;\n\n if (scrollY.value < maxY) {\n const delta = Math.abs(scrollY.value - maxY);\n if (delta < wHeight / 2) {\n let yValue = 0;\n if (scrollDirection.value === 'up') {\n yValue = maxY;\n }\n runOnJS(scrollTo)(yValue);\n }\n }\n },\n },\n [scrollTo]\n );\n\n return {\n scrollHandler,\n collapse,\n expand,\n };\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useInternalCollapsibleContext = useInternalCollapsibleContext;
6
+ exports.default = useInternalCollapsibleContext;
7
7
  exports.InternalCollapsibleContext = void 0;
8
8
 
9
9
  var _react = require("react");
@@ -1 +1 @@
1
- {"version":3,"sources":["useInternalCollapsibleContext.ts"],"names":["InternalCollapsibleContext","useInternalCollapsibleContext","ctx","Error"],"mappings":";;;;;;;;AAAA;;AAGO,MAAMA,0BAA0B;AAAA;AACrC;AACA,2BAFK;;;AAIA,SAASC,6BAAT,GAAyC;AAC9C,QAAMC,GAAG,GAAG,uBAAWF,0BAAX,CAAZ;;AACA,MAAI,CAACE,GAAL,EAAU;AACR,UAAM,IAAIC,KAAJ,CAAU,yDAAV,CAAN;AACD;;AACD,SAAOD,GAAP;AACD","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { CollapsibleContextInternalType } from '../types';\n\nexport const InternalCollapsibleContext =\n // @ts-ignore\n createContext<CollapsibleContextInternalType>();\n\nexport function useInternalCollapsibleContext() {\n const ctx = useContext(InternalCollapsibleContext);\n if (!ctx) {\n throw new Error('Component should be wrapped with withCollapsibleContext');\n }\n return ctx;\n}\n"]}
1
+ {"version":3,"sources":["useInternalCollapsibleContext.ts"],"names":["InternalCollapsibleContext","useInternalCollapsibleContext","ctx","Error"],"mappings":";;;;;;;;AAAA;;AAGO,MAAMA,0BAA0B;AAAA;AACrC;AACA,2BAFK;;;AAIQ,SAASC,6BAAT,GAAyC;AACtD,QAAMC,GAAG,GAAG,uBAAWF,0BAAX,CAAZ;;AACA,MAAI,CAACE,GAAL,EAAU;AACR,UAAM,IAAIC,KAAJ,CAAU,yDAAV,CAAN;AACD;;AACD,SAAOD,GAAP;AACD","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { CollapsibleContextInternalType } from '../types';\n\nexport const InternalCollapsibleContext =\n // @ts-ignore\n createContext<CollapsibleContextInternalType>();\n\nexport default function useInternalCollapsibleContext() {\n const ctx = useContext(InternalCollapsibleContext);\n if (!ctx) {\n throw new Error('Component should be wrapped with withCollapsibleContext');\n }\n return ctx;\n}\n"]}
@@ -10,8 +10,9 @@ var _exportNames = {
10
10
  CollapsibleFlatList: true,
11
11
  CollapsibleScrollView: true,
12
12
  CollapsibleHeaderContainer: true,
13
- CollapsibleView: true,
14
- StickyView: true
13
+ StickyView: true,
14
+ RefreshControl: true,
15
+ CollapsibleView: true
15
16
  };
16
17
  Object.defineProperty(exports, "withCollapsibleContext", {
17
18
  enumerable: true,
@@ -49,30 +50,40 @@ Object.defineProperty(exports, "CollapsibleHeaderContainer", {
49
50
  return _CollapsibleHeaderContainer.default;
50
51
  }
51
52
  });
52
- Object.defineProperty(exports, "CollapsibleView", {
53
+ Object.defineProperty(exports, "StickyView", {
53
54
  enumerable: true,
54
55
  get: function () {
55
- return _CollapsibleView.default;
56
+ return _StickyView.default;
56
57
  }
57
58
  });
58
- Object.defineProperty(exports, "StickyView", {
59
+ Object.defineProperty(exports, "RefreshControl", {
59
60
  enumerable: true,
60
61
  get: function () {
61
- return _StickyView.default;
62
+ return _RefreshControl.default;
63
+ }
64
+ });
65
+ Object.defineProperty(exports, "CollapsibleView", {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _CollapsibleView.default;
62
69
  }
63
70
  });
64
71
 
65
- var _withCollapsibleContext = _interopRequireDefault(require("./hooks/withCollapsibleContext"));
72
+ var _withCollapsibleContext = _interopRequireDefault(require("./withCollapsibleContext"));
66
73
 
67
74
  var _useCollapsibleContext = _interopRequireDefault(require("./hooks/useCollapsibleContext"));
68
75
 
69
76
  var _CollapsibleContainer = _interopRequireDefault(require("./components/CollapsibleContainer"));
70
77
 
71
- var _CollapsibleFlatList = _interopRequireDefault(require("./components/CollapsibleFlatList"));
78
+ var _CollapsibleFlatList = _interopRequireDefault(require("./components/scrollable/CollapsibleFlatList"));
72
79
 
73
- var _CollapsibleScrollView = _interopRequireDefault(require("./components/CollapsibleScrollView"));
80
+ var _CollapsibleScrollView = _interopRequireDefault(require("./components/scrollable/CollapsibleScrollView"));
74
81
 
75
- var _CollapsibleHeaderContainer = _interopRequireDefault(require("./components/CollapsibleHeaderContainer"));
82
+ var _CollapsibleHeaderContainer = _interopRequireDefault(require("./components/header/CollapsibleHeaderContainer"));
83
+
84
+ var _StickyView = _interopRequireDefault(require("./components/header/StickyView"));
85
+
86
+ var _RefreshControl = _interopRequireDefault(require("./components/pullToRefresh/RefreshControl"));
76
87
 
77
88
  var _CollapsibleView = _interopRequireWildcard(require("./components/CollapsibleView"));
78
89
 
@@ -88,8 +99,6 @@ Object.keys(_CollapsibleView).forEach(function (key) {
88
99
  });
89
100
  });
90
101
 
91
- var _StickyView = _interopRequireDefault(require("./components/StickyView"));
92
-
93
102
  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); }
94
103
 
95
104
  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; }
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AADA","sourcesContent":["export { default as withCollapsibleContext } from './hooks/withCollapsibleContext';\nexport { default as useCollapsibleContext } from './hooks/useCollapsibleContext';\n\nexport { default as CollapsibleContainer } from './components/CollapsibleContainer';\nexport { default as CollapsibleFlatList } from './components/CollapsibleFlatList';\nexport { default as CollapsibleScrollView } from './components/CollapsibleScrollView';\nexport { default as CollapsibleHeaderContainer } from './components/CollapsibleHeaderContainer';\nexport { default as CollapsibleView } from './components/CollapsibleView';\nexport { default as StickyView } from './components/StickyView';\nexport * from './components/CollapsibleView';\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export { default as withCollapsibleContext } from './withCollapsibleContext';\nexport { default as useCollapsibleContext } from './hooks/useCollapsibleContext';\n\nexport { default as CollapsibleContainer } from './components/CollapsibleContainer';\nexport { default as CollapsibleFlatList } from './components/scrollable/CollapsibleFlatList';\nexport { default as CollapsibleScrollView } from './components/scrollable/CollapsibleScrollView';\nexport { default as CollapsibleHeaderContainer } from './components/header/CollapsibleHeaderContainer';\nexport { default as StickyView } from './components/header/StickyView';\nexport { default as RefreshControl } from './components/pullToRefresh/RefreshControl';\nexport { default as CollapsibleView } from './components/CollapsibleView';\nexport * from './components/CollapsibleView';\n"]}
@@ -3,4 +3,4 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- //# sourceMappingURL=types.js.map
6
+ //# sourceMappingURL=types.d.js.map
File without changes
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.debounce = debounce;
7
+
8
+ // https://gist.github.com/ca0v/73a31f57b397606c9813472f7493a940
9
+ function debounce(cb, wait = 20) {
10
+ let h = 0;
11
+
12
+ let callable = (...args) => {
13
+ clearTimeout(h); // @ts-ignore
14
+
15
+ h = setTimeout(() => cb(...args), wait);
16
+ };
17
+
18
+ return callable;
19
+ }
20
+ //# sourceMappingURL=debounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["debounce.ts"],"names":["debounce","cb","wait","h","callable","args","clearTimeout","setTimeout"],"mappings":";;;;;;;AAAA;AACO,SAASA,QAAT,CAAsCC,EAAtC,EAA6CC,IAAI,GAAG,EAApD,EAAwD;AAC7D,MAAIC,CAAC,GAAG,CAAR;;AACA,MAAIC,QAAQ,GAAG,CAAC,GAAGC,IAAJ,KAAkB;AAC/BC,IAAAA,YAAY,CAACH,CAAD,CAAZ,CAD+B,CAE/B;;AACAA,IAAAA,CAAC,GAAGI,UAAU,CAAC,MAAMN,EAAE,CAAC,GAAGI,IAAJ,CAAT,EAAoBH,IAApB,CAAd;AACD,GAJD;;AAKA,SAAgBE,QAAhB;AACD","sourcesContent":["// https://gist.github.com/ca0v/73a31f57b397606c9813472f7493a940\nexport function debounce<T extends Function>(cb: T, wait = 20) {\n let h = 0;\n let callable = (...args: any) => {\n clearTimeout(h);\n // @ts-ignore\n h = setTimeout(() => cb(...args), wait);\n };\n return <T>(<any>callable);\n}\n"]}
@@ -7,86 +7,119 @@ exports.default = withCollapsibleContext;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _useCollapsibleContext = require("./useCollapsibleContext");
10
+ var _useCollapsibleContext = require("./hooks/useCollapsibleContext");
11
11
 
12
- var _useInternalCollapsibleContext = require("./useInternalCollapsibleContext");
12
+ var _useInternalCollapsibleContext = require("./hooks/useInternalCollapsibleContext");
13
13
 
14
14
  var _reactNativeReanimated = require("react-native-reanimated");
15
15
 
16
+ var _debounce = require("./utils/debounce");
17
+
18
+ var _PullToRefreshProvider = _interopRequireDefault(require("./components/pullToRefresh/PullToRefreshProvider"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
16
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); }
17
23
 
18
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; }
19
25
 
26
+ /* eslint-disable no-shadow */
27
+
20
28
  /* eslint-disable react-hooks/exhaustive-deps */
21
29
  function withCollapsibleContext(Component) {
22
30
  return props => {
23
31
  const collapsibleHandlers = (0, _react.useRef)();
24
32
  const headerHeight = (0, _reactNativeReanimated.useSharedValue)(0);
25
33
  const scrollY = (0, _reactNativeReanimated.useSharedValue)(0);
26
- const headerCollapsed = (0, _reactNativeReanimated.useSharedValue)(false);
27
- const contentMinHeight = (0, _reactNativeReanimated.useSharedValue)(0);
34
+ const stickyViewRefs = (0, _react.useRef)({});
28
35
  const stickyViewTops = (0, _reactNativeReanimated.useSharedValue)({});
29
- const stickyHeaderHeight = (0, _react.useRef)(0);
30
- const containerHeight = (0, _react.useRef)(0);
31
- const firstStickyViewY = (0, _react.useRef)(1000000);
32
- const fixedHeaderHeight = (0, _react.useRef)(0);
36
+ const stickyViewPositionsRef = (0, _react.useRef)({});
37
+ const stickyViewPositions = (0, _reactNativeReanimated.useSharedValue)({});
38
+ const fixedHeaderHeight = (0, _reactNativeReanimated.useSharedValue)(0);
39
+ const stickyHeaderHeight = (0, _reactNativeReanimated.useSharedValue)(0);
40
+ const containerHeight = (0, _reactNativeReanimated.useSharedValue)(0);
41
+ const firstStickyViewY = (0, _reactNativeReanimated.useSharedValue)(1000000);
33
42
  const headerContainersHeight = (0, _react.useRef)({});
34
- const stickyViewPositions = (0, _react.useRef)({});
35
43
  const containerRef = (0, _react.useRef)(null);
36
44
  const setCollapsibleHandlers = (0, _react.useCallback)(handlers => {
37
45
  collapsibleHandlers.current = handlers;
38
46
  }, []);
39
- const refreshHeaderCollapsed = (0, _react.useCallback)(() => {
40
- const maxY = fixedHeaderHeight.current - firstStickyViewY.current;
41
- const isCollapsed = scrollY.value >= maxY;
42
- headerCollapsed.value = isCollapsed;
47
+ const headerCollapsed = (0, _reactNativeReanimated.useDerivedValue)(() => {
48
+ const maxY = fixedHeaderHeight.value - firstStickyViewY.value;
49
+ return scrollY.value >= maxY;
43
50
  }, []);
44
- const refreshMinContentHeight = (0, _react.useCallback)(() => {
45
- contentMinHeight.value = containerHeight.current + fixedHeaderHeight.current - stickyHeaderHeight.current;
51
+ const contentMinHeight = (0, _reactNativeReanimated.useDerivedValue)(() => {
52
+ return containerHeight.value + fixedHeaderHeight.value - stickyHeaderHeight.value;
46
53
  }, []);
47
- const populateData = (0, _react.useCallback)(() => {
48
- var _viewPositions$sorted;
54
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => {
55
+ const totalHeight = Object.keys(stickyViewPositions.value).reduce((acc, item) => {
56
+ return acc + stickyViewPositions.value[item].top;
57
+ }, 0);
58
+ return totalHeight - fixedHeaderHeight.value;
59
+ }, (result, previous) => {
60
+ if (result !== previous) {
61
+ var _viewPositions$sorted;
62
+
63
+ const viewPositions = stickyViewPositions.value;
64
+ const headerHeight = fixedHeaderHeight.value;
65
+ const sortedKeys = Object.keys(viewPositions).sort((a, b) => viewPositions[a].top - viewPositions[b].top);
66
+ let totalTop = 0;
67
+ const values = {};
68
+
69
+ for (let i = 0; i < sortedKeys.length; i++) {
70
+ values[sortedKeys[i]] = totalTop; // Try minus 1 make it filled when scrolling up.
71
+ // Otherwise, we can see a small space between the persits views
72
+
73
+ totalTop += viewPositions[sortedKeys[i]].height - 1;
74
+ }
49
75
 
50
- const viewPositions = stickyViewPositions.current;
51
- const headerHeight = fixedHeaderHeight.current;
52
- const sortedKeys = Object.keys(viewPositions).sort((a, b) => viewPositions[a].top - viewPositions[b].top);
53
- let totalTop = 0;
54
- const values = {};
76
+ stickyViewTops.value = values;
77
+ firstStickyViewY.value = ((_viewPositions$sorted = viewPositions[sortedKeys[0]]) === null || _viewPositions$sorted === void 0 ? void 0 : _viewPositions$sorted.top) || 0;
78
+ const stickyHeader = sortedKeys.reduce((acc, key) => {
79
+ const data = viewPositions[key];
80
+ const isInsideHeader = data.top < headerHeight;
55
81
 
56
- for (let i = 0; i < sortedKeys.length; i++) {
57
- values[sortedKeys[i]] = totalTop; // Try minus 1 make it filled when scrolling up.
58
- // Otherwise, we can see a small space between the persits views
82
+ if (isInsideHeader) {
83
+ return acc + data.height;
84
+ }
59
85
 
60
- totalTop += viewPositions[sortedKeys[i]].height - 1;
86
+ return acc;
87
+ }, 0);
88
+ stickyHeaderHeight.value = stickyHeader;
61
89
  }
62
-
63
- stickyViewTops.value = values;
64
- firstStickyViewY.current = ((_viewPositions$sorted = viewPositions[sortedKeys[0]]) === null || _viewPositions$sorted === void 0 ? void 0 : _viewPositions$sorted.top) || 0;
65
- refreshHeaderCollapsed();
66
- const stickyHeader = sortedKeys.reduce((acc, key) => {
67
- const data = viewPositions[key];
68
- const isInsideHeader = data.top < headerHeight;
69
-
70
- if (isInsideHeader) {
71
- return acc + data.height;
72
- }
73
-
74
- return acc;
75
- }, 0);
76
- stickyHeaderHeight.current = stickyHeader;
77
- refreshMinContentHeight();
78
- }, [stickyViewPositions.current, fixedHeaderHeight.current]);
79
- const handleStickyViewLayout = (0, _react.useCallback)((viewKey, layout) => {
80
- if (!layout) {
81
- delete stickyViewPositions.current[viewKey];
90
+ });
91
+ const handleStickyViewLayout = (0, _react.useCallback)((viewKey, viewRef) => {
92
+ if (viewRef && viewRef.current && containerRef.current) {
93
+ stickyViewRefs.current[viewKey] = viewRef;
94
+ viewRef.current.measureLayout( // @ts-ignore
95
+ containerRef.current, (left, top, width, height) => {
96
+ stickyViewPositionsRef.current = { ...stickyViewPositionsRef.current,
97
+ [viewKey]: {
98
+ left,
99
+ top,
100
+ width,
101
+ height
102
+ }
103
+ };
104
+ stickyViewPositions.value = stickyViewPositionsRef.current;
105
+ }, () => {});
82
106
  } else {
83
- stickyViewPositions.current = { ...stickyViewPositions.current,
84
- [viewKey]: layout
85
- };
107
+ delete stickyViewRefs.current[viewKey];
108
+ delete stickyViewPositionsRef.current[viewKey];
109
+ stickyViewPositions.value = stickyViewPositionsRef.current;
86
110
  }
87
-
88
- populateData();
89
- }, [populateData, fixedHeaderHeight]);
111
+ }, []);
112
+ const debounceRefreshStickyPositions = (0, _react.useMemo)(() => {
113
+ return (0, _debounce.debounce)(() => {
114
+ Object.keys(stickyViewRefs.current).forEach(key => {
115
+ const viewRef = stickyViewRefs.current[key];
116
+
117
+ if (viewRef) {
118
+ handleStickyViewLayout(key, viewRef);
119
+ }
120
+ });
121
+ }, 200);
122
+ }, []);
90
123
  const handleHeaderContainerLayout = (0, _react.useCallback)((viewKey, height) => {
91
124
  if (!height) {
92
125
  delete headerContainersHeight.current[viewKey];
@@ -96,17 +129,15 @@ function withCollapsibleContext(Component) {
96
129
 
97
130
  const totalHeight = Object.keys(headerContainersHeight.current).reduce((acc, key) => headerContainersHeight.current[key] + acc, 0);
98
131
  headerHeight.value = (0, _reactNativeReanimated.withTiming)(totalHeight, {
99
- duration: fixedHeaderHeight.current === 0 ? 0 : 200
132
+ duration: fixedHeaderHeight.value === 0 ? 0 : 200
100
133
  });
101
- fixedHeaderHeight.current = totalHeight;
102
- populateData();
103
- refreshHeaderCollapsed();
104
- refreshMinContentHeight();
105
- }, [populateData, refreshHeaderCollapsed, refreshMinContentHeight]);
134
+ fixedHeaderHeight.value = totalHeight; // Try refresh sticky positions
135
+
136
+ debounceRefreshStickyPositions();
137
+ }, []);
106
138
  const handleContainerHeight = (0, _react.useCallback)(height => {
107
- containerHeight.current = height;
108
- refreshMinContentHeight();
109
- }, [refreshMinContentHeight]);
139
+ containerHeight.value = height;
140
+ }, []);
110
141
  const context = (0, _react.useMemo)(() => {
111
142
  return {
112
143
  collapse: () => {
@@ -137,15 +168,15 @@ function withCollapsibleContext(Component) {
137
168
  handleContainerHeight,
138
169
  firstStickyViewY,
139
170
  stickyViewTops,
171
+ stickyViewPositions,
140
172
  fixedHeaderHeight,
141
- stickyHeaderHeight,
142
173
  contentMinHeight
143
- }), [setCollapsibleHandlers, handleStickyViewLayout, handleHeaderContainerLayout, handleContainerHeight, firstStickyViewY, stickyViewTops, fixedHeaderHeight, stickyHeaderHeight, contentMinHeight]);
174
+ }), [setCollapsibleHandlers, handleStickyViewLayout, handleHeaderContainerLayout, handleContainerHeight, firstStickyViewY, stickyViewTops, stickyViewPositions, fixedHeaderHeight, contentMinHeight]);
144
175
  return /*#__PURE__*/_react.default.createElement(_useCollapsibleContext.CollapsibleContext.Provider, {
145
176
  value: context
146
177
  }, /*#__PURE__*/_react.default.createElement(_useInternalCollapsibleContext.InternalCollapsibleContext.Provider, {
147
178
  value: internalContext
148
- }, /*#__PURE__*/_react.default.createElement(Component, props)));
179
+ }, /*#__PURE__*/_react.default.createElement(_PullToRefreshProvider.default, null, /*#__PURE__*/_react.default.createElement(Component, props))));
149
180
  };
150
181
  }
151
182
  //# sourceMappingURL=withCollapsibleContext.js.map