@fountain-ui/lab 2.0.0-beta.10 → 2.0.0-beta.13

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 (266) 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 +86 -21
  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 +82 -34
  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 +35 -26
  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 +5 -41
  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 +120 -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 +46 -0
  99. package/build/module/Carousel/components/ItemView.js.map +1 -0
  100. package/build/module/Carousel/components/RootView.js +65 -0
  101. package/build/module/Carousel/components/RootView.js.map +1 -0
  102. package/build/module/Carousel/components/ScrollViewGesture.js +67 -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 +48 -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 +153 -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 +80 -23
  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 +81 -34
  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 +29 -24
  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 +2 -32
  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 +33 -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 +9 -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 +79 -0
  184. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +2 -1
  185. package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
  186. package/build/typescript/ViewPager/ViewPagerNative.d.ts +4 -1
  187. package/build/typescript/ViewPager/ViewPagerProps.d.ts +31 -19
  188. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +4 -1
  189. package/build/typescript/ViewPager/index.d.ts +2 -1
  190. package/build/typescript/ViewPager/index.native.d.ts +1 -0
  191. package/build/typescript/ViewPager/utils.d.ts +3 -19
  192. package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
  193. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
  194. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
  195. package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
  196. package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
  197. package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
  198. package/build/typescript/hooks/index.d.ts +2 -0
  199. package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
  200. package/build/typescript/hooks/useIsMounted.d.ts +4 -0
  201. package/build/typescript/index.d.ts +2 -0
  202. package/package.json +4 -19
  203. package/src/Carousel/Carousel.tsx +152 -0
  204. package/src/Carousel/CarouselProps.ts +35 -53
  205. package/src/Carousel/animation/animationUtils.ts +1 -0
  206. package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
  207. package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
  208. package/src/Carousel/animation/index.ts +4 -0
  209. package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
  210. package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
  211. package/src/Carousel/components/InternalContext.ts +33 -0
  212. package/src/Carousel/components/ItemView.tsx +66 -0
  213. package/src/Carousel/components/RootView.tsx +79 -0
  214. package/src/Carousel/components/ScrollViewGesture.tsx +87 -0
  215. package/src/Carousel/components/index.ts +4 -0
  216. package/src/Carousel/hooks/index.ts +7 -0
  217. package/src/Carousel/hooks/useAutoplayController.ts +57 -0
  218. package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
  219. package/src/Carousel/hooks/useIndexController.tsx +76 -0
  220. package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
  221. package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
  222. package/src/Carousel/hooks/useLoopedData.ts +26 -0
  223. package/src/Carousel/hooks/usePagingAnimation.ts +195 -0
  224. package/src/Carousel/index.ts +4 -2
  225. package/src/Carousel/types.ts +97 -0
  226. package/src/ViewPager/ChildrenMemoizedPage.tsx +97 -23
  227. package/src/ViewPager/PageStateContext.ts +15 -0
  228. package/src/ViewPager/ViewPagerNative.tsx +101 -39
  229. package/src/ViewPager/ViewPagerProps.ts +33 -19
  230. package/src/ViewPager/ViewPagerWeb.tsx +38 -29
  231. package/src/ViewPager/index.native.ts +1 -0
  232. package/src/ViewPager/index.ts +2 -1
  233. package/src/ViewPager/utils.tsx +4 -56
  234. package/src/ViewabilityTrackerView/Viewability.ts +3 -0
  235. package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
  236. package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
  237. package/src/ViewabilityTrackerView/index.ts +2 -0
  238. package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
  239. package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
  240. package/src/hooks/index.ts +2 -0
  241. package/src/hooks/useDeferredExecutor.ts +46 -0
  242. package/src/hooks/useIsMounted.ts +19 -0
  243. package/src/index.ts +3 -0
  244. package/build/commonjs/Carousel/CarouselNative.js +0 -72
  245. package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
  246. package/build/commonjs/Carousel/CarouselWeb.js +0 -237
  247. package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
  248. package/build/commonjs/Carousel/index.native.js.map +0 -1
  249. package/build/commonjs/Carousel/utils.js +0 -19
  250. package/build/commonjs/Carousel/utils.js.map +0 -1
  251. package/build/module/Carousel/CarouselNative.js +0 -54
  252. package/build/module/Carousel/CarouselNative.js.map +0 -1
  253. package/build/module/Carousel/CarouselWeb.js +0 -215
  254. package/build/module/Carousel/CarouselWeb.js.map +0 -1
  255. package/build/module/Carousel/index.native.js +0 -2
  256. package/build/module/Carousel/index.native.js.map +0 -1
  257. package/build/module/Carousel/utils.js +0 -7
  258. package/build/module/Carousel/utils.js.map +0 -1
  259. package/build/typescript/Carousel/CarouselNative.d.ts +0 -2
  260. package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
  261. package/build/typescript/Carousel/index.native.d.ts +0 -1
  262. package/build/typescript/Carousel/utils.d.ts +0 -6
  263. package/src/Carousel/CarouselNative.tsx +0 -67
  264. package/src/Carousel/CarouselWeb.tsx +0 -222
  265. package/src/Carousel/index.native.ts +0 -1
  266. 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;AAU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B,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"}
@@ -5,44 +5,109 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ 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
+ var _core = require("@fountain-ui/core");
15
+
16
+ var _PageStateContext = _interopRequireDefault(require("./PageStateContext"));
17
+
12
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
19
 
14
- 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); }
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); }
21
+
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; }
23
+
24
+ const styles = _core.StyleSheet.create({
25
+ fill: {
26
+ width: '100%',
27
+ height: '100%'
28
+ },
29
+ none: {
30
+ display: 'none'
31
+ }
32
+ });
15
33
 
16
- const Page = function Page(props) {
34
+ function Page(props) {
17
35
  const {
18
- isVisible,
19
- ...otherProps
36
+ index,
37
+ children,
38
+ loading,
39
+ offscreenPageRerenderLimit,
40
+ sharedIndex
20
41
  } = props;
21
- return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({
22
- collapsable: false
23
- }, otherProps));
24
- };
25
42
 
26
- var _default = /*#__PURE__*/_react.default.memo(Page, (prevProps, nextProps) => {
27
- if (prevProps.children === null && nextProps.children === null) {
28
- return true;
29
- } // isVisible is an important condition for determining memos on the web.
30
- // Reference ViewPagerWeb's return.
43
+ const assumeInitialPageState = () => {
44
+ const activeIndex = sharedIndex.value;
45
+ const isActive = index === activeIndex;
31
46
 
47
+ if (loading === 'eager') {
48
+ return {
49
+ isActive,
50
+ isLoaded: true
51
+ };
52
+ }
32
53
 
33
- if (prevProps.isVisible !== nextProps.isVisible) {
34
- return false;
35
- }
54
+ const isLoaded = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
55
+ return {
56
+ isActive,
57
+ isLoaded
58
+ };
59
+ };
36
60
 
37
- if (nextProps.isVisible || nextProps.isNeighbor) {
38
- return false;
39
- }
61
+ const [pageState, setPageState] = (0, _react.useState)(assumeInitialPageState);
62
+ const content = pageState.isLoaded ? children : null;
63
+
64
+ const onActiveStateChange = isActive => {
65
+ setPageState(prevState => ({ ...prevState,
66
+ isActive,
67
+ isLoaded: isActive || prevState.isLoaded
68
+ }));
69
+ };
70
+
71
+ const onBecomeNeighbor = () => {
72
+ setPageState(prevState => ({ ...prevState,
73
+ isLoaded: true
74
+ }));
75
+ };
76
+
77
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => {
78
+ const activeIndex = sharedIndex.value;
79
+ const isActive = index === activeIndex;
80
+ const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
81
+ const becomeNeighbor = shouldRerender && !isActive;
82
+ return {
83
+ isActive,
84
+ becomeNeighbor
85
+ };
86
+ }, (nextState, prevState) => {
87
+ if (nextState.isActive !== (prevState === null || prevState === void 0 ? void 0 : prevState.isActive)) {
88
+ (0, _reactNativeReanimated.runOnJS)(onActiveStateChange)(nextState.isActive);
89
+ } else if (nextState.becomeNeighbor) {
90
+ (0, _reactNativeReanimated.runOnJS)(onBecomeNeighbor)();
91
+ }
92
+ }, [index]);
93
+ const contextValue = (0, _react.useMemo)(() => ({
94
+ isActive: pageState.isActive
95
+ }), [pageState.isActive]);
96
+ const style = _reactNative.Platform.OS === 'web' ? pageState.isActive ? _core.StyleSheet.absoluteFill : styles.none : styles.fill;
97
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
98
+ collapsable: false,
99
+ style: style
100
+ }, /*#__PURE__*/_react.default.createElement(_PageStateContext.default.Provider, {
101
+ value: contextValue
102
+ }, content));
103
+ }
40
104
 
105
+ var _default = /*#__PURE__*/(0, _react.memo)(Page, (prevProps, nextProps) => {
41
106
  if (prevProps.rerenderKey !== nextProps.rerenderKey) {
42
107
  return false;
43
108
  }
44
109
 
45
- return prevProps.children !== null && nextProps.children !== null;
110
+ return prevProps.index !== nextProps.index;
46
111
  });
47
112
 
48
113
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["Page","props","isVisible","otherProps","React","memo","prevProps","nextProps","children","isNeighbor","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React from 'react';\nimport { View } from 'react-native';\nimport type { PageProps } from './ViewPagerProps';\n\nconst Page = function Page(props: PageProps) {\n const { isVisible, ...otherProps } = props;\n\n return (\n <View\n collapsable={false}\n {...otherProps}\n />\n );\n};\n\nexport default React.memo(Page, (prevProps, nextProps) => {\n if (prevProps.children === null && nextProps.children === null) {\n return true;\n }\n\n // isVisible is an important condition for determining memos on the web.\n // Reference ViewPagerWeb's return.\n if (prevProps.isVisible !== nextProps.isVisible) {\n return false;\n }\n\n if (nextProps.isVisible || nextProps.isNeighbor) {\n return false;\n }\n\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.children !== null && nextProps.children !== null;\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAGA,MAAMA,IAAI,GAAG,SAASA,IAAT,CAAcC,KAAd,EAAgC;EACzC,MAAM;IAAEC,SAAF;IAAa,GAAGC;EAAhB,IAA+BF,KAArC;EAEA,oBACI,6BAAC,iBAAD;IACI,WAAW,EAAE;EADjB,GAEQE,UAFR,EADJ;AAMH,CATD;;4BAWeC,cAAA,CAAMC,IAAN,CAAWL,IAAX,EAAiB,CAACM,SAAD,EAAYC,SAAZ,KAA0B;EACtD,IAAID,SAAS,CAACE,QAAV,KAAuB,IAAvB,IAA+BD,SAAS,CAACC,QAAV,KAAuB,IAA1D,EAAgE;IAC5D,OAAO,IAAP;EACH,CAHqD,CAKtD;EACA;;;EACA,IAAIF,SAAS,CAACJ,SAAV,KAAwBK,SAAS,CAACL,SAAtC,EAAiD;IAC7C,OAAO,KAAP;EACH;;EAED,IAAIK,SAAS,CAACL,SAAV,IAAuBK,SAAS,CAACE,UAArC,EAAiD;IAC7C,OAAO,KAAP;EACH;;EAED,IAAIH,SAAS,CAACI,WAAV,KAA0BH,SAAS,CAACG,WAAxC,EAAqD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOJ,SAAS,CAACE,QAAV,KAAuB,IAAvB,IAA+BD,SAAS,CAACC,QAAV,KAAuB,IAA7D;AACH,CApBc,C"}
1
+ {"version":3,"names":["styles","StyleSheet","create","fill","width","height","none","display","Page","props","index","children","loading","offscreenPageRerenderLimit","sharedIndex","assumeInitialPageState","activeIndex","value","isActive","isLoaded","pageState","setPageState","useState","content","onActiveStateChange","prevState","onBecomeNeighbor","useAnimatedReaction","shouldRerender","becomeNeighbor","nextState","runOnJS","contextValue","useMemo","style","Platform","OS","absoluteFill","memo","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useMemo, 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';\nimport PageStateContext from './PageStateContext';\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 children,\n loading,\n offscreenPageRerenderLimit,\n sharedIndex,\n } = props;\n\n const assumeInitialPageState = (): InternalPageState => {\n const activeIndex = sharedIndex.value;\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 const onActiveStateChange = (isActive: boolean) => {\n setPageState(prevState => ({\n ...prevState,\n isActive,\n isLoaded: isActive || prevState.isLoaded,\n }));\n };\n\n const onBecomeNeighbor = () => {\n setPageState(prevState => ({\n ...prevState,\n isLoaded: true,\n }));\n };\n\n useAnimatedReaction(\n () => {\n const activeIndex = sharedIndex.value;\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 return { isActive, becomeNeighbor };\n },\n (nextState, prevState) => {\n if (nextState.isActive !== prevState?.isActive) {\n runOnJS(onActiveStateChange)(nextState.isActive);\n } else if (nextState.becomeNeighbor) {\n runOnJS(onBecomeNeighbor)();\n }\n },\n [index],\n );\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;;AACA;;AAEA;;;;;;;;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,QAFE;IAGFC,OAHE;IAIFC,0BAJE;IAKFC;EALE,IAMFL,KANJ;;EAQA,MAAMM,sBAAsB,GAAG,MAAyB;IACpD,MAAMC,WAAW,GAAGF,WAAW,CAACG,KAAhC;IAEA,MAAMC,QAAQ,GAAGR,KAAK,KAAKM,WAA3B;;IAEA,IAAIJ,OAAO,KAAK,OAAhB,EAAyB;MACrB,OAAO;QAAEM,QAAF;QAAYC,QAAQ,EAAE;MAAtB,CAAP;IACH;;IAED,MAAMA,QAAQ,GAAGT,KAAK,IAAIM,WAAW,GAAGH,0BAAvB,IACVH,KAAK,IAAIM,WAAW,GAAGH,0BAD9B;IAGA,OAAO;MAAEK,QAAF;MAAYC;IAAZ,CAAP;EACH,CAbD;;EAeA,MAAM,CAACC,SAAD,EAAYC,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AACF;EADY,CAAP,CAAR,EAEjB,CAACE,SAAS,CAACF,QAAX,CAFiB,CAArB;EAIA,MAAMgB,KAAK,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GACPhB,SAAS,CAACF,QAAV,GAAqBjB,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,GACKT,OADL,CAJJ,CADJ;AAUH;;4BAEc,IAAAe,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,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"}
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = ViewPager;
6
+ exports.default = void 0;
7
7
 
8
8
  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");
13
+
12
14
  var _utils = require("./utils");
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -17,59 +19,105 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
17
19
 
18
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
21
 
20
- function ViewPager(props) {
22
+ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props, ref) {
21
23
  const {
22
24
  children,
23
- enableVisibleHint = _utils.defaultEnableVisibleHint,
24
- index,
25
+ initialPage = _utils.defaultInitialPage,
25
26
  keyboardDismissMode = 'on-drag',
26
27
  loading = _utils.defaultLoading,
28
+ offscreenPageRerenderLimit = _utils.defaultOffscreenPageRerenderLimit,
27
29
  onChange,
28
30
  pageComponent = _utils.defaultPageComponent,
29
- enableNeighborPageRerender = _utils.defaultEnableNeighborPageRerender,
30
31
  pageForceRerenderKey,
31
32
  scrollEnabled = true,
32
- style
33
+ style,
34
+ UNSTABLE_sharedPage
33
35
  } = props;
34
- const indexRef = (0, _react.useRef)(index);
36
+ const fallbackSharedPage = (0, _reactNativeReanimated.useSharedValue)(initialPage);
37
+ const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
38
+ const desiredPageRef = (0, _react.useRef)(NaN);
35
39
  const pagerRef = (0, _react.useRef)(null);
36
- const renderer = (0, _utils.usePageRenderer)({
37
- enableVisibleHint,
38
- index,
39
- loading,
40
- pageComponent,
41
- pageForceRerenderKey,
42
- enableNeighborPageRerender
43
- });
44
- const handlePageSelected = (0, _react.useCallback)(e => {
45
- indexRef.current = e.nativeEvent.position;
46
-
47
- if (onChange) {
48
- onChange(indexRef.current);
40
+ const animationFrameRef = (0, _react.useRef)(NaN);
41
+ const setPage = (0, _react.useCallback)(newPage => {
42
+ if (!Number.isInteger(newPage)) {
43
+ return;
49
44
  }
50
- }, [onChange]);
51
- (0, _react.useEffect)(() => {
52
- const handleNumber = index !== indexRef.current ? requestAnimationFrame(() => {
45
+
46
+ animationFrameRef.current = requestAnimationFrame(() => {
53
47
  var _pagerRef$current;
54
48
 
55
- return (_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(index);
56
- }) : undefined;
49
+ if (Number.isFinite(desiredPageRef.current)) {
50
+ if (sharedPage.value === desiredPageRef.current) {
51
+ // end of state machine. clear desired page.
52
+ desiredPageRef.current = NaN;
53
+ return;
54
+ }
55
+
56
+ if (newPage === desiredPageRef.current) {
57
+ return;
58
+ }
59
+ }
60
+
61
+ desiredPageRef.current = newPage;
62
+ (_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newPage);
63
+ });
64
+ }, []);
65
+ (0, _react.useEffect)(() => {
57
66
  return () => {
58
- if (handleNumber) {
59
- cancelAnimationFrame(handleNumber);
67
+ if (animationFrameRef.current) {
68
+ cancelAnimationFrame(animationFrameRef.current);
60
69
  }
61
70
  };
62
- }, [index]);
71
+ }, []);
72
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => sharedPage.value, result => {
73
+ (0, _reactNativeReanimated.runOnJS)(setPage)(result);
74
+ }, [setPage]);
75
+ const handlePageSelected = (0, _react.useCallback)(e => {
76
+ if (Number.isFinite(desiredPageRef.current)) {
77
+ // onPageSelected is called from outer controlling mechanism
78
+ // e.g. sharedPage.value is changed, setPage() is called
79
+ // Due to the onPageSelected bug,
80
+ // we don't trust the value from event, (e.nativeEvent.position)
81
+ // other than that trust the value from desiredPageRef.
82
+ const desiredPage = desiredPageRef.current;
83
+
84
+ if (sharedPage.value === desiredPage) {
85
+ // end of state machine. clear desired page.
86
+ desiredPageRef.current = NaN;
87
+ } else {
88
+ sharedPage.value = desiredPage;
89
+ }
90
+
91
+ onChange === null || onChange === void 0 ? void 0 : onChange(desiredPage);
92
+ } else {
93
+ const trustfulNextPage = e.nativeEvent.position;
94
+ desiredPageRef.current = trustfulNextPage;
95
+ sharedPage.value = trustfulNextPage;
96
+ onChange === null || onChange === void 0 ? void 0 : onChange(trustfulNextPage);
97
+ }
98
+ }, [onChange]);
99
+ (0, _react.useImperativeHandle)(ref, () => ({
100
+ setPage
101
+ }), [setPage]);
102
+ const PageComponent = pageComponent;
63
103
  return /*#__PURE__*/_react.default.createElement(_reactNativePagerView.default, {
64
- initialPage: index,
104
+ ref: pagerRef,
105
+ initialPage: sharedPage.value,
65
106
  keyboardDismissMode: keyboardDismissMode,
66
107
  onPageSelected: handlePageSelected,
67
108
  pageMargin: 8,
68
- ref: pagerRef,
69
109
  scrollEnabled: scrollEnabled,
70
110
  style: style
71
- }, renderer(children));
72
- }
73
-
74
- ;
111
+ }, _react.Children.map(children, (child, index) => /*#__PURE__*/_react.default.createElement(PageComponent, {
112
+ key: index,
113
+ children: child,
114
+ index: index,
115
+ loading: loading,
116
+ offscreenPageRerenderLimit: offscreenPageRerenderLimit,
117
+ rerenderKey: pageForceRerenderKey,
118
+ sharedIndex: sharedPage
119
+ })));
120
+ });
121
+ var _default = ViewPager;
122
+ exports.default = _default;
75
123
  //# sourceMappingURL=ViewPagerNative.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ViewPager","props","children","enableVisibleHint","defaultEnableVisibleHint","index","keyboardDismissMode","loading","defaultLoading","onChange","pageComponent","defaultPageComponent","enableNeighborPageRerender","defaultEnableNeighborPageRerender","pageForceRerenderKey","scrollEnabled","style","indexRef","useRef","pagerRef","renderer","usePageRenderer","handlePageSelected","useCallback","e","current","nativeEvent","position","useEffect","handleNumber","requestAnimationFrame","setPage","undefined","cancelAnimationFrame"],"sources":["ViewPagerNative.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef } from 'react';\nimport type { ViewPagerOnPageSelectedEvent } from 'react-native-pager-view';\nimport RNViewPager from 'react-native-pager-view';\nimport type ViewPagerProps from './ViewPagerProps';\nimport {\n defaultEnableNeighborPageRerender,\n defaultEnableVisibleHint,\n defaultLoading,\n defaultPageComponent,\n usePageRenderer,\n} from './utils';\n\nexport default function ViewPager(props: ViewPagerProps) {\n const {\n children,\n enableVisibleHint = defaultEnableVisibleHint,\n index,\n keyboardDismissMode = 'on-drag',\n loading = defaultLoading,\n onChange,\n pageComponent = defaultPageComponent,\n enableNeighborPageRerender = defaultEnableNeighborPageRerender,\n pageForceRerenderKey,\n scrollEnabled = true,\n style,\n } = props;\n\n const indexRef = useRef<number>(index);\n const pagerRef = useRef<RNViewPager | null>(null);\n\n const renderer = usePageRenderer({\n enableVisibleHint,\n index,\n loading,\n pageComponent,\n pageForceRerenderKey,\n enableNeighborPageRerender,\n });\n\n const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {\n indexRef.current = e.nativeEvent.position;\n\n if (onChange) {\n onChange(indexRef.current);\n }\n }, [onChange]);\n\n useEffect(() => {\n const handleNumber = index !== indexRef.current\n ? requestAnimationFrame(() => pagerRef.current?.setPage(index))\n : undefined;\n\n return () => {\n if (handleNumber) {\n cancelAnimationFrame(handleNumber);\n }\n };\n }, [index]);\n\n return (\n <RNViewPager\n initialPage={index}\n keyboardDismissMode={keyboardDismissMode}\n onPageSelected={handlePageSelected}\n pageMargin={8}\n ref={pagerRef}\n scrollEnabled={scrollEnabled}\n style={style}\n >\n {renderer(children)}\n </RNViewPager>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;;;;;AAQe,SAASA,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,QADE;IAEFC,iBAAiB,GAAGC,+BAFlB;IAGFC,KAHE;IAIFC,mBAAmB,GAAG,SAJpB;IAKFC,OAAO,GAAGC,qBALR;IAMFC,QANE;IAOFC,aAAa,GAAGC,2BAPd;IAQFC,0BAA0B,GAAGC,wCAR3B;IASFC,oBATE;IAUFC,aAAa,GAAG,IAVd;IAWFC;EAXE,IAYFf,KAZJ;EAcA,MAAMgB,QAAQ,GAAG,IAAAC,aAAA,EAAeb,KAAf,CAAjB;EACA,MAAMc,QAAQ,GAAG,IAAAD,aAAA,EAA2B,IAA3B,CAAjB;EAEA,MAAME,QAAQ,GAAG,IAAAC,sBAAA,EAAgB;IAC7BlB,iBAD6B;IAE7BE,KAF6B;IAG7BE,OAH6B;IAI7BG,aAJ6B;IAK7BI,oBAL6B;IAM7BF;EAN6B,CAAhB,CAAjB;EASA,MAAMU,kBAAkB,GAAG,IAAAC,kBAAA,EAAaC,CAAD,IAAqC;IACxEP,QAAQ,CAACQ,OAAT,GAAmBD,CAAC,CAACE,WAAF,CAAcC,QAAjC;;IAEA,IAAIlB,QAAJ,EAAc;MACVA,QAAQ,CAACQ,QAAQ,CAACQ,OAAV,CAAR;IACH;EACJ,CAN0B,EAMxB,CAAChB,QAAD,CANwB,CAA3B;EAQA,IAAAmB,gBAAA,EAAU,MAAM;IACZ,MAAMC,YAAY,GAAGxB,KAAK,KAAKY,QAAQ,CAACQ,OAAnB,GACfK,qBAAqB,CAAC;MAAA;;MAAA,4BAAMX,QAAQ,CAACM,OAAf,sDAAM,kBAAkBM,OAAlB,CAA0B1B,KAA1B,CAAN;IAAA,CAAD,CADN,GAEf2B,SAFN;IAIA,OAAO,MAAM;MACT,IAAIH,YAAJ,EAAkB;QACdI,oBAAoB,CAACJ,YAAD,CAApB;MACH;IACJ,CAJD;EAKH,CAVD,EAUG,CAACxB,KAAD,CAVH;EAYA,oBACI,6BAAC,6BAAD;IACI,WAAW,EAAEA,KADjB;IAEI,mBAAmB,EAAEC,mBAFzB;IAGI,cAAc,EAAEgB,kBAHpB;IAII,UAAU,EAAE,CAJhB;IAKI,GAAG,EAAEH,QALT;IAMI,aAAa,EAAEJ,aANnB;IAOI,KAAK,EAAEC;EAPX,GASKI,QAAQ,CAAClB,QAAD,CATb,CADJ;AAaH;;AAAA"}
1
+ {"version":3,"names":["ViewPager","forwardRef","props","ref","children","initialPage","defaultInitialPage","keyboardDismissMode","loading","defaultLoading","offscreenPageRerenderLimit","defaultOffscreenPageRerenderLimit","onChange","pageComponent","defaultPageComponent","pageForceRerenderKey","scrollEnabled","style","UNSTABLE_sharedPage","fallbackSharedPage","useSharedValue","sharedPage","desiredPageRef","useRef","NaN","pagerRef","animationFrameRef","setPage","useCallback","newPage","Number","isInteger","current","requestAnimationFrame","isFinite","value","useEffect","cancelAnimationFrame","useAnimatedReaction","result","runOnJS","handlePageSelected","e","desiredPage","trustfulNextPage","nativeEvent","position","useImperativeHandle","PageComponent","Children","map","child","index"],"sources":["ViewPagerNative.tsx"],"sourcesContent":["import React, { Children, forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from 'react';\nimport type { ViewPagerOnPageSelectedEvent } from 'react-native-pager-view';\nimport RNViewPager from 'react-native-pager-view';\nimport { runOnJS, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './ViewPagerProps';\nimport { defaultInitialPage, defaultLoading, defaultOffscreenPageRerenderLimit, defaultPageComponent } from './utils';\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n keyboardDismissMode = 'on-drag',\n loading = defaultLoading,\n offscreenPageRerenderLimit = defaultOffscreenPageRerenderLimit,\n onChange,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n scrollEnabled = true,\n style,\n UNSTABLE_sharedPage,\n } = props;\n\n const fallbackSharedPage = useSharedValue<number>(initialPage);\n\n const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;\n\n const desiredPageRef = useRef<number>(NaN);\n\n const pagerRef = useRef<RNViewPager | null>(null);\n\n const animationFrameRef = useRef<number>(NaN);\n\n const setPage = useCallback((newPage: number) => {\n if (!Number.isInteger(newPage)) {\n return;\n }\n\n animationFrameRef.current = requestAnimationFrame(() => {\n if (Number.isFinite(desiredPageRef.current)) {\n if (sharedPage.value === desiredPageRef.current) {\n // end of state machine. clear desired page.\n desiredPageRef.current = NaN;\n return;\n }\n\n if (newPage === desiredPageRef.current) {\n return;\n }\n }\n\n desiredPageRef.current = newPage;\n pagerRef.current?.setPage(newPage);\n });\n }, []);\n\n useEffect(() => {\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current);\n }\n };\n }, []);\n\n useAnimatedReaction(\n () => sharedPage.value,\n (result) => {\n runOnJS(setPage)(result);\n },\n [setPage],\n );\n\n const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {\n if (Number.isFinite(desiredPageRef.current)) {\n // onPageSelected is called from outer controlling mechanism\n // e.g. sharedPage.value is changed, setPage() is called\n // Due to the onPageSelected bug,\n // we don't trust the value from event, (e.nativeEvent.position)\n // other than that trust the value from desiredPageRef.\n\n const desiredPage = desiredPageRef.current;\n\n if (sharedPage.value === desiredPage) {\n // end of state machine. clear desired page.\n desiredPageRef.current = NaN;\n } else {\n sharedPage.value = desiredPage;\n }\n\n onChange?.(desiredPage);\n } else {\n const trustfulNextPage = e.nativeEvent.position;\n\n desiredPageRef.current = trustfulNextPage;\n\n sharedPage.value = trustfulNextPage;\n\n onChange?.(trustfulNextPage);\n }\n }, [onChange]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const PageComponent = pageComponent;\n\n return (\n <RNViewPager\n ref={pagerRef}\n initialPage={sharedPage.value}\n keyboardDismissMode={keyboardDismissMode}\n onPageSelected={handlePageSelected}\n pageMargin={8}\n scrollEnabled={scrollEnabled}\n style={style}\n >\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n loading={loading}\n offscreenPageRerenderLimit={offscreenPageRerenderLimit}\n rerenderKey={pageForceRerenderKey}\n sharedIndex={sharedPage}\n />\n ))}\n </RNViewPager>\n );\n});\n\nexport default ViewPager;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAGA;;;;;;;;AAEA,MAAMA,SAAS,gBAAG,IAAAC,iBAAA,EAA8C,SAASD,SAAT,CAAmBE,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGC,yBAFZ;IAGFC,mBAAmB,GAAG,SAHpB;IAIFC,OAAO,GAAGC,qBAJR;IAKFC,0BAA0B,GAAGC,wCAL3B;IAMFC,QANE;IAOFC,aAAa,GAAGC,2BAPd;IAQFC,oBARE;IASFC,aAAa,GAAG,IATd;IAUFC,KAVE;IAWFC;EAXE,IAYFhB,KAZJ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B,6BAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,OAAO,EAAE5C,OAJb;IAKI,0BAA0B,EAAEE,0BALhC;IAMI,WAAW,EAAEK,oBANjB;IAOI,WAAW,EAAEM;EAPjB,EADH,CATL,CADJ;AAuBH,CA5HiB,CAAlB;eA8HerB,S"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["ViewPagerProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { ComponentProps } from '@fountain-ui/core';\n\nexport type KeyboardDismissMode = 'none' | 'on-drag';\n\nexport type PageProps = React.PropsWithChildren<ViewProps> & {\n isNeighbor: boolean;\n isVisible: boolean;\n rerenderKey?: any;\n};\n\nexport type PageComponent = React.ComponentType<PageProps>;\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ViewPagerProps extends ComponentProps<{\n /**\n * Collection of ViewPager components.\n */\n children?: React.ReactNode;\n\n /**\n * If `true`, enable page visible hint.\n * @default false\n */\n enableVisibleHint?: boolean;\n\n /**\n * If `true`, Based on the current index, the pages on the left and right are also rerender.\n * @default false\n */\n enableNeighborPageRerender?: boolean;\n\n /**\n * A number representing the index of the active page.\n */\n index: number,\n\n /**\n * Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * Callback fired when an index is changed.\n */\n onChange?: (newIndex: number) => void,\n\n /**\n * The component used to render the wrapper of the page.\n * @default 'ChildrenMemoizedPage'\n */\n pageComponent?: PageComponent,\n\n /**\n * When this value is changed, page will be rerender.\n */\n pageForceRerenderKey?: any;\n\n /**\n * Mobile only. Should pager view scroll, when scroll enabled.\n * @default true\n */\n scrollEnabled?: boolean;\n\n /**\n * Mobile only. Determines whether the keyboard gets dismissed in response to a drag.\n * @default 'on-drag'\n */\n keyboardDismissMode?: KeyboardDismissMode;\n}> {}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["ViewPagerProps.ts"],"sourcesContent":["import type { ComponentType, PropsWithChildren, ReactNode, Ref } from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { ComponentProps } from '@fountain-ui/core';\n\nexport type KeyboardDismissMode = 'none' | 'on-drag';\n\nexport type PageProps = PropsWithChildren<ViewProps> & {\n index: number;\n loading: ViewPagerProps['loading'];\n offscreenPageRerenderLimit: number;\n sharedIndex: SharedValue<number>;\n rerenderKey?: ViewPagerProps['pageForceRerenderKey'];\n};\n\nexport type PageComponent = ComponentType<PageProps>;\n\nexport type Loading = 'lazy' | 'eager';\n\nexport interface ViewPagerInstance {\n /**\n * Function to scroll to a specific page in the ViewPager. Invalid index is ignored.\n * @param index\n */\n setPage: (index: number) => void;\n}\n\nexport default interface ViewPagerProps extends ComponentProps<{\n ref?: Ref<ViewPagerInstance>;\n\n /**\n * Collection of ViewPager components.\n */\n children?: ReactNode;\n\n /**\n * Index of initial page that should be selected.\n * @default 0\n */\n initialPage?: number;\n\n /**\n * Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * Mobile only. The number of pages that should be re-rendered to either side of the current page.\n * Changing this value after the component mount has no effect.\n * @default 0\n */\n offscreenPageRerenderLimit?: number;\n\n /**\n * Callback fired when an index is changed.\n */\n onChange?: (newIndex: number) => void,\n\n /**\n * The component used to render the wrapper of the page.\n * @default 'ChildrenMemoizedPage'\n */\n pageComponent?: PageComponent,\n\n /**\n * When this value is changed, page will be rerender.\n */\n pageForceRerenderKey?: any;\n\n /**\n * Mobile only. Should pager view scroll, when scroll enabled.\n * @default true\n */\n scrollEnabled?: boolean;\n\n /**\n * Mobile only. Determines whether the keyboard gets dismissed in response to a drag.\n * @default 'on-drag'\n */\n keyboardDismissMode?: KeyboardDismissMode;\n\n /**\n * Unstable API.\n */\n UNSTABLE_sharedPage?: SharedValue<number>;\n}> {}\n"],"mappings":""}