@fountain-ui/lab 2.0.0-beta.11 → 2.0.0-beta.12

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 (265) hide show
  1. package/build/commonjs/Carousel/Carousel.js +137 -0
  2. package/build/commonjs/Carousel/Carousel.js.map +1 -0
  3. package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
  4. package/build/commonjs/Carousel/animation/animationUtils.js +9 -0
  5. package/build/commonjs/Carousel/animation/animationUtils.js.map +1 -0
  6. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js +15 -0
  7. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  8. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +20 -0
  9. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  10. package/build/commonjs/Carousel/animation/index.js +40 -0
  11. package/build/commonjs/Carousel/animation/index.js.map +1 -0
  12. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js +27 -0
  13. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  14. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +65 -0
  15. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  16. package/build/commonjs/Carousel/components/InternalContext.js +29 -0
  17. package/build/commonjs/Carousel/components/InternalContext.js.map +1 -0
  18. package/build/commonjs/Carousel/components/ItemView.js +64 -0
  19. package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
  20. package/build/commonjs/Carousel/components/RootView.js +68 -0
  21. package/build/commonjs/Carousel/components/RootView.js.map +1 -0
  22. package/build/commonjs/Carousel/components/ScrollViewGesture.js +76 -0
  23. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -0
  24. package/build/commonjs/Carousel/components/index.js +40 -0
  25. package/build/commonjs/Carousel/components/index.js.map +1 -0
  26. package/build/commonjs/Carousel/hooks/index.js +64 -0
  27. package/build/commonjs/Carousel/hooks/index.js.map +1 -0
  28. package/build/commonjs/Carousel/hooks/useAutoplayController.js +55 -0
  29. package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -0
  30. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +23 -0
  31. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  32. package/build/commonjs/Carousel/hooks/useIndexController.js +70 -0
  33. package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -0
  34. package/build/commonjs/Carousel/hooks/useItemInterpolation.js +63 -0
  35. package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +1 -0
  36. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +95 -0
  37. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  38. package/build/commonjs/Carousel/hooks/useLoopedData.js +33 -0
  39. package/build/commonjs/Carousel/hooks/useLoopedData.js.map +1 -0
  40. package/build/commonjs/Carousel/hooks/usePagingAnimation.js +124 -0
  41. package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -0
  42. package/build/commonjs/Carousel/index.js +16 -2
  43. package/build/commonjs/Carousel/index.js.map +1 -1
  44. package/build/commonjs/Carousel/types.js +7 -0
  45. package/build/commonjs/Carousel/types.js.map +1 -0
  46. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +44 -47
  47. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  48. package/build/commonjs/ViewPager/PageStateContext.js +22 -0
  49. package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
  50. package/build/commonjs/ViewPager/ViewPagerNative.js +23 -10
  51. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  52. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  53. package/build/commonjs/ViewPager/ViewPagerWeb.js +9 -7
  54. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  55. package/build/commonjs/ViewPager/index.js +8 -0
  56. package/build/commonjs/ViewPager/index.js.map +1 -1
  57. package/build/commonjs/ViewPager/index.native.js +8 -0
  58. package/build/commonjs/ViewPager/index.native.js.map +1 -1
  59. package/build/commonjs/ViewPager/utils.js +3 -1
  60. package/build/commonjs/ViewPager/utils.js.map +1 -1
  61. package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
  62. package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
  63. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
  64. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  65. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  66. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  67. package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
  68. package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
  69. package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
  70. package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
  71. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
  72. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  73. package/build/commonjs/hooks/index.js +16 -0
  74. package/build/commonjs/hooks/index.js.map +1 -1
  75. package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
  76. package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
  77. package/build/commonjs/hooks/useIsMounted.js +22 -0
  78. package/build/commonjs/hooks/useIsMounted.js.map +1 -0
  79. package/build/commonjs/index.js +22 -1
  80. package/build/commonjs/index.js.map +1 -1
  81. package/build/module/Carousel/Carousel.js +115 -0
  82. package/build/module/Carousel/Carousel.js.map +1 -0
  83. package/build/module/Carousel/CarouselProps.js.map +1 -1
  84. package/build/module/Carousel/animation/animationUtils.js +2 -0
  85. package/build/module/Carousel/animation/animationUtils.js.map +1 -0
  86. package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
  87. package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  88. package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
  89. package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  90. package/build/module/Carousel/animation/index.js +5 -0
  91. package/build/module/Carousel/animation/index.js.map +1 -0
  92. package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
  93. package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  94. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
  95. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  96. package/build/module/Carousel/components/InternalContext.js +19 -0
  97. package/build/module/Carousel/components/InternalContext.js.map +1 -0
  98. package/build/module/Carousel/components/ItemView.js +44 -0
  99. package/build/module/Carousel/components/ItemView.js.map +1 -0
  100. package/build/module/Carousel/components/RootView.js +47 -0
  101. package/build/module/Carousel/components/RootView.js.map +1 -0
  102. package/build/module/Carousel/components/ScrollViewGesture.js +62 -0
  103. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
  104. package/build/module/Carousel/components/index.js +5 -0
  105. package/build/module/Carousel/components/index.js.map +1 -0
  106. package/build/module/Carousel/hooks/index.js +8 -0
  107. package/build/module/Carousel/hooks/index.js.map +1 -0
  108. package/build/module/Carousel/hooks/useAutoplayController.js +45 -0
  109. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
  110. package/build/module/Carousel/hooks/useDimensionChangeReaction.js +14 -0
  111. package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  112. package/build/module/Carousel/hooks/useIndexController.js +54 -0
  113. package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
  114. package/build/module/Carousel/hooks/useItemInterpolation.js +51 -0
  115. package/build/module/Carousel/hooks/useItemInterpolation.js.map +1 -0
  116. package/build/module/Carousel/hooks/useItemVisibilityStore.js +87 -0
  117. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  118. package/build/module/Carousel/hooks/useLoopedData.js +24 -0
  119. package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
  120. package/build/module/Carousel/hooks/usePagingAnimation.js +115 -0
  121. package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -0
  122. package/build/module/Carousel/index.js +2 -1
  123. package/build/module/Carousel/index.js.map +1 -1
  124. package/build/module/Carousel/types.js +3 -0
  125. package/build/module/Carousel/types.js.map +1 -0
  126. package/build/module/ViewPager/ChildrenMemoizedPage.js +40 -45
  127. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  128. package/build/module/ViewPager/PageStateContext.js +10 -0
  129. package/build/module/ViewPager/PageStateContext.js.map +1 -0
  130. package/build/module/ViewPager/ViewPagerNative.js +26 -13
  131. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  132. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  133. package/build/module/ViewPager/ViewPagerWeb.js +10 -8
  134. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  135. package/build/module/ViewPager/index.js +1 -0
  136. package/build/module/ViewPager/index.js.map +1 -1
  137. package/build/module/ViewPager/index.native.js +1 -0
  138. package/build/module/ViewPager/index.native.js.map +1 -1
  139. package/build/module/ViewPager/utils.js +1 -0
  140. package/build/module/ViewPager/utils.js.map +1 -1
  141. package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
  142. package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
  143. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
  144. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  145. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  146. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  147. package/build/module/ViewabilityTrackerView/index.js +2 -0
  148. package/build/module/ViewabilityTrackerView/index.js.map +1 -0
  149. package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
  150. package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
  151. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
  152. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  153. package/build/module/hooks/index.js +2 -0
  154. package/build/module/hooks/index.js.map +1 -1
  155. package/build/module/hooks/useDeferredExecutor.js +33 -0
  156. package/build/module/hooks/useDeferredExecutor.js.map +1 -0
  157. package/build/module/hooks/useIsMounted.js +13 -0
  158. package/build/module/hooks/useIsMounted.js.map +1 -0
  159. package/build/module/index.js +2 -0
  160. package/build/module/index.js.map +1 -1
  161. package/build/typescript/Carousel/Carousel.d.ts +5 -0
  162. package/build/typescript/Carousel/CarouselProps.d.ts +32 -48
  163. package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
  164. package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
  165. package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
  166. package/build/typescript/Carousel/animation/index.d.ts +4 -0
  167. package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
  168. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
  169. package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
  170. package/build/typescript/Carousel/components/ItemView.d.ts +7 -0
  171. package/build/typescript/Carousel/components/RootView.d.ts +16 -0
  172. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
  173. package/build/typescript/Carousel/components/index.d.ts +4 -0
  174. package/build/typescript/Carousel/hooks/index.d.ts +7 -0
  175. package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
  176. package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +7 -0
  177. package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
  178. package/build/typescript/Carousel/hooks/useItemInterpolation.d.ts +2 -0
  179. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
  180. package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
  181. package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +18 -0
  182. package/build/typescript/Carousel/index.d.ts +3 -1
  183. package/build/typescript/Carousel/types.d.ts +57 -0
  184. package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
  185. package/build/typescript/ViewPager/ViewPagerNative.d.ts +1 -1
  186. package/build/typescript/ViewPager/ViewPagerProps.d.ts +11 -0
  187. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +1 -1
  188. package/build/typescript/ViewPager/index.d.ts +1 -0
  189. package/build/typescript/ViewPager/index.native.d.ts +1 -0
  190. package/build/typescript/ViewPager/utils.d.ts +1 -0
  191. package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
  192. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
  193. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
  194. package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
  195. package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
  196. package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
  197. package/build/typescript/hooks/index.d.ts +2 -0
  198. package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
  199. package/build/typescript/hooks/useIsMounted.d.ts +4 -0
  200. package/build/typescript/index.d.ts +2 -0
  201. package/package.json +4 -19
  202. package/src/Carousel/Carousel.tsx +151 -0
  203. package/src/Carousel/CarouselProps.ts +34 -53
  204. package/src/Carousel/animation/animationUtils.ts +1 -0
  205. package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
  206. package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
  207. package/src/Carousel/animation/index.ts +4 -0
  208. package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
  209. package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
  210. package/src/Carousel/components/InternalContext.ts +33 -0
  211. package/src/Carousel/components/ItemView.tsx +56 -0
  212. package/src/Carousel/components/RootView.tsx +66 -0
  213. package/src/Carousel/components/ScrollViewGesture.tsx +80 -0
  214. package/src/Carousel/components/index.ts +4 -0
  215. package/src/Carousel/hooks/index.ts +7 -0
  216. package/src/Carousel/hooks/useAutoplayController.ts +54 -0
  217. package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
  218. package/src/Carousel/hooks/useIndexController.tsx +76 -0
  219. package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
  220. package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
  221. package/src/Carousel/hooks/useLoopedData.ts +26 -0
  222. package/src/Carousel/hooks/usePagingAnimation.ts +148 -0
  223. package/src/Carousel/index.ts +4 -2
  224. package/src/Carousel/types.ts +67 -0
  225. package/src/ViewPager/ChildrenMemoizedPage.tsx +48 -43
  226. package/src/ViewPager/PageStateContext.ts +15 -0
  227. package/src/ViewPager/ViewPagerNative.tsx +35 -11
  228. package/src/ViewPager/ViewPagerProps.ts +13 -0
  229. package/src/ViewPager/ViewPagerWeb.tsx +9 -5
  230. package/src/ViewPager/index.native.ts +1 -0
  231. package/src/ViewPager/index.ts +1 -0
  232. package/src/ViewPager/utils.tsx +2 -1
  233. package/src/ViewabilityTrackerView/Viewability.ts +3 -0
  234. package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
  235. package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
  236. package/src/ViewabilityTrackerView/index.ts +2 -0
  237. package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
  238. package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
  239. package/src/hooks/index.ts +2 -0
  240. package/src/hooks/useDeferredExecutor.ts +46 -0
  241. package/src/hooks/useIsMounted.ts +19 -0
  242. package/src/index.ts +3 -0
  243. package/build/commonjs/Carousel/CarouselNative.js +0 -72
  244. package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
  245. package/build/commonjs/Carousel/CarouselWeb.js +0 -237
  246. package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
  247. package/build/commonjs/Carousel/index.native.js.map +0 -1
  248. package/build/commonjs/Carousel/utils.js +0 -19
  249. package/build/commonjs/Carousel/utils.js.map +0 -1
  250. package/build/module/Carousel/CarouselNative.js +0 -54
  251. package/build/module/Carousel/CarouselNative.js.map +0 -1
  252. package/build/module/Carousel/CarouselWeb.js +0 -215
  253. package/build/module/Carousel/CarouselWeb.js.map +0 -1
  254. package/build/module/Carousel/index.native.js +0 -2
  255. package/build/module/Carousel/index.native.js.map +0 -1
  256. package/build/module/Carousel/utils.js +0 -7
  257. package/build/module/Carousel/utils.js.map +0 -1
  258. package/build/typescript/Carousel/CarouselNative.d.ts +0 -2
  259. package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
  260. package/build/typescript/Carousel/index.native.d.ts +0 -1
  261. package/build/typescript/Carousel/utils.d.ts +0 -6
  262. package/src/Carousel/CarouselNative.tsx +0 -67
  263. package/src/Carousel/CarouselWeb.tsx +0 -222
  264. package/src/Carousel/index.native.ts +0 -1
  265. package/src/Carousel/utils.ts +0 -11
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","createDefaultItemStyle","createDefaultScrollAnimation","normalItemStyleFactory","parallaxItemStyleFactory"],"sources":["index.ts"],"sourcesContent":["export { default as createDefaultItemStyle } from './createDefaultItemStyle';\nexport { default as createDefaultScrollAnimation } from './createDefaultScrollAnimation';\nexport { default as normalItemStyleFactory } from './normalItemStyleFactory';\nexport { default as parallaxItemStyleFactory } from './parallaxItemStyleFactory';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,sBAApB,QAAkD,0BAAlD;AACA,SAASD,OAAO,IAAIE,4BAApB,QAAwD,gCAAxD;AACA,SAASF,OAAO,IAAIG,sBAApB,QAAkD,0BAAlD;AACA,SAASH,OAAO,IAAII,wBAApB,QAAoD,4BAApD"}
@@ -0,0 +1,18 @@
1
+ import { itemInterpolationInputRange } from './animationUtils';
2
+ export default function normalItemStyleFactory() {
3
+ const createItemStyle = (itemInterpolation, itemWidth) => {
4
+ const translate = itemInterpolation.interpolate({
5
+ inputRange: itemInterpolationInputRange,
6
+ outputRange: [-itemWidth, 0, itemWidth]
7
+ });
8
+ return {
9
+ transform: [{
10
+ translateX: translate
11
+ }]
12
+ };
13
+ };
14
+
15
+ return createItemStyle;
16
+ }
17
+ ;
18
+ //# sourceMappingURL=normalItemStyleFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["itemInterpolationInputRange","normalItemStyleFactory","createItemStyle","itemInterpolation","itemWidth","translate","interpolate","inputRange","outputRange","transform","translateX"],"sources":["normalItemStyleFactory.ts"],"sourcesContent":["import type { CreateItemStyle } from '../types';\nimport { itemInterpolationInputRange } from './animationUtils';\n\nexport default function normalItemStyleFactory() {\n const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {\n const translate = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n -itemWidth,\n 0,\n itemWidth,\n ],\n });\n\n return { transform: [{ translateX: translate }] };\n };\n\n return createItemStyle;\n};\n"],"mappings":"AACA,SAASA,2BAAT,QAA4C,kBAA5C;AAEA,eAAe,SAASC,sBAAT,GAAkC;EAC7C,MAAMC,eAAgC,GAAG,CAACC,iBAAD,EAAoBC,SAApB,KAAkC;IACvE,MAAMC,SAAS,GAAGF,iBAAiB,CAACG,WAAlB,CAA8B;MAC5CC,UAAU,EAAEP,2BADgC;MAE5CQ,WAAW,EAAE,CACT,CAACJ,SADQ,EAET,CAFS,EAGTA,SAHS;IAF+B,CAA9B,CAAlB;IASA,OAAO;MAAEK,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEL;MAAd,CAAD;IAAb,CAAP;EACH,CAXD;;EAaA,OAAOH,eAAP;AACH;AAAA"}
@@ -0,0 +1,55 @@
1
+ import { itemInterpolationInputRange } from './animationUtils';
2
+ const defaultParallaxAnimationConfig = {
3
+ parallaxActiveItemScale: 0.9,
4
+ parallaxActiveItemOpacity: 1,
5
+ parallaxAdjacentItemScale: Math.pow(0.9, 2),
6
+ parallaxAdjacentItemOpacity: 0.5,
7
+ parallaxScrollingOffset: 50
8
+ };
9
+ export default function parallaxItemStyleFactory() {
10
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultParallaxAnimationConfig;
11
+ const {
12
+ parallaxActiveItemScale,
13
+ parallaxActiveItemOpacity,
14
+ parallaxAdjacentItemOpacity,
15
+ parallaxAdjacentItemScale,
16
+ parallaxScrollingOffset
17
+ } = { ...config,
18
+ ...defaultParallaxAnimationConfig
19
+ };
20
+
21
+ const createItemStyle = (itemInterpolation, itemWidth) => {
22
+ const translate = itemInterpolation.interpolate({
23
+ inputRange: itemInterpolationInputRange,
24
+ outputRange: [-itemWidth + parallaxScrollingOffset, 0, itemWidth - parallaxScrollingOffset]
25
+ });
26
+ const zIndex = itemInterpolation.interpolate({
27
+ inputRange: itemInterpolationInputRange,
28
+ outputRange: [0, itemWidth, 0],
29
+ extrapolate: 'clamp'
30
+ });
31
+ const scale = itemInterpolation.interpolate({
32
+ inputRange: itemInterpolationInputRange,
33
+ outputRange: [parallaxAdjacentItemScale, parallaxActiveItemScale, parallaxAdjacentItemScale],
34
+ extrapolate: 'clamp'
35
+ });
36
+ const opacity = itemInterpolation.interpolate({
37
+ inputRange: itemInterpolationInputRange,
38
+ outputRange: [parallaxAdjacentItemOpacity, parallaxActiveItemOpacity, parallaxAdjacentItemOpacity],
39
+ extrapolate: 'clamp'
40
+ });
41
+ return {
42
+ transform: [{
43
+ translateX: translate
44
+ }, {
45
+ scale
46
+ }],
47
+ zIndex,
48
+ opacity
49
+ };
50
+ };
51
+
52
+ return createItemStyle;
53
+ }
54
+ ;
55
+ //# sourceMappingURL=parallaxItemStyleFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["itemInterpolationInputRange","defaultParallaxAnimationConfig","parallaxActiveItemScale","parallaxActiveItemOpacity","parallaxAdjacentItemScale","Math","pow","parallaxAdjacentItemOpacity","parallaxScrollingOffset","parallaxItemStyleFactory","config","createItemStyle","itemInterpolation","itemWidth","translate","interpolate","inputRange","outputRange","zIndex","extrapolate","scale","opacity","transform","translateX"],"sources":["parallaxItemStyleFactory.ts"],"sourcesContent":["import type { CreateItemStyle } from '../types';\nimport { itemInterpolationInputRange } from './animationUtils';\n\nexport interface ParallaxAnimationConfig {\n parallaxActiveItemScale?: number;\n parallaxActiveItemOpacity?: number;\n parallaxAdjacentItemScale?: number;\n parallaxAdjacentItemOpacity?: number;\n parallaxScrollingOffset?: number;\n}\n\nconst defaultParallaxAnimationConfig: Required<Readonly<ParallaxAnimationConfig>> = {\n parallaxActiveItemScale: 0.9,\n parallaxActiveItemOpacity: 1,\n parallaxAdjacentItemScale: Math.pow(0.9, 2),\n parallaxAdjacentItemOpacity: 0.5,\n parallaxScrollingOffset: 50,\n};\n\nexport default function parallaxItemStyleFactory(config: ParallaxAnimationConfig = defaultParallaxAnimationConfig) {\n const {\n parallaxActiveItemScale,\n parallaxActiveItemOpacity,\n parallaxAdjacentItemOpacity,\n parallaxAdjacentItemScale,\n parallaxScrollingOffset,\n }: Required<ParallaxAnimationConfig> = {\n ...config,\n ...defaultParallaxAnimationConfig,\n };\n\n const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {\n const translate = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n -itemWidth + parallaxScrollingOffset,\n 0,\n itemWidth - parallaxScrollingOffset,\n ],\n });\n\n const zIndex = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [0, itemWidth, 0],\n extrapolate: 'clamp',\n });\n\n const scale = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n parallaxAdjacentItemScale,\n parallaxActiveItemScale,\n parallaxAdjacentItemScale,\n ],\n extrapolate: 'clamp',\n });\n\n const opacity = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n parallaxAdjacentItemOpacity,\n parallaxActiveItemOpacity,\n parallaxAdjacentItemOpacity,\n ],\n extrapolate: 'clamp',\n });\n\n return {\n transform: [\n { translateX: translate },\n { scale },\n ],\n zIndex,\n opacity,\n };\n };\n\n return createItemStyle;\n};\n"],"mappings":"AACA,SAASA,2BAAT,QAA4C,kBAA5C;AAUA,MAAMC,8BAA2E,GAAG;EAChFC,uBAAuB,EAAE,GADuD;EAEhFC,yBAAyB,EAAE,CAFqD;EAGhFC,yBAAyB,EAAEC,IAAI,CAACC,GAAL,CAAS,GAAT,EAAc,CAAd,CAHqD;EAIhFC,2BAA2B,EAAE,GAJmD;EAKhFC,uBAAuB,EAAE;AALuD,CAApF;AAQA,eAAe,SAASC,wBAAT,GAAoG;EAAA,IAAlEC,MAAkE,uEAAhCT,8BAAgC;EAC/G,MAAM;IACFC,uBADE;IAEFC,yBAFE;IAGFI,2BAHE;IAIFH,yBAJE;IAKFI;EALE,IAMiC,EACnC,GAAGE,MADgC;IAEnC,GAAGT;EAFgC,CANvC;;EAWA,MAAMU,eAAgC,GAAG,CAACC,iBAAD,EAAoBC,SAApB,KAAkC;IACvE,MAAMC,SAAS,GAAGF,iBAAiB,CAACG,WAAlB,CAA8B;MAC5CC,UAAU,EAAEhB,2BADgC;MAE5CiB,WAAW,EAAE,CACT,CAACJ,SAAD,GAAaL,uBADJ,EAET,CAFS,EAGTK,SAAS,GAAGL,uBAHH;IAF+B,CAA9B,CAAlB;IASA,MAAMU,MAAM,GAAGN,iBAAiB,CAACG,WAAlB,CAA8B;MACzCC,UAAU,EAAEhB,2BAD6B;MAEzCiB,WAAW,EAAE,CAAC,CAAD,EAAIJ,SAAJ,EAAe,CAAf,CAF4B;MAGzCM,WAAW,EAAE;IAH4B,CAA9B,CAAf;IAMA,MAAMC,KAAK,GAAGR,iBAAiB,CAACG,WAAlB,CAA8B;MACxCC,UAAU,EAAEhB,2BAD4B;MAExCiB,WAAW,EAAE,CACTb,yBADS,EAETF,uBAFS,EAGTE,yBAHS,CAF2B;MAOxCe,WAAW,EAAE;IAP2B,CAA9B,CAAd;IAUA,MAAME,OAAO,GAAGT,iBAAiB,CAACG,WAAlB,CAA8B;MAC1CC,UAAU,EAAEhB,2BAD8B;MAE1CiB,WAAW,EAAE,CACTV,2BADS,EAETJ,yBAFS,EAGTI,2BAHS,CAF6B;MAO1CY,WAAW,EAAE;IAP6B,CAA9B,CAAhB;IAUA,OAAO;MACHG,SAAS,EAAE,CACP;QAAEC,UAAU,EAAET;MAAd,CADO,EAEP;QAAEM;MAAF,CAFO,CADR;MAKHF,MALG;MAMHG;IANG,CAAP;EAQH,CA5CD;;EA8CA,OAAOV,eAAP;AACH;AAAA"}
@@ -0,0 +1,19 @@
1
+ import { createContext } from 'react';
2
+ import { Animated } from 'react-native';
3
+ const mockItemVisibilityStore = {
4
+ dispatch: () => void 0,
5
+ subscribe: () => () => void 0,
6
+ removeAllListeners: () => void 0
7
+ };
8
+ const initialValue = {
9
+ createItemStyle: () => ({}),
10
+ data: [],
11
+ globalInterpolation: Animated.add(new Animated.Value(0), 0),
12
+ itemHeight: 0,
13
+ itemWidth: 0,
14
+ itemVisibilityStore: mockItemVisibilityStore,
15
+ loop: false
16
+ };
17
+ const InternalContext = /*#__PURE__*/createContext(initialValue);
18
+ export default InternalContext;
19
+ //# sourceMappingURL=InternalContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContext","Animated","mockItemVisibilityStore","dispatch","subscribe","removeAllListeners","initialValue","createItemStyle","data","globalInterpolation","add","Value","itemHeight","itemWidth","itemVisibilityStore","loop","InternalContext"],"sources":["InternalContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { Animated } from 'react-native';\nimport type { CreateItemStyle, ItemVisibilityStore } from '../types';\n\nexport interface InternalContextValue<ItemT> {\n createItemStyle: CreateItemStyle;\n data: ReadonlyArray<ItemT>;\n globalInterpolation: Animated.AnimatedInterpolation;\n itemHeight: number;\n itemWidth: number;\n itemVisibilityStore: ItemVisibilityStore;\n loop: boolean;\n}\n\nconst mockItemVisibilityStore: ItemVisibilityStore = {\n dispatch: () => void 0,\n subscribe: () => () => void 0,\n removeAllListeners: () => void 0,\n};\n\nconst initialValue: Readonly<InternalContextValue<any>> = {\n createItemStyle: () => ({}),\n data: [],\n globalInterpolation: Animated.add(new Animated.Value(0), 0),\n itemHeight: 0,\n itemWidth: 0,\n itemVisibilityStore: mockItemVisibilityStore,\n loop: false,\n};\n\nconst InternalContext = createContext<InternalContextValue<any>>(initialValue);\n\nexport default InternalContext;\n"],"mappings":"AAAA,SAASA,aAAT,QAA8B,OAA9B;AACA,SAASC,QAAT,QAAyB,cAAzB;AAaA,MAAMC,uBAA4C,GAAG;EACjDC,QAAQ,EAAE,MAAM,KAAK,CAD4B;EAEjDC,SAAS,EAAE,MAAM,MAAM,KAAK,CAFqB;EAGjDC,kBAAkB,EAAE,MAAM,KAAK;AAHkB,CAArD;AAMA,MAAMC,YAAiD,GAAG;EACtDC,eAAe,EAAE,OAAO,EAAP,CADqC;EAEtDC,IAAI,EAAE,EAFgD;EAGtDC,mBAAmB,EAAER,QAAQ,CAACS,GAAT,CAAa,IAAIT,QAAQ,CAACU,KAAb,CAAmB,CAAnB,CAAb,EAAoC,CAApC,CAHiC;EAItDC,UAAU,EAAE,CAJ0C;EAKtDC,SAAS,EAAE,CAL2C;EAMtDC,mBAAmB,EAAEZ,uBANiC;EAOtDa,IAAI,EAAE;AAPgD,CAA1D;AAUA,MAAMC,eAAe,gBAAGhB,aAAa,CAA4BM,YAA5B,CAArC;AAEA,eAAeU,eAAf"}
@@ -0,0 +1,44 @@
1
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { StyleSheet } from '@fountain-ui/core';
4
+ import { useItemInterpolation } from '../hooks';
5
+ import InternalContext from './InternalContext';
6
+ export default function ItemView(props) {
7
+ const {
8
+ children,
9
+ index
10
+ } = props;
11
+ const {
12
+ createItemStyle,
13
+ itemHeight,
14
+ itemWidth,
15
+ itemVisibilityStore
16
+ } = useContext(InternalContext);
17
+ const [visible, setVisible] = useState(false);
18
+ const interpolation = useItemInterpolation(index);
19
+ const itemStyle = useMemo(() => createItemStyle(interpolation, itemWidth), [createItemStyle, interpolation]);
20
+ useEffect(() => {
21
+ return itemVisibilityStore.subscribe(ranges => {
22
+ const nextVisible = ranges.some(_ref => {
23
+ let [from, to] = _ref;
24
+ return index >= from && index <= to;
25
+ });
26
+ setVisible(nextVisible);
27
+ });
28
+ }, [itemVisibilityStore]);
29
+ return /*#__PURE__*/React.createElement(Animated.View, {
30
+ children: visible ? children(interpolation) : null,
31
+ style: [{
32
+ width: itemWidth,
33
+ height: itemHeight
34
+ }, styles.absolute, // @ts-ignore
35
+ itemStyle]
36
+ });
37
+ }
38
+ ;
39
+ const styles = StyleSheet.create({
40
+ absolute: {
41
+ position: 'absolute'
42
+ }
43
+ });
44
+ //# sourceMappingURL=ItemView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useContext","useEffect","useMemo","useState","Animated","StyleSheet","useItemInterpolation","InternalContext","ItemView","props","children","index","createItemStyle","itemHeight","itemWidth","itemVisibilityStore","visible","setVisible","interpolation","itemStyle","subscribe","ranges","nextVisible","some","from","to","width","height","styles","absolute","create","position"],"sources":["ItemView.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useMemo, useState } from 'react';\nimport { Animated } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport { useItemInterpolation } from '../hooks';\nimport InternalContext from './InternalContext';\n\nexport interface ItemViewProps {\n children: (interpolation: Animated.AnimatedInterpolation) => ReactElement | null;\n index: number;\n}\n\nexport default function ItemView(props: ItemViewProps) {\n const { children, index } = props;\n\n const {\n createItemStyle,\n itemHeight,\n itemWidth,\n itemVisibilityStore,\n } = useContext(InternalContext);\n\n const [visible, setVisible] = useState(false);\n\n const interpolation = useItemInterpolation(index);\n\n const itemStyle = useMemo(\n () => createItemStyle(interpolation, itemWidth),\n [createItemStyle, interpolation],\n );\n\n useEffect(() => {\n return itemVisibilityStore.subscribe(ranges => {\n const nextVisible = ranges.some(([from, to]) => index >= from && index <= to);\n setVisible(nextVisible);\n });\n }, [itemVisibilityStore]);\n\n return (\n <Animated.View\n children={visible ? children(interpolation) : null}\n style={[\n { width: itemWidth, height: itemHeight },\n styles.absolute,\n // @ts-ignore\n itemStyle,\n ]}\n />\n );\n};\n\nconst styles = StyleSheet.create({\n absolute: {\n position: 'absolute',\n },\n});\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,SAA5B,EAAuCC,OAAvC,EAAgDC,QAAhD,QAAgE,OAAhE;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,UAAT,QAA2B,mBAA3B;AACA,SAASC,oBAAT,QAAqC,UAArC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAOA,eAAe,SAASC,QAAT,CAAkBC,KAAlB,EAAwC;EACnD,MAAM;IAAEC,QAAF;IAAYC;EAAZ,IAAsBF,KAA5B;EAEA,MAAM;IACFG,eADE;IAEFC,UAFE;IAGFC,SAHE;IAIFC;EAJE,IAKFf,UAAU,CAACO,eAAD,CALd;EAOA,MAAM,CAACS,OAAD,EAAUC,UAAV,IAAwBd,QAAQ,CAAC,KAAD,CAAtC;EAEA,MAAMe,aAAa,GAAGZ,oBAAoB,CAACK,KAAD,CAA1C;EAEA,MAAMQ,SAAS,GAAGjB,OAAO,CACrB,MAAMU,eAAe,CAACM,aAAD,EAAgBJ,SAAhB,CADA,EAErB,CAACF,eAAD,EAAkBM,aAAlB,CAFqB,CAAzB;EAKAjB,SAAS,CAAC,MAAM;IACZ,OAAOc,mBAAmB,CAACK,SAApB,CAA8BC,MAAM,IAAI;MAC3C,MAAMC,WAAW,GAAGD,MAAM,CAACE,IAAP,CAAY;QAAA,IAAC,CAACC,IAAD,EAAOC,EAAP,CAAD;QAAA,OAAgBd,KAAK,IAAIa,IAAT,IAAiBb,KAAK,IAAIc,EAA1C;MAAA,CAAZ,CAApB;MACAR,UAAU,CAACK,WAAD,CAAV;IACH,CAHM,CAAP;EAIH,CALQ,EAKN,CAACP,mBAAD,CALM,CAAT;EAOA,oBACI,oBAAC,QAAD,CAAU,IAAV;IACI,QAAQ,EAAEC,OAAO,GAAGN,QAAQ,CAACQ,aAAD,CAAX,GAA6B,IADlD;IAEI,KAAK,EAAE,CACH;MAAEQ,KAAK,EAAEZ,SAAT;MAAoBa,MAAM,EAAEd;IAA5B,CADG,EAEHe,MAAM,CAACC,QAFJ,EAGH;IACAV,SAJG;EAFX,EADJ;AAWH;AAAA;AAED,MAAMS,MAAM,GAAGvB,UAAU,CAACyB,MAAX,CAAkB;EAC7BD,QAAQ,EAAE;IACNE,QAAQ,EAAE;EADJ;AADmB,CAAlB,CAAf"}
@@ -0,0 +1,47 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { memo, forwardRef } from 'react';
4
+ import { Animated } from 'react-native';
5
+ import { StyleSheet } from '@fountain-ui/core';
6
+ import ItemView from './ItemView';
7
+ const styles = StyleSheet.create({
8
+ root: {
9
+ width: '100%',
10
+ justifyContent: 'center'
11
+ },
12
+ horizontal: {
13
+ flexDirection: 'row',
14
+ overflow: 'hidden'
15
+ }
16
+ });
17
+ const RootView = /*#__PURE__*/forwardRef(function RootView(props, ref) {
18
+ const {
19
+ data,
20
+ itemHeight,
21
+ originalData,
22
+ renderItem,
23
+ style,
24
+ ...otherProps
25
+ } = props;
26
+
27
+ const renderItemView = (item, index) => /*#__PURE__*/React.createElement(ItemView, {
28
+ key: index,
29
+ index: index
30
+ }, interpolation => renderItem({
31
+ item,
32
+ index: index % originalData.length,
33
+ interpolation
34
+ }));
35
+
36
+ const viewStyles = [styles.root, styles.horizontal, {
37
+ height: itemHeight
38
+ }, style];
39
+ return /*#__PURE__*/React.createElement(Animated.View, _extends({
40
+ ref: ref
41
+ }, otherProps, {
42
+ children: data.map(renderItemView),
43
+ style: viewStyles
44
+ }));
45
+ });
46
+ export default /*#__PURE__*/memo(RootView);
47
+ //# sourceMappingURL=RootView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","memo","forwardRef","Animated","StyleSheet","ItemView","styles","create","root","width","justifyContent","horizontal","flexDirection","overflow","RootView","props","ref","data","itemHeight","originalData","renderItem","style","otherProps","renderItemView","item","index","interpolation","length","viewStyles","height","map"],"sources":["RootView.tsx"],"sourcesContent":["import React, { memo, ReactElement, forwardRef } from 'react';\nimport type { ViewProps, View } from 'react-native';\nimport { Animated } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { RenderItem } from '../types';\nimport ItemView from './ItemView';\n\nconst styles = StyleSheet.create({\n root: {\n width: '100%',\n justifyContent: 'center',\n },\n horizontal: {\n flexDirection: 'row',\n overflow: 'hidden',\n },\n});\n\nexport type RootViewProps<ItemT> = ViewProps & {\n data: ReadonlyArray<ItemT>;\n itemHeight: number;\n originalData: ReadonlyArray<ItemT>;\n renderItem: RenderItem<ItemT>;\n};\n\nconst RootView = forwardRef<View, RootViewProps<any>>(function RootView(props, ref) {\n const {\n data,\n itemHeight,\n originalData,\n renderItem,\n style,\n ...otherProps\n } = props;\n\n const renderItemView = (item: any, index: number): ReactElement => (\n <ItemView\n key={index}\n index={index}\n >\n {(interpolation) => renderItem({\n item,\n index: index % originalData.length,\n interpolation,\n })}\n </ItemView>\n );\n\n const viewStyles = [\n styles.root,\n styles.horizontal,\n { height: itemHeight },\n style,\n ];\n\n return (\n <Animated.View\n ref={ref}\n {...otherProps}\n children={data.map(renderItemView)}\n style={viewStyles}\n />\n );\n});\n\nexport default memo(RootView);\n"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,IAAhB,EAAoCC,UAApC,QAAsD,OAAtD;AAEA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA,OAAOC,QAAP,MAAqB,YAArB;AAEA,MAAMC,MAAM,GAAGF,UAAU,CAACG,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IACFC,KAAK,EAAE,MADL;IAEFC,cAAc,EAAE;EAFd,CADuB;EAK7BC,UAAU,EAAE;IACRC,aAAa,EAAE,KADP;IAERC,QAAQ,EAAE;EAFF;AALiB,CAAlB,CAAf;AAkBA,MAAMC,QAAQ,gBAAGZ,UAAU,CAA2B,SAASY,QAAT,CAAkBC,KAAlB,EAAyBC,GAAzB,EAA8B;EAChF,MAAM;IACFC,IADE;IAEFC,UAFE;IAGFC,YAHE;IAIFC,UAJE;IAKFC,KALE;IAMF,GAAGC;EAND,IAOFP,KAPJ;;EASA,MAAMQ,cAAc,GAAG,CAACC,IAAD,EAAYC,KAAZ,kBACnB,oBAAC,QAAD;IACI,GAAG,EAAEA,KADT;IAEI,KAAK,EAAEA;EAFX,GAIMC,aAAD,IAAmBN,UAAU,CAAC;IAC3BI,IAD2B;IAE3BC,KAAK,EAAEA,KAAK,GAAGN,YAAY,CAACQ,MAFD;IAG3BD;EAH2B,CAAD,CAJlC,CADJ;;EAaA,MAAME,UAAU,GAAG,CACftB,MAAM,CAACE,IADQ,EAEfF,MAAM,CAACK,UAFQ,EAGf;IAAEkB,MAAM,EAAEX;EAAV,CAHe,EAIfG,KAJe,CAAnB;EAOA,oBACI,oBAAC,QAAD,CAAU,IAAV;IACI,GAAG,EAAEL;EADT,GAEQM,UAFR;IAGI,QAAQ,EAAEL,IAAI,CAACa,GAAL,CAASP,cAAT,CAHd;IAII,KAAK,EAAEK;EAJX,GADJ;AAQH,CAtC0B,CAA3B;AAwCA,4BAAe3B,IAAI,CAACa,QAAD,CAAnB"}
@@ -0,0 +1,62 @@
1
+ import React, { useCallback } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { PanGestureHandler, State as GestureHandlerState } from 'react-native-gesture-handler';
4
+ const SCROLL_TO_ADJACENT_TX_THRESHOLD = 60;
5
+ const SCROLL_TO_ADJACENT_VX_THRESHOLD = 500;
6
+ const ACTIVE_OFFSET_ABS_X = 5;
7
+ const activeOffsetX = [-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X];
8
+ const endAnimationStates = [GestureHandlerState.CANCELLED, GestureHandlerState.END];
9
+
10
+ function shouldScrollToAdjacent(translationX, velocityX) {
11
+ return Math.abs(translationX) >= SCROLL_TO_ADJACENT_TX_THRESHOLD || Math.abs(velocityX) >= SCROLL_TO_ADJACENT_VX_THRESHOLD;
12
+ }
13
+
14
+ export default function ScrollViewGesture(props) {
15
+ const {
16
+ autoplayController,
17
+ children,
18
+ finalizeAnimation,
19
+ offsetTx,
20
+ scrollEnabled,
21
+ startAnimation
22
+ } = props;
23
+ const {
24
+ pause: pauseAutoplay,
25
+ resume: resumeAutoplay
26
+ } = autoplayController;
27
+ const handleGestureBegin = useCallback(() => {
28
+ pauseAutoplay();
29
+ finalizeAnimation();
30
+ }, [finalizeAnimation, pauseAutoplay]);
31
+ const handleGestureEvent = useCallback(Animated.event([{
32
+ nativeEvent: {
33
+ translationX: offsetTx
34
+ }
35
+ }], {
36
+ useNativeDriver: true
37
+ }), []);
38
+ const handleHandlerStateChange = useCallback(event => {
39
+ const {
40
+ nativeEvent: {
41
+ translationX,
42
+ velocityX,
43
+ state
44
+ }
45
+ } = event;
46
+
47
+ if (endAnimationStates.includes(state)) {
48
+ const userDirection = shouldScrollToAdjacent(translationX, velocityX) ? translationX < 0 ? 'next' : 'prev' : 'stay';
49
+ startAnimation(userDirection, true);
50
+ resumeAutoplay();
51
+ }
52
+ }, [startAnimation, resumeAutoplay]);
53
+ return /*#__PURE__*/React.createElement(PanGestureHandler, {
54
+ activeOffsetX: activeOffsetX,
55
+ children: children,
56
+ enabled: scrollEnabled,
57
+ onBegan: handleGestureBegin,
58
+ onGestureEvent: handleGestureEvent,
59
+ onHandlerStateChange: handleHandlerStateChange
60
+ });
61
+ }
62
+ //# sourceMappingURL=ScrollViewGesture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useCallback","Animated","PanGestureHandler","State","GestureHandlerState","SCROLL_TO_ADJACENT_TX_THRESHOLD","SCROLL_TO_ADJACENT_VX_THRESHOLD","ACTIVE_OFFSET_ABS_X","activeOffsetX","endAnimationStates","CANCELLED","END","shouldScrollToAdjacent","translationX","velocityX","Math","abs","ScrollViewGesture","props","autoplayController","children","finalizeAnimation","offsetTx","scrollEnabled","startAnimation","pause","pauseAutoplay","resume","resumeAutoplay","handleGestureBegin","handleGestureEvent","event","nativeEvent","useNativeDriver","handleHandlerStateChange","state","includes","userDirection"],"sources":["ScrollViewGesture.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport React, { useCallback } from 'react';\nimport { Animated } from 'react-native';\nimport type { PanGestureHandlerStateChangeEvent } from 'react-native-gesture-handler';\nimport { PanGestureHandler, State as GestureHandlerState } from 'react-native-gesture-handler';\nimport type { AutoplayController, PagingDirection, StartPagingAnimation } from '../types';\n\nexport interface ScrollViewGestureProps {\n autoplayController: AutoplayController;\n children: ReactNode;\n finalizeAnimation: () => void;\n offsetTx: Animated.Value,\n scrollEnabled: boolean;\n startAnimation: StartPagingAnimation;\n}\n\nconst SCROLL_TO_ADJACENT_TX_THRESHOLD = 60;\nconst SCROLL_TO_ADJACENT_VX_THRESHOLD = 500;\n\nconst ACTIVE_OFFSET_ABS_X = 5;\nconst activeOffsetX: number[] = [-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X];\n\nconst endAnimationStates: Readonly<GestureHandlerState[]> = [\n GestureHandlerState.CANCELLED,\n GestureHandlerState.END,\n];\n\nfunction shouldScrollToAdjacent(translationX: number, velocityX: number): boolean {\n return Math.abs(translationX) >= SCROLL_TO_ADJACENT_TX_THRESHOLD\n || Math.abs(velocityX) >= SCROLL_TO_ADJACENT_VX_THRESHOLD;\n}\n\nexport default function ScrollViewGesture(props: ScrollViewGestureProps) {\n const {\n autoplayController,\n children,\n finalizeAnimation,\n offsetTx,\n scrollEnabled,\n startAnimation,\n } = props;\n\n const { pause: pauseAutoplay, resume: resumeAutoplay } = autoplayController;\n\n const handleGestureBegin = useCallback(() => {\n pauseAutoplay();\n\n finalizeAnimation();\n }, [finalizeAnimation, pauseAutoplay]);\n\n const handleGestureEvent = useCallback(Animated.event(\n [{ nativeEvent: { translationX: offsetTx } }],\n { useNativeDriver: true },\n ), []);\n\n const handleHandlerStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {\n const { nativeEvent: { translationX, velocityX, state } } = event;\n\n if (endAnimationStates.includes(state)) {\n const userDirection: PagingDirection = shouldScrollToAdjacent(translationX, velocityX)\n ? (translationX < 0 ? 'next' : 'prev')\n : 'stay';\n\n startAnimation(userDirection, true);\n\n resumeAutoplay();\n }\n }, [startAnimation, resumeAutoplay]);\n\n return (\n <PanGestureHandler\n activeOffsetX={activeOffsetX}\n children={children}\n enabled={scrollEnabled}\n onBegan={handleGestureBegin}\n onGestureEvent={handleGestureEvent}\n onHandlerStateChange={handleHandlerStateChange}\n />\n );\n}\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,iBAAT,EAA4BC,KAAK,IAAIC,mBAArC,QAAgE,8BAAhE;AAYA,MAAMC,+BAA+B,GAAG,EAAxC;AACA,MAAMC,+BAA+B,GAAG,GAAxC;AAEA,MAAMC,mBAAmB,GAAG,CAA5B;AACA,MAAMC,aAAuB,GAAG,CAAC,CAACD,mBAAF,EAAuBA,mBAAvB,CAAhC;AAEA,MAAME,kBAAmD,GAAG,CACxDL,mBAAmB,CAACM,SADoC,EAExDN,mBAAmB,CAACO,GAFoC,CAA5D;;AAKA,SAASC,sBAAT,CAAgCC,YAAhC,EAAsDC,SAAtD,EAAkF;EAC9E,OAAOC,IAAI,CAACC,GAAL,CAASH,YAAT,KAA0BR,+BAA1B,IACAU,IAAI,CAACC,GAAL,CAASF,SAAT,KAAuBR,+BAD9B;AAEH;;AAED,eAAe,SAASW,iBAAT,CAA2BC,KAA3B,EAA0D;EACrE,MAAM;IACFC,kBADE;IAEFC,QAFE;IAGFC,iBAHE;IAIFC,QAJE;IAKFC,aALE;IAMFC;EANE,IAOFN,KAPJ;EASA,MAAM;IAAEO,KAAK,EAAEC,aAAT;IAAwBC,MAAM,EAAEC;EAAhC,IAAmDT,kBAAzD;EAEA,MAAMU,kBAAkB,GAAG7B,WAAW,CAAC,MAAM;IACzC0B,aAAa;IAEbL,iBAAiB;EACpB,CAJqC,EAInC,CAACA,iBAAD,EAAoBK,aAApB,CAJmC,CAAtC;EAMA,MAAMI,kBAAkB,GAAG9B,WAAW,CAACC,QAAQ,CAAC8B,KAAT,CACnC,CAAC;IAAEC,WAAW,EAAE;MAAEnB,YAAY,EAAES;IAAhB;EAAf,CAAD,CADmC,EAEnC;IAAEW,eAAe,EAAE;EAAnB,CAFmC,CAAD,EAGnC,EAHmC,CAAtC;EAKA,MAAMC,wBAAwB,GAAGlC,WAAW,CAAE+B,KAAD,IAA8C;IACvF,MAAM;MAAEC,WAAW,EAAE;QAAEnB,YAAF;QAAgBC,SAAhB;QAA2BqB;MAA3B;IAAf,IAAsDJ,KAA5D;;IAEA,IAAItB,kBAAkB,CAAC2B,QAAnB,CAA4BD,KAA5B,CAAJ,EAAwC;MACpC,MAAME,aAA8B,GAAGzB,sBAAsB,CAACC,YAAD,EAAeC,SAAf,CAAtB,GAChCD,YAAY,GAAG,CAAf,GAAmB,MAAnB,GAA4B,MADI,GAEjC,MAFN;MAIAW,cAAc,CAACa,aAAD,EAAgB,IAAhB,CAAd;MAEAT,cAAc;IACjB;EACJ,CAZ2C,EAYzC,CAACJ,cAAD,EAAiBI,cAAjB,CAZyC,CAA5C;EAcA,oBACI,oBAAC,iBAAD;IACI,aAAa,EAAEpB,aADnB;IAEI,QAAQ,EAAEY,QAFd;IAGI,OAAO,EAAEG,aAHb;IAII,OAAO,EAAEM,kBAJb;IAKI,cAAc,EAAEC,kBALpB;IAMI,oBAAoB,EAAEI;EAN1B,EADJ;AAUH"}
@@ -0,0 +1,5 @@
1
+ export { default as InternalContext } from './InternalContext';
2
+ export { default as ItemView } from './ItemView';
3
+ export { default as RootView } from './RootView';
4
+ export { default as ScrollViewGesture } from './ScrollViewGesture';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","InternalContext","ItemView","RootView","ScrollViewGesture"],"sources":["index.ts"],"sourcesContent":["export { default as InternalContext } from './InternalContext';\nexport { default as ItemView } from './ItemView';\nexport { default as RootView } from './RootView';\nexport { default as ScrollViewGesture } from './ScrollViewGesture';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,eAApB,QAA2C,mBAA3C;AACA,SAASD,OAAO,IAAIE,QAApB,QAAoC,YAApC;AACA,SAASF,OAAO,IAAIG,QAApB,QAAoC,YAApC;AACA,SAASH,OAAO,IAAII,iBAApB,QAA6C,qBAA7C"}
@@ -0,0 +1,8 @@
1
+ export { default as useAutoplayController } from './useAutoplayController';
2
+ export { default as useDimensionChangeReaction } from './useDimensionChangeReaction';
3
+ export { default as useIndexController } from './useIndexController';
4
+ export { default as useItemInterpolation } from './useItemInterpolation';
5
+ export { default as useLoopedData } from './useLoopedData';
6
+ export { default as usePagingAnimation } from './usePagingAnimation';
7
+ export { default as useItemVisibilityStore } from './useItemVisibilityStore';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","useAutoplayController","useDimensionChangeReaction","useIndexController","useItemInterpolation","useLoopedData","usePagingAnimation","useItemVisibilityStore"],"sources":["index.ts"],"sourcesContent":["export { default as useAutoplayController } from './useAutoplayController';\nexport { default as useDimensionChangeReaction } from './useDimensionChangeReaction';\nexport { default as useIndexController } from './useIndexController';\nexport { default as useItemInterpolation } from './useItemInterpolation';\nexport { default as useLoopedData } from './useLoopedData';\nexport { default as usePagingAnimation } from './usePagingAnimation';\nexport { default as useItemVisibilityStore } from './useItemVisibilityStore';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,qBAApB,QAAiD,yBAAjD;AACA,SAASD,OAAO,IAAIE,0BAApB,QAAsD,8BAAtD;AACA,SAASF,OAAO,IAAIG,kBAApB,QAA8C,sBAA9C;AACA,SAASH,OAAO,IAAII,oBAApB,QAAgD,wBAAhD;AACA,SAASJ,OAAO,IAAIK,aAApB,QAAyC,iBAAzC;AACA,SAASL,OAAO,IAAIM,kBAApB,QAA8C,sBAA9C;AACA,SAASN,OAAO,IAAIO,sBAApB,QAAkD,0BAAlD"}
@@ -0,0 +1,45 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { useDeferredExecutor } from '../../hooks';
3
+ export default function useAutoplayController(config) {
4
+ const {
5
+ enabled,
6
+ intervalMillis,
7
+ startPagingAnimation
8
+ } = config;
9
+ const paused = useRef(false);
10
+ const executor = useDeferredExecutor();
11
+ const play = useCallback(() => {
12
+ if (paused.current) {
13
+ return;
14
+ }
15
+
16
+ executor.execute(() => {
17
+ startPagingAnimation('next', false);
18
+ play();
19
+ }, intervalMillis);
20
+ }, [intervalMillis, startPagingAnimation]);
21
+ const pause = useCallback(() => {
22
+ executor.cancel();
23
+ paused.current = true;
24
+ }, []);
25
+ const resume = useCallback(() => {
26
+ paused.current = false;
27
+
28
+ if (enabled) {
29
+ play();
30
+ }
31
+ }, [play, enabled]);
32
+ useEffect(() => {
33
+ if (enabled) {
34
+ resume();
35
+ } else {
36
+ pause();
37
+ }
38
+ }, [enabled]);
39
+ return {
40
+ pause,
41
+ resume
42
+ };
43
+ }
44
+ ;
45
+ //# sourceMappingURL=useAutoplayController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useEffect","useRef","useDeferredExecutor","useAutoplayController","config","enabled","intervalMillis","startPagingAnimation","paused","executor","play","current","execute","pause","cancel","resume"],"sources":["useAutoplayController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { AutoplayController, StartPagingAnimation } from '../types';\nimport { useDeferredExecutor } from '../../hooks';\n\nexport interface AutoplayConfig {\n enabled: boolean;\n intervalMillis: number;\n startPagingAnimation: StartPagingAnimation;\n}\n\nexport default function useAutoplayController(config: AutoplayConfig): AutoplayController {\n const {\n enabled,\n intervalMillis,\n startPagingAnimation,\n } = config;\n\n const paused = useRef<boolean>(false);\n\n const executor = useDeferredExecutor();\n\n const play = useCallback(() => {\n if (paused.current) {\n return;\n }\n\n executor.execute(() => {\n startPagingAnimation('next', false);\n play();\n }, intervalMillis);\n }, [intervalMillis, startPagingAnimation]);\n\n const pause = useCallback(() => {\n executor.cancel();\n paused.current = true;\n }, []);\n\n const resume = useCallback(() => {\n paused.current = false;\n if (enabled) {\n play();\n }\n }, [play, enabled]);\n\n useEffect(() => {\n if (enabled) {\n resume();\n } else {\n pause();\n }\n }, [enabled]);\n\n return { pause, resume };\n};\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,QAA+C,OAA/C;AAEA,SAASC,mBAAT,QAAoC,aAApC;AAQA,eAAe,SAASC,qBAAT,CAA+BC,MAA/B,EAA2E;EACtF,MAAM;IACFC,OADE;IAEFC,cAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,MAAMI,MAAM,GAAGP,MAAM,CAAU,KAAV,CAArB;EAEA,MAAMQ,QAAQ,GAAGP,mBAAmB,EAApC;EAEA,MAAMQ,IAAI,GAAGX,WAAW,CAAC,MAAM;IAC3B,IAAIS,MAAM,CAACG,OAAX,EAAoB;MAChB;IACH;;IAEDF,QAAQ,CAACG,OAAT,CAAiB,MAAM;MACnBL,oBAAoB,CAAC,MAAD,EAAS,KAAT,CAApB;MACAG,IAAI;IACP,CAHD,EAGGJ,cAHH;EAIH,CATuB,EASrB,CAACA,cAAD,EAAiBC,oBAAjB,CATqB,CAAxB;EAWA,MAAMM,KAAK,GAAGd,WAAW,CAAC,MAAM;IAC5BU,QAAQ,CAACK,MAAT;IACAN,MAAM,CAACG,OAAP,GAAiB,IAAjB;EACH,CAHwB,EAGtB,EAHsB,CAAzB;EAKA,MAAMI,MAAM,GAAGhB,WAAW,CAAC,MAAM;IAC7BS,MAAM,CAACG,OAAP,GAAiB,KAAjB;;IACA,IAAIN,OAAJ,EAAa;MACTK,IAAI;IACP;EACJ,CALyB,EAKvB,CAACA,IAAD,EAAOL,OAAP,CALuB,CAA1B;EAOAL,SAAS,CAAC,MAAM;IACZ,IAAIK,OAAJ,EAAa;MACTU,MAAM;IACT,CAFD,MAEO;MACHF,KAAK;IACR;EACJ,CANQ,EAMN,CAACR,OAAD,CANM,CAAT;EAQA,OAAO;IAAEQ,KAAF;IAASE;EAAT,CAAP;AACH;AAAA"}
@@ -0,0 +1,14 @@
1
+ import { useEffect } from 'react';
2
+ export default function useDimensionChangeReaction(params) {
3
+ const {
4
+ controlledTx,
5
+ currentIndex,
6
+ itemWidth
7
+ } = params;
8
+ useEffect(() => {
9
+ const newTx = -currentIndex * itemWidth;
10
+ controlledTx.setValue(newTx);
11
+ }, [controlledTx, currentIndex, itemWidth]);
12
+ }
13
+ ;
14
+ //# sourceMappingURL=useDimensionChangeReaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useDimensionChangeReaction","params","controlledTx","currentIndex","itemWidth","newTx","setValue"],"sources":["useDimensionChangeReaction.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { Animated } from 'react-native';\n\nexport interface Parameters {\n controlledTx: Animated.AnimatedValue;\n currentIndex: number;\n itemWidth: number;\n}\n\nexport default function useDimensionChangeReaction(params: Parameters) {\n const {\n controlledTx,\n currentIndex,\n itemWidth,\n } = params;\n\n useEffect(() => {\n const newTx = -currentIndex * itemWidth;\n controlledTx.setValue(newTx);\n }, [\n controlledTx,\n currentIndex,\n itemWidth,\n ]);\n};\n"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AASA,eAAe,SAASC,0BAAT,CAAoCC,MAApC,EAAwD;EACnE,MAAM;IACFC,YADE;IAEFC,YAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMAF,SAAS,CAAC,MAAM;IACZ,MAAMM,KAAK,GAAG,CAACF,YAAD,GAAgBC,SAA9B;IACAF,YAAY,CAACI,QAAb,CAAsBD,KAAtB;EACH,CAHQ,EAGN,CACCH,YADD,EAECC,YAFD,EAGCC,SAHD,CAHM,CAAT;AAQH;AAAA"}
@@ -0,0 +1,54 @@
1
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Animated } from 'react-native';
3
+
4
+ const normalizeIndex = (maybeIndex, numberOfData) => Math.abs(Math.floor(maybeIndex)) % numberOfData;
5
+
6
+ export default function useIndexController(params) {
7
+ const {
8
+ controlledTx,
9
+ initialIndex,
10
+ itemWidth,
11
+ numberOfOriginalData,
12
+ onIndexChange
13
+ } = params;
14
+ const indexRef = useRef(initialIndex);
15
+ const [index, setIndex] = useState(indexRef.current);
16
+ const maybeIndex = useMemo(() => {
17
+ const negative = new Animated.Value(-1);
18
+ const reversedTx = Animated.multiply(controlledTx, negative);
19
+ const normalized = Animated.divide(reversedTx, itemWidth);
20
+ return Animated.modulo(normalized, numberOfOriginalData);
21
+ }, [controlledTx, itemWidth, numberOfOriginalData]);
22
+ useEffect(() => {
23
+ const subscriptionId = maybeIndex.addListener(observedValue => {
24
+ const newIndex = normalizeIndex(observedValue.value, numberOfOriginalData);
25
+
26
+ if (indexRef.current !== newIndex) {
27
+ indexRef.current = newIndex;
28
+ setIndex(newIndex);
29
+ onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(newIndex);
30
+ }
31
+ });
32
+ return () => {
33
+ maybeIndex.removeListener(subscriptionId);
34
+ };
35
+ }, [maybeIndex, numberOfOriginalData, onIndexChange]);
36
+ const getCurrentIndex = useCallback(() => indexRef.current, []);
37
+ return {
38
+ currentIndex: index,
39
+ getCurrentIndex,
40
+ lastIndex: numberOfOriginalData - 1,
41
+ monitorElement: /*#__PURE__*/React.createElement(Animated.View, {
42
+ collapsable: false,
43
+ style: [{
44
+ zIndex: maybeIndex
45
+ }, {
46
+ width: 1,
47
+ height: 1,
48
+ position: 'absolute'
49
+ }]
50
+ })
51
+ };
52
+ }
53
+ ;
54
+ //# sourceMappingURL=useIndexController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useCallback","useEffect","useMemo","useRef","useState","Animated","normalizeIndex","maybeIndex","numberOfData","Math","abs","floor","useIndexController","params","controlledTx","initialIndex","itemWidth","numberOfOriginalData","onIndexChange","indexRef","index","setIndex","current","negative","Value","reversedTx","multiply","normalized","divide","modulo","subscriptionId","addListener","observedValue","newIndex","value","removeListener","getCurrentIndex","currentIndex","lastIndex","monitorElement","zIndex","width","height","position"],"sources":["useIndexController.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { Animated } from 'react-native';\nimport type { IndexController } from '../types';\n\nexport interface UseIndexControllerParameters {\n controlledTx: Animated.AnimatedValue;\n initialIndex: number;\n itemWidth: number;\n numberOfOriginalData: number;\n onIndexChange?: (newIndex: number) => void;\n}\n\nconst normalizeIndex = (maybeIndex: number, numberOfData: number): number =>\n Math.abs(Math.floor(maybeIndex)) % numberOfData;\n\nexport default function useIndexController(params: UseIndexControllerParameters): IndexController {\n const {\n controlledTx,\n initialIndex,\n itemWidth,\n numberOfOriginalData,\n onIndexChange,\n } = params;\n\n const indexRef = useRef<number>(initialIndex);\n const [index, setIndex] = useState<number>(indexRef.current);\n\n const maybeIndex = useMemo(() => {\n const negative = new Animated.Value(-1);\n const reversedTx = Animated.multiply(controlledTx, negative);\n const normalized = Animated.divide(reversedTx, itemWidth);\n return Animated.modulo(normalized, numberOfOriginalData);\n }, [\n controlledTx,\n itemWidth,\n numberOfOriginalData,\n ]);\n\n useEffect(() => {\n const subscriptionId = maybeIndex.addListener((observedValue) => {\n const newIndex = normalizeIndex(observedValue.value, numberOfOriginalData);\n\n if (indexRef.current !== newIndex) {\n indexRef.current = newIndex;\n setIndex(newIndex);\n\n onIndexChange?.(newIndex);\n }\n });\n\n return () => {\n maybeIndex.removeListener(subscriptionId);\n };\n }, [\n maybeIndex,\n numberOfOriginalData,\n onIndexChange,\n ]);\n\n const getCurrentIndex = useCallback(() => indexRef.current, []);\n\n return {\n currentIndex: index,\n getCurrentIndex,\n lastIndex: numberOfOriginalData - 1,\n monitorElement: (\n <Animated.View\n collapsable={false}\n style={[\n { zIndex: maybeIndex },\n { width: 1, height: 1, position: 'absolute' },\n ]}\n />\n ),\n };\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,OAAxC,EAAiDC,MAAjD,EAAyDC,QAAzD,QAAyE,OAAzE;AACA,SAASC,QAAT,QAAyB,cAAzB;;AAWA,MAAMC,cAAc,GAAG,CAACC,UAAD,EAAqBC,YAArB,KACnBC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,KAAL,CAAWJ,UAAX,CAAT,IAAmCC,YADvC;;AAGA,eAAe,SAASI,kBAAT,CAA4BC,MAA5B,EAAmF;EAC9F,MAAM;IACFC,YADE;IAEFC,YAFE;IAGFC,SAHE;IAIFC,oBAJE;IAKFC;EALE,IAMFL,MANJ;EAQA,MAAMM,QAAQ,GAAGhB,MAAM,CAASY,YAAT,CAAvB;EACA,MAAM,CAACK,KAAD,EAAQC,QAAR,IAAoBjB,QAAQ,CAASe,QAAQ,CAACG,OAAlB,CAAlC;EAEA,MAAMf,UAAU,GAAGL,OAAO,CAAC,MAAM;IAC7B,MAAMqB,QAAQ,GAAG,IAAIlB,QAAQ,CAACmB,KAAb,CAAmB,CAAC,CAApB,CAAjB;IACA,MAAMC,UAAU,GAAGpB,QAAQ,CAACqB,QAAT,CAAkBZ,YAAlB,EAAgCS,QAAhC,CAAnB;IACA,MAAMI,UAAU,GAAGtB,QAAQ,CAACuB,MAAT,CAAgBH,UAAhB,EAA4BT,SAA5B,CAAnB;IACA,OAAOX,QAAQ,CAACwB,MAAT,CAAgBF,UAAhB,EAA4BV,oBAA5B,CAAP;EACH,CALyB,EAKvB,CACCH,YADD,EAECE,SAFD,EAGCC,oBAHD,CALuB,CAA1B;EAWAhB,SAAS,CAAC,MAAM;IACZ,MAAM6B,cAAc,GAAGvB,UAAU,CAACwB,WAAX,CAAwBC,aAAD,IAAmB;MAC7D,MAAMC,QAAQ,GAAG3B,cAAc,CAAC0B,aAAa,CAACE,KAAf,EAAsBjB,oBAAtB,CAA/B;;MAEA,IAAIE,QAAQ,CAACG,OAAT,KAAqBW,QAAzB,EAAmC;QAC/Bd,QAAQ,CAACG,OAAT,GAAmBW,QAAnB;QACAZ,QAAQ,CAACY,QAAD,CAAR;QAEAf,aAAa,SAAb,IAAAA,aAAa,WAAb,YAAAA,aAAa,CAAGe,QAAH,CAAb;MACH;IACJ,CATsB,CAAvB;IAWA,OAAO,MAAM;MACT1B,UAAU,CAAC4B,cAAX,CAA0BL,cAA1B;IACH,CAFD;EAGH,CAfQ,EAeN,CACCvB,UADD,EAECU,oBAFD,EAGCC,aAHD,CAfM,CAAT;EAqBA,MAAMkB,eAAe,GAAGpC,WAAW,CAAC,MAAMmB,QAAQ,CAACG,OAAhB,EAAyB,EAAzB,CAAnC;EAEA,OAAO;IACHe,YAAY,EAAEjB,KADX;IAEHgB,eAFG;IAGHE,SAAS,EAAErB,oBAAoB,GAAG,CAH/B;IAIHsB,cAAc,eACV,oBAAC,QAAD,CAAU,IAAV;MACI,WAAW,EAAE,KADjB;MAEI,KAAK,EAAE,CACH;QAAEC,MAAM,EAAEjC;MAAV,CADG,EAEH;QAAEkC,KAAK,EAAE,CAAT;QAAYC,MAAM,EAAE,CAApB;QAAuBC,QAAQ,EAAE;MAAjC,CAFG;IAFX;EALD,CAAP;AAcH;AAAA"}
@@ -0,0 +1,51 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { InternalContext } from '../components';
4
+ const OVERSCROLL_FRICTION_FACTOR = 4;
5
+ export default function useItemInterpolation(index) {
6
+ const {
7
+ itemWidth,
8
+ data,
9
+ globalInterpolation,
10
+ loop
11
+ } = useContext(InternalContext);
12
+ const numberOfData = data.length;
13
+ const interpolationConfigOnLoop = useMemo(() => {
14
+ const lastIndex = numberOfData - 1;
15
+ const maxWidth = Math.abs(itemWidth * numberOfData);
16
+ const halfOfItemWidth = 0.5 * itemWidth;
17
+ const positiveCount = Math.round(lastIndex / 2);
18
+ const startPosition = index > positiveCount ? (index - numberOfData) * itemWidth : itemWidth * index;
19
+ const max = positiveCount * itemWidth;
20
+ const min = -((lastIndex - positiveCount) * itemWidth);
21
+ const inputRange = [-maxWidth, min - halfOfItemWidth - startPosition - Number.MIN_VALUE, min - halfOfItemWidth - startPosition, 0, max + halfOfItemWidth - startPosition, max + halfOfItemWidth - startPosition + Number.MIN_VALUE, maxWidth];
22
+ const outputRange = [startPosition, max + halfOfItemWidth - Number.MIN_VALUE, min - halfOfItemWidth, startPosition, max + halfOfItemWidth, min - halfOfItemWidth + Number.MIN_VALUE, startPosition];
23
+ return {
24
+ inputRange,
25
+ outputRange,
26
+ extrapolate: 'clamp'
27
+ };
28
+ }, [index, itemWidth, numberOfData]);
29
+ const interpolationConfigOnNoLoop = useMemo(() => {
30
+ const lastIndex = numberOfData - 1;
31
+ const maxWidth = itemWidth * lastIndex;
32
+ const startPosition = itemWidth * index;
33
+ const friction = itemWidth / OVERSCROLL_FRICTION_FACTOR;
34
+ const inputRange = [-(maxWidth + itemWidth), // overscroll
35
+ -maxWidth, 0, itemWidth // overscroll
36
+ ];
37
+ const outputRange = [-maxWidth + startPosition - friction, -maxWidth + startPosition, startPosition, startPosition + friction];
38
+ return {
39
+ inputRange,
40
+ outputRange,
41
+ extrapolate: 'clamp'
42
+ };
43
+ }, [index, itemWidth, numberOfData]);
44
+ return useMemo(() => {
45
+ const interpolationConfig = loop ? interpolationConfigOnLoop : interpolationConfigOnNoLoop;
46
+ const offsetX = globalInterpolation.interpolate(interpolationConfig);
47
+ return Animated.divide(offsetX, itemWidth);
48
+ }, [globalInterpolation, interpolationConfigOnLoop, interpolationConfigOnNoLoop, itemWidth, loop]);
49
+ }
50
+ ;
51
+ //# sourceMappingURL=useItemInterpolation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useContext","useMemo","Animated","InternalContext","OVERSCROLL_FRICTION_FACTOR","useItemInterpolation","index","itemWidth","data","globalInterpolation","loop","numberOfData","length","interpolationConfigOnLoop","lastIndex","maxWidth","Math","abs","halfOfItemWidth","positiveCount","round","startPosition","max","min","inputRange","Number","MIN_VALUE","outputRange","extrapolate","interpolationConfigOnNoLoop","friction","interpolationConfig","offsetX","interpolate","divide"],"sources":["useItemInterpolation.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\nimport { Animated } from 'react-native';\nimport { InternalContext } from '../components';\n\nconst OVERSCROLL_FRICTION_FACTOR = 4;\n\nexport default function useItemInterpolation(index: number): Animated.AnimatedInterpolation {\n const {\n itemWidth,\n data,\n globalInterpolation,\n loop,\n } = useContext(InternalContext);\n\n const numberOfData = data.length;\n\n const interpolationConfigOnLoop = useMemo<Animated.InterpolationConfigType>(() => {\n const lastIndex = numberOfData - 1;\n const maxWidth = Math.abs(itemWidth * numberOfData);\n const halfOfItemWidth = 0.5 * itemWidth;\n\n const positiveCount = Math.round(lastIndex / 2);\n const startPosition = index > positiveCount\n ? (index - numberOfData) * itemWidth\n : itemWidth * index;\n\n const max = positiveCount * itemWidth;\n const min = -((lastIndex - positiveCount) * itemWidth);\n\n const inputRange = [\n -maxWidth,\n min - halfOfItemWidth - startPosition - Number.MIN_VALUE,\n min - halfOfItemWidth - startPosition,\n 0,\n max + halfOfItemWidth - startPosition,\n max + halfOfItemWidth - startPosition + Number.MIN_VALUE,\n maxWidth,\n ];\n\n const outputRange = [\n startPosition,\n max + halfOfItemWidth - Number.MIN_VALUE,\n min - halfOfItemWidth,\n startPosition,\n max + halfOfItemWidth,\n min - halfOfItemWidth + Number.MIN_VALUE,\n startPosition,\n ];\n\n return {\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n };\n }, [\n index,\n itemWidth,\n numberOfData,\n ]);\n\n const interpolationConfigOnNoLoop = useMemo<Animated.InterpolationConfigType>(() => {\n const lastIndex = numberOfData - 1;\n const maxWidth = itemWidth * lastIndex;\n const startPosition = itemWidth * index;\n const friction = itemWidth / OVERSCROLL_FRICTION_FACTOR;\n\n const inputRange = [\n -(maxWidth + itemWidth), // overscroll\n -maxWidth,\n 0,\n itemWidth, // overscroll\n ];\n\n const outputRange = [\n -maxWidth + startPosition - friction,\n -maxWidth + startPosition,\n startPosition,\n startPosition + friction,\n ];\n\n return {\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n };\n }, [\n index,\n itemWidth,\n numberOfData,\n ]);\n\n return useMemo(() => {\n const interpolationConfig = loop\n ? interpolationConfigOnLoop\n : interpolationConfigOnNoLoop;\n\n const offsetX = globalInterpolation.interpolate(interpolationConfig);\n\n return Animated.divide(offsetX, itemWidth);\n }, [\n globalInterpolation,\n interpolationConfigOnLoop,\n interpolationConfigOnNoLoop,\n itemWidth,\n loop,\n ]);\n};\n"],"mappings":"AAAA,SAASA,UAAT,EAAqBC,OAArB,QAAoC,OAApC;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,eAAT,QAAgC,eAAhC;AAEA,MAAMC,0BAA0B,GAAG,CAAnC;AAEA,eAAe,SAASC,oBAAT,CAA8BC,KAA9B,EAA6E;EACxF,MAAM;IACFC,SADE;IAEFC,IAFE;IAGFC,mBAHE;IAIFC;EAJE,IAKFV,UAAU,CAACG,eAAD,CALd;EAOA,MAAMQ,YAAY,GAAGH,IAAI,CAACI,MAA1B;EAEA,MAAMC,yBAAyB,GAAGZ,OAAO,CAAmC,MAAM;IAC9E,MAAMa,SAAS,GAAGH,YAAY,GAAG,CAAjC;IACA,MAAMI,QAAQ,GAAGC,IAAI,CAACC,GAAL,CAASV,SAAS,GAAGI,YAArB,CAAjB;IACA,MAAMO,eAAe,GAAG,MAAMX,SAA9B;IAEA,MAAMY,aAAa,GAAGH,IAAI,CAACI,KAAL,CAAWN,SAAS,GAAG,CAAvB,CAAtB;IACA,MAAMO,aAAa,GAAGf,KAAK,GAAGa,aAAR,GAChB,CAACb,KAAK,GAAGK,YAAT,IAAyBJ,SADT,GAEhBA,SAAS,GAAGD,KAFlB;IAIA,MAAMgB,GAAG,GAAGH,aAAa,GAAGZ,SAA5B;IACA,MAAMgB,GAAG,GAAG,EAAE,CAACT,SAAS,GAAGK,aAAb,IAA8BZ,SAAhC,CAAZ;IAEA,MAAMiB,UAAU,GAAG,CACf,CAACT,QADc,EAEfQ,GAAG,GAAGL,eAAN,GAAwBG,aAAxB,GAAwCI,MAAM,CAACC,SAFhC,EAGfH,GAAG,GAAGL,eAAN,GAAwBG,aAHT,EAIf,CAJe,EAKfC,GAAG,GAAGJ,eAAN,GAAwBG,aALT,EAMfC,GAAG,GAAGJ,eAAN,GAAwBG,aAAxB,GAAwCI,MAAM,CAACC,SANhC,EAOfX,QAPe,CAAnB;IAUA,MAAMY,WAAW,GAAG,CAChBN,aADgB,EAEhBC,GAAG,GAAGJ,eAAN,GAAwBO,MAAM,CAACC,SAFf,EAGhBH,GAAG,GAAGL,eAHU,EAIhBG,aAJgB,EAKhBC,GAAG,GAAGJ,eALU,EAMhBK,GAAG,GAAGL,eAAN,GAAwBO,MAAM,CAACC,SANf,EAOhBL,aAPgB,CAApB;IAUA,OAAO;MACHG,UADG;MAEHG,WAFG;MAGHC,WAAW,EAAE;IAHV,CAAP;EAKH,CAtCwC,EAsCtC,CACCtB,KADD,EAECC,SAFD,EAGCI,YAHD,CAtCsC,CAAzC;EA4CA,MAAMkB,2BAA2B,GAAG5B,OAAO,CAAmC,MAAM;IAChF,MAAMa,SAAS,GAAGH,YAAY,GAAG,CAAjC;IACA,MAAMI,QAAQ,GAAGR,SAAS,GAAGO,SAA7B;IACA,MAAMO,aAAa,GAAGd,SAAS,GAAGD,KAAlC;IACA,MAAMwB,QAAQ,GAAGvB,SAAS,GAAGH,0BAA7B;IAEA,MAAMoB,UAAU,GAAG,CACf,EAAET,QAAQ,GAAGR,SAAb,CADe,EACU;IACzB,CAACQ,QAFc,EAGf,CAHe,EAIfR,SAJe,CAIJ;IAJI,CAAnB;IAOA,MAAMoB,WAAW,GAAG,CAChB,CAACZ,QAAD,GAAYM,aAAZ,GAA4BS,QADZ,EAEhB,CAACf,QAAD,GAAYM,aAFI,EAGhBA,aAHgB,EAIhBA,aAAa,GAAGS,QAJA,CAApB;IAOA,OAAO;MACHN,UADG;MAEHG,WAFG;MAGHC,WAAW,EAAE;IAHV,CAAP;EAKH,CAzB0C,EAyBxC,CACCtB,KADD,EAECC,SAFD,EAGCI,YAHD,CAzBwC,CAA3C;EA+BA,OAAOV,OAAO,CAAC,MAAM;IACjB,MAAM8B,mBAAmB,GAAGrB,IAAI,GAC1BG,yBAD0B,GAE1BgB,2BAFN;IAIA,MAAMG,OAAO,GAAGvB,mBAAmB,CAACwB,WAApB,CAAgCF,mBAAhC,CAAhB;IAEA,OAAO7B,QAAQ,CAACgC,MAAT,CAAgBF,OAAhB,EAAyBzB,SAAzB,CAAP;EACH,CARa,EAQX,CACCE,mBADD,EAECI,yBAFD,EAGCgB,2BAHD,EAICtB,SAJD,EAKCG,IALD,CARW,CAAd;AAeH;AAAA"}
@@ -0,0 +1,87 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ import { useEffect, useRef, useState } from 'react';
4
+
5
+ class SimpleItemVisibilityStore {
6
+ constructor(initialValue) {
7
+ _defineProperty(this, "store", void 0);
8
+
9
+ _defineProperty(this, "listeners", []);
10
+
11
+ this.store = initialValue;
12
+ }
13
+
14
+ subscribe(listener) {
15
+ this.listeners.push(listener);
16
+ listener(this.store);
17
+ return () => {
18
+ const index = this.listeners.indexOf(listener);
19
+ this.listeners.splice(index, 1);
20
+ };
21
+ }
22
+
23
+ dispatch(ranges) {
24
+ this.store = ranges;
25
+
26
+ for (const id in this.listeners) {
27
+ const listener = this.listeners[id];
28
+ listener === null || listener === void 0 ? void 0 : listener(ranges);
29
+ }
30
+ }
31
+
32
+ removeAllListeners() {
33
+ this.listeners.splice(0, this.listeners.length);
34
+ }
35
+
36
+ }
37
+
38
+ function normalize(windowSize, numberOfData) {
39
+ if (windowSize <= 0) {
40
+ return numberOfData;
41
+ }
42
+
43
+ if (windowSize > 0 && windowSize % 2 === 0) {
44
+ return windowSize + 1;
45
+ }
46
+
47
+ return windowSize;
48
+ }
49
+
50
+ function mod(value, modulo) {
51
+ return (value % modulo + modulo) % modulo;
52
+ }
53
+
54
+ function makeVisibleIndexRanges(numberOfData, windowSize, index) {
55
+ const ws = normalize(windowSize, numberOfData);
56
+ const firstIndex = 0;
57
+ const lastIndex = numberOfData - 1;
58
+ const halfNumberOfAdjacent = Math.floor(ws / 2);
59
+ const leftSide = index - halfNumberOfAdjacent;
60
+ const rightSide = index + halfNumberOfAdjacent;
61
+ const leftRanges = leftSide >= 0 ? [[leftSide, index]] : [[firstIndex, index], [mod(leftSide, numberOfData), lastIndex]];
62
+ const rightRanges = rightSide < numberOfData ? [[index, rightSide]] : [[index, lastIndex], [firstIndex, mod(rightSide, numberOfData)]]; // @ts-ignore
63
+
64
+ return [...leftRanges, ...rightRanges];
65
+ }
66
+
67
+ export default function useItemVisibilityStore(params) {
68
+ const {
69
+ currentIndex,
70
+ numberOfData,
71
+ windowSize
72
+ } = params;
73
+ const [initialRange] = useState(() => makeVisibleIndexRanges(numberOfData, windowSize, currentIndex));
74
+ const store = useRef(new SimpleItemVisibilityStore(initialRange)).current;
75
+ useEffect(() => {
76
+ const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, currentIndex);
77
+ store.dispatch(newRanges);
78
+ }, [currentIndex, numberOfData, windowSize]);
79
+ useEffect(() => {
80
+ return () => {
81
+ store.removeAllListeners();
82
+ };
83
+ }, []);
84
+ return store;
85
+ }
86
+ ;
87
+ //# sourceMappingURL=useItemVisibilityStore.js.map