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

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 (289) hide show
  1. package/build/commonjs/Carousel/Carousel.js +142 -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 +66 -0
  19. package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
  20. package/build/commonjs/Carousel/components/RootView.js +86 -0
  21. package/build/commonjs/Carousel/components/RootView.js.map +1 -0
  22. package/build/commonjs/Carousel/components/ScrollViewGesture.js +81 -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 +58 -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 +162 -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 +53 -59
  47. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  48. package/build/commonjs/ViewPager/InternalContext.js +17 -0
  49. package/build/commonjs/ViewPager/InternalContext.js.map +1 -0
  50. package/build/commonjs/ViewPager/PageStateContext.js +22 -0
  51. package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
  52. package/build/commonjs/ViewPager/ViewPagerNative.js +90 -25
  53. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  54. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  55. package/build/commonjs/ViewPager/ViewPagerWeb.js +27 -14
  56. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  57. package/build/commonjs/ViewPager/index.js +8 -0
  58. package/build/commonjs/ViewPager/index.js.map +1 -1
  59. package/build/commonjs/ViewPager/index.native.js +8 -0
  60. package/build/commonjs/ViewPager/index.native.js.map +1 -1
  61. package/build/commonjs/ViewPager/types.js +6 -0
  62. package/build/commonjs/ViewPager/types.js.map +1 -0
  63. package/build/commonjs/ViewPager/usePageStore.js +30 -0
  64. package/build/commonjs/ViewPager/usePageStore.js.map +1 -0
  65. package/build/commonjs/ViewPager/utils.js +3 -1
  66. package/build/commonjs/ViewPager/utils.js.map +1 -1
  67. package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
  68. package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
  69. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
  70. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  71. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  72. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  73. package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
  74. package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
  75. package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
  76. package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
  77. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
  78. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  79. package/build/commonjs/hooks/index.js +16 -0
  80. package/build/commonjs/hooks/index.js.map +1 -1
  81. package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
  82. package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
  83. package/build/commonjs/hooks/useIsMounted.js +22 -0
  84. package/build/commonjs/hooks/useIsMounted.js.map +1 -0
  85. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +1 -1
  86. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  87. package/build/commonjs/index.js +22 -1
  88. package/build/commonjs/index.js.map +1 -1
  89. package/build/module/Carousel/Carousel.js +120 -0
  90. package/build/module/Carousel/Carousel.js.map +1 -0
  91. package/build/module/Carousel/CarouselProps.js.map +1 -1
  92. package/build/module/Carousel/animation/animationUtils.js +2 -0
  93. package/build/module/Carousel/animation/animationUtils.js.map +1 -0
  94. package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
  95. package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  96. package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
  97. package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  98. package/build/module/Carousel/animation/index.js +5 -0
  99. package/build/module/Carousel/animation/index.js.map +1 -0
  100. package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
  101. package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  102. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
  103. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  104. package/build/module/Carousel/components/InternalContext.js +19 -0
  105. package/build/module/Carousel/components/InternalContext.js.map +1 -0
  106. package/build/module/Carousel/components/ItemView.js +46 -0
  107. package/build/module/Carousel/components/ItemView.js.map +1 -0
  108. package/build/module/Carousel/components/RootView.js +65 -0
  109. package/build/module/Carousel/components/RootView.js.map +1 -0
  110. package/build/module/Carousel/components/ScrollViewGesture.js +67 -0
  111. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
  112. package/build/module/Carousel/components/index.js +5 -0
  113. package/build/module/Carousel/components/index.js.map +1 -0
  114. package/build/module/Carousel/hooks/index.js +8 -0
  115. package/build/module/Carousel/hooks/index.js.map +1 -0
  116. package/build/module/Carousel/hooks/useAutoplayController.js +48 -0
  117. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
  118. package/build/module/Carousel/hooks/useDimensionChangeReaction.js +14 -0
  119. package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  120. package/build/module/Carousel/hooks/useIndexController.js +54 -0
  121. package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
  122. package/build/module/Carousel/hooks/useItemInterpolation.js +51 -0
  123. package/build/module/Carousel/hooks/useItemInterpolation.js.map +1 -0
  124. package/build/module/Carousel/hooks/useItemVisibilityStore.js +87 -0
  125. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  126. package/build/module/Carousel/hooks/useLoopedData.js +24 -0
  127. package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
  128. package/build/module/Carousel/hooks/usePagingAnimation.js +153 -0
  129. package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -0
  130. package/build/module/Carousel/index.js +2 -1
  131. package/build/module/Carousel/index.js.map +1 -1
  132. package/build/module/Carousel/types.js +3 -0
  133. package/build/module/Carousel/types.js.map +1 -0
  134. package/build/module/ViewPager/ChildrenMemoizedPage.js +48 -56
  135. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  136. package/build/module/ViewPager/InternalContext.js +7 -0
  137. package/build/module/ViewPager/InternalContext.js.map +1 -0
  138. package/build/module/ViewPager/PageStateContext.js +10 -0
  139. package/build/module/ViewPager/PageStateContext.js.map +1 -0
  140. package/build/module/ViewPager/ViewPagerNative.js +90 -27
  141. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  142. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  143. package/build/module/ViewPager/ViewPagerWeb.js +25 -15
  144. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  145. package/build/module/ViewPager/index.js +1 -0
  146. package/build/module/ViewPager/index.js.map +1 -1
  147. package/build/module/ViewPager/index.native.js +1 -0
  148. package/build/module/ViewPager/index.native.js.map +1 -1
  149. package/build/module/ViewPager/types.js +2 -0
  150. package/build/module/ViewPager/types.js.map +1 -0
  151. package/build/module/ViewPager/usePageStore.js +20 -0
  152. package/build/module/ViewPager/usePageStore.js.map +1 -0
  153. package/build/module/ViewPager/utils.js +1 -0
  154. package/build/module/ViewPager/utils.js.map +1 -1
  155. package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
  156. package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
  157. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
  158. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  159. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  160. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  161. package/build/module/ViewabilityTrackerView/index.js +2 -0
  162. package/build/module/ViewabilityTrackerView/index.js.map +1 -0
  163. package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
  164. package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
  165. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
  166. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  167. package/build/module/hooks/index.js +2 -0
  168. package/build/module/hooks/index.js.map +1 -1
  169. package/build/module/hooks/useDeferredExecutor.js +33 -0
  170. package/build/module/hooks/useDeferredExecutor.js.map +1 -0
  171. package/build/module/hooks/useIsMounted.js +13 -0
  172. package/build/module/hooks/useIsMounted.js.map +1 -0
  173. package/build/module/hooks/useUnstableCollapsibleAppBar.js +1 -1
  174. package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  175. package/build/module/index.js +2 -0
  176. package/build/module/index.js.map +1 -1
  177. package/build/typescript/Carousel/Carousel.d.ts +5 -0
  178. package/build/typescript/Carousel/CarouselProps.d.ts +33 -48
  179. package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
  180. package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
  181. package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
  182. package/build/typescript/Carousel/animation/index.d.ts +4 -0
  183. package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
  184. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
  185. package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
  186. package/build/typescript/Carousel/components/ItemView.d.ts +9 -0
  187. package/build/typescript/Carousel/components/RootView.d.ts +16 -0
  188. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
  189. package/build/typescript/Carousel/components/index.d.ts +4 -0
  190. package/build/typescript/Carousel/hooks/index.d.ts +7 -0
  191. package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
  192. package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +7 -0
  193. package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
  194. package/build/typescript/Carousel/hooks/useItemInterpolation.d.ts +2 -0
  195. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
  196. package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
  197. package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +18 -0
  198. package/build/typescript/Carousel/index.d.ts +3 -1
  199. package/build/typescript/Carousel/types.d.ts +79 -0
  200. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +1 -1
  201. package/build/typescript/ViewPager/InternalContext.d.ts +7 -0
  202. package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
  203. package/build/typescript/ViewPager/ViewPagerNative.d.ts +2 -2
  204. package/build/typescript/ViewPager/ViewPagerProps.d.ts +13 -20
  205. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +2 -2
  206. package/build/typescript/ViewPager/index.d.ts +3 -1
  207. package/build/typescript/ViewPager/index.native.d.ts +1 -0
  208. package/build/typescript/ViewPager/types.d.ts +19 -0
  209. package/build/typescript/ViewPager/usePageStore.d.ts +2 -0
  210. package/build/typescript/ViewPager/utils.d.ts +2 -1
  211. package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
  212. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
  213. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
  214. package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
  215. package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
  216. package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
  217. package/build/typescript/hooks/index.d.ts +2 -0
  218. package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
  219. package/build/typescript/hooks/useIsMounted.d.ts +4 -0
  220. package/build/typescript/index.d.ts +2 -0
  221. package/package.json +4 -19
  222. package/src/Carousel/Carousel.tsx +152 -0
  223. package/src/Carousel/CarouselProps.ts +35 -53
  224. package/src/Carousel/animation/animationUtils.ts +1 -0
  225. package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
  226. package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
  227. package/src/Carousel/animation/index.ts +4 -0
  228. package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
  229. package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
  230. package/src/Carousel/components/InternalContext.ts +33 -0
  231. package/src/Carousel/components/ItemView.tsx +66 -0
  232. package/src/Carousel/components/RootView.tsx +79 -0
  233. package/src/Carousel/components/ScrollViewGesture.tsx +87 -0
  234. package/src/Carousel/components/index.ts +4 -0
  235. package/src/Carousel/hooks/index.ts +7 -0
  236. package/src/Carousel/hooks/useAutoplayController.ts +57 -0
  237. package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
  238. package/src/Carousel/hooks/useIndexController.tsx +76 -0
  239. package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
  240. package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
  241. package/src/Carousel/hooks/useLoopedData.ts +26 -0
  242. package/src/Carousel/hooks/usePagingAnimation.ts +195 -0
  243. package/src/Carousel/index.ts +4 -2
  244. package/src/Carousel/types.ts +97 -0
  245. package/src/ViewPager/ChildrenMemoizedPage.tsx +55 -54
  246. package/src/ViewPager/InternalContext.ts +13 -0
  247. package/src/ViewPager/PageStateContext.ts +15 -0
  248. package/src/ViewPager/ViewPagerNative.tsx +114 -43
  249. package/src/ViewPager/ViewPagerProps.ts +15 -25
  250. package/src/ViewPager/ViewPagerWeb.tsx +30 -21
  251. package/src/ViewPager/index.native.ts +1 -0
  252. package/src/ViewPager/index.ts +3 -1
  253. package/src/ViewPager/types.ts +24 -0
  254. package/src/ViewPager/usePageStore.ts +24 -0
  255. package/src/ViewPager/utils.tsx +3 -2
  256. package/src/ViewabilityTrackerView/Viewability.ts +3 -0
  257. package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
  258. package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
  259. package/src/ViewabilityTrackerView/index.ts +2 -0
  260. package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
  261. package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
  262. package/src/hooks/index.ts +2 -0
  263. package/src/hooks/useDeferredExecutor.ts +46 -0
  264. package/src/hooks/useIsMounted.ts +19 -0
  265. package/src/hooks/useUnstableCollapsibleAppBar.ts +1 -1
  266. package/src/index.ts +3 -0
  267. package/build/commonjs/Carousel/CarouselNative.js +0 -72
  268. package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
  269. package/build/commonjs/Carousel/CarouselWeb.js +0 -237
  270. package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
  271. package/build/commonjs/Carousel/index.native.js.map +0 -1
  272. package/build/commonjs/Carousel/utils.js +0 -19
  273. package/build/commonjs/Carousel/utils.js.map +0 -1
  274. package/build/module/Carousel/CarouselNative.js +0 -54
  275. package/build/module/Carousel/CarouselNative.js.map +0 -1
  276. package/build/module/Carousel/CarouselWeb.js +0 -215
  277. package/build/module/Carousel/CarouselWeb.js.map +0 -1
  278. package/build/module/Carousel/index.native.js +0 -2
  279. package/build/module/Carousel/index.native.js.map +0 -1
  280. package/build/module/Carousel/utils.js +0 -7
  281. package/build/module/Carousel/utils.js.map +0 -1
  282. package/build/typescript/Carousel/CarouselNative.d.ts +0 -2
  283. package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
  284. package/build/typescript/Carousel/index.native.d.ts +0 -1
  285. package/build/typescript/Carousel/utils.d.ts +0 -6
  286. package/src/Carousel/CarouselNative.tsx +0 -67
  287. package/src/Carousel/CarouselWeb.tsx +0 -222
  288. package/src/Carousel/index.native.ts +0 -1
  289. package/src/Carousel/utils.ts +0 -11
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = usePagingAnimation;
7
+
8
+ var _react = require("react");
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ function directionToValue(itemWidth) {
13
+ return function (direction) {
14
+ switch (direction) {
15
+ case 'next':
16
+ return -itemWidth;
17
+
18
+ case 'prev':
19
+ return itemWidth;
20
+
21
+ case 'stay':
22
+ return 0;
23
+ }
24
+ };
25
+ }
26
+
27
+ function usePagingAnimation(params) {
28
+ const {
29
+ controlledTx,
30
+ createScrollAnimation,
31
+ getCurrentIndex,
32
+ itemWidth,
33
+ lastIndex,
34
+ loop,
35
+ numberOfData,
36
+ offsetTx
37
+ } = params;
38
+ const animationRef = (0, _react.useRef)(null);
39
+ const toValueRef = (0, _react.useRef)(0);
40
+ const globalInterpolation = (0, _react.useMemo)(() => _reactNative.Animated.add(controlledTx, offsetTx), [controlledTx, offsetTx]);
41
+ (0, _react.useEffect)(() => {
42
+ const subscriptionId = controlledTx.addListener(value => {
43
+ const currentTx = value.value; // Prevent infinite loop
44
+
45
+ if (currentTx !== 0) {
46
+ const maxWidth = numberOfData * itemWidth;
47
+
48
+ if (Math.abs(Math.round(currentTx)) === Math.round(maxWidth)) {
49
+ // reset position
50
+ controlledTx.setValue(0);
51
+ }
52
+ }
53
+ });
54
+ return () => {
55
+ controlledTx.removeListener(subscriptionId);
56
+ };
57
+ }, [numberOfData, itemWidth]);
58
+ const finalizeAnimation = (0, _react.useCallback)(() => {
59
+ const stopUnfinishedSnapAnimation = () => {
60
+ if (animationRef.current) {
61
+ var _animationRef$current;
62
+
63
+ (_animationRef$current = animationRef.current) === null || _animationRef$current === void 0 ? void 0 : _animationRef$current.stop();
64
+ animationRef.current = null;
65
+ }
66
+ };
67
+
68
+ const resetBoundary = () => {
69
+ controlledTx.setOffset(toValueRef.current);
70
+ controlledTx.flattenOffset(); // FIXME: react-native-web bug maybe?
71
+ // `AnimatedValue.flattenOffset()` does not trigger any event listener.
72
+ // Accessing value directly via `_value` is dangerous but working on web (`useNativeDriver` always false).
73
+ // So setting same value with `value.setValue(value._value)` will trigger event listener.
74
+
75
+ if (_reactNative.Platform.OS === 'web') {
76
+ // @ts-ignore
77
+ controlledTx.setValue(controlledTx._value);
78
+ }
79
+
80
+ offsetTx.setValue(0);
81
+ toValueRef.current = 0;
82
+ };
83
+
84
+ stopUnfinishedSnapAnimation();
85
+ resetBoundary();
86
+ }, [controlledTx]);
87
+ const startPagingAnimation = (0, _react.useCallback)((type, config) => {
88
+ const configWithDefaults = {
89
+ animated: true,
90
+ ...config
91
+ };
92
+ const currentIndex = getCurrentIndex();
93
+ const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);
94
+
95
+ const getValueByDirectionalPagingOnLoopDisabled = _config => {
96
+ const {
97
+ direction,
98
+ isOriginatedFromGesture
99
+ } = _config;
100
+
101
+ if (currentIndex === 0 && direction === 'prev') {
102
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : -lastIndex * itemWidth; // last position
103
+ } else if (currentIndex === lastIndex && direction === 'next') {
104
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : lastIndex * itemWidth; // first position
105
+ }
106
+
107
+ return getValueByDirectionOnAllAdjacentItemsVisible(direction);
108
+ };
109
+
110
+ const getValueByDirectionalPaging = _config => {
111
+ const _configWithDefaults = {
112
+ isOriginatedFromGesture: false,
113
+ ..._config
114
+ };
115
+ return loop ? getValueByDirectionOnAllAdjacentItemsVisible(_configWithDefaults.direction) : getValueByDirectionalPagingOnLoopDisabled(_configWithDefaults);
116
+ };
117
+
118
+ const getValueByIndexPaging = _ref => {
119
+ let {
120
+ index
121
+ } = _ref;
122
+
123
+ if (index < 0 || index > lastIndex || index === currentIndex) {
124
+ // no animation if index is invalid or equals to current index
125
+ return 0;
126
+ }
127
+
128
+ const distance = Math.abs(currentIndex - index) * itemWidth;
129
+ const direction = index > currentIndex ? -1 : 1;
130
+ return distance * direction;
131
+ };
132
+
133
+ const toValue = type === 'directional' // @ts-ignore
134
+ ? getValueByDirectionalPaging(configWithDefaults) // @ts-ignore
135
+ : getValueByIndexPaging(configWithDefaults);
136
+ toValueRef.current = toValue;
137
+
138
+ if (configWithDefaults.animated) {
139
+ const animation = createScrollAnimation(offsetTx, toValue);
140
+ animationRef.current = animation;
141
+ animation.start(_ref2 => {
142
+ let {
143
+ finished
144
+ } = _ref2;
145
+
146
+ if (finished) {
147
+ finalizeAnimation();
148
+ }
149
+ });
150
+ } else {
151
+ finalizeAnimation();
152
+ }
153
+ }, [createScrollAnimation, getCurrentIndex, finalizeAnimation, itemWidth, lastIndex, loop]);
154
+ return {
155
+ globalInterpolation,
156
+ finalizeAnimation,
157
+ startPagingAnimation
158
+ };
159
+ }
160
+
161
+ ;
162
+ //# sourceMappingURL=usePagingAnimation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["directionToValue","itemWidth","direction","usePagingAnimation","params","controlledTx","createScrollAnimation","getCurrentIndex","lastIndex","loop","numberOfData","offsetTx","animationRef","useRef","toValueRef","globalInterpolation","useMemo","Animated","add","useEffect","subscriptionId","addListener","value","currentTx","maxWidth","Math","abs","round","setValue","removeListener","finalizeAnimation","useCallback","stopUnfinishedSnapAnimation","current","stop","resetBoundary","setOffset","flattenOffset","Platform","OS","_value","startPagingAnimation","type","config","configWithDefaults","animated","currentIndex","getValueByDirectionOnAllAdjacentItemsVisible","getValueByDirectionalPagingOnLoopDisabled","_config","isOriginatedFromGesture","getValueByDirectionalPaging","_configWithDefaults","getValueByIndexPaging","index","distance","toValue","animation","start","finished"],"sources":["usePagingAnimation.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { Animated, Platform } from 'react-native';\nimport type {\n CreateScrollAnimation,\n DirectionalPagingAnimationConfig,\n GetCurrentIndex,\n IndexPagingAnimationConfig,\n PagingAnimationConfig,\n PagingAnimationType,\n PagingDirection,\n StartPagingAnimation,\n} from '../types';\n\nexport interface PagingAnimationParameters {\n controlledTx: Animated.Value;\n createScrollAnimation: CreateScrollAnimation;\n getCurrentIndex: GetCurrentIndex;\n itemWidth: number;\n lastIndex: number;\n loop: boolean;\n numberOfData: number;\n offsetTx: Animated.Value;\n}\n\nexport interface UsePagingAnimation {\n finalizeAnimation: () => void;\n globalInterpolation: Animated.AnimatedInterpolation;\n startPagingAnimation: StartPagingAnimation;\n}\n\nfunction directionToValue(itemWidth: number) {\n return function (direction: PagingDirection): number {\n switch (direction) {\n case 'next':\n return -itemWidth;\n case 'prev':\n return itemWidth;\n case 'stay':\n return 0;\n }\n };\n}\n\nexport default function usePagingAnimation(params: PagingAnimationParameters): UsePagingAnimation {\n const {\n controlledTx,\n createScrollAnimation,\n getCurrentIndex,\n itemWidth,\n lastIndex,\n loop,\n numberOfData,\n offsetTx,\n } = params;\n\n const animationRef = useRef<Animated.CompositeAnimation | null>(null);\n const toValueRef = useRef<number>(0);\n\n const globalInterpolation = useMemo(\n () => Animated.add(controlledTx, offsetTx),\n [controlledTx, offsetTx],\n );\n\n useEffect(() => {\n const subscriptionId = controlledTx.addListener((value) => {\n const currentTx = value.value;\n\n // Prevent infinite loop\n if (currentTx !== 0) {\n const maxWidth = numberOfData * itemWidth;\n\n if (Math.abs(Math.round(currentTx)) === Math.round(maxWidth)) {\n // reset position\n controlledTx.setValue(0);\n }\n }\n });\n\n return () => {\n controlledTx.removeListener(subscriptionId);\n };\n }, [numberOfData, itemWidth]);\n\n const finalizeAnimation = useCallback(() => {\n const stopUnfinishedSnapAnimation = () => {\n if (animationRef.current) {\n animationRef.current?.stop();\n animationRef.current = null;\n }\n };\n\n const resetBoundary = () => {\n controlledTx.setOffset(toValueRef.current);\n controlledTx.flattenOffset();\n\n // FIXME: react-native-web bug maybe?\n // `AnimatedValue.flattenOffset()` does not trigger any event listener.\n // Accessing value directly via `_value` is dangerous but working on web (`useNativeDriver` always false).\n // So setting same value with `value.setValue(value._value)` will trigger event listener.\n if (Platform.OS === 'web') {\n // @ts-ignore\n controlledTx.setValue(controlledTx._value);\n }\n\n offsetTx.setValue(0);\n toValueRef.current = 0;\n };\n\n stopUnfinishedSnapAnimation();\n\n resetBoundary();\n }, [controlledTx]);\n\n const startPagingAnimation = useCallback((type: PagingAnimationType, config: PagingAnimationConfig) => {\n const configWithDefaults: PagingAnimationConfig = {\n animated: true,\n ...config,\n };\n\n const currentIndex = getCurrentIndex();\n\n const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);\n\n const getValueByDirectionalPagingOnLoopDisabled = (_config: DirectionalPagingAnimationConfig): number => {\n const { direction, isOriginatedFromGesture } = _config;\n\n if (currentIndex === 0 && direction === 'prev') {\n return isOriginatedFromGesture\n ? getValueByDirectionOnAllAdjacentItemsVisible('stay')\n : -lastIndex * itemWidth; // last position\n } else if (currentIndex === lastIndex && direction === 'next') {\n return isOriginatedFromGesture\n ? getValueByDirectionOnAllAdjacentItemsVisible('stay')\n : lastIndex * itemWidth; // first position\n }\n return getValueByDirectionOnAllAdjacentItemsVisible(direction);\n };\n\n const getValueByDirectionalPaging = (_config: DirectionalPagingAnimationConfig): number => {\n const _configWithDefaults: DirectionalPagingAnimationConfig = {\n isOriginatedFromGesture: false,\n ..._config,\n };\n\n return loop\n ? getValueByDirectionOnAllAdjacentItemsVisible(_configWithDefaults.direction)\n : getValueByDirectionalPagingOnLoopDisabled(_configWithDefaults);\n };\n\n const getValueByIndexPaging = ({ index }: IndexPagingAnimationConfig): number => {\n if (index < 0 || index > lastIndex || index === currentIndex) {\n // no animation if index is invalid or equals to current index\n return 0;\n }\n\n const distance = Math.abs(currentIndex - index) * itemWidth;\n const direction = index > currentIndex ? -1 : 1;\n\n return distance * direction;\n };\n\n const toValue = type === 'directional'\n // @ts-ignore\n ? getValueByDirectionalPaging(configWithDefaults)\n // @ts-ignore\n : getValueByIndexPaging(configWithDefaults);\n\n toValueRef.current = toValue;\n\n if (configWithDefaults.animated) {\n const animation = createScrollAnimation(offsetTx, toValue);\n animationRef.current = animation;\n animation.start(({ finished }) => {\n if (finished) {\n finalizeAnimation();\n }\n });\n } else {\n finalizeAnimation();\n }\n }, [\n createScrollAnimation,\n getCurrentIndex,\n finalizeAnimation,\n itemWidth,\n lastIndex,\n loop,\n ]);\n\n return {\n globalInterpolation,\n finalizeAnimation,\n startPagingAnimation,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AA6BA,SAASA,gBAAT,CAA0BC,SAA1B,EAA6C;EACzC,OAAO,UAAUC,SAAV,EAA8C;IACjD,QAAQA,SAAR;MACI,KAAK,MAAL;QACI,OAAO,CAACD,SAAR;;MACJ,KAAK,MAAL;QACI,OAAOA,SAAP;;MACJ,KAAK,MAAL;QACI,OAAO,CAAP;IANR;EAQH,CATD;AAUH;;AAEc,SAASE,kBAAT,CAA4BC,MAA5B,EAAmF;EAC9F,MAAM;IACFC,YADE;IAEFC,qBAFE;IAGFC,eAHE;IAIFN,SAJE;IAKFO,SALE;IAMFC,IANE;IAOFC,YAPE;IAQFC;EARE,IASFP,MATJ;EAWA,MAAMQ,YAAY,GAAG,IAAAC,aAAA,EAA2C,IAA3C,CAArB;EACA,MAAMC,UAAU,GAAG,IAAAD,aAAA,EAAe,CAAf,CAAnB;EAEA,MAAME,mBAAmB,GAAG,IAAAC,cAAA,EACxB,MAAMC,qBAAA,CAASC,GAAT,CAAab,YAAb,EAA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AAG,CAAR,IAAaA,KAAK,GAAG9C,SAArB,IAAkC8C,KAAK,KAAKR,YAAhD,EAA8D;QAC1D;QACA,OAAO,CAAP;MACH;;MAED,MAAMS,QAAQ,GAAG9B,IAAI,CAACC,GAAL,CAASoB,YAAY,GAAGQ,KAAxB,IAAiCrD,SAAlD;MACA,MAAMC,SAAS,GAAGoD,KAAK,GAAGR,YAAR,GAAuB,CAAC,CAAxB,GAA4B,CAA9C;MAEA,OAAOS,QAAQ,GAAGrD,SAAlB;IACH,CAVD;;IAYA,MAAMsD,OAAO,GAAGd,IAAI,KAAK,aAAT,CACZ;IADY,EAEVS,2BAA2B,CAACP,kBAAD,CAFjB,CAGZ;IAHY,EAIVS,qBAAqB,CAACT,kBAAD,CAJ3B;IAMA9B,UAAU,CAACmB,OAAX,GAAqBuB,OAArB;;IAEA,IAAIZ,kBAAkB,CAACC,QAAvB,EAAiC;MAC7B,MAAMY,SAAS,GAAGnD,qBAAqB,CAACK,QAAD,EAAW6C,OAAX,CAAvC;MACA5C,YAAY,CAACqB,OAAb,GAAuBwB,SAAvB;MACAA,SAAS,CAACC,KAAV,CAAgB,SAAkB;QAAA,IAAjB;UAAEC;QAAF,CAAiB;;QAC9B,IAAIA,QAAJ,EAAc;UACV7B,iBAAiB;QACpB;MACJ,CAJD;IAKH,CARD,MAQO;MACHA,iBAAiB;IACpB;EACJ,CAnE4B,EAmE1B,CACCxB,qBADD,EAECC,eAFD,EAGCuB,iBAHD,EAIC7B,SAJD,EAKCO,SALD,EAMCC,IAND,CAnE0B,CAA7B;EA4EA,OAAO;IACHM,mBADG;IAEHe,iBAFG;IAGHW;EAHG,CAAP;AAKH;;AAAA"}
@@ -6,11 +6,25 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "default", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _CarouselWeb.default;
9
+ return _Carousel.default;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "normalItemStyleFactory", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _animation.normalItemStyleFactory;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "parallaxItemStyleFactory", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _animation.parallaxItemStyleFactory;
22
+ }
23
+ });
24
+
25
+ var _Carousel = _interopRequireDefault(require("./Carousel"));
12
26
 
13
- var _CarouselWeb = _interopRequireDefault(require("./CarouselWeb"));
27
+ var _animation = require("./animation");
14
28
 
15
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './CarouselWeb';\nexport type { default as CarouselProps } from './CarouselProps';"],"mappings":";;;;;;;;;;;;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Carousel';\nexport type { default as CarouselProps } from './CarouselProps';\nexport type { CarouselInstance } from './types';\nexport { normalItemStyleFactory, parallaxItemStyleFactory } from './animation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAGA"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ const directions = ['next', 'prev', 'stay'];
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["directions"],"sources":["types.ts"],"sourcesContent":["import type { ReactElement } from 'react';\nimport type { Animated, ViewProps } from 'react-native';\n\nconst directions = ['next', 'prev', 'stay'] as const;\n\nexport type PagingDirection = (typeof directions)[number];\n\nexport type ItemHeight = number | 'auto';\n\nexport interface RenderItem<T> {\n (info: { item: T, index: number, interpolation: Animated.AnimatedInterpolation }): ReactElement | null;\n}\n\nexport interface CreateScrollAnimation {\n (aValue: Animated.AnimatedValue, toValue: number): Animated.CompositeAnimation;\n}\n\nexport interface CreateItemStyle {\n (itemInterpolation: Animated.AnimatedInterpolation, itemWidth: number): Animated.AnimatedProps<ViewProps['style']>;\n}\n\nexport interface GetCurrentIndex {\n (): number;\n}\n\nexport interface IndexController {\n currentIndex: number;\n getCurrentIndex: GetCurrentIndex;\n lastIndex: number;\n monitorElement: ReactElement;\n}\n\nexport type PagingAnimationType = 'directional' | 'index';\n\nexport interface BasePagingAnimationConfig {\n animated?: boolean;\n}\n\nexport interface DirectionalPagingAnimationConfig extends BasePagingAnimationConfig {\n direction: PagingDirection;\n isOriginatedFromGesture?: boolean;\n}\n\nexport interface IndexPagingAnimationConfig extends BasePagingAnimationConfig {\n index: number;\n}\n\nexport type PagingAnimationConfig = DirectionalPagingAnimationConfig | IndexPagingAnimationConfig;\n\nexport interface StartPagingAnimation {\n (type: PagingAnimationType, config: PagingAnimationConfig): void;\n}\n\nexport type VisibleIndexRanges = Array<[number, number]>;\n\nexport interface StoreSubscription {\n (): void;\n}\n\nexport interface ItemVisibilityStore {\n dispatch: (ranges: VisibleIndexRanges) => void;\n subscribe: (listener: (ranges: VisibleIndexRanges) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n\nexport interface AutoplayController {\n pause: () => void;\n resume: () => void;\n}\n\nexport interface ScrollToOption {\n index: number;\n animated?: boolean;\n}\n\nexport interface CarouselInstance {\n /**\n * Get current visible item index.\n */\n getCurrentIndex: GetCurrentIndex;\n\n /**\n * Scroll to next visible item.\n */\n next: () => void;\n\n /**\n * Scroll to previous visible item.\n */\n prev: () => void;\n\n /**\n * Scroll to desired indexed item.\n * Invalid index is ignored.\n */\n scrollTo: (option: ScrollToOption) => void;\n}\n"],"mappings":";;;;;AAGA,MAAMA,UAAU,GAAG,CAAC,MAAD,EAAS,MAAT,EAAiB,MAAjB,CAAnB"}
@@ -9,17 +9,23 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactNative = require("react-native");
11
11
 
12
- var _reactNativeReanimated = require("react-native-reanimated");
13
-
14
12
  var _core = require("@fountain-ui/core");
15
13
 
14
+ var _PageStateContext = _interopRequireDefault(require("./PageStateContext"));
15
+
16
+ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
16
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
21
 
18
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
23
 
20
- const OFFSCREEN_RERENDER_LIMIT = 1;
21
-
22
24
  const styles = _core.StyleSheet.create({
25
+ fill: {
26
+ width: '100%',
27
+ height: '100%'
28
+ },
23
29
  none: {
24
30
  display: 'none'
25
31
  }
@@ -28,81 +34,69 @@ const styles = _core.StyleSheet.create({
28
34
  function Page(props) {
29
35
  const {
30
36
  index,
37
+ initialPage,
31
38
  children,
32
39
  loading,
33
- sharedIndex
40
+ offscreenPageRerenderLimit
34
41
  } = props;
42
+ const {
43
+ pageStore
44
+ } = (0, _react.useContext)(_InternalContext.default);
35
45
 
36
46
  const assumeInitialPageState = () => {
37
- const activeIndex = sharedIndex.value;
38
- const active = index === activeIndex;
39
-
40
- if (_reactNative.Platform.OS === 'web') {
41
- return {
42
- active,
43
- visited: active
44
- };
45
- }
47
+ const activeIndex = initialPage;
48
+ const isActive = index === activeIndex;
46
49
 
47
50
  if (loading === 'eager') {
48
51
  return {
49
- active,
50
- visited: true
52
+ isActive,
53
+ isLoaded: true
51
54
  };
52
55
  }
53
56
 
54
- const visited = index >= activeIndex - OFFSCREEN_RERENDER_LIMIT && index <= activeIndex + OFFSCREEN_RERENDER_LIMIT;
57
+ const isLoaded = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
55
58
  return {
56
- active,
57
- visited
59
+ isActive,
60
+ isLoaded
58
61
  };
59
62
  };
60
63
 
61
64
  const [pageState, setPageState] = (0, _react.useState)(assumeInitialPageState);
62
- const content = pageState.visited ? children : null;
63
-
64
- const updatePageState = (active, neighbor) => {
65
- setPageState(prevState => {
66
- if (prevState.active !== active) {
67
- return {
68
- active,
69
- visited: active || prevState.visited
70
- };
71
- }
72
-
73
- if (neighbor && !prevState.visited) {
74
- return { ...prevState,
75
- visited: true
76
- };
77
- }
78
-
79
- return prevState;
65
+ const content = pageState.isLoaded ? children : null;
66
+ (0, _react.useEffect)(() => {
67
+ return pageStore.subscribe(newPage => {
68
+ const activeIndex = newPage;
69
+ const isActive = index === activeIndex;
70
+ const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
71
+ const becomeNeighbor = shouldRerender && !isActive;
72
+ setPageState(prevState => {
73
+ if (prevState.isActive !== isActive) {
74
+ return { ...prevState,
75
+ isActive,
76
+ isLoaded: isActive || prevState.isLoaded
77
+ };
78
+ }
79
+
80
+ if (becomeNeighbor && !prevState.isLoaded) {
81
+ return { ...prevState,
82
+ isLoaded: true
83
+ };
84
+ }
85
+
86
+ return prevState;
87
+ });
80
88
  });
81
- };
82
-
83
- (0, _reactNativeReanimated.useAnimatedReaction)(() => {
84
- const activeIndex = sharedIndex.value;
85
- const willVisible = index >= activeIndex - OFFSCREEN_RERENDER_LIMIT && index <= activeIndex + OFFSCREEN_RERENDER_LIMIT;
86
- const willActive = index === activeIndex;
87
- const willNeighbor = _reactNative.Platform.OS === 'web' ? false : willVisible && !willActive;
88
- return {
89
- willActive,
90
- willNeighbor
91
- };
92
- }, (nextState, prevState) => {
93
- const activeStateChanged = nextState.willActive !== (prevState === null || prevState === void 0 ? void 0 : prevState.willActive);
94
- const willNewNeighbor = nextState.willNeighbor && !(prevState !== null && prevState !== void 0 && prevState.willNeighbor);
95
-
96
- if (activeStateChanged || willNewNeighbor) {
97
- (0, _reactNativeReanimated.runOnJS)(updatePageState)(nextState.willActive, nextState.willNeighbor);
98
- }
99
- }, [index]);
100
- const style = _reactNative.Platform.OS === 'web' ? pageState.active ? _core.StyleSheet.absoluteFill : styles.none : undefined;
89
+ }, [pageStore, index]);
90
+ const contextValue = (0, _react.useMemo)(() => ({
91
+ isActive: pageState.isActive
92
+ }), [pageState.isActive]);
93
+ const style = _reactNative.Platform.OS === 'web' ? pageState.isActive ? _core.StyleSheet.absoluteFill : styles.none : styles.fill;
101
94
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
102
- children: content,
103
95
  collapsable: false,
104
96
  style: style
105
- });
97
+ }, /*#__PURE__*/_react.default.createElement(_PageStateContext.default.Provider, {
98
+ value: contextValue
99
+ }, content));
106
100
  }
107
101
 
108
102
  var _default = /*#__PURE__*/(0, _react.memo)(Page, (prevProps, nextProps) => {
@@ -1 +1 @@
1
- {"version":3,"names":["OFFSCREEN_RERENDER_LIMIT","styles","StyleSheet","create","none","display","Page","props","index","children","loading","sharedIndex","assumeInitialPageState","activeIndex","value","active","Platform","OS","visited","pageState","setPageState","useState","content","updatePageState","neighbor","prevState","useAnimatedReaction","willVisible","willActive","willNeighbor","nextState","activeStateChanged","willNewNeighbor","runOnJS","style","absoluteFill","undefined","memo","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useState } from 'react';\nimport { Platform, View } from 'react-native';\nimport { runOnJS, useAnimatedReaction } from 'react-native-reanimated';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { PageProps } from './ViewPagerProps';\n\nconst OFFSCREEN_RERENDER_LIMIT = 1;\n\nconst styles = StyleSheet.create({\n none: { display: 'none' },\n});\n\ninterface PageState {\n active: boolean;\n visited: boolean;\n}\n\nfunction Page(props: PageProps) {\n const {\n index,\n children,\n loading,\n sharedIndex,\n } = props;\n\n const assumeInitialPageState = (): PageState => {\n const activeIndex = sharedIndex.value;\n\n const active = index === activeIndex;\n\n if (Platform.OS === 'web') {\n return { active, visited: active };\n }\n\n if (loading === 'eager') {\n return { active, visited: true };\n }\n\n const visited = index >= activeIndex - OFFSCREEN_RERENDER_LIMIT\n && index <= activeIndex + OFFSCREEN_RERENDER_LIMIT;\n\n return { active, visited };\n };\n\n const [pageState, setPageState] = useState<PageState>(assumeInitialPageState);\n\n const content = pageState.visited ? children : null;\n\n const updatePageState = (active: boolean, neighbor: boolean) => {\n setPageState(prevState => {\n if (prevState.active !== active) {\n return { active, visited: active || prevState.visited };\n }\n\n if (neighbor && !prevState.visited) {\n return { ...prevState, visited: true };\n }\n\n return prevState;\n });\n };\n\n useAnimatedReaction(\n () => {\n const activeIndex = sharedIndex.value;\n\n const willVisible = index >= activeIndex - OFFSCREEN_RERENDER_LIMIT\n && index <= activeIndex + OFFSCREEN_RERENDER_LIMIT;\n\n const willActive = index === activeIndex;\n const willNeighbor = Platform.OS === 'web' ? false : (willVisible && !willActive);\n\n return { willActive, willNeighbor };\n },\n (nextState, prevState) => {\n const activeStateChanged = nextState.willActive !== prevState?.willActive;\n const willNewNeighbor = nextState.willNeighbor && !prevState?.willNeighbor;\n\n if (activeStateChanged || willNewNeighbor) {\n runOnJS(updatePageState)(nextState.willActive, nextState.willNeighbor);\n }\n },\n [index],\n );\n\n const style = Platform.OS === 'web'\n ? (pageState.active ? StyleSheet.absoluteFill : styles.none)\n : undefined;\n\n return (\n <View\n children={content}\n collapsable={false}\n style={style}\n />\n );\n}\n\nexport default memo(Page, (prevProps, nextProps) => {\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.index !== nextProps.index;\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;AAGA,MAAMA,wBAAwB,GAAG,CAAjC;;AAEA,MAAMC,MAAM,GAAGC,gBAAA,CAAWC,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IAAEC,OAAO,EAAE;EAAX;AADuB,CAAlB,CAAf;;AASA,SAASC,IAAT,CAAcC,KAAd,EAAgC;EAC5B,MAAM;IACFC,KADE;IAEFC,QAFE;IAGFC,OAHE;IAIFC;EAJE,IAKFJ,KALJ;;EAOA,MAAMK,sBAAsB,GAAG,MAAiB;IAC5C,MAAMC,WAAW,GAAGF,WAAW,CAACG,KAAhC;IAEA,MAAMC,MAAM,GAAGP,KAAK,KAAKK,WAAzB;;IAEA,IAAIG,qBAAA,CAASC,EAAT,KAAgB,KAApB,EAA2B;MACvB,OAAO;QAAEF,MAAF;QAAUG,OAAO,EAAEH;MAAnB,CAAP;IACH;;IAED,IAAIL,OAAO,KAAK,OAAhB,EAAyB;MACrB,OAAO;QAAEK,MAAF;QAAUG,OAAO,EAAE;MAAnB,CAAP;IACH;;IAED,MAAMA,OAAO,GAAGV,KAAK,IAAIK,WAAW,GAAGb,wBAAvB,IACTQ,KAAK,IAAIK,WAAW,GAAGb,wBAD9B;IAGA,OAAO;MAAEe,MAAF;MAAUG;IAAV,CAAP;EACH,CAjBD;;EAmBA,MAAM,CAACC,SAAD,EAAYC,YAAZ,IAA4B,IAAAC,eAAA,EAAoBT,sBAApB,CAAlC;EAEA,MAAMU,OAAO,GAAGH,SAAS,CAACD,OAAV,GAAoBT,QAApB,GAA+B,IAA/C;;EAEA,MAAMc,eAAe,GAAG,CAACR,MAAD,EAAkBS,QAAlB,KAAwC;IAC5DJ,YAAY,CAACK,SAAS,IAAI;MACtB,IAAIA,SAAS,CAACV,MAAV,KAAqBA,MAAzB,EAAiC;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ClC,MAAM,CAACG,IAD7C,GAERgC,SAFN;EAIA,oBACI,6BAAC,iBAAD;IACI,QAAQ,EAAEd,OADd;IAEI,WAAW,EAAE,KAFjB;IAGI,KAAK,EAAEY;EAHX,EADJ;AAOH;;4BAEc,IAAAG,WAAA,EAAK/B,IAAL,EAAW,CAACgC,SAAD,EAAYC,SAAZ,KAA0B;EAChD,IAAID,SAAS,CAACE,WAAV,KAA0BD,SAAS,CAACC,WAAxC,EAAqD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOF,SAAS,CAAC9B,KAAV,KAAoB+B,SAAS,CAAC/B,KAArC;AACH,CANc,C"}
1
+ {"version":3,"names":["styles","StyleSheet","create","fill","width","height","none","display","Page","props","index","initialPage","children","loading","offscreenPageRerenderLimit","pageStore","useContext","InternalContext","assumeInitialPageState","activeIndex","isActive","isLoaded","pageState","setPageState","useState","content","useEffect","subscribe","newPage","shouldRerender","becomeNeighbor","prevState","contextValue","useMemo","style","Platform","OS","absoluteFill","memo","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useContext, useEffect, useMemo, useState } from 'react';\nimport { Platform, View } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { PageProps } from './types';\nimport PageStateContext from './PageStateContext';\nimport InternalContext from './InternalContext';\n\nconst styles = StyleSheet.create({\n fill: { width: '100%', height: '100%' },\n none: { display: 'none' },\n});\n\ninterface InternalPageState {\n isActive: boolean;\n isLoaded: boolean;\n}\n\nfunction Page(props: PageProps) {\n const {\n index,\n initialPage,\n children,\n loading,\n offscreenPageRerenderLimit,\n } = props;\n\n const { pageStore } = useContext(InternalContext);\n\n const assumeInitialPageState = (): InternalPageState => {\n const activeIndex = initialPage;\n\n const isActive = index === activeIndex;\n\n if (loading === 'eager') {\n return { isActive, isLoaded: true };\n }\n\n const isLoaded = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n return { isActive, isLoaded };\n };\n\n const [pageState, setPageState] = useState<InternalPageState>(assumeInitialPageState);\n\n const content = pageState.isLoaded ? children : null;\n\n useEffect(() => {\n return pageStore.subscribe(newPage => {\n const activeIndex = newPage;\n\n const isActive = index === activeIndex;\n\n const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n const becomeNeighbor = shouldRerender && !isActive;\n\n setPageState(prevState => {\n if (prevState.isActive !== isActive) {\n return {\n ...prevState,\n isActive,\n isLoaded: isActive || prevState.isLoaded,\n };\n }\n\n if (becomeNeighbor && !prevState.isLoaded) {\n return {\n ...prevState,\n isLoaded: true,\n };\n }\n\n return prevState;\n });\n });\n }, [pageStore, index]);\n\n const contextValue = useMemo(() => ({\n isActive: pageState.isActive,\n }), [pageState.isActive]);\n\n const style = Platform.OS === 'web'\n ? (pageState.isActive ? StyleSheet.absoluteFill : styles.none)\n : styles.fill;\n\n return (\n <View\n collapsable={false}\n style={style}\n >\n <PageStateContext.Provider value={contextValue}>\n {content}\n </PageStateContext.Provider>\n </View>\n );\n}\n\nexport default memo(Page, (prevProps, nextProps) => {\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.index !== nextProps.index;\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;AAEA,MAAMA,MAAM,GAAGC,gBAAA,CAAWC,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IAAEC,KAAK,EAAE,MAAT;IAAiBC,MAAM,EAAE;EAAzB,CADuB;EAE7BC,IAAI,EAAE;IAAEC,OAAO,EAAE;EAAX;AAFuB,CAAlB,CAAf;;AAUA,SAASC,IAAT,CAAcC,KAAd,EAAgC;EAC5B,MAAM;IACFC,KADE;IAEFC,WAFE;IAGFC,QAHE;IAIFC,OAJE;IAKFC;EALE,IAMFL,KANJ;EAQA,MAAM;IAAEM;EAAF,IAAgB,IAAAC,iBAAA,EAAWC,wBAAX,CAAtB;;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BM,CAAP;EA6BH,CA9BD,EA8BG,CAAChB,SAAD,EAAYL,KAAZ,CA9BH;EAgCA,MAAMsB,YAAY,GAAG,IAAAC,cAAA,EAAQ,OAAO;IAChCb,QAAQ,EAAEE,SAAS,CAACF;EADY,CAAP,CAAR,EAEjB,CAACE,SAAS,CAACF,QAAX,CAFiB,CAArB;EAIA,MAAMc,KAAK,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GACPd,SAAS,CAACF,QAAV,GAAqBnB,gBAAA,CAAWoC,YAAhC,GAA+CrC,MAAM,CAACM,IAD/C,GAERN,MAAM,CAACG,IAFb;EAIA,oBACI,6BAAC,iBAAD;IACI,WAAW,EAAE,KADjB;IAEI,KAAK,EAAE+B;EAFX,gBAII,6BAAC,yBAAD,CAAkB,QAAlB;IAA2B,KAAK,EAAEF;EAAlC,GACKP,OADL,CAJJ,CADJ;AAUH;;4BAEc,IAAAa,WAAA,EAAK9B,IAAL,EAAW,CAAC+B,SAAD,EAAYC,SAAZ,KAA0B;EAChD,IAAID,SAAS,CAACE,WAAV,KAA0BD,SAAS,CAACC,WAAxC,EAAqD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOF,SAAS,CAAC7B,KAAV,KAAoB8B,SAAS,CAAC9B,KAArC;AACH,CANc,C"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _core = require("@fountain-ui/core");
11
+
12
+ const InternalContext = /*#__PURE__*/(0, _react.createContext)({
13
+ pageStore: new _core.MockStore()
14
+ });
15
+ var _default = InternalContext;
16
+ exports.default = _default;
17
+ //# sourceMappingURL=InternalContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InternalContext","createContext","pageStore","MockStore"],"sources":["InternalContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport type { MonoStore } from '@fountain-ui/core';\nimport { MockStore } from '@fountain-ui/core';\n\nexport interface InternalContextValue {\n pageStore: MonoStore<number>;\n}\n\nconst InternalContext = createContext<InternalContextValue>({\n pageStore: new MockStore(),\n});\n\nexport default InternalContext;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAMA,MAAMA,eAAe,gBAAG,IAAAC,oBAAA,EAAoC;EACxDC,SAAS,EAAE,IAAIC,eAAJ;AAD6C,CAApC,CAAxB;eAIeH,e"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useViewPagerPageState = exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ const initialPageState = {
11
+ isActive: false
12
+ };
13
+ const PageStateContext = /*#__PURE__*/(0, _react.createContext)(initialPageState);
14
+
15
+ const useViewPagerPageState = () => {
16
+ return (0, _react.useContext)(PageStateContext);
17
+ };
18
+
19
+ exports.useViewPagerPageState = useViewPagerPageState;
20
+ var _default = PageStateContext;
21
+ exports.default = _default;
22
+ //# sourceMappingURL=PageStateContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["initialPageState","isActive","PageStateContext","createContext","useViewPagerPageState","useContext"],"sources":["PageStateContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\ninterface PageState {\n isActive: boolean;\n}\n\nconst initialPageState: Readonly<PageState> = { isActive: false };\n\nconst PageStateContext = createContext<PageState>(initialPageState);\n\nexport const useViewPagerPageState = () => {\n return useContext(PageStateContext);\n};\n\nexport default PageStateContext;\n"],"mappings":";;;;;;;AAAA;;AAMA,MAAMA,gBAAqC,GAAG;EAAEC,QAAQ,EAAE;AAAZ,CAA9C;AAEA,MAAMC,gBAAgB,gBAAG,IAAAC,oBAAA,EAAyBH,gBAAzB,CAAzB;;AAEO,MAAMI,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAAC,iBAAA,EAAWH,gBAAX,CAAP;AACH,CAFM;;;eAIQA,gB"}
@@ -9,10 +9,14 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactNativePagerView = _interopRequireDefault(require("react-native-pager-view"));
11
11
 
12
- var _reactNativeReanimated = require("react-native-reanimated");
12
+ var _core = require("@fountain-ui/core");
13
13
 
14
14
  var _utils = require("./utils");
15
15
 
16
+ var _usePageStore = _interopRequireDefault(require("./usePageStore"));
17
+
18
+ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
19
+
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
18
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -25,44 +29,104 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
25
29
  initialPage = _utils.defaultInitialPage,
26
30
  keyboardDismissMode = 'on-drag',
27
31
  loading = _utils.defaultLoading,
32
+ offscreenPageRerenderLimit = _utils.defaultOffscreenPageRerenderLimit,
28
33
  onChange,
29
34
  pageComponent = _utils.defaultPageComponent,
30
35
  pageForceRerenderKey,
31
36
  scrollEnabled = true,
32
- style
37
+ style,
38
+ UNSTABLE_sharedPage
33
39
  } = props;
34
- const sharedIndex = (0, _reactNativeReanimated.useSharedValue)(initialPage);
40
+ const fallbackSharedPage = (0, _core.useSyncAnimatedValue)({
41
+ initialValue: initialPage
42
+ });
43
+ const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
44
+ const pageRef = (0, _react.useRef)(sharedPage.initialValue);
45
+ const desiredPageRef = (0, _react.useRef)(NaN);
35
46
  const pagerRef = (0, _react.useRef)(null);
47
+ const animationFrameRef = (0, _react.useRef)(NaN);
48
+ const setPage = (0, _react.useCallback)(newPage => {
49
+ if (!Number.isInteger(newPage)) {
50
+ return;
51
+ }
36
52
 
37
- const setPage = newIndex => {
38
- requestAnimationFrame(() => {
53
+ animationFrameRef.current = requestAnimationFrame(() => {
39
54
  var _pagerRef$current;
40
55
 
41
- (_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newIndex);
42
- });
43
- };
56
+ if (Number.isFinite(desiredPageRef.current)) {
57
+ if (pageRef.current === desiredPageRef.current) {
58
+ // end of state machine. clear desired page.
59
+ desiredPageRef.current = NaN;
60
+ return;
61
+ }
44
62
 
45
- (0, _react.useImperativeHandle)(ref, () => ({
46
- setPage
47
- }), []);
63
+ if (newPage === desiredPageRef.current) {
64
+ return;
65
+ }
66
+ }
67
+
68
+ desiredPageRef.current = newPage;
69
+ (_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newPage);
70
+ });
71
+ }, []);
72
+ (0, _react.useEffect)(() => {
73
+ return () => {
74
+ if (animationFrameRef.current) {
75
+ cancelAnimationFrame(animationFrameRef.current);
76
+ }
77
+ };
78
+ }, []);
79
+ (0, _react.useEffect)(() => {
80
+ const animatedValue = sharedPage.animatedValue;
81
+ const id = animatedValue.addListener(newValue => {
82
+ const newPage = newValue.value;
83
+ pageRef.current = newPage;
84
+ setPage(newPage);
85
+ });
86
+ return () => {
87
+ animatedValue.removeListener(id);
88
+ };
89
+ }, [sharedPage]);
48
90
  const handlePageSelected = (0, _react.useCallback)(e => {
49
- const currentIndex = sharedIndex.value;
50
- const nextIndex = e.nativeEvent.position;
91
+ if (Number.isFinite(desiredPageRef.current)) {
92
+ // onPageSelected is called from outer controlling mechanism
93
+ // e.g. sharedPage.value is changed, setPage() is called
94
+ // Due to the onPageSelected bug,
95
+ // we don't trust the value from event, (e.nativeEvent.position)
96
+ // other than that trust the value from desiredPageRef.
97
+ const desiredPage = desiredPageRef.current;
51
98
 
52
- if (currentIndex === nextIndex) {
53
- return;
54
- }
99
+ if (pageRef.current === desiredPage) {
100
+ // end of state machine. clear desired page.
101
+ desiredPageRef.current = NaN;
102
+ } else {
103
+ sharedPage.animatedValue.setValue(desiredPage);
104
+ }
55
105
 
56
- sharedIndex.value = nextIndex;
106
+ onChange === null || onChange === void 0 ? void 0 : onChange(desiredPage);
107
+ } else {
108
+ const trustfulNextPage = e.nativeEvent.position;
57
109
 
58
- if (onChange) {
59
- onChange(nextIndex);
110
+ if (trustfulNextPage !== pageRef.current) {
111
+ desiredPageRef.current = trustfulNextPage;
112
+ sharedPage.animatedValue.setValue(trustfulNextPage);
113
+ }
114
+
115
+ onChange === null || onChange === void 0 ? void 0 : onChange(trustfulNextPage);
60
116
  }
61
- }, [onChange]);
117
+ }, [onChange, sharedPage]);
118
+ (0, _react.useImperativeHandle)(ref, () => ({
119
+ setPage
120
+ }), [setPage]);
121
+ const pageStore = (0, _usePageStore.default)(sharedPage);
62
122
  const PageComponent = pageComponent;
63
- return /*#__PURE__*/_react.default.createElement(_reactNativePagerView.default, {
123
+ return /*#__PURE__*/_react.default.createElement(_InternalContext.default.Provider, {
124
+ value: {
125
+ pageStore
126
+ }
127
+ }, /*#__PURE__*/_react.default.createElement(_reactNativePagerView.default, {
64
128
  ref: pagerRef,
65
- initialPage: initialPage,
129
+ initialPage: sharedPage.initialValue,
66
130
  keyboardDismissMode: keyboardDismissMode,
67
131
  onPageSelected: handlePageSelected,
68
132
  pageMargin: 8,
@@ -72,10 +136,11 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
72
136
  key: index,
73
137
  children: child,
74
138
  index: index,
139
+ initialPage: sharedPage.initialValue,
75
140
  loading: loading,
76
- rerenderKey: pageForceRerenderKey,
77
- sharedIndex: sharedIndex
78
- })));
141
+ offscreenPageRerenderLimit: offscreenPageRerenderLimit,
142
+ rerenderKey: pageForceRerenderKey
143
+ }))));
79
144
  });
80
145
  var _default = ViewPager;
81
146
  exports.default = _default;