@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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["withCollapsibleContext.tsx"],"names":["withCollapsibleContext","Component","props","collapsibleHandlers","headerHeight","scrollY","stickyViewRefs","stickyViewTops","stickyViewPositionsRef","stickyViewPositions","fixedHeaderHeight","stickyHeaderHeight","containerHeight","firstStickyViewY","headerContainersHeight","containerRef","setCollapsibleHandlers","handlers","current","headerCollapsed","maxY","value","contentMinHeight","totalHeight","Object","keys","reduce","acc","item","top","result","previous","viewPositions","sortedKeys","sort","a","b","totalTop","values","i","length","height","stickyHeader","key","data","isInsideHeader","handleStickyViewLayout","viewKey","viewRef","measureLayout","left","width","debounceRefreshStickyPositions","forEach","handleHeaderContainerLayout","duration","handleContainerHeight","context","collapse","expand","scrollTo","offset","animate","internalContext"],"mappings":";;;;;;;AAEA;;AAEA;;AACA;;AACA;;AAOA;;AACA;;;;;;;;AAdA;;AACA;AAee,SAASA,sBAAT,CAAmCC,SAAnC,EAAqD;AAClE,SAAQC,KAAD,IAAc;AACnB,UAAMC,mBAAmB,GAAG,oB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int-disable no-shadow */\n/* eslint-disable react-hooks/exhaustive-deps */\nimport React, { FC, useCallback, useMemo, useRef } from 'react';\nimport type { CollapsibleHandles, LayoutParams } from './types';\nimport { CollapsibleContext } from './hooks/useCollapsibleContext';\nimport { InternalCollapsibleContext } from './hooks/useInternalCollapsibleContext';\nimport {\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport type { View } from 'react-native';\nimport { debounce } from './utils/debounce';\nimport PullToRefreshProvider from './components/pullToRefresh/PullToRefreshProvider';\n\nexport default function withCollapsibleContext<T>(Component: FC<T>) {\n return (props: T) => {\n const collapsibleHandlers = useRef<CollapsibleHandles>();\n const headerHeight = useSharedValue(0);\n const scrollY = useSharedValue(0);\n const stickyViewRefs = useRef<Record<string, React.RefObject<View>>>({});\n const stickyViewTops = useSharedValue<Record<string, number>>({});\n const stickyViewPositionsRef = useRef<Record<string, LayoutParams>>({});\n const stickyViewPositions = useSharedValue<Record<string, LayoutParams>>(\n {}\n );\n const fixedHeaderHeight = useSharedValue(0);\n const stickyHeaderHeight = useSharedValue(0);\n const containerHeight = useSharedValue(0);\n const firstStickyViewY = useSharedValue(1000000);\n const headerContainersHeight = useRef<Record<string, number>>({});\n const containerRef = useRef<View>(null);\n\n const setCollapsibleHandlers = useCallback((handlers) => {\n collapsibleHandlers.current = handlers;\n }, []);\n\n const headerCollapsed = useDerivedValue(() => {\n const maxY = fixedHeaderHeight.value - firstStickyViewY.value;\n return scrollY.value >= maxY;\n }, []);\n\n const contentMinHeight = useDerivedValue(() => {\n return (\n containerHeight.value +\n fixedHeaderHeight.value -\n stickyHeaderHeight.value\n );\n }, []);\n\n useAnimatedReaction(\n () => {\n const totalHeight = Object.keys(stickyViewPositions.value).reduce(\n (acc, item) => {\n return acc + stickyViewPositions.value[item].top;\n },\n 0\n );\n return totalHeight - fixedHeaderHeight.value;\n },\n (result, previous) => {\n if (result !== previous) {\n const viewPositions = stickyViewPositions.value;\n const headerHeight = fixedHeaderHeight.value;\n const sortedKeys = Object.keys(viewPositions).sort(\n (a, b) => viewPositions[a].top - viewPositions[b].top\n );\n let totalTop = 0;\n const values: any = {};\n for (let i = 0; i < sortedKeys.length; i++) {\n values[sortedKeys[i]] = totalTop;\n // Try minus 1 make it filled when scrolling up.\n // Otherwise, we can see a small space between the persits views\n totalTop += viewPositions[sortedKeys[i]].height - 1;\n }\n stickyViewTops.value = values;\n firstStickyViewY.value = viewPositions[sortedKeys[0]]?.top || 0;\n const stickyHeader = sortedKeys.reduce((acc, key) => {\n const data = viewPositions[key];\n const isInsideHeader = data.top < headerHeight;\n if (isInsideHeader) {\n return acc + data.height;\n }\n return acc;\n }, 0);\n stickyHeaderHeight.value = stickyHeader;\n }\n }\n );\n\n const handleStickyViewLayout = useCallback(\n (viewKey: string, viewRef?: React.RefObject<View>) => {\n if (viewRef && viewRef.current && containerRef.current) {\n stickyViewRefs.current[viewKey] = viewRef;\n viewRef.current.measureLayout(\n // @ts-ignore\n containerRef.current,\n (left, top, width, height) => {\n stickyViewPositionsRef.current = {\n ...stickyViewPositionsRef.current,\n [viewKey]: { left, top, width, height },\n };\n stickyViewPositions.value = stickyViewPositionsRef.current;\n },\n () => {}\n );\n } else {\n delete stickyViewRefs.current[viewKey];\n delete stickyViewPositionsRef.current[viewKey];\n stickyViewPositions.value = stickyViewPositionsRef.current;\n }\n },\n []\n );\n\n const debounceRefreshStickyPositions = useMemo(() => {\n return debounce(() => {\n Object.keys(stickyViewRefs.current).forEach((key) => {\n const viewRef = stickyViewRefs.current[key];\n if (viewRef) {\n handleStickyViewLayout(key, viewRef);\n }\n });\n }, 200);\n }, []);\n\n const handleHeaderContainerLayout = useCallback(\n (viewKey: string, height?: number) => {\n if (!height) {\n delete headerContainersHeight.current[viewKey];\n } else {\n headerContainersHeight.current[viewKey] = height;\n }\n const totalHeight = Object.keys(headerContainersHeight.current).reduce(\n (acc, key) => headerContainersHeight.current[key] + acc,\n 0\n );\n headerHeight.value = withTiming(totalHeight, {\n duration: fixedHeaderHeight.value === 0 ? 0 : 200,\n });\n fixedHeaderHeight.value = totalHeight;\n // Try refresh sticky positions\n debounceRefreshStickyPositions();\n },\n []\n );\n\n const handleContainerHeight = useCallback((height: number) => {\n containerHeight.value = height;\n }, []);\n\n const context = useMemo(() => {\n return {\n collapse: () => collapsibleHandlers.current?.collapse(),\n expand: () => collapsibleHandlers.current?.expand(),\n scrollTo: (offset: number, animate?: boolean) =>\n collapsibleHandlers.current?.scrollTo(offset, animate),\n headerHeight,\n scrollY,\n headerCollapsed,\n };\n }, [scrollY, headerHeight, headerCollapsed]);\n\n const internalContext = useMemo(\n () => ({\n containerRef,\n handleStickyViewLayout,\n handleHeaderContainerLayout,\n setCollapsibleHandlers,\n handleContainerHeight,\n firstStickyViewY,\n stickyViewTops,\n stickyViewPositions,\n fixedHeaderHeight,\n contentMinHeight,\n }),\n [\n setCollapsibleHandlers,\n handleStickyViewLayout,\n handleHeaderContainerLayout,\n handleContainerHeight,\n firstStickyViewY,\n stickyViewTops,\n stickyViewPositions,\n fixedHeaderHeight,\n contentMinHeight,\n ]\n );\n\n return (\n <CollapsibleContext.Provider value={context}>\n <InternalCollapsibleContext.Provider value={internalContext}>\n <PullToRefreshProvider>\n <Component {...props} />\n </PullToRefreshProvider>\n </InternalCollapsibleContext.Provider>\n </CollapsibleContext.Provider>\n );\n };\n}\n"]}
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React, { useCallback } from 'react';
4
4
  import { StyleSheet, View } from 'react-native';
5
- import { useInternalCollapsibleContext } from '../hooks/useInternalCollapsibleContext';
5
+ import useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';
6
6
  export default function CollapsibleContainer({
7
7
  children,
8
8
  ...props
@@ -1 +1 @@
1
- {"version":3,"sources":["CollapsibleContainer.tsx"],"names":["React","useCallback","StyleSheet","View","useInternalCollapsibleContext","CollapsibleContainer","children","props","containerRef","handleContainerHeight","handleContainerLayout","layout","height","nativeEvent","styles","container","style","create","flex","overflow"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,SAA4BC,UAA5B,EAAwCC,IAAxC,QAA+D,cAA/D;AACA,SAASC,6BAAT,QAA8C,wCAA9C;AAMA,eAAe,SAASC,oBAAT,CAA8B;AAAEC,EAAAA,QAAF;AAAY,KAAGC;AAAf,CAA9B,EAA6D;AAC1E,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MACJL,6BAA6B,EAD/B;AAGA,QAAMM,qBAAqB,GAAGT,WAAW,CACtCU,MAAD,IAA+B;AAC7B,UAAMC,MAAM,GAAGD,MAAM,CAACE,WAAP,CAAmBF,MAAnB,CAA0BC,MAAzC;AACAH,IAAAA,qBAAqB,CAACG,MAAD,CAArB;AACD,GAJsC,EAKvC,CAACH,qBAAD,CALuC,CAAzC;AAQA,sBACE,oBAAC,IAAD,eACMF,KADN;AAEE,IAAA,GAAG,EAAEC,YAFP;AAGE,IAAA,KAAK,EAAE,CAACM,MAAM,CAACC,SAAR,EAAmBR,KAAK,CAACS,KAAzB,CAHT;AAIE,IAAA,QAAQ,EAAEN;AAJZ,MAMGJ,QANH,CADF;AAUD;AAED,MAAMQ,MAAM,GAAGZ,UAAU,CAACe,MAAX,CAAkB;AAC/BF,EAAAA,SAAS,EAAE;AACTG,IAAAA,IAAI,EAAE,CADG;AAETC,IAAAA,QAAQ,EAAE;AAFD;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback } from 'react';\nimport { LayoutChangeEvent, StyleSheet, View, ViewProps } from 'react-native';\nimport { useInternalCollapsibleContext } from '../hooks/useInternalCollapsibleContext';\n\ntype Props = Omit<ViewProps, 'ref' | 'onLayout'> & {\n children: Element;\n};\n\nexport default function CollapsibleContainer({ children, ...props }: Props) {\n const { containerRef, handleContainerHeight } =\n useInternalCollapsibleContext();\n\n const handleContainerLayout = useCallback(\n (layout: LayoutChangeEvent) => {\n const height = layout.nativeEvent.layout.height;\n handleContainerHeight(height);\n },\n [handleContainerHeight]\n );\n\n return (\n <View\n {...props}\n ref={containerRef}\n style={[styles.container, props.style]}\n onLayout={handleContainerLayout}\n >\n {children}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"]}
1
+ {"version":3,"sources":["CollapsibleContainer.tsx"],"names":["React","useCallback","StyleSheet","View","useInternalCollapsibleContext","CollapsibleContainer","children","props","containerRef","handleContainerHeight","handleContainerLayout","layout","height","nativeEvent","styles","container","style","create","flex","overflow"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,SAA4BC,UAA5B,EAAwCC,IAAxC,QAA+D,cAA/D;AACA,OAAOC,6BAAP,MAA0C,wCAA1C;AAMA,eAAe,SAASC,oBAAT,CAA8B;AAAEC,EAAAA,QAAF;AAAY,KAAGC;AAAf,CAA9B,EAA6D;AAC1E,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MACJL,6BAA6B,EAD/B;AAGA,QAAMM,qBAAqB,GAAGT,WAAW,CACtCU,MAAD,IAA+B;AAC7B,UAAMC,MAAM,GAAGD,MAAM,CAACE,WAAP,CAAmBF,MAAnB,CAA0BC,MAAzC;AACAH,IAAAA,qBAAqB,CAACG,MAAD,CAArB;AACD,GAJsC,EAKvC,CAACH,qBAAD,CALuC,CAAzC;AAQA,sBACE,oBAAC,IAAD,eACMF,KADN;AAEE,IAAA,GAAG,EAAEC,YAFP;AAGE,IAAA,KAAK,EAAE,CAACM,MAAM,CAACC,SAAR,EAAmBR,KAAK,CAACS,KAAzB,CAHT;AAIE,IAAA,QAAQ,EAAEN;AAJZ,MAMGJ,QANH,CADF;AAUD;AAED,MAAMQ,MAAM,GAAGZ,UAAU,CAACe,MAAX,CAAkB;AAC/BF,EAAAA,SAAS,EAAE;AACTG,IAAAA,IAAI,EAAE,CADG;AAETC,IAAAA,QAAQ,EAAE;AAFD;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback } from 'react';\nimport { LayoutChangeEvent, StyleSheet, View, ViewProps } from 'react-native';\nimport useInternalCollapsibleContext from '../hooks/useInternalCollapsibleContext';\n\ntype Props = Omit<ViewProps, 'ref' | 'onLayout'> & {\n children: Element;\n};\n\nexport default function CollapsibleContainer({ children, ...props }: Props) {\n const { containerRef, handleContainerHeight } =\n useInternalCollapsibleContext();\n\n const handleContainerLayout = useCallback(\n (layout: LayoutChangeEvent) => {\n const height = layout.nativeEvent.layout.height;\n handleContainerHeight(height);\n },\n [handleContainerHeight]\n );\n\n return (\n <View\n {...props}\n ref={containerRef}\n style={[styles.container, props.style]}\n onLayout={handleContainerLayout}\n >\n {children}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"]}
@@ -31,7 +31,7 @@ export default function CollapsibleView({
31
31
  });
32
32
  }, []);
33
33
  const handleLayout = useCallback(event => {
34
- if (event.nativeEvent.layout.height > 0) {
34
+ if (event.nativeEvent.layout.height >= 0) {
35
35
  actualHeight.value = event.nativeEvent.layout.height;
36
36
  }
37
37
  }, []);
@@ -97,7 +97,7 @@ export function CollapsibleHeaderText({
97
97
  return /*#__PURE__*/React.createElement(TouchableOpacity, {
98
98
  activeOpacity: 0.9,
99
99
  onPress: onToggle,
100
- style: [style]
100
+ style: style
101
101
  }, /*#__PURE__*/React.createElement(View, {
102
102
  style: styles.headerContainer
103
103
  }, /*#__PURE__*/React.createElement(Text, {
@@ -112,7 +112,8 @@ const styles = StyleSheet.create({
112
112
  },
113
113
  content: {},
114
114
  headerContainer: {
115
- flexDirection: 'row'
115
+ flexDirection: 'row',
116
+ alignItems: 'center'
116
117
  },
117
118
  headerTitle: {
118
119
  flex: 1
@@ -1 +1 @@
1
- {"version":3,"sources":["CollapsibleView.tsx"],"names":["React","useCallback","useEffect","useMemo","StyleSheet","Text","TouchableOpacity","View","Animated","useAnimatedStyle","useSharedValue","withSpring","interpolateColor","interpolate","key","CollapsibleView","initialState","collapseState","renderHeader","children","containerStyle","collapsedBackgroundColor","expandedBackgroundColor","actualHeight","contentKey","newValue","value","onToggle","overshootClamping","handleLayout","event","nativeEvent","layout","height","wrapperStyle","damping","stiffness","contentHeight","undefined","containerAnimatedStyle","backgroundColor","headerProps","collapsed","styles","wrapper","content","CollapsibleHeaderText","title","style","titleStyle","icon","iconInitialAngle","iconStyle","rotate","transform","headerContainer","headerTitle","create","overflow","flexDirection","flex"],"mappings":"AAAA;;AACA;AACA,OAAOA,KAAP,IAA2BC,WAA3B,EAAwCC,SAAxC,EAAmDC,OAAnD,QAAkE,OAAlE;AACA,SAGEC,UAHF,EAIEC,IAJF,EAMEC,gBANF,EAOEC,IAPF,QASO,cATP;AAUA,OAAOC,QAAP,IACEC,gBADF,EAEEC,cAFF,EAGEC,UAHF,EAIEC,gBAJF,EAKEC,WALF,QAMO,yBANP;AAwBA,IAAIC,GAAG,GAAG,CAAV;AACA,eAAe,SAASC,eAAT,CAAyB;AACtCC,EAAAA,YAAY,GAAG,WADuB;AAEtCC,EAAAA,aAAa,GAAGP,cAAc,CAAC,CAAD,CAFQ;AAGtCQ,EAAAA,YAHsC;AAItCC,EAAAA,QAJsC;AAKtCC,EAAAA,cALsC;AAMtCC,EAAAA,wBANsC;AAOtCC,EAAAA;AAPsC,CAAzB,EAQL;AACR,QAAMC,YAAY,GAAGb,cAAc,CAAC,KAAD,CAAnC;AACA,QAAMc,UAAU,GAAGrB,OAAO,CAAC,MAAO,oBAAmBW,GAAG,EAAG,EAAjC,EAAoC,EAApC,CAA1B;AAEAZ,EAAAA,SAAS,CAAC,MAAM;AACd,UAAMuB,QAAQ,GAAGT,YAAY,KAAK,WAAjB,GAA+B,CAA/B,GAAmC,CAApD;;AACA,QAAIS,QAAQ,KAAKR,aAAa,CAACS,KAA/B,EAAsC;AACpC;AACD;;AACDT,IAAAA,aAAa,CAACS,KAAd,GAAsBD,QAAtB;AAC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C,EAAAA;AARoC,CAA/B,EAgBqB;AAC1B,QAAMiC,SAAS,GAAG3C,gBAAgB,CAAC,MAAM;AACvC,UAAM4C,MAAM,GAAGxC,WAAW,CACxB6B,SAAS,CAAChB,KADc,EAExB,CAAC,CAAD,EAAI,CAAJ,CAFwB,EAGxB,CAACyB,gBAAD,EAAmB,GAAnB,CAHwB,CAA1B;AAKA,WAAO;AACLG,MAAAA,SAAS,EAAE,CACT;AACED,QAAAA,MAAM,EAAG,GAAEA,MAAO;AADpB,OADS;AADN,KAAP;AAOD,GAbiC,EAa/B,CAACF,gBAAD,CAb+B,CAAlC;AAeA,sBACE,oBAAC,gBAAD;AAAkB,IAAA,aAAa,EAAE,GAAjC;AAAsC,IAAA,OAAO,EAAExB,QAA/C;AAAyD,IAAA,KAAK,EAAE,CAACqB,KAAD;AAAhE,kBACE,oBAAC,IAAD;AAAM,IAAA,KAAK,EAAEL,MAAM,CAACY;AAApB,kBACE,oBAAC,IAAD;AAAM,IAAA,KAAK,EAAE,CAACZ,MAAM,CAACa,WAAR,EAAqBP,UAArB;AAAb,KAAgDF,KAAhD,CADF,EAEGG,IAAI,iBAAI,oBAAC,QAAD,CAAU,IAAV;AAAe,IAAA,KAAK,EAAEE;AAAtB,KAAkCF,IAAlC,CAFX,CADF,EAKG/B,QALH,CADF;AASD;AAED,MAAMwB,MAAM,GAAGvC,UAAU,CAACqD,MAAX,CAAkB;AAC/Bb,EAAAA,OAAO,EAAE;AACPc,IAAAA,QAAQ,EAAE;AADH,GADsB;AAI/Bb,EAAAA,OAAO,EAAE,EAJsB;AAK/BU,EAAAA,eAAe,EAAE;AACfI,IAAAA,aAAa,EAAE;AADA,GALc;AAQ/BH,EAAAA,WAAW,EAAE;AACXI,IAAAA,IAAI,EAAE;AADK;AARkB,CAAlB,CAAf","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\n/* eslint-disable react-hooks/rules-of-hooks */\nimport React, { ReactNode, useCallback, useEffect, useMemo } from 'react';\nimport {\n LayoutChangeEvent,\n StyleProp,\n StyleSheet,\n Text,\n TextStyle,\n TouchableOpacity,\n View,\n ViewStyle,\n} from 'react-native';\nimport Animated, {\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n interpolateColor,\n interpolate,\n} from 'react-native-reanimated';\n\nexport type CollapsibleHeaderProps = {\n onToggle: () => void;\n collapsed: Animated.SharedValue<number>;\n};\n\ntype Props = {\n initialState?: 'collapsed' | 'expanded';\n collapseState?: Animated.SharedValue<number>;\n renderHeader: (props: CollapsibleHeaderProps) => ReactNode;\n children: ReactNode;\n containerStyle?: StyleProp<ViewStyle>;\n collapsedBackgroundColor?: string;\n expandedBackgroundColor?: string;\n useDynamicLayout?: boolean;\n};\n\nlet key = 0;\nexport default function CollapsibleView({\n initialState = 'collapsed',\n collapseState = useSharedValue(0),\n renderHeader,\n children,\n containerStyle,\n collapsedBackgroundColor,\n expandedBackgroundColor,\n}: Props) {\n const actualHeight = useSharedValue(11110);\n const contentKey = useMemo(() => `collapsible-view-${key++}`, []);\n\n useEffect(() => {\n const newValue = initialState === 'collapsed' ? 0 : 1;\n if (newValue === collapseState.value) {\n return;\n }\n collapseState.value = newValue;\n }, [initialState]);\n\n const onToggle = useCallback(() => {\n collapseState.value = withSpring(collapseState.value === 0 ? 1 : 0, {\n overshootClamping: true,\n });\n }, []);\n\n const handleLayout = useCallback((event: LayoutChangeEvent) => {\n if (event.nativeEvent.layout.height > 0) {\n actualHeight.value = event.nativeEvent.layout.height;\n }\n }, []);\n\n const wrapperStyle = useAnimatedStyle(\n () => ({\n height: withSpring(collapseState.value === 1 ? actualHeight.value : 0, {\n damping: 5,\n stiffness: 130,\n overshootClamping: true,\n }),\n }),\n [actualHeight, contentKey]\n );\n\n const contentHeight = useAnimatedStyle(\n () => ({\n height: actualHeight.value > 0 ? actualHeight.value : undefined,\n }),\n [actualHeight, contentKey]\n );\n\n // @ts-ignore\n const containerAnimatedStyle = useAnimatedStyle(() => {\n if (collapsedBackgroundColor && expandedBackgroundColor) {\n return {\n backgroundColor: interpolateColor(\n collapseState.value,\n [0, 1],\n [collapsedBackgroundColor, expandedBackgroundColor]\n ),\n };\n }\n return {};\n }, []);\n\n const headerProps = useMemo(\n () => ({ onToggle, collapsed: collapseState }),\n [onToggle, collapseState]\n );\n\n return (\n <Animated.View\n style={[containerStyle, containerAnimatedStyle]}\n pointerEvents=\"box-none\"\n >\n <View pointerEvents=\"box-none\">{renderHeader(headerProps)}</View>\n <Animated.View\n style={[styles.wrapper, wrapperStyle]}\n pointerEvents=\"box-none\"\n >\n <Animated.View\n style={[styles.content, contentHeight]}\n pointerEvents=\"box-none\"\n >\n <View\n key={contentKey}\n onLayout={handleLayout}\n pointerEvents=\"box-none\"\n >\n {children}\n </View>\n </Animated.View>\n </Animated.View>\n </Animated.View>\n );\n}\n\nexport function CollapsibleHeaderText({\n title,\n collapsed,\n onToggle,\n style,\n titleStyle,\n icon,\n iconInitialAngle = 0,\n children,\n}: {\n title: string;\n style?: StyleProp<ViewStyle>;\n titleStyle?: StyleProp<TextStyle>;\n icon?: ReactNode;\n iconInitialAngle?: number;\n children?: ReactNode;\n} & CollapsibleHeaderProps) {\n const iconStyle = useAnimatedStyle(() => {\n const rotate = interpolate(\n collapsed.value,\n [0, 1],\n [iconInitialAngle, 180]\n );\n return {\n transform: [\n {\n rotate: `${rotate}deg`,\n },\n ],\n };\n }, [iconInitialAngle]);\n\n return (\n <TouchableOpacity activeOpacity={0.9} onPress={onToggle} style={[style]}>\n <View style={styles.headerContainer}>\n <Text style={[styles.headerTitle, titleStyle]}>{title}</Text>\n {icon && <Animated.View style={iconStyle}>{icon}</Animated.View>}\n </View>\n {children}\n </TouchableOpacity>\n );\n}\n\nconst styles = StyleSheet.create({\n wrapper: {\n overflow: 'hidden',\n },\n content: {},\n headerContainer: {\n flexDirection: 'row',\n },\n headerTitle: {\n flex: 1,\n },\n});\n"]}
1
+ {"version":3,"sources":["CollapsibleView.tsx"],"names":["React","useCallback","useEffect","useMemo","StyleSheet","Text","TouchableOpacity","View","Animated","useAnimatedStyle","useSharedValue","withSpring","interpolateColor","interpolate","key","CollapsibleView","initialState","collapseState","renderHeader","children","containerStyle","collapsedBackgroundColor","expandedBackgroundColor","actualHeight","contentKey","newValue","value","onToggle","overshootClamping","handleLayout","event","nativeEvent","layout","height","wrapperStyle","damping","stiffness","contentHeight","undefined","containerAnimatedStyle","backgroundColor","headerProps","collapsed","styles","wrapper","content","CollapsibleHeaderText","title","style","titleStyle","icon","iconInitialAngle","iconStyle","rotate","transform","headerContainer","headerTitle","create","overflow","flexDirection","alignItems","flex"],"mappings":"AAAA;;AACA;AACA,OAAOA,KAAP,IAA2BC,WAA3B,EAAwCC,SAAxC,EAAmDC,OAAnD,QAAkE,OAAlE;AACA,SAGEC,UAHF,EAIEC,IAJF,EAMEC,gBANF,EAOEC,IAPF,QASO,cATP;AAUA,OAAOC,QAAP,IACEC,gBADF,EAEEC,cAFF,EAGEC,UAHF,EAIEC,gBAJF,EAKEC,WALF,QAMO,yBANP;AAwBA,IAAIC,GAAG,GAAG,CAAV;AACA,eAAe,SAASC,eAAT,CAAyB;AACtCC,EAAAA,YAAY,GAAG,WADuB;AAEtCC,EAAAA,aAAa,GAAGP,cAAc,CAAC,CAAD,CAFQ;AAGtCQ,EAAAA,YAHsC;AAItCC,EAAAA,QAJsC;AAKtCC,EAAAA,cALsC;AAMtCC,EAAAA,wBANsC;AAOtCC,EAAAA;AAPsC,CAAzB,EAQL;AACR,QAAMC,YAAY,GAAGb,cAAc,CAAC,KAAD,CAAnC;AACA,QAAMc,UAAU,GAAGrB,OAAO,CAAC,MAAO,oBAAmBW,GAAG,EAAG,EAAjC,EAAoC,EAApC,CAA1B;AAEAZ,EAAAA,SAAS,CAAC,MAAM;AACd,UAAMuB,QAAQ,GAAGT,YAAY,KAAK,WAAjB,GAA+B,CAA/B,GAAmC,CAApD;;AACA,QAAIS,QAAQ,KAAKR,aAAa,CAACS,KAA/B,EAAsC;AACpC;AACD;;AACDT,IAAAA,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ules-of-hooks */\nimport React, { ReactNode, useCallback, useEffect, useMemo } from 'react';\nimport {\n LayoutChangeEvent,\n StyleProp,\n StyleSheet,\n Text,\n TextStyle,\n TouchableOpacity,\n View,\n ViewStyle,\n} from 'react-native';\nimport Animated, {\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n interpolateColor,\n interpolate,\n} from 'react-native-reanimated';\n\nexport type CollapsibleHeaderProps = {\n onToggle: () => void;\n collapsed: Animated.SharedValue<number>;\n};\n\ntype Props = {\n initialState?: 'collapsed' | 'expanded';\n collapseState?: Animated.SharedValue<number>;\n renderHeader: (props: CollapsibleHeaderProps) => ReactNode;\n children: ReactNode;\n containerStyle?: StyleProp<ViewStyle>;\n collapsedBackgroundColor?: string;\n expandedBackgroundColor?: string;\n useDynamicLayout?: boolean;\n};\n\nlet key = 0;\nexport default function CollapsibleView({\n initialState = 'collapsed',\n collapseState = useSharedValue(0),\n renderHeader,\n children,\n containerStyle,\n collapsedBackgroundColor,\n expandedBackgroundColor,\n}: Props) {\n const actualHeight = useSharedValue(11110);\n const contentKey = useMemo(() => `collapsible-view-${key++}`, []);\n\n useEffect(() => {\n const newValue = initialState === 'collapsed' ? 0 : 1;\n if (newValue === collapseState.value) {\n return;\n }\n collapseState.value = newValue;\n }, [initialState]);\n\n const onToggle = useCallback(() => {\n collapseState.value = withSpring(collapseState.value === 0 ? 1 : 0, {\n overshootClamping: true,\n });\n }, []);\n\n const handleLayout = useCallback((event: LayoutChangeEvent) => {\n if (event.nativeEvent.layout.height >= 0) {\n actualHeight.value = event.nativeEvent.layout.height;\n }\n }, []);\n\n const wrapperStyle = useAnimatedStyle(\n () => ({\n height: withSpring(collapseState.value === 1 ? actualHeight.value : 0, {\n damping: 5,\n stiffness: 130,\n overshootClamping: true,\n }),\n }),\n [actualHeight, contentKey]\n );\n\n const contentHeight = useAnimatedStyle(\n () => ({\n height: actualHeight.value > 0 ? actualHeight.value : undefined,\n }),\n [actualHeight, contentKey]\n );\n\n // @ts-ignore\n const containerAnimatedStyle = useAnimatedStyle(() => {\n if (collapsedBackgroundColor && expandedBackgroundColor) {\n return {\n backgroundColor: interpolateColor(\n collapseState.value,\n [0, 1],\n [collapsedBackgroundColor, expandedBackgroundColor]\n ),\n };\n }\n return {};\n }, []);\n\n const headerProps = useMemo(\n () => ({ onToggle, collapsed: collapseState }),\n [onToggle, collapseState]\n );\n\n return (\n <Animated.View\n style={[containerStyle, containerAnimatedStyle]}\n pointerEvents=\"box-none\"\n >\n <View pointerEvents=\"box-none\">{renderHeader(headerProps)}</View>\n <Animated.View\n style={[styles.wrapper, wrapperStyle]}\n pointerEvents=\"box-none\"\n >\n <Animated.View\n style={[styles.content, contentHeight]}\n pointerEvents=\"box-none\"\n >\n <View\n key={contentKey}\n onLayout={handleLayout}\n pointerEvents=\"box-none\"\n >\n {children}\n </View>\n </Animated.View>\n </Animated.View>\n </Animated.View>\n );\n}\n\nexport function CollapsibleHeaderText({\n title,\n collapsed,\n onToggle,\n style,\n titleStyle,\n icon,\n iconInitialAngle = 0,\n children,\n}: {\n title: string | Element;\n style?: StyleProp<ViewStyle>;\n titleStyle?: StyleProp<TextStyle>;\n icon?: ReactNode;\n iconInitialAngle?: number;\n children?: ReactNode;\n} & CollapsibleHeaderProps) {\n const iconStyle = useAnimatedStyle(() => {\n const rotate = interpolate(\n collapsed.value,\n [0, 1],\n [iconInitialAngle, 180]\n );\n return {\n transform: [\n {\n rotate: `${rotate}deg`,\n },\n ],\n };\n }, [iconInitialAngle]);\n\n return (\n <TouchableOpacity activeOpacity={0.9} onPress={onToggle} style={style}>\n <View style={styles.headerContainer}>\n <Text style={[styles.headerTitle, titleStyle]}>{title}</Text>\n {icon && <Animated.View style={iconStyle}>{icon}</Animated.View>}\n </View>\n {children}\n </TouchableOpacity>\n );\n}\n\nconst styles = StyleSheet.create({\n wrapper: {\n overflow: 'hidden',\n },\n content: {},\n headerContainer: {\n flexDirection: 'row',\n alignItems: 'center',\n },\n headerTitle: {\n flex: 1,\n },\n});\n"]}
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable react-hooks/exhaustive-deps */
2
- import { useInternalCollapsibleContext } from '../hooks/useInternalCollapsibleContext';
2
+ import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
3
3
  import React, { useCallback, useEffect, useMemo } from 'react';
4
- import { StyleSheet, View } from 'react-native';
4
+ import { Platform, StyleSheet, View } from 'react-native';
5
5
  import Animated, { interpolate, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
6
- import useCollapsibleContext from '../hooks/useCollapsibleContext';
6
+ import useCollapsibleContext from '../../hooks/useCollapsibleContext';
7
7
  let key = 0;
8
8
  export default function CollapsibleHeaderContainer({
9
9
  children,
@@ -48,18 +48,19 @@ export default function CollapsibleHeaderContainer({
48
48
  };
49
49
  }, []);
50
50
  return /*#__PURE__*/React.createElement(Animated.View, {
51
- style: [styles.container, headerStyle, internalStyle],
51
+ style: [headerStyle, internalStyle],
52
52
  pointerEvents: "box-none"
53
53
  }, /*#__PURE__*/React.createElement(View, {
54
54
  key: contentKey,
55
55
  onLayout: handleHeaderLayout,
56
56
  pointerEvents: "box-none",
57
- style: containerStyle
57
+ style: [styles.container, containerStyle]
58
58
  }, children));
59
59
  }
60
60
  const styles = StyleSheet.create({
61
61
  container: {
62
- backgroundColor: 'white'
62
+ backgroundColor: 'white',
63
+ marginTop: Platform.OS === 'android' ? -1 : 0
63
64
  }
64
65
  });
65
66
  //# sourceMappingURL=CollapsibleHeaderContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["CollapsibleHeaderContainer.tsx"],"names":["useInternalCollapsibleContext","React","useCallback","useEffect","useMemo","Platform","StyleSheet","View","Animated","interpolate","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","useCollapsibleContext","key","CollapsibleHeaderContainer","children","containerStyle","contentKey","scrollY","handleHeaderContainerLayout","headerHeight","undefined","handleHeaderLayout","nativeEvent","layout","height","value","duration","headerTranslate","Extrapolate","CLAMP","headerStyle","transform","translateY","minHeight","internalStyle","zIndex","styles","container","create","backgroundColor","marginTop","OS"],"mappings":"AAAA;AACA,OAAOA,6BAAP,MAA0C,2CAA1C;AACA,OAAOC,KAAP,IAA2BC,WAA3B,EAAwCC,SAAxC,EAAmDC,OAAnD,QAAkE,OAAlE;AACA,SAEEC,QAFF,EAIEC,UAJF,EAKEC,IALF,QAOO,cAPP;AAQA,OAAOC,QAAP,IACEC,WADF,EAEEC,gBAFF,EAGEC,eAHF,EAIEC,cAJF,EAKEC,UALF,QAMO,yBANP;AAOA,OAAOC,qBAAP,MAAkC,mCAAlC;AAOA,IAAIC,GAAG,GAAG,CAAV;AAEA,eAAe,SAASC,0BAAT,CAAoC;AACjDC,EAAAA,QADiD;AAEjDC,EAAAA;AAFiD,CAApC,EAGL;AACR,QAAMC,UAAU,GAAGf,OAAO,CAAC,MAAO,sBAAqBW,GAAG,EAAG,EAAnC,EAAsC,EAAtC,CAA1B;AACA,QAAM;AAAEK,IAAAA;AAAF,MAAcN,qBAAqB,EAAzC;AACA,QAAM;AAAEO,IAAAA;AAAF,MAAkCrB,6BAA6B,EAArE;AACA,QAAMsB,YAAY,GAAGV,cAAc,CAAC,CAAD,CAAnC;AAEAT,EAAAA,SAAS,CAAC,MAAM;AACd,WAAO,MAAMkB,2BAA2B,CAACF,UAAD,EAAaI,SAAb,CAAxC;AACD,GAFQ,EAEN,EAFM,CAAT;AAIA,QAAMC,kBAAkB,GAAGtB,WAAW,CACpC,CAAC;AACCuB,IAAAA,WAAW,EAAE;AACXC,MAAAA,MAAM,EAAE;AAAEC,QAAAA;AAAF;AADG;AADd,GAAD,KAIyB;AACvBL,IAAAA,YAAY,CAACM,KAAb,GAAqBf,UAAU,CAACc,MAAD,EAAS;AACtCE,MAAAA,QAAQ,EAAE;AAD4B,KAAT,CAA/B;AAGAR,IAAAA,2BAA2B,CAACF,UAAD,EAAaQ,MAAb,CAA3B;AACD,GAVmC,EAWpC,CAACR,UAAD,EAAaE,2BAA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lB,CAAf","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\nimport React, { ReactNode, useCallback, useEffect, useMemo } from 'react';\nimport {\n LayoutChangeEvent,\n Platform,\n StyleProp,\n StyleSheet,\n View,\n ViewStyle,\n} from 'react-native';\nimport Animated, {\n interpolate,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\n\ntype Props = {\n children: ReactNode;\n containerStyle?: StyleProp<ViewStyle>;\n};\n\nlet key = 0;\n\nexport default function CollapsibleHeaderContainer({\n children,\n containerStyle,\n}: Props) {\n const contentKey = useMemo(() => `collapsible-header-${key++}`, []);\n const { scrollY } = useCollapsibleContext();\n const { handleHeaderContainerLayout } = useInternalCollapsibleContext();\n const headerHeight = useSharedValue(0);\n\n useEffect(() => {\n return () => handleHeaderContainerLayout(contentKey, undefined);\n }, []);\n\n const handleHeaderLayout = useCallback(\n ({\n nativeEvent: {\n layout: { height },\n },\n }: LayoutChangeEvent) => {\n headerHeight.value = withTiming(height, {\n duration: 200,\n });\n handleHeaderContainerLayout(contentKey, height);\n },\n [contentKey, handleHeaderContainerLayout]\n );\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 minHeight: headerHeight.value,\n };\n }, [headerHeight, headerTranslate]);\n\n const internalStyle = useMemo(() => {\n return {\n zIndex: 100000 - key,\n };\n }, []);\n\n return (\n <Animated.View\n style={[headerStyle, internalStyle]}\n pointerEvents=\"box-none\"\n >\n <View\n key={contentKey}\n onLayout={handleHeaderLayout}\n pointerEvents=\"box-none\"\n style={[styles.container, containerStyle]}\n >\n {children}\n </View>\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: 'white',\n marginTop: Platform.OS === 'android' ? -1 : 0,\n },\n});\n"]}
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable react-hooks/exhaustive-deps */
2
- import { useInternalCollapsibleContext } from '../hooks/useInternalCollapsibleContext';
3
2
  import React, { useCallback, useEffect, useMemo, useRef } from 'react';
4
3
  import { StyleSheet } from 'react-native';
5
- import useCollapsibleContext from '../hooks/useCollapsibleContext';
6
- import Animated, { Extrapolate, interpolate, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
4
+ import useCollapsibleContext from '../../hooks/useCollapsibleContext';
5
+ import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
6
+ import Animated, { Extrapolate, interpolate, useAnimatedStyle, useDerivedValue } from 'react-native-reanimated';
7
7
  let stickyKey = 0;
8
8
  export default function StickyView({
9
9
  children,
@@ -12,47 +12,34 @@ export default function StickyView({
12
12
  const key = useMemo(() => `sticky_${stickyKey++}`, []);
13
13
  const viewRef = useRef(null);
14
14
  const {
15
- containerRef,
16
15
  handleStickyViewLayout,
17
- stickyViewTops
16
+ stickyViewTops,
17
+ stickyViewPositions
18
18
  } = useInternalCollapsibleContext();
19
19
  const {
20
20
  scrollY
21
21
  } = useCollapsibleContext();
22
- const layoutValues = useSharedValue({
23
- top: 0,
24
- height: 0
25
- });
26
22
  useEffect(() => {
27
23
  return () => handleStickyViewLayout(key, undefined);
28
24
  }, []);
29
25
  const handleLayout = useCallback(() => {
30
- if (viewRef.current && containerRef.current) {
31
- viewRef.current.measureLayout( // @ts-ignore
32
- containerRef.current, (left, top, width, height) => {
33
- handleStickyViewLayout(key, {
34
- left,
35
- top,
36
- width,
37
- height
38
- });
39
- layoutValues.value = {
40
- top,
41
- height
42
- };
43
- }, () => {});
44
- }
45
- }, [handleStickyViewLayout]);
46
- const animatedStyle = useAnimatedStyle(() => {
26
+ handleStickyViewLayout(key, viewRef);
27
+ }, [handleStickyViewLayout, key]);
28
+ const translateY = useDerivedValue(() => {
47
29
  const top = stickyViewTops.value[key] || 0;
48
- const inputMid = layoutValues.value.top - top;
49
- const translateY = interpolate(scrollY.value, [0, inputMid, inputMid + 100000], [0, 0, 100000], Extrapolate.CLAMP);
30
+ const layoutValues = stickyViewPositions.value[key] || {
31
+ top: 0
32
+ };
33
+ const inputMid = layoutValues.top - top;
34
+ return interpolate(scrollY.value, [0, inputMid, inputMid + 100000], [0, 0, 100000], Extrapolate.CLAMP);
35
+ }, []);
36
+ const animatedStyle = useAnimatedStyle(() => {
50
37
  return {
51
38
  transform: [{
52
- translateY: translateY
39
+ translateY: translateY.value
53
40
  }]
54
41
  };
55
- }, [stickyViewTops, layoutValues, scrollY]);
42
+ }, []);
56
43
  return /*#__PURE__*/React.createElement(Animated.View, {
57
44
  key: key // @ts-ignore
58
45
  ,
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["StickyView.tsx"],"names":["React","useCallback","useEffect","useMemo","useRef","StyleSheet","useCollapsibleContext","useInternalCollapsibleContext","Animated","Extrapolate","interpolate","useAnimatedStyle","useDerivedValue","stickyKey","StickyView","children","style","key","viewRef","handleStickyViewLayout","stickyViewTops","stickyViewPositions","scrollY","undefined","handleLayout","translateY","top","value","layoutValues","inputMid","CLAMP","animatedStyle","transform","styles","container","create","backgroundColor","zIndex"],"mappings":"AAAA;AACA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,OAAxC,EAAiDC,MAAjD,QAA+D,OAA/D;AACA,SAAoBC,UAApB,QAAuD,cAAvD;AACA,OAAOC,qBAAP,MAAkC,mCAAlC;AACA,OAAOC,6BAAP,MAA0C,2CAA1C;AACA,OAAOC,QAAP,IACEC,WADF,EAEEC,WAFF,EAGEC,gBAHF,EAIEC,eAJF,QAKO,yBALP;AAYA,IAAIC,SAAS,GAAG,CAAhB;AAEA,eAAe,SAASC,UAAT,CAAoB;AAAEC,EAAAA,QAAF;AA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AACEP,QAAAA,UAAU,EAAEA,UAAU,CAACE;AADzB,OADS;AADN,KAAP;AAOD,GARqC,EAQnC,EARmC,CAAtC;AAUA,sBACE,oBAAC,QAAD,CAAU,IAAV;AACE,IAAA,GAAG,EAAEV,GADP,CAEE;AAFF;AAGE,IAAA,GAAG,EAAEC,OAHP;AAIE,IAAA,QAAQ,EAAEM,YAJZ;AAKE,IAAA,KAAK,EAAE,CAACS,MAAM,CAACC,SAAR,EAAmBH,aAAnB,EAAkCf,KAAlC,CALT;AAME,IAAA,aAAa,EAAC;AANhB,KAQGD,QARH,CADF;AAYD;AAED,MAAMkB,MAAM,GAAG5B,UAAU,CAAC8B,MAAX,CAAkB;AAC/BD,EAAAA,SAAS,EAAE;AACTE,IAAAA,eAAe,EAAE,OADR;AAETC,IAAAA,MAAM,EAAE;AAFC;AADoB,CAAlB,CAAf","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';\nimport useCollapsibleContext from '../../hooks/useCollapsibleContext';\nimport useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';\nimport Animated, {\n Extrapolate,\n interpolate,\n useAnimatedStyle,\n useDerivedValue,\n} from 'react-native-reanimated';\n\ntype Props = {\n style?: StyleProp<ViewStyle>;\n children: Element;\n};\n\nlet stickyKey = 0;\n\nexport default function StickyView({ children, style }: Props) {\n const key = useMemo(() => `sticky_${stickyKey++}`, []);\n const viewRef = useRef<View>(null);\n const { handleStickyViewLayout, stickyViewTops, stickyViewPositions } =\n useInternalCollapsibleContext();\n const { scrollY } = useCollapsibleContext();\n\n useEffect(() => {\n return () => handleStickyViewLayout(key, undefined);\n }, []);\n\n const handleLayout = useCallback(() => {\n handleStickyViewLayout(key, viewRef);\n }, [handleStickyViewLayout, key]);\n\n const translateY = useDerivedValue(() => {\n const top = stickyViewTops.value[key] || 0;\n const layoutValues = stickyViewPositions.value[key] || { top: 0 };\n const inputMid = layoutValues.top - top;\n return interpolate(\n scrollY.value,\n [0, inputMid, inputMid + 100000],\n [0, 0, 100000],\n Extrapolate.CLAMP\n );\n }, []);\n\n const animatedStyle = useAnimatedStyle(() => {\n return {\n transform: [\n {\n translateY: translateY.value,\n },\n ],\n };\n }, []);\n\n return (\n <Animated.View\n key={key}\n // @ts-ignore\n ref={viewRef}\n onLayout={handleLayout}\n style={[styles.container, animatedStyle, style]}\n pointerEvents=\"box-none\"\n >\n {children}\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: 'white',\n zIndex: 10,\n },\n});\n"]}
@@ -0,0 +1,56 @@
1
+ import { NativeViewGestureHandler, PanGestureHandler } from 'react-native-gesture-handler';
2
+ import React, { useRef } from 'react';
3
+ import Animated, { useAnimatedGestureHandler, withTiming } from 'react-native-reanimated';
4
+ import usePullToRefreshContext from './usePullToRefreshContext';
5
+ import { StyleSheet } from 'react-native';
6
+ import { rubberClamp } from './utils';
7
+ export default function PullToRefreshContainer({
8
+ children,
9
+ scrollY
10
+ }) {
11
+ const scrollRef = useRef();
12
+ const panRef = useRef();
13
+ const {
14
+ refreshValue,
15
+ internalRefreshing,
16
+ internalHeight
17
+ } = usePullToRefreshContext();
18
+ const gestureHandler = useAnimatedGestureHandler({
19
+ onStart: (_, ctx) => {
20
+ ctx.startY = internalRefreshing.value ? refreshValue.value : 0;
21
+ },
22
+ onActive: (event, ctx) => {
23
+ if (scrollY.value <= 1) {
24
+ const tranY = event.translationY + ctx.startY;
25
+ const clampedValue = rubberClamp(tranY, 0, internalHeight.value);
26
+ refreshValue.value = clampedValue;
27
+
28
+ if (clampedValue > internalHeight.value) {
29
+ internalRefreshing.value = true;
30
+ }
31
+ } else {
32
+ refreshValue.value = 0;
33
+ }
34
+ },
35
+ onEnd: () => {
36
+ if (refreshValue.value > 0) {
37
+ const value = internalRefreshing.value ? internalHeight.value : 0;
38
+ refreshValue.value = withTiming(value);
39
+ }
40
+ }
41
+ });
42
+ return /*#__PURE__*/React.createElement(PanGestureHandler, {
43
+ ref: panRef,
44
+ simultaneousHandlers: scrollRef,
45
+ onGestureEvent: gestureHandler,
46
+ shouldCancelWhenOutside: false,
47
+ enableTrackpadTwoFingerGesture: true,
48
+ maxPointers: 1
49
+ }, /*#__PURE__*/React.createElement(Animated.View, {
50
+ style: StyleSheet.absoluteFill
51
+ }, /*#__PURE__*/React.createElement(NativeViewGestureHandler, {
52
+ ref: scrollRef,
53
+ simultaneousHandlers: panRef
54
+ }, children)));
55
+ }
56
+ //# sourceMappingURL=PullToRefreshContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PullToRefreshContainer.tsx"],"names":["NativeViewGestureHandler","PanGestureHandler","React","useRef","Animated","useAnimatedGestureHandler","withTiming","usePullToRefreshContext","StyleSheet","rubberClamp","PullToRefreshContainer","children","scrollY","scrollRef","panRef","refreshValue","internalRefreshing","internalHeight","gestureHandler","onStart","_","ctx","startY","value","onActive","event","tranY","translationY","clampedValue","onEnd","absoluteFill"],"mappings":"AAAA,SACEA,wBADF,EAEEC,iBAFF,QAGO,8BAHP;AAIA,OAAOC,KAAP,IAAgBC,MAAhB,QAA8B,OAA9B;AACA,OAAOC,QAAP,IACEC,yBADF,EAEEC,UAFF,QAGO,yBAHP;AAIA,OAAOC,uBAAP,MAAoC,2BAApC;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,SAASC,WAAT,QAA4B,SAA5B;AAOA,eAAe,SAASC,sBAAT,CAAgC;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAhC,EAA8D;AAC3E,QAAMC,SAAS,GAAGV,MAAM,EAAxB;AACA,QAAMW,MAAM,GAAGX,MAAM,EAArB;AACA,QAAM;AAAEY,IAAAA,YAAF;AAAgBC,IAAAA,kBAAhB;AAAoCC,IAAAA;AAApC,MACJV,uBAAuB,EADzB;AAGA,QAAMW,cAAc,GAAGb,yBAAyB,CAAC;AAC/Cc,IAAAA,OAA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;AAAjC,kBACE,oBAAC,wBAAD;AAA0B,IAAA,GAAG,EAAEjB,SAA/B;AAA0C,IAAA,oBAAoB,EAAEC;AAAhE,KACGH,QADH,CADF,CARF,CADF;AAgBD","sourcesContent":["import {\n NativeViewGestureHandler,\n PanGestureHandler,\n} from 'react-native-gesture-handler';\nimport React, { useRef } from 'react';\nimport Animated, {\n useAnimatedGestureHandler,\n withTiming,\n} from 'react-native-reanimated';\nimport usePullToRefreshContext from './usePullToRefreshContext';\nimport { StyleSheet } from 'react-native';\nimport { rubberClamp } from './utils';\n\ntype Props = {\n children: React.ReactNode;\n scrollY: Animated.SharedValue<number>;\n};\n\nexport default function PullToRefreshContainer({ children, scrollY }: Props) {\n const scrollRef = useRef();\n const panRef = useRef();\n const { refreshValue, internalRefreshing, internalHeight } =\n usePullToRefreshContext();\n\n const gestureHandler = useAnimatedGestureHandler({\n onStart: (_, ctx: any) => {\n ctx.startY = internalRefreshing.value ? refreshValue.value : 0;\n },\n onActive: (event, ctx: any) => {\n if (scrollY.value <= 1) {\n const tranY = event.translationY + ctx.startY;\n const clampedValue = rubberClamp(tranY, 0, internalHeight.value);\n refreshValue.value = clampedValue;\n if (clampedValue > internalHeight.value) {\n internalRefreshing.value = true;\n }\n } else {\n refreshValue.value = 0;\n }\n },\n onEnd: () => {\n if (refreshValue.value > 0) {\n const value = internalRefreshing.value ? internalHeight.value : 0;\n refreshValue.value = withTiming(value);\n }\n },\n });\n\n return (\n <PanGestureHandler\n ref={panRef}\n simultaneousHandlers={scrollRef}\n onGestureEvent={gestureHandler}\n shouldCancelWhenOutside={false}\n enableTrackpadTwoFingerGesture\n maxPointers={1}\n >\n <Animated.View style={StyleSheet.absoluteFill}>\n <NativeViewGestureHandler ref={scrollRef} simultaneousHandlers={panRef}>\n {children}\n </NativeViewGestureHandler>\n </Animated.View>\n </PanGestureHandler>\n );\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import React, { useMemo } from 'react';
2
+ import { useSharedValue } from 'react-native-reanimated';
3
+ import { PullToRefreshContext } from './usePullToRefreshContext';
4
+ export default function PullToRefreshProvider({
5
+ children
6
+ }) {
7
+ const refreshValue = useSharedValue(0);
8
+ const internalRefreshing = useSharedValue(false);
9
+ const internalHeight = useSharedValue(0);
10
+ const context = useMemo(() => {
11
+ return {
12
+ refreshValue: refreshValue,
13
+ internalRefreshing,
14
+ internalHeight
15
+ };
16
+ }, [refreshValue, internalRefreshing, internalHeight]);
17
+ return /*#__PURE__*/React.createElement(PullToRefreshContext.Provider, {
18
+ value: context
19
+ }, children);
20
+ }
21
+ //# sourceMappingURL=PullToRefreshProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PullToRefreshProvider.tsx"],"names":["React","useMemo","useSharedValue","PullToRefreshContext","PullToRefreshProvider","children","refreshValue","internalRefreshing","internalHeight","context"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,OAAhB,QAA+B,OAA/B;AACA,SAASC,cAAT,QAA+B,yBAA/B;AACA,SAASC,oBAAT,QAAqC,2BAArC;AAMA,eAAe,SAASC,qBAAT,CAA+B;AAAEC,EAAAA;AAAF,CAA/B,EAAoD;AACjE,QAAMC,YAAY,GAAGJ,cAAc,CAAC,CAAD,CAAnC;AACA,QAAMK,kBAAkB,GAAGL,cAAc,CAAC,KAAD,CAAzC;AACA,QAAMM,cAAc,GAAGN,cAAc,CAAC,CAAD,CAArC;AAEA,QAAMO,OAAO,GAAGR,OAAO,CAAC,MAAM;AAC5B,WAAO;AACLK,MAAAA,YAAY,EAAEA,YADT;AAELC,MAAAA,kBAFK;AAGLC,MAAAA;AAHK,KAAP;AAKD,GANsB,EAMpB,CAACF,YAAD,EAAeC,kBAAf,EAAmCC,cAAnC,CANoB,CAAvB;AAQA,sBACE,oBAAC,oBAAD,CAAsB,QAAtB;AAA+B,IAAA,KAAK,EAAEC;AAAtC,KACGJ,QADH,CADF;AAKD","sourcesContent":["import React, { useMemo } from 'react';\nimport { useSharedValue } from 'react-native-reanimated';\nimport { PullToRefreshContext } from './usePullToRefreshContext';\n\ntype Props = {\n children: React.ReactNode;\n};\n\nexport default function PullToRefreshProvider({ children }: Props) {\n const refreshValue = useSharedValue(0);\n const internalRefreshing = useSharedValue(false);\n const internalHeight = useSharedValue(0);\n\n const context = useMemo(() => {\n return {\n refreshValue: refreshValue,\n internalRefreshing,\n internalHeight,\n };\n }, [refreshValue, internalRefreshing, internalHeight]);\n\n return (\n <PullToRefreshContext.Provider value={context}>\n {children}\n </PullToRefreshContext.Provider>\n );\n}\n"]}
@@ -0,0 +1,55 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
2
+ import React, { useCallback, useEffect } from 'react';
3
+ import { StyleSheet } from 'react-native';
4
+ import Animated, { runOnJS, useAnimatedProps, useAnimatedReaction, useAnimatedStyle, withTiming } from 'react-native-reanimated';
5
+ import usePullToRefreshContext from './usePullToRefreshContext';
6
+ export default function RefreshControl({
7
+ height = 100,
8
+ refreshing,
9
+ onRefresh,
10
+ renderAnimation
11
+ }) {
12
+ const {
13
+ refreshValue,
14
+ internalRefreshing,
15
+ internalHeight
16
+ } = usePullToRefreshContext();
17
+ useEffect(() => {
18
+ internalHeight.value = height;
19
+ }, [height]);
20
+ useEffect(() => {
21
+ internalRefreshing.value = refreshing;
22
+ }, [refreshing]);
23
+ const animatedStyle = useAnimatedStyle(() => {
24
+ return {
25
+ height: refreshValue.value
26
+ };
27
+ }, []);
28
+ const handleRefresh = useCallback(() => {
29
+ console.log('refresh');
30
+ onRefresh();
31
+ }, [onRefresh]);
32
+ useAnimatedReaction(() => internalRefreshing.value, (result, prev) => {
33
+ if (result !== prev) {
34
+ if (result) {
35
+ runOnJS(handleRefresh)();
36
+ } else {
37
+ refreshValue.value = withTiming(0);
38
+ }
39
+ }
40
+ });
41
+ const animatedProps = useAnimatedProps(() => {
42
+ return {
43
+ progress: internalRefreshing.value ? undefined : Math.min(refreshValue.value / height, 1)
44
+ };
45
+ }, [height]);
46
+ return /*#__PURE__*/React.createElement(Animated.View, {
47
+ style: [styles.container, animatedStyle]
48
+ }, renderAnimation(animatedProps));
49
+ }
50
+ const styles = StyleSheet.create({
51
+ container: {
52
+ overflow: 'hidden'
53
+ }
54
+ });
55
+ //# sourceMappingURL=RefreshControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RefreshControl.tsx"],"names":["React","useCallback","useEffect","StyleSheet","Animated","runOnJS","useAnimatedProps","useAnimatedReaction","useAnimatedStyle","withTiming","usePullToRefreshContext","RefreshControl","height","refreshing","onRefresh","renderAnimation","refreshValue","internalRefreshing","internalHeight","value","animatedStyle","handleRefresh","console","log","result","prev","animatedProps","progress","undefined","Math","min","styles","container","create","overflow"],"mappings":"AAAA;AACA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,QAA8C,OAA9C;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,OAAOC,QAAP,IACEC,OADF,EAEEC,gBAFF,EAGEC,mBAHF,EAIEC,gBAJF,EAKEC,UALF,QAMO,yBANP;AAOA,OAAOC,uBAAP,MAAoC,2BAApC;AASA,eAAe,SAASC,cAAT,CAAwB;AACrCC,EAAAA,MAAM,GAAG,GAD4B;AAErCC,EAAAA,UAFqC;AAGrCC,EAAAA,SAHqC;AAIrCC,EAAAA;AAJqC,CAAxB,EAKL;AACR,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA,kBAAhB;AAAoCC,IAAAA;AAApC,MACJR,uBAAuB,EADzB;AAGAR,EAAAA,SAAS,CAAC,MAAM;AACdgB,IAAAA,cAAc,CAACC,KAAf,GAAuBP,MAAvB;AACD,GAFQ,EAEN,CAACA,MAAD,CAFM,CAAT;AAIAV,EAAAA,SAAS,CAAC,MAAM;AACde,IAAAA,kBAAkB,CAACE,KAAnB,GAA2BN,UAA3B;AACD,GAFQ,EAEN,CAACA,UAAD,CAFM,CAAT;AAIA,QAAMO,aAAa,GAAGZ,gBAAgB,CAAC,MAAM;AAC3C,WAAO;AACLI,MAAAA,MAAM,EAAEI,YAAY,CAACG;AADhB,KAAP;AAGD,GAJqC,EAInC,EAJmC,CAAtC;AAMA,QAAME,aAAa,GAAGpB,WAAW,CAAC,MAAM;AACtCqB,IAAAA,OAAO,CAACC,GAAR,CAAY,SAAZ;AACAT,IAAAA,SAAS;AACV,GAHgC,EAG9B,CAACA,SAAD,CAH8B,CAAjC;AAKAP,EAAAA,mBAAmB,CACjB,MAAMU,kBAAkB,CAACE,KADR,EAEjB,CAACK,MAAD,EAASC,IAAT,KAAkB;AAChB,QAAID,MAAM,KAAKC,IAAf,EAAqB;AACnB,UAAID,MAAJ,EAAY;AACVnB,QAAAA,OAAO,CAACgB,aAAD,CAAP;AACD,OAFD,MAEO;AACLL,QAAAA,YAAY,CAACG,KAAb,GAAqBV,UAAU,CAAC,CAAD,CAA/B;AACD;AACF;AACF,GAVgB,CAAnB;AAaA,QAAMiB,aAAa,GAAGpB,gBAAgB,CAAC,MAAM;AAC3C,WAAO;AACLqB,MAAAA,QAAQ,EAAEV,kBAAkB,CAACE,KAAnB,GACNS,SADM,GAENC,IAAI,CAACC,GAAL,CAASd,YAAY,CAACG,KAAb,GAAqBP,MAA9B,EAAsC,CAAtC;AAHC,KAAP;AAKD,GANqC,EAMnC,CAACA,MAAD,CANmC,CAAtC;AAQA,sBACE,oBAAC,QAAD,CAAU,IAAV;AAAe,IAAA,KAAK,EAAE,CAACmB,MAAM,CAACC,SAAR,EAAmBZ,aAAnB;AAAtB,KACGL,eAAe,CAACW,aAAD,CADlB,CADF;AAKD;AAED,MAAMK,MAAM,GAAG5B,UAAU,CAAC8B,MAAX,CAAkB;AAC/BD,EAAAA,SAAS,EAAE;AACTE,IAAAA,QAAQ,EAAE;AADD;AADoB,CAAlB,CAAf","sourcesContent":["/* eslint-disable react-hooks/exhaustive-deps */\nimport React, { useCallback, useEffect } from 'react';\nimport { StyleSheet } from 'react-native';\nimport Animated, {\n runOnJS,\n useAnimatedProps,\n useAnimatedReaction,\n useAnimatedStyle,\n withTiming,\n} from 'react-native-reanimated';\nimport usePullToRefreshContext from './usePullToRefreshContext';\n\ntype Props = {\n height?: number;\n refreshing: boolean;\n onRefresh: () => void;\n renderAnimation: (animatedProps: any) => React.ReactNode;\n};\n\nexport default function RefreshControl({\n height = 100,\n refreshing,\n onRefresh,\n renderAnimation,\n}: Props) {\n const { refreshValue, internalRefreshing, internalHeight } =\n usePullToRefreshContext();\n\n useEffect(() => {\n internalHeight.value = height;\n }, [height]);\n\n useEffect(() => {\n internalRefreshing.value = refreshing;\n }, [refreshing]);\n\n const animatedStyle = useAnimatedStyle(() => {\n return {\n height: refreshValue.value,\n };\n }, []);\n\n const handleRefresh = useCallback(() => {\n console.log('refresh');\n onRefresh();\n }, [onRefresh]);\n\n useAnimatedReaction(\n () => internalRefreshing.value,\n (result, prev) => {\n if (result !== prev) {\n if (result) {\n runOnJS(handleRefresh)();\n } else {\n refreshValue.value = withTiming(0);\n }\n }\n }\n );\n\n const animatedProps = useAnimatedProps(() => {\n return {\n progress: internalRefreshing.value\n ? undefined\n : Math.min(refreshValue.value / height, 1),\n };\n }, [height]);\n\n return (\n <Animated.View style={[styles.container, animatedStyle]}>\n {renderAnimation(animatedProps)}\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n});\n"]}
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from 'react';
2
+ // @ts-ignore
3
+ export const PullToRefreshContext = /*#__PURE__*/createContext({});
4
+ export default function usePullToRefreshContext() {
5
+ const ctx = useContext(PullToRefreshContext);
6
+
7
+ if (!ctx) {
8
+ throw new Error('Component should be wrapped with withCollapsibleContext');
9
+ }
10
+
11
+ return ctx;
12
+ }
13
+ //# sourceMappingURL=usePullToRefreshContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePullToRefreshContext.ts"],"names":["createContext","useContext","PullToRefreshContext","usePullToRefreshContext","ctx","Error"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAGA;AACA,OAAO,MAAMC,oBAAoB,gBAAGF,aAAa,CAA2B,EAA3B,CAA1C;AAEP,eAAe,SAASG,uBAAT,GAAmC;AAChD,QAAMC,GAAG,GAAGH,UAAU,CAACC,oBAAD,CAAtB;;AACA,MAAI,CAACE,GAAL,EAAU;AACR,UAAM,IAAIC,KAAJ,CAAU,yDAAV,CAAN;AACD;;AACD,SAAOD,GAAP;AACD","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { PullToRefreshContextType } from '../../types';\n\n// @ts-ignore\nexport const PullToRefreshContext = createContext<PullToRefreshContextType>({});\n\nexport default function usePullToRefreshContext() {\n const ctx = useContext(PullToRefreshContext);\n if (!ctx) {\n throw new Error('Component should be wrapped with withCollapsibleContext');\n }\n return ctx;\n}\n"]}
@@ -0,0 +1,42 @@
1
+ export const springConfig = velocity => {
2
+ 'worklet';
3
+
4
+ return {
5
+ stiffness: 1000,
6
+ damping: 500,
7
+ mass: 3,
8
+ overshootClamping: true,
9
+ restDisplacementThreshold: 0.01,
10
+ restSpeedThreshold: 0.01,
11
+ velocity
12
+ };
13
+ };
14
+ export function clamp(value, lowerbound, upperbound) {
15
+ 'worklet';
16
+
17
+ return Math.min(Math.max(value, lowerbound), upperbound);
18
+ }
19
+ /**
20
+ * calculates rubber value
21
+ *
22
+ * @param x distance from the edge
23
+ * @param dim dimension, either width or height
24
+ * @param coeff constant value, UIScrollView uses 0.55
25
+ * @returns rubber = (1.0 – (1.0 / ((x * coeff / dim) + 1.0))) * dim
26
+ */
27
+
28
+ export const rubberBandClamp = (x, dim, coeff) => {
29
+ 'worklet';
30
+
31
+ return (1.0 - 1.0 / (x * coeff / dim + 1.0)) * dim;
32
+ };
33
+ export const rubberClamp = (y, topBound, bottomBound, coeff = 0.55) => {
34
+ 'worklet';
35
+
36
+ const clampedY = clamp(y, topBound, bottomBound);
37
+ const diff = Math.abs(y - clampedY);
38
+ const sign = clampedY > y ? -1 : 1;
39
+ const dimension = bottomBound - topBound;
40
+ return clampedY + sign * rubberBandClamp(diff, dimension, coeff);
41
+ };
42
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils.ts"],"names":["springConfig","velocity","stiffness","damping","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","clamp","value","lowerbound","upperbound","Math","min","max","rubberBandClamp","x","dim","coeff","rubberClamp","y","topBound","bottomBound","clampedY","diff","abs","sign","dimension"],"mappings":"AAAA,OAAO,MAAMA,YAAY,GAAIC,QAAD,IAAsB;AAChD;;AAEA,SAAO;AACLC,IAAAA,SAAS,EAAE,IADN;AAELC,IAAAA,OAAO,EAAE,GAFJ;AAGLC,IAAAA,IAAI,EAAE,CAHD;AAILC,IAAAA,iBAAiB,EAAE,IAJd;AAKLC,IAAAA,yBAAyB,EAAE,IALtB;AAMLC,IAAAA,kBAAkB,EAAE,IANf;AAOLN,IAAAA;AAPK,GAAP;AASD,CAZM;AAcP,OAAO,SAASO,KAAT,CAAeC,KAAf,EAA8BC,UAA9B,EAAkDC,UAAlD,EAAsE;AAC3E;;AAEA,SAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASL,KAAT,EAAgBC,UAAhB,CAAT,EAAsCC,UAAtC,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMI,eAAe,GAAG,CAACC,CAAD,EAAYC,GAAZ,EAAyBC,KAAzB,KAA2C;AACxE;;AAEA,SAAO,CAAC,MAAM,OAAQF,CAAC,GAAGE,KAAL,GAAcD,GAAd,GAAoB,GAA3B,CAAP,IAA0CA,GAAjD;AACD,CAJM;AAMP,OAAO,MAAME,WAAW,GAAG,CACzBC,CADyB,EAEzBC,QAFyB,EAGzBC,WAHyB,EAIzBJ,KAAK,GAAG,IAJiB,KAKtB;AACH;;AAEA,QAAMK,QAAQ,GAAGf,KAAK,CAACY,CAAD,EAAIC,QAAJ,EAAcC,WAAd,CAAtB;AACA,QAAME,IAAI,GAAGZ,IAAI,CAACa,GAAL,CAASL,CAAC,GAAGG,QAAb,CAAb;AACA,QAAMG,IAAI,GAAGH,QAAQ,GAAGH,CAAX,GAAe,CAAC,CAAhB,GAAoB,CAAjC;AACA,QAAMO,SAAS,GAAGL,WAAW,GAAGD,QAAhC;AAEA,SAAOE,QAAQ,GAAGG,IAAI,GAAGX,eAAe,CAACS,IAAD,EAAOG,SAAP,EAAkBT,KAAlB,CAAxC;AACD,CAdM","sourcesContent":["export const springConfig = (velocity: number) => {\n 'worklet';\n\n return {\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n velocity,\n };\n};\n\nexport function clamp(value: number, lowerbound: number, upperbound: number) {\n 'worklet';\n\n return Math.min(Math.max(value, lowerbound), upperbound);\n}\n\n/**\n * calculates rubber value\n *\n * @param x distance from the edge\n * @param dim dimension, either width or height\n * @param coeff constant value, UIScrollView uses 0.55\n * @returns rubber = (1.0 – (1.0 / ((x * coeff / dim) + 1.0))) * dim\n */\nexport const rubberBandClamp = (x: number, dim: number, coeff: number) => {\n 'worklet';\n\n return (1.0 - 1.0 / ((x * coeff) / dim + 1.0)) * dim;\n};\n\nexport const rubberClamp = (\n y: number,\n topBound: number,\n bottomBound: number,\n coeff = 0.55\n) => {\n 'worklet';\n\n const clampedY = clamp(y, topBound, bottomBound);\n const diff = Math.abs(y - clampedY);\n const sign = clampedY > y ? -1 : 1;\n const dimension = bottomBound - topBound;\n\n return clampedY + sign * rubberBandClamp(diff, dimension, coeff);\n};\n"]}