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

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 (154) hide show
  1. package/build/commonjs/Carousel/Carousel.js +39 -37
  2. package/build/commonjs/Carousel/Carousel.js.map +1 -1
  3. package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
  4. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +2 -2
  5. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -1
  6. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +15 -15
  7. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -1
  8. package/build/commonjs/Carousel/components/InternalContext.js.map +1 -1
  9. package/build/commonjs/Carousel/components/ItemView.js +6 -4
  10. package/build/commonjs/Carousel/components/ItemView.js.map +1 -1
  11. package/build/commonjs/Carousel/components/RootView.js +21 -3
  12. package/build/commonjs/Carousel/components/RootView.js.map +1 -1
  13. package/build/commonjs/Carousel/components/ScrollViewGesture.js +18 -13
  14. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -1
  15. package/build/commonjs/Carousel/{hooks → components}/useItemInterpolation.js +6 -4
  16. package/build/commonjs/Carousel/components/useItemInterpolation.js.map +1 -0
  17. package/build/commonjs/Carousel/hooks/index.js +0 -16
  18. package/build/commonjs/Carousel/hooks/index.js.map +1 -1
  19. package/build/commonjs/Carousel/hooks/useAutoplayController.js +4 -1
  20. package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -1
  21. package/build/commonjs/Carousel/hooks/useIndexController.js +15 -46
  22. package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -1
  23. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +12 -12
  24. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -1
  25. package/build/commonjs/Carousel/hooks/usePagingAnimation.js +121 -69
  26. package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -1
  27. package/build/commonjs/Carousel/tick.js +16 -0
  28. package/build/commonjs/Carousel/tick.js.map +1 -0
  29. package/build/commonjs/Carousel/types.js.map +1 -1
  30. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +53 -47
  31. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  32. package/build/commonjs/ViewPager/InternalContext.js +17 -0
  33. package/build/commonjs/ViewPager/InternalContext.js.map +1 -0
  34. package/build/commonjs/ViewPager/ViewPagerNative.js +74 -23
  35. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  36. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  37. package/build/commonjs/ViewPager/ViewPagerWeb.js +23 -12
  38. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  39. package/build/commonjs/ViewPager/index.js.map +1 -1
  40. package/build/commonjs/ViewPager/types.js +6 -0
  41. package/build/commonjs/ViewPager/types.js.map +1 -0
  42. package/build/commonjs/ViewPager/usePageStore.js +35 -0
  43. package/build/commonjs/ViewPager/usePageStore.js.map +1 -0
  44. package/build/commonjs/ViewPager/utils.js.map +1 -1
  45. package/build/commonjs/ViewabilityTrackerView/measureViewability.js +6 -6
  46. package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -1
  47. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +1 -1
  48. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  49. package/build/module/Carousel/Carousel.js +39 -39
  50. package/build/module/Carousel/Carousel.js.map +1 -1
  51. package/build/module/Carousel/CarouselProps.js.map +1 -1
  52. package/build/module/Carousel/animation/createDefaultScrollAnimation.js +2 -2
  53. package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -1
  54. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +15 -15
  55. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -1
  56. package/build/module/Carousel/components/InternalContext.js.map +1 -1
  57. package/build/module/Carousel/components/ItemView.js +5 -3
  58. package/build/module/Carousel/components/ItemView.js.map +1 -1
  59. package/build/module/Carousel/components/RootView.js +22 -4
  60. package/build/module/Carousel/components/RootView.js.map +1 -1
  61. package/build/module/Carousel/components/ScrollViewGesture.js +18 -13
  62. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -1
  63. package/build/module/Carousel/{hooks → components}/useItemInterpolation.js +3 -3
  64. package/build/module/Carousel/components/useItemInterpolation.js.map +1 -0
  65. package/build/module/Carousel/hooks/index.js +0 -2
  66. package/build/module/Carousel/hooks/index.js.map +1 -1
  67. package/build/module/Carousel/hooks/useAutoplayController.js +4 -1
  68. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -1
  69. package/build/module/Carousel/hooks/useIndexController.js +14 -39
  70. package/build/module/Carousel/hooks/useIndexController.js.map +1 -1
  71. package/build/module/Carousel/hooks/useItemVisibilityStore.js +10 -11
  72. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -1
  73. package/build/module/Carousel/hooks/usePagingAnimation.js +122 -69
  74. package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -1
  75. package/build/module/Carousel/tick.js +6 -0
  76. package/build/module/Carousel/tick.js.map +1 -0
  77. package/build/module/Carousel/types.js.map +1 -1
  78. package/build/module/ViewPager/ChildrenMemoizedPage.js +53 -47
  79. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  80. package/build/module/ViewPager/InternalContext.js +7 -0
  81. package/build/module/ViewPager/InternalContext.js.map +1 -0
  82. package/build/module/ViewPager/ViewPagerNative.js +72 -23
  83. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  84. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  85. package/build/module/ViewPager/ViewPagerWeb.js +21 -13
  86. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  87. package/build/module/ViewPager/index.js.map +1 -1
  88. package/build/module/ViewPager/types.js +2 -0
  89. package/build/module/ViewPager/types.js.map +1 -0
  90. package/build/module/ViewPager/usePageStore.js +25 -0
  91. package/build/module/ViewPager/usePageStore.js.map +1 -0
  92. package/build/module/ViewPager/utils.js.map +1 -1
  93. package/build/module/ViewabilityTrackerView/measureViewability.js +2 -2
  94. package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -1
  95. package/build/module/hooks/useUnstableCollapsibleAppBar.js +1 -1
  96. package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  97. package/build/typescript/Carousel/CarouselProps.d.ts +4 -3
  98. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +5 -5
  99. package/build/typescript/Carousel/components/InternalContext.d.ts +2 -2
  100. package/build/typescript/Carousel/components/ItemView.d.ts +2 -0
  101. package/build/typescript/Carousel/components/RootView.d.ts +4 -4
  102. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +3 -3
  103. package/build/typescript/Carousel/{hooks → components}/useItemInterpolation.d.ts +0 -0
  104. package/build/typescript/Carousel/hooks/index.d.ts +0 -2
  105. package/build/typescript/Carousel/hooks/useIndexController.d.ts +0 -2
  106. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +5 -2
  107. package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +8 -10
  108. package/build/typescript/Carousel/tick.d.ts +2 -0
  109. package/build/typescript/Carousel/types.d.ts +26 -5
  110. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +1 -1
  111. package/build/typescript/ViewPager/InternalContext.d.ts +7 -0
  112. package/build/typescript/ViewPager/ViewPagerNative.d.ts +2 -2
  113. package/build/typescript/ViewPager/ViewPagerProps.d.ts +4 -22
  114. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +2 -2
  115. package/build/typescript/ViewPager/index.d.ts +2 -1
  116. package/build/typescript/ViewPager/types.d.ts +19 -0
  117. package/build/typescript/ViewPager/usePageStore.d.ts +2 -0
  118. package/build/typescript/ViewPager/utils.d.ts +1 -1
  119. package/package.json +3 -3
  120. package/src/Carousel/Carousel.tsx +32 -40
  121. package/src/Carousel/CarouselProps.ts +4 -3
  122. package/src/Carousel/animation/createDefaultScrollAnimation.ts +2 -2
  123. package/src/Carousel/animation/parallaxItemStyleFactory.ts +24 -24
  124. package/src/Carousel/components/InternalContext.ts +2 -2
  125. package/src/Carousel/components/ItemView.tsx +13 -3
  126. package/src/Carousel/components/RootView.tsx +19 -6
  127. package/src/Carousel/components/ScrollViewGesture.tsx +23 -15
  128. package/src/Carousel/{hooks → components}/useItemInterpolation.ts +3 -3
  129. package/src/Carousel/hooks/index.ts +0 -2
  130. package/src/Carousel/hooks/useAutoplayController.ts +4 -1
  131. package/src/Carousel/hooks/useIndexController.tsx +14 -44
  132. package/src/Carousel/hooks/useItemVisibilityStore.ts +17 -13
  133. package/src/Carousel/hooks/usePagingAnimation.ts +161 -83
  134. package/src/Carousel/tick.ts +6 -0
  135. package/src/Carousel/types.ts +34 -5
  136. package/src/ViewPager/ChildrenMemoizedPage.tsx +53 -50
  137. package/src/ViewPager/InternalContext.ts +13 -0
  138. package/src/ViewPager/ViewPagerNative.tsx +91 -44
  139. package/src/ViewPager/ViewPagerProps.ts +4 -27
  140. package/src/ViewPager/ViewPagerWeb.tsx +28 -23
  141. package/src/ViewPager/index.ts +2 -1
  142. package/src/ViewPager/types.ts +24 -0
  143. package/src/ViewPager/usePageStore.ts +30 -0
  144. package/src/ViewPager/utils.tsx +1 -1
  145. package/src/ViewabilityTrackerView/measureViewability.ts +1 -3
  146. package/src/hooks/useUnstableCollapsibleAppBar.ts +1 -1
  147. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +0 -23
  148. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +0 -1
  149. package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +0 -1
  150. package/build/module/Carousel/hooks/useDimensionChangeReaction.js +0 -14
  151. package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +0 -1
  152. package/build/module/Carousel/hooks/useItemInterpolation.js.map +0 -1
  153. package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +0 -7
  154. package/src/Carousel/hooks/useDimensionChangeReaction.ts +0 -25
@@ -9,24 +9,12 @@ Object.defineProperty(exports, "useAutoplayController", {
9
9
  return _useAutoplayController.default;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "useDimensionChangeReaction", {
13
- enumerable: true,
14
- get: function () {
15
- return _useDimensionChangeReaction.default;
16
- }
17
- });
18
12
  Object.defineProperty(exports, "useIndexController", {
19
13
  enumerable: true,
20
14
  get: function () {
21
15
  return _useIndexController.default;
22
16
  }
23
17
  });
24
- Object.defineProperty(exports, "useItemInterpolation", {
25
- enumerable: true,
26
- get: function () {
27
- return _useItemInterpolation.default;
28
- }
29
- });
30
18
  Object.defineProperty(exports, "useItemVisibilityStore", {
31
19
  enumerable: true,
32
20
  get: function () {
@@ -48,12 +36,8 @@ Object.defineProperty(exports, "usePagingAnimation", {
48
36
 
49
37
  var _useAutoplayController = _interopRequireDefault(require("./useAutoplayController"));
50
38
 
51
- var _useDimensionChangeReaction = _interopRequireDefault(require("./useDimensionChangeReaction"));
52
-
53
39
  var _useIndexController = _interopRequireDefault(require("./useIndexController"));
54
40
 
55
- var _useItemInterpolation = _interopRequireDefault(require("./useItemInterpolation"));
56
-
57
41
  var _useLoopedData = _interopRequireDefault(require("./useLoopedData"));
58
42
 
59
43
  var _usePagingAnimation = _interopRequireDefault(require("./usePagingAnimation"));
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useAutoplayController } from './useAutoplayController';\nexport { default as useDimensionChangeReaction } from './useDimensionChangeReaction';\nexport { default as useIndexController } from './useIndexController';\nexport { default as useItemInterpolation } from './useItemInterpolation';\nexport { default as useLoopedData } from './useLoopedData';\nexport { default as usePagingAnimation } from './usePagingAnimation';\nexport { default as useItemVisibilityStore } from './useItemVisibilityStore';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useAutoplayController } from './useAutoplayController';\nexport { default as useIndexController } from './useIndexController';\nexport { default as useLoopedData } from './useLoopedData';\nexport { default as usePagingAnimation } from './usePagingAnimation';\nexport { default as useItemVisibilityStore } from './useItemVisibilityStore';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA"}
@@ -23,7 +23,10 @@ function useAutoplayController(config) {
23
23
  }
24
24
 
25
25
  executor.execute(() => {
26
- startPagingAnimation('next', false);
26
+ startPagingAnimation('directional', {
27
+ direction: 'next',
28
+ isOriginatedFromGesture: false
29
+ });
27
30
  play();
28
31
  }, intervalMillis);
29
32
  }, [intervalMillis, startPagingAnimation]);
@@ -1 +1 @@
1
- {"version":3,"names":["useAutoplayController","config","enabled","intervalMillis","startPagingAnimation","paused","useRef","executor","useDeferredExecutor","play","useCallback","current","execute","pause","cancel","resume","useEffect"],"sources":["useAutoplayController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { AutoplayController, StartPagingAnimation } from '../types';\nimport { useDeferredExecutor } from '../../hooks';\n\nexport interface AutoplayConfig {\n enabled: boolean;\n intervalMillis: number;\n startPagingAnimation: StartPagingAnimation;\n}\n\nexport default function useAutoplayController(config: AutoplayConfig): AutoplayController {\n const {\n enabled,\n intervalMillis,\n startPagingAnimation,\n } = config;\n\n const paused = useRef<boolean>(false);\n\n const executor = useDeferredExecutor();\n\n const play = useCallback(() => {\n if (paused.current) {\n return;\n }\n\n executor.execute(() => {\n startPagingAnimation('next', false);\n play();\n }, intervalMillis);\n }, [intervalMillis, startPagingAnimation]);\n\n const pause = useCallback(() => {\n executor.cancel();\n paused.current = true;\n }, []);\n\n const resume = useCallback(() => {\n paused.current = false;\n if (enabled) {\n play();\n }\n }, [play, enabled]);\n\n useEffect(() => {\n if (enabled) {\n resume();\n } else {\n pause();\n }\n }, [enabled]);\n\n return { pause, resume };\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAQe,SAASA,qBAAT,CAA+BC,MAA/B,EAA2E;EACtF,MAAM;IACFC,OADE;IAEFC,cAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,MAAMI,MAAM,GAAG,IAAAC,aAAA,EAAgB,KAAhB,CAAf;EAEA,MAAMC,QAAQ,GAAG,IAAAC,0BAAA,GAAjB;EAEA,MAAMC,IAAI,GAAG,IAAAC,kBAAA,EAAY,MAAM;IAC3B,IAAIL,MAAM,CAACM,OAAX,EAAoB;MAChB;IACH;;IAEDJ,QAAQ,CAACK,OAAT,CAAiB,MAAM;MACnBR,oBAAoB,CAAC,MAAD,EAAS,KAAT,CAApB;MACAK,IAAI;IACP,CAHD,EAGGN,cAHH;EAIH,CATY,EASV,CAACA,cAAD,EAAiBC,oBAAjB,CATU,CAAb;EAWA,MAAMS,KAAK,GAAG,IAAAH,kBAAA,EAAY,MAAM;IAC5BH,QAAQ,CAACO,MAAT;IACAT,MAAM,CAACM,OAAP,GAAiB,IAAjB;EACH,CAHa,EAGX,EAHW,CAAd;EAKA,MAAMI,MAAM,GAAG,IAAAL,kBAAA,EAAY,MAAM;IAC7BL,MAAM,CAACM,OAAP,GAAiB,KAAjB;;IACA,IAAIT,OAAJ,EAAa;MACTO,IAAI;IACP;EACJ,CALc,EAKZ,CAACA,IAAD,EAAOP,OAAP,CALY,CAAf;EAOA,IAAAc,gBAAA,EAAU,MAAM;IACZ,IAAId,OAAJ,EAAa;MACTa,MAAM;IACT,CAFD,MAEO;MACHF,KAAK;IACR;EACJ,CAND,EAMG,CAACX,OAAD,CANH;EAQA,OAAO;IAAEW,KAAF;IAASE;EAAT,CAAP;AACH;;AAAA"}
1
+ {"version":3,"names":["useAutoplayController","config","enabled","intervalMillis","startPagingAnimation","paused","useRef","executor","useDeferredExecutor","play","useCallback","current","execute","direction","isOriginatedFromGesture","pause","cancel","resume","useEffect"],"sources":["useAutoplayController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { AutoplayController, StartPagingAnimation } from '../types';\nimport { useDeferredExecutor } from '../../hooks';\n\nexport interface AutoplayConfig {\n enabled: boolean;\n intervalMillis: number;\n startPagingAnimation: StartPagingAnimation;\n}\n\nexport default function useAutoplayController(config: AutoplayConfig): AutoplayController {\n const {\n enabled,\n intervalMillis,\n startPagingAnimation,\n } = config;\n\n const paused = useRef<boolean>(false);\n\n const executor = useDeferredExecutor();\n\n const play = useCallback(() => {\n if (paused.current) {\n return;\n }\n\n executor.execute(() => {\n startPagingAnimation(\n 'directional',\n { direction: 'next', isOriginatedFromGesture: false },\n );\n play();\n }, intervalMillis);\n }, [intervalMillis, startPagingAnimation]);\n\n const pause = useCallback(() => {\n executor.cancel();\n paused.current = true;\n }, []);\n\n const resume = useCallback(() => {\n paused.current = false;\n if (enabled) {\n play();\n }\n }, [play, enabled]);\n\n useEffect(() => {\n if (enabled) {\n resume();\n } else {\n pause();\n }\n }, [enabled]);\n\n return { pause, resume };\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAQe,SAASA,qBAAT,CAA+BC,MAA/B,EAA2E;EACtF,MAAM;IACFC,OADE;IAEFC,cAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,MAAMI,MAAM,GAAG,IAAAC,aAAA,EAAgB,KAAhB,CAAf;EAEA,MAAMC,QAAQ,GAAG,IAAAC,0BAAA,GAAjB;EAEA,MAAMC,IAAI,GAAG,IAAAC,kBAAA,EAAY,MAAM;IAC3B,IAAIL,MAAM,CAACM,OAAX,EAAoB;MAChB;IACH;;IAEDJ,QAAQ,CAACK,OAAT,CAAiB,MAAM;MACnBR,oBAAoB,CAChB,aADgB,EAEhB;QAAES,SAAS,EAAE,MAAb;QAAqBC,uBAAuB,EAAE;MAA9C,CAFgB,CAApB;MAIAL,IAAI;IACP,CAND,EAMGN,cANH;EAOH,CAZY,EAYV,CAACA,cAAD,EAAiBC,oBAAjB,CAZU,CAAb;EAcA,MAAMW,KAAK,GAAG,IAAAL,kBAAA,EAAY,MAAM;IAC5BH,QAAQ,CAACS,MAAT;IACAX,MAAM,CAACM,OAAP,GAAiB,IAAjB;EACH,CAHa,EAGX,EAHW,CAAd;EAKA,MAAMM,MAAM,GAAG,IAAAP,kBAAA,EAAY,MAAM;IAC7BL,MAAM,CAACM,OAAP,GAAiB,KAAjB;;IACA,IAAIT,OAAJ,EAAa;MACTO,IAAI;IACP;EACJ,CALc,EAKZ,CAACA,IAAD,EAAOP,OAAP,CALY,CAAf;EAOA,IAAAgB,gBAAA,EAAU,MAAM;IACZ,IAAIhB,OAAJ,EAAa;MACTe,MAAM;IACT,CAFD,MAEO;MACHF,KAAK;IACR;EACJ,CAND,EAMG,CAACb,OAAD,CANH;EAQA,OAAO;IAAEa,KAAF;IAASE;EAAT,CAAP;AACH;;AAAA"}
@@ -5,64 +5,33 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useIndexController;
7
7
 
8
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = require("react");
9
9
 
10
- var _reactNative = require("react-native");
11
-
12
- 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); }
13
-
14
- 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; }
15
-
16
- const normalizeIndex = (maybeIndex, numberOfData) => Math.abs(Math.floor(maybeIndex)) % numberOfData;
10
+ var _utils = require("@fountain-ui/utils");
17
11
 
18
12
  function useIndexController(params) {
19
13
  const {
20
- controlledTx,
21
14
  initialIndex,
22
15
  itemWidth,
23
16
  numberOfOriginalData,
24
17
  onIndexChange
25
18
  } = params;
26
- const indexRef = (0, _react.useRef)(initialIndex);
27
- const [index, setIndex] = (0, _react.useState)(indexRef.current);
28
- const maybeIndex = (0, _react.useMemo)(() => {
29
- const negative = new _reactNative.Animated.Value(-1);
30
-
31
- const reversedTx = _reactNative.Animated.multiply(controlledTx, negative);
32
-
33
- const normalized = _reactNative.Animated.divide(reversedTx, itemWidth);
34
-
35
- return _reactNative.Animated.modulo(normalized, numberOfOriginalData);
36
- }, [controlledTx, itemWidth, numberOfOriginalData]);
37
- (0, _react.useEffect)(() => {
38
- const subscriptionId = maybeIndex.addListener(observedValue => {
39
- const newIndex = normalizeIndex(observedValue.value, numberOfOriginalData);
40
-
41
- if (indexRef.current !== newIndex) {
42
- indexRef.current = newIndex;
43
- setIndex(newIndex);
44
- onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(newIndex);
45
- }
46
- });
47
- return () => {
48
- maybeIndex.removeListener(subscriptionId);
49
- };
50
- }, [maybeIndex, numberOfOriginalData, onIndexChange]);
51
- const getCurrentIndex = (0, _react.useCallback)(() => indexRef.current, []);
19
+ const currentIndexRef = (0, _react.useRef)(initialIndex);
20
+ const getCurrentIndex = (0, _react.useCallback)(() => currentIndexRef.current, []);
21
+ const notifyOffsetHasChanged = (0, _react.useCallback)(offset => {
22
+ const roundedOffset = Math.round(offset / itemWidth) * itemWidth; // To prevent floating point problem, make sure index is integer type.
23
+
24
+ const nextIndex = Math.floor((0, _utils.mod)(-roundedOffset / itemWidth, numberOfOriginalData));
25
+
26
+ if (nextIndex !== currentIndexRef.current) {
27
+ currentIndexRef.current = nextIndex;
28
+ onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(nextIndex);
29
+ }
30
+ }, [itemWidth, numberOfOriginalData, onIndexChange]);
52
31
  return {
53
- currentIndex: index,
54
32
  getCurrentIndex,
55
33
  lastIndex: numberOfOriginalData - 1,
56
- monitorElement: /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
57
- collapsable: false,
58
- style: [{
59
- zIndex: maybeIndex
60
- }, {
61
- width: 1,
62
- height: 1,
63
- position: 'absolute'
64
- }]
65
- })
34
+ notifyOffsetHasChanged
66
35
  };
67
36
  }
68
37
 
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeIndex","maybeIndex","numberOfData","Math","abs","floor","useIndexController","params","controlledTx","initialIndex","itemWidth","numberOfOriginalData","onIndexChange","indexRef","useRef","index","setIndex","useState","current","useMemo","negative","Animated","Value","reversedTx","multiply","normalized","divide","modulo","useEffect","subscriptionId","addListener","observedValue","newIndex","value","removeListener","getCurrentIndex","useCallback","currentIndex","lastIndex","monitorElement","zIndex","width","height","position"],"sources":["useIndexController.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { Animated } from 'react-native';\nimport type { IndexController } from '../types';\n\nexport interface UseIndexControllerParameters {\n controlledTx: Animated.AnimatedValue;\n initialIndex: number;\n itemWidth: number;\n numberOfOriginalData: number;\n onIndexChange?: (newIndex: number) => void;\n}\n\nconst normalizeIndex = (maybeIndex: number, numberOfData: number): number =>\n Math.abs(Math.floor(maybeIndex)) % numberOfData;\n\nexport default function useIndexController(params: UseIndexControllerParameters): IndexController {\n const {\n controlledTx,\n initialIndex,\n itemWidth,\n numberOfOriginalData,\n onIndexChange,\n } = params;\n\n const indexRef = useRef<number>(initialIndex);\n const [index, setIndex] = useState<number>(indexRef.current);\n\n const maybeIndex = useMemo(() => {\n const negative = new Animated.Value(-1);\n const reversedTx = Animated.multiply(controlledTx, negative);\n const normalized = Animated.divide(reversedTx, itemWidth);\n return Animated.modulo(normalized, numberOfOriginalData);\n }, [\n controlledTx,\n itemWidth,\n numberOfOriginalData,\n ]);\n\n useEffect(() => {\n const subscriptionId = maybeIndex.addListener((observedValue) => {\n const newIndex = normalizeIndex(observedValue.value, numberOfOriginalData);\n\n if (indexRef.current !== newIndex) {\n indexRef.current = newIndex;\n setIndex(newIndex);\n\n onIndexChange?.(newIndex);\n }\n });\n\n return () => {\n maybeIndex.removeListener(subscriptionId);\n };\n }, [\n maybeIndex,\n numberOfOriginalData,\n onIndexChange,\n ]);\n\n const getCurrentIndex = useCallback(() => indexRef.current, []);\n\n return {\n currentIndex: index,\n getCurrentIndex,\n lastIndex: numberOfOriginalData - 1,\n monitorElement: (\n <Animated.View\n collapsable={false}\n style={[\n { zIndex: maybeIndex },\n { width: 1, height: 1, position: 'absolute' },\n ]}\n />\n ),\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAWA,MAAMA,cAAc,GAAG,CAACC,UAAD,EAAqBC,YAArB,KACnBC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,KAAL,CAAWJ,UAAX,CAAT,IAAmCC,YADvC;;AAGe,SAASI,kBAAT,CAA4BC,MAA5B,EAAmF;EAC9F,MAAM;IACFC,YADE;IAEFC,YAFE;IAGFC,SAHE;IAIFC,oBAJE;IAKFC;EALE,IAMFL,MANJ;EAQA,MAAMM,QAAQ,GAAG,IAAAC,aAAA,EAAeL,YAAf,CAAjB;EACA,MAAM,CAACM,KAAD,EAAQC,QAAR,IAAoB,IAAAC,eAAA,EAAiBJ,QAAQ,CAACK,OAA1B,CAA1B;EAEA,MAAMjB,UAAU,GAAG,IAAAkB,cAAA,EAAQ,MAAM;IAC7B,MAAMC,QAAQ,GAAG,IAAIC,qBAAA,CAASC,KAAb,CAAmB,CAAC,CAApB,CAAjB;;IACA,MAAMC,UAAU,GAAGF,qBAAA,CAASG,QAA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FG;IAFX;EALD,CAAP;AAcH;;AAAA"}
1
+ {"version":3,"names":["useIndexController","params","initialIndex","itemWidth","numberOfOriginalData","onIndexChange","currentIndexRef","useRef","getCurrentIndex","useCallback","current","notifyOffsetHasChanged","offset","roundedOffset","Math","round","nextIndex","floor","mod","lastIndex"],"sources":["useIndexController.tsx"],"sourcesContent":["import React, { useCallback, useRef } from 'react';\nimport { mod } from '@fountain-ui/utils';\nimport type { IndexController } from '../types';\n\nexport interface UseIndexControllerParameters {\n initialIndex: number;\n itemWidth: number;\n numberOfOriginalData: number;\n onIndexChange?: (newIndex: number) => void;\n}\n\nexport default function useIndexController(params: UseIndexControllerParameters): IndexController {\n const {\n initialIndex,\n itemWidth,\n numberOfOriginalData,\n onIndexChange,\n } = params;\n\n const currentIndexRef = useRef<number>(initialIndex);\n\n const getCurrentIndex = useCallback(() => currentIndexRef.current, []);\n\n const notifyOffsetHasChanged = useCallback((offset: number) => {\n const roundedOffset = Math.round(offset / itemWidth) * itemWidth;\n\n // To prevent floating point problem, make sure index is integer type.\n const nextIndex = Math.floor(mod((-roundedOffset / itemWidth), numberOfOriginalData));\n\n if (nextIndex !== currentIndexRef.current) {\n currentIndexRef.current = nextIndex;\n\n onIndexChange?.(nextIndex);\n }\n }, [\n itemWidth,\n numberOfOriginalData,\n onIndexChange,\n ]);\n\n return {\n getCurrentIndex,\n lastIndex: numberOfOriginalData - 1,\n notifyOffsetHasChanged,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAUe,SAASA,kBAAT,CAA4BC,MAA5B,EAAmF;EAC9F,MAAM;IACFC,YADE;IAEFC,SAFE;IAGFC,oBAHE;IAIFC;EAJE,IAKFJ,MALJ;EAOA,MAAMK,eAAe,GAAG,IAAAC,aAAA,EAAeL,YAAf,CAAxB;EAEA,MAAMM,eAAe,GAAG,IAAAC,kBAAA,EAAY,MAAMH,eAAe,CAACI,OAAlC,EAA2C,EAA3C,CAAxB;EAEA,MAAMC,sBAAsB,GAAG,IAAAF,kBAAA,EAAaG,MAAD,IAAoB;IAC3D,MAAMC,aAAa,GAAGC,IAAI,CAACC,KAAL,CAAWH,MAAM,GAAGT,SAApB,IAAiCA,SAAvD,CAD2D,CAG3D;;IACA,MAAMa,SAAS,GAAGF,IAAI,CAACG,KAAL,CAAW,IAAAC,UAAA,EAAK,CAACL,aAAD,GAAiBV,SAAtB,EAAkCC,oBAAlC,CAAX,CAAlB;;IAEA,IAAIY,SAAS,KAAKV,eAAe,CAACI,OAAlC,EAA2C;MACvCJ,eAAe,CAACI,OAAhB,GAA0BM,SAA1B;MAEAX,aAAa,SAAb,IAAAA,aAAa,WAAb,YAAAA,aAAa,CAAGW,SAAH,CAAb;IACH;EACJ,CAX8B,EAW5B,CACCb,SADD,EAECC,oBAFD,EAGCC,aAHD,CAX4B,CAA/B;EAiBA,OAAO;IACHG,eADG;IAEHW,SAAS,EAAEf,oBAAoB,GAAG,CAF/B;IAGHO;EAHG,CAAP;AAKH;;AAAA"}
@@ -7,6 +7,8 @@ exports.default = useItemVisibilityStore;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
+ var _utils = require("@fountain-ui/utils");
11
+
10
12
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
13
 
12
14
  class SimpleItemVisibilityStore {
@@ -54,10 +56,6 @@ function normalize(windowSize, numberOfData) {
54
56
  return windowSize;
55
57
  }
56
58
 
57
- function mod(value, modulo) {
58
- return (value % modulo + modulo) % modulo;
59
- }
60
-
61
59
  function makeVisibleIndexRanges(numberOfData, windowSize, index) {
62
60
  const ws = normalize(windowSize, numberOfData);
63
61
  const firstIndex = 0;
@@ -65,30 +63,32 @@ function makeVisibleIndexRanges(numberOfData, windowSize, index) {
65
63
  const halfNumberOfAdjacent = Math.floor(ws / 2);
66
64
  const leftSide = index - halfNumberOfAdjacent;
67
65
  const rightSide = index + halfNumberOfAdjacent;
68
- const leftRanges = leftSide >= 0 ? [[leftSide, index]] : [[firstIndex, index], [mod(leftSide, numberOfData), lastIndex]];
69
- const rightRanges = rightSide < numberOfData ? [[index, rightSide]] : [[index, lastIndex], [firstIndex, mod(rightSide, numberOfData)]]; // @ts-ignore
66
+ const leftRanges = leftSide >= 0 ? [[leftSide, index]] : [[firstIndex, index], [(0, _utils.mod)(leftSide, numberOfData), lastIndex]];
67
+ const rightRanges = rightSide < numberOfData ? [[index, rightSide]] : [[index, lastIndex], [firstIndex, (0, _utils.mod)(rightSide, numberOfData)]]; // @ts-ignore
70
68
 
71
69
  return [...leftRanges, ...rightRanges];
72
70
  }
73
71
 
74
72
  function useItemVisibilityStore(params) {
75
73
  const {
76
- currentIndex,
74
+ initialIndex,
77
75
  numberOfData,
78
76
  windowSize
79
77
  } = params;
80
- const [initialRange] = (0, _react.useState)(() => makeVisibleIndexRanges(numberOfData, windowSize, currentIndex));
78
+ const [initialRange] = (0, _react.useState)(() => {
79
+ return makeVisibleIndexRanges(numberOfData, windowSize, initialIndex);
80
+ });
81
81
  const store = (0, _react.useRef)(new SimpleItemVisibilityStore(initialRange)).current;
82
- (0, _react.useEffect)(() => {
83
- const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, currentIndex);
82
+ const onIndexChange = (0, _react.useCallback)(newIndex => {
83
+ const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, newIndex);
84
84
  store.dispatch(newRanges);
85
- }, [currentIndex, numberOfData, windowSize]);
85
+ }, [numberOfData, windowSize]);
86
86
  (0, _react.useEffect)(() => {
87
87
  return () => {
88
88
  store.removeAllListeners();
89
89
  };
90
90
  }, []);
91
- return store;
91
+ return [store, onIndexChange];
92
92
  }
93
93
 
94
94
  ;
@@ -1 +1 @@
1
- {"version":3,"names":["SimpleItemVisibilityStore","constructor","initialValue","store","subscribe","listener","listeners","push","index","indexOf","splice","dispatch","ranges","id","removeAllListeners","length","normalize","windowSize","numberOfData","mod","value","modulo","makeVisibleIndexRanges","ws","firstIndex","lastIndex","halfNumberOfAdjacent","Math","floor","leftSide","rightSide","leftRanges","rightRanges","useItemVisibilityStore","params","currentIndex","initialRange","useState","useRef","current","useEffect","newRanges"],"sources":["useItemVisibilityStore.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport type { ItemVisibilityStore, VisibleIndexRanges } from '../types';\n\nexport interface Parameters {\n currentIndex: number;\n numberOfData: number;\n windowSize: number;\n}\n\nclass SimpleItemVisibilityStore implements ItemVisibilityStore {\n\n private store: VisibleIndexRanges;\n\n constructor(initialValue: VisibleIndexRanges) {\n this.store = initialValue;\n }\n\n private listeners: Array<(ranges: VisibleIndexRanges) => void> = [];\n\n subscribe(listener: (ranges: VisibleIndexRanges) => void) {\n this.listeners.push(listener);\n\n listener(this.store);\n\n return () => {\n const index = this.listeners.indexOf(listener);\n this.listeners.splice(index, 1);\n };\n }\n\n dispatch(ranges: VisibleIndexRanges): void {\n this.store = ranges;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(ranges);\n }\n }\n\n removeAllListeners(): void {\n this.listeners.splice(0, this.listeners.length);\n }\n\n}\n\nfunction normalize(windowSize: number, numberOfData: number): number {\n if (windowSize <= 0) {\n return numberOfData;\n }\n if (windowSize > 0 && windowSize % 2 === 0) {\n return windowSize + 1;\n }\n return windowSize;\n}\n\nfunction mod(value: number, modulo: number): number {\n return ((value % modulo) + modulo) % modulo;\n}\n\nfunction makeVisibleIndexRanges(numberOfData: number, windowSize: number, index: number): VisibleIndexRanges {\n const ws = normalize(windowSize, numberOfData);\n\n const firstIndex = 0;\n const lastIndex = numberOfData - 1;\n const halfNumberOfAdjacent = Math.floor(ws / 2);\n\n const leftSide = index - halfNumberOfAdjacent;\n const rightSide = index + halfNumberOfAdjacent;\n\n const leftRanges = leftSide >= 0\n ? [[leftSide, index]]\n : [[firstIndex, index], [mod(leftSide, numberOfData), lastIndex]];\n\n const rightRanges = rightSide < numberOfData\n ? [[index, rightSide]]\n : [[index, lastIndex], [firstIndex, mod(rightSide, numberOfData)]];\n\n // @ts-ignore\n return [\n ...leftRanges,\n ...rightRanges,\n ];\n}\n\nexport default function useItemVisibilityStore(params: Parameters): ItemVisibilityStore {\n const {\n currentIndex,\n numberOfData,\n windowSize,\n } = params;\n\n const [initialRange] = useState(() => makeVisibleIndexRanges(numberOfData, windowSize, currentIndex));\n const store = useRef(new SimpleItemVisibilityStore(initialRange)).current;\n\n useEffect(() => {\n const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, currentIndex);\n\n store.dispatch(newRanges);\n }, [currentIndex, numberOfData, windowSize]);\n\n useEffect(() => {\n return () => {\n store.removeAllListeners();\n };\n }, []);\n\n return store;\n};\n"],"mappings":";;;;;;;AAAA;;;;AASA,MAAMA,yBAAN,CAA+D;EAI3DC,WAAW,CAACC,YAAD,EAAmC;IAAA;;IAAA,mCAImB,EAJnB;;IAC1C,KAAKC,KAAL,GAAaD,YAAb;EACH;;EAIDE,SAAS,CAACC,QAAD,EAAiD;IACtD,KAAKC,SAAL,CAAeC,IAAf,CAAoBF,QAApB;IAEAA,QAAQ,CAAC,KAAKF,KAAN,CAAR;IAEA,OAAO,MAAM;MACT,MAAMK,KAAK,GAAG,KAAKF,SAAL,CAAeG,OAAf,CAAuBJ,QAAvB,CAAd;MACA,KAAKC,SAAL,CAAeI,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,QAAQ,CAACC,MAAD,EAAmC;IACvC,KAAKT,KAAL,GAAaS,MAAb;;IACA,KAAK,MAAMC,EAAX,IAAiB,KAAKP,SAAtB,EAAiC;MAC7B,MAAMD,QAAQ,GAAG,KAAKC,SAAL,CAAeO,EAAf,CAAjB;MACAR,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGO,MAAH,CAAR;IACH;EACJ;;EAEDE,kBAAkB,GAAS;IACvB,KAAKR,SAAL,CAAeI,MAAf,CAAsB,CAAtB,EAAyB,KAAKJ,SAAL,CAAeS,MAAxC;EACH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FN,CAdyG,CAkBzG;;EACA,OAAO,CACH,GAAGa,UADA,EAEH,GAAGC,WAFA,CAAP;AAIH;;AAEc,SAASC,sBAAT,CAAgCC,MAAhC,EAAyE;EACpF,MAAM;IACFC,YADE;IAEFjB,YAFE;IAGFD;EAHE,IAIFiB,MAJJ;EAMA,MAAM,CAACE,YAAD,IAAiB,IAAAC,eAAA,EAAS,MAAMf,sBAAsB,CAACJ,YAAD,EAAeD,UAAf,EAA2BkB,YAA3B,CAArC,CAAvB;EACA,MAAMhC,KAAK,GAAG,IAAAmC,aAAA,EAAO,IAAItC,yBAAJ,CAA8BoC,YAA9B,CAAP,EAAoDG,OAAlE;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACZ,MAAMC,SAAS,GAAGnB,sBAAsB,CAACJ,YAAD,EAAeD,UAAf,EAA2BkB,YAA3B,CAAxC;IAEAhC,KAAK,CAACQ,QAAN,CAAe8B,SAAf;EACH,CAJD,EAIG,CAACN,YAAD,EAAejB,YAAf,EAA6BD,UAA7B,CAJH;EAMA,IAAAuB,gBAAA,EAAU,MAAM;IACZ,OAAO,MAAM;MACTrC,KAAK,CAACW,kBAAN;IACH,CAFD;EAGH,CAJD,EAIG,EAJH;EAMA,OAAOX,KAAP;AACH;;AAAA"}
1
+ {"version":3,"names":["SimpleItemVisibilityStore","constructor","initialValue","store","subscribe","listener","listeners","push","index","indexOf","splice","dispatch","ranges","id","removeAllListeners","length","normalize","windowSize","numberOfData","makeVisibleIndexRanges","ws","firstIndex","lastIndex","halfNumberOfAdjacent","Math","floor","leftSide","rightSide","leftRanges","mod","rightRanges","useItemVisibilityStore","params","initialIndex","initialRange","useState","useRef","current","onIndexChange","useCallback","newIndex","newRanges","useEffect"],"sources":["useItemVisibilityStore.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { mod } from '@fountain-ui/utils';\nimport type { ItemVisibilityStore, VisibleIndexRanges } from '../types';\n\nexport interface Parameters {\n initialIndex: number;\n numberOfData: number;\n windowSize: number;\n}\n\nexport interface OnIndexChange {\n (newIndex: number): void;\n}\n\nclass SimpleItemVisibilityStore implements ItemVisibilityStore {\n\n private store: VisibleIndexRanges;\n\n constructor(initialValue: VisibleIndexRanges) {\n this.store = initialValue;\n }\n\n private listeners: Array<(ranges: VisibleIndexRanges) => void> = [];\n\n subscribe(listener: (ranges: VisibleIndexRanges) => void) {\n this.listeners.push(listener);\n\n listener(this.store);\n\n return () => {\n const index = this.listeners.indexOf(listener);\n this.listeners.splice(index, 1);\n };\n }\n\n dispatch(ranges: VisibleIndexRanges): void {\n this.store = ranges;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(ranges);\n }\n }\n\n removeAllListeners(): void {\n this.listeners.splice(0, this.listeners.length);\n }\n\n}\n\nfunction normalize(windowSize: number, numberOfData: number): number {\n if (windowSize <= 0) {\n return numberOfData;\n }\n if (windowSize > 0 && windowSize % 2 === 0) {\n return windowSize + 1;\n }\n return windowSize;\n}\n\nfunction makeVisibleIndexRanges(numberOfData: number, windowSize: number, index: number): VisibleIndexRanges {\n const ws = normalize(windowSize, numberOfData);\n\n const firstIndex = 0;\n const lastIndex = numberOfData - 1;\n const halfNumberOfAdjacent = Math.floor(ws / 2);\n\n const leftSide = index - halfNumberOfAdjacent;\n const rightSide = index + halfNumberOfAdjacent;\n\n const leftRanges = leftSide >= 0\n ? [[leftSide, index]]\n : [[firstIndex, index], [mod(leftSide, numberOfData), lastIndex]];\n\n const rightRanges = rightSide < numberOfData\n ? [[index, rightSide]]\n : [[index, lastIndex], [firstIndex, mod(rightSide, numberOfData)]];\n\n // @ts-ignore\n return [\n ...leftRanges,\n ...rightRanges,\n ];\n}\n\nexport default function useItemVisibilityStore(params: Parameters): [ItemVisibilityStore, OnIndexChange] {\n const {\n initialIndex,\n numberOfData,\n windowSize,\n } = params;\n\n const [initialRange] = useState(() => {\n return makeVisibleIndexRanges(numberOfData, windowSize, initialIndex);\n });\n\n const store = useRef(new SimpleItemVisibilityStore(initialRange)).current;\n\n const onIndexChange: OnIndexChange = useCallback((newIndex) => {\n const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, newIndex);\n\n store.dispatch(newRanges);\n }, [numberOfData, windowSize]);\n\n useEffect(() => {\n return () => {\n store.removeAllListeners();\n };\n }, []);\n\n return [store, onIndexChange];\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAaA,MAAMA,yBAAN,CAA+D;EAI3DC,WAAW,CAACC,YAAD,EAAmC;IAAA;;IAAA,mCAImB,EAJnB;;IAC1C,KAAKC,KAAL,GAAaD,YAAb;EACH;;EAIDE,SAAS,CAACC,QAAD,EAAiD;IACtD,KAAKC,SAAL,CAAeC,IAAf,CAAoBF,QAApB;IAEAA,QAAQ,CAAC,KAAKF,KAAN,CAAR;IAEA,OAAO,MAAM;MACT,MAAMK,KAAK,GAAG,KAAKF,SAAL,CAAeG,OAAf,CAAuBJ,QAAvB,CAAd;MACA,KAAKC,SAAL,CAAeI,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,QAAQ,CAACC,MAAD,EAAmC;IACvC,KAAKT,KAAL,GAAaS,MAAb;;IACA,KAAK,MAAMC,EAAX,IAAiB,KAAKP,SAAtB,EAAiC;MAC7B,MAAMD,QAAQ,GAAG,KAAKC,SAAL,CAAeO,EAAf,CAAjB;MACAR,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGO,MAAH,CAAR;IACH;EACJ;;EAEDE,kBAAkB,GAAS;IACvB,KAAKR,SAAL,CAAeI,MAAf,CAAsB,CAAtB,EAAyB,KAAKJ,SAAL,CAAeS,MAAxC;EACH;;AA/B0D;;AAmC/D,SAASC,SAAT,CAAmBC,UAAnB,EAAuCC,YAAvC,EAAqE;EACjE,IAAID,UAAU,IAAI,CAAlB,EAAqB;IACjB,OAAOC,YAAP;EACH;;EACD,IAAID,UAAU,GAAG,CAAb,IAAkBA,UAAU,GAAG,CAAb,KAAmB,CAAzC,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CAFsB,CAAvB;EAIA,MAAM9B,KAAK,GAAG,IAAAiC,aAAA,EAAO,IAAIpC,yBAAJ,CAA8BkC,YAA9B,CAAP,EAAoDG,OAAlE;EAEA,MAAMC,aAA4B,GAAG,IAAAC,kBAAA,EAAaC,QAAD,IAAc;IAC3D,MAAMC,SAAS,GAAGtB,sBAAsB,CAACD,YAAD,EAAeD,UAAf,EAA2BuB,QAA3B,CAAxC;IAEArC,KAAK,CAACQ,QAAN,CAAe8B,SAAf;EACH,CAJoC,EAIlC,CAACvB,YAAD,EAAeD,UAAf,CAJkC,CAArC;EAMA,IAAAyB,gBAAA,EAAU,MAAM;IACZ,OAAO,MAAM;MACTvC,KAAK,CAACW,kBAAN;IACH,CAFD;EAGH,CAJD,EAIG,EAJH;EAMA,OAAO,CAACX,KAAD,EAAQmC,aAAR,CAAP;AACH;;AAAA"}
@@ -7,8 +7,6 @@ exports.default = usePagingAnimation;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _reactNative = require("react-native");
11
-
12
10
  function directionToValue(itemWidth) {
13
11
  return function (direction) {
14
12
  switch (direction) {
@@ -24,99 +22,153 @@ function directionToValue(itemWidth) {
24
22
  };
25
23
  }
26
24
 
27
- function usePagingAnimation(config) {
25
+ function toValueCompensator(itemWidth) {
26
+ return function (toValue, currentOffset) {
27
+ const remainder = Math.abs(currentOffset % itemWidth);
28
+ const halfOfItemWidth = Math.abs(itemWidth / 2);
29
+ const compensateVector = remainder > halfOfItemWidth ? remainder - itemWidth : remainder;
30
+ const direction = currentOffset > 0 ? -1 : 1;
31
+ return toValue + direction * compensateVector;
32
+ };
33
+ }
34
+
35
+ function usePagingAnimation(params) {
28
36
  const {
29
- controlledTx,
30
37
  createScrollAnimation,
31
- getCurrentIndex,
32
38
  itemWidth,
33
- lastIndex,
39
+ indexController,
34
40
  loop,
35
41
  numberOfData,
36
- offsetTx
37
- } = config;
38
- const animationRef = (0, _react.useRef)(null);
42
+ offsetX,
43
+ translateX
44
+ } = params;
45
+ const {
46
+ getCurrentIndex,
47
+ lastIndex,
48
+ notifyOffsetHasChanged
49
+ } = indexController;
39
50
  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
51
+ const currentOffsetRef = (0, _react.useRef)(0);
52
+ const isAnimatingRef = (0, _react.useRef)(false);
53
+ const maxWidth = Math.abs(numberOfData * itemWidth);
54
+ const ensureOffsetBoundary = (0, _react.useCallback)(offset => {
55
+ if (loop) {
56
+ const isCloseToEnd = Math.abs(offset) >= maxWidth - itemWidth;
57
+
58
+ if (isCloseToEnd) {
59
+ const signOfOffset = offset > 0 ? 1 : -1;
60
+ return offset + -signOfOffset * maxWidth;
61
+ }
62
+ }
44
63
 
45
- if (currentTx !== 0) {
46
- const maxWidth = numberOfData * itemWidth;
64
+ return offset % maxWidth;
65
+ }, [itemWidth, loop, maxWidth]);
66
+ const requireNewOffset = (0, _react.useCallback)(newOffset => {
67
+ const nextOffset = ensureOffsetBoundary(newOffset);
68
+ currentOffsetRef.current = nextOffset;
69
+ offsetX.setValue(nextOffset);
70
+ toValueRef.current = 0;
71
+ translateX.setValue(0);
72
+ }, [ensureOffsetBoundary, offsetX, translateX]);
73
+ const interruptAnimation = (0, _react.useCallback)(() => {
74
+ if (toValueRef.current === 0) {
75
+ // Performance optimization
76
+ return;
77
+ }
47
78
 
48
- if (Math.abs(Math.round(currentTx)) === Math.round(maxWidth)) {
49
- // reset position
50
- controlledTx.setValue(0);
51
- }
52
- }
79
+ translateX.stopAnimation(lastValue => {
80
+ isAnimatingRef.current = false;
81
+ const prevOffset = currentOffsetRef.current;
82
+ const totalOffset = prevOffset + lastValue;
83
+ notifyOffsetHasChanged(totalOffset);
84
+ requireNewOffset(totalOffset);
53
85
  });
54
- return () => {
55
- controlledTx.removeListener(subscriptionId);
56
- };
57
- }, [numberOfData, itemWidth]);
86
+ }, [requireNewOffset, translateX]);
58
87
  const finalizeAnimation = (0, _react.useCallback)(() => {
59
- const stopUnfinishedSnapAnimation = () => {
60
- if (animationRef.current) {
61
- var _animationRef$current;
88
+ isAnimatingRef.current = false;
89
+ const prevOffset = currentOffsetRef.current;
90
+ const toValue = toValueRef.current;
91
+ const totalOffset = prevOffset + toValue;
92
+ requireNewOffset(totalOffset);
93
+ }, [requireNewOffset]);
94
+ const startPagingAnimation = (0, _react.useCallback)((type, config) => {
95
+ if (isAnimatingRef.current) {
96
+ return;
97
+ }
62
98
 
63
- (_animationRef$current = animationRef.current) === null || _animationRef$current === void 0 ? void 0 : _animationRef$current.stop();
64
- animationRef.current = null;
65
- }
99
+ const configWithDefaults = {
100
+ animated: true,
101
+ ...config
66
102
  };
103
+ const currentIndex = getCurrentIndex();
104
+ const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);
105
+ const compensateToValue = toValueCompensator(itemWidth);
67
106
 
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.
107
+ const getValueByDirectionalPagingOnLoopDisabled = _config => {
108
+ const {
109
+ direction,
110
+ isOriginatedFromGesture
111
+ } = _config;
74
112
 
75
- if (_reactNative.Platform.OS === 'web') {
76
- // @ts-ignore
77
- controlledTx.setValue(controlledTx._value);
113
+ if (currentIndex === 0 && direction === 'prev') {
114
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : -lastIndex * itemWidth; // last position
115
+ } else if (currentIndex === lastIndex && direction === 'next') {
116
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : lastIndex * itemWidth; // first position
78
117
  }
79
118
 
80
- offsetTx.setValue(0);
81
- toValueRef.current = 0;
119
+ return getValueByDirectionOnAllAdjacentItemsVisible(direction);
82
120
  };
83
121
 
84
- stopUnfinishedSnapAnimation();
85
- resetBoundary();
86
- }, [controlledTx]);
87
- const startAnimation = (0, _react.useCallback)(function (direction) {
88
- let isGesture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
89
- const getToValueByDirection = directionToValue(itemWidth);
90
- const currentIndex = getCurrentIndex();
122
+ const getValueByDirectionalPaging = _config => {
123
+ const _configWithDefaults = {
124
+ isOriginatedFromGesture: false,
125
+ ..._config
126
+ };
127
+ return loop ? getValueByDirectionOnAllAdjacentItemsVisible(_configWithDefaults.direction) : getValueByDirectionalPagingOnLoopDisabled(_configWithDefaults);
128
+ };
91
129
 
92
- const computeToValueOnNoLoop = () => {
93
- if (currentIndex === 0 && direction === 'prev') {
94
- return isGesture ? getToValueByDirection('stay') : -lastIndex * itemWidth; // last position
95
- } else if (currentIndex === lastIndex && direction === 'next') {
96
- return isGesture ? getToValueByDirection('stay') : lastIndex * itemWidth; // first position
130
+ const getValueByIndexPaging = _ref => {
131
+ let {
132
+ index
133
+ } = _ref;
134
+
135
+ if (index < 0 || index > lastIndex || index === currentIndex) {
136
+ // no animation if index is invalid or equals to current index
137
+ return 0;
97
138
  }
98
139
 
99
- return getToValueByDirection(direction);
140
+ const distance = Math.abs(currentIndex - index) * itemWidth;
141
+ const direction = index > currentIndex ? -1 : 1;
142
+ return distance * direction;
100
143
  };
101
144
 
102
- const toValue = loop ? getToValueByDirection(direction) : computeToValueOnNoLoop();
103
- const animation = createScrollAnimation(offsetTx, toValue);
104
- animationRef.current = animation;
145
+ const wantedToValue = type === 'directional' // @ts-ignore
146
+ ? getValueByDirectionalPaging(configWithDefaults) // @ts-ignore
147
+ : getValueByIndexPaging(configWithDefaults);
148
+ const toValue = compensateToValue(wantedToValue, currentOffsetRef.current);
105
149
  toValueRef.current = toValue;
106
- animation.start(_ref => {
107
- let {
108
- finished
109
- } = _ref;
150
+ isAnimatingRef.current = true;
110
151
 
111
- if (finished) {
112
- finalizeAnimation();
113
- }
114
- });
115
- }, [createScrollAnimation, getCurrentIndex, finalizeAnimation, itemWidth, lastIndex, loop]);
152
+ if (configWithDefaults.animated) {
153
+ const animation = createScrollAnimation(translateX, toValue);
154
+ animation.start(_ref2 => {
155
+ let {
156
+ finished
157
+ } = _ref2;
158
+
159
+ if (finished) {
160
+ finalizeAnimation();
161
+ }
162
+ });
163
+ } else {
164
+ finalizeAnimation();
165
+ }
166
+
167
+ notifyOffsetHasChanged(currentOffsetRef.current + toValue);
168
+ }, [createScrollAnimation, getCurrentIndex, finalizeAnimation, itemWidth, lastIndex, loop, notifyOffsetHasChanged]);
116
169
  return {
117
- globalInterpolation,
118
- finalizeAnimation,
119
- startAnimation
170
+ interruptAnimation,
171
+ startPagingAnimation
120
172
  };
121
173
  }
122
174
 
@@ -1 +1 @@
1
- {"version":3,"names":["directionToValue","itemWidth","direction","usePagingAnimation","config","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","startAnimation","isGesture","getToValueByDirection","currentIndex","computeToValueOnNoLoop","toValue","animation","start","finished"],"sources":["usePagingAnimation.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { Animated, Platform } from 'react-native';\nimport type { CreateScrollAnimation, GetCurrentIndex, PagingDirection, StartPagingAnimation } from '../types';\n\nexport interface PagingAnimationConfig {\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 startAnimation: 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(config: PagingAnimationConfig): UsePagingAnimation {\n const {\n controlledTx,\n createScrollAnimation,\n getCurrentIndex,\n itemWidth,\n lastIndex,\n loop,\n numberOfData,\n offsetTx,\n } = config;\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 startAnimation = useCallback((direction: PagingDirection, isGesture: boolean = false) => {\n const getToValueByDirection = directionToValue(itemWidth);\n\n const currentIndex = getCurrentIndex();\n\n const computeToValueOnNoLoop = (): number => {\n if (currentIndex === 0 && direction === 'prev') {\n return isGesture\n ? getToValueByDirection('stay')\n : -lastIndex * itemWidth; // last position\n } else if (currentIndex === lastIndex && direction === 'next') {\n return isGesture\n ? getToValueByDirection('stay')\n : lastIndex * itemWidth; // first position\n }\n return getToValueByDirection(direction);\n };\n\n const toValue = loop ? getToValueByDirection(direction) : computeToValueOnNoLoop();\n const animation = createScrollAnimation(offsetTx, toValue);\n\n animationRef.current = animation;\n toValueRef.current = toValue;\n\n animation.start(({ finished }) => {\n if (finished) {\n finalizeAnimation();\n }\n });\n }, [\n createScrollAnimation,\n getCurrentIndex,\n finalizeAnimation,\n itemWidth,\n lastIndex,\n loop,\n ]);\n\n return {\n globalInterpolation,\n finalizeAnimation,\n startAnimation,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAoBA,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,EAA+E;EAC1F,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,EAA2BM,QAA3B,CADkB,EAExB,CA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AsCA,OAAO;IACHM,mBADG;IAEHe,iBAFG;IAGHW;EAHG,CAAP;AAKH;;AAAA"}
1
+ {"version":3,"names":["directionToValue","itemWidth","direction","toValueCompensator","toValue","currentOffset","remainder","Math","abs","halfOfItemWidth","compensateVector","usePagingAnimation","params","createScrollAnimation","indexController","loop","numberOfData","offsetX","translateX","getCurrentIndex","lastIndex","notifyOffsetHasChanged","toValueRef","useRef","currentOffsetRef","isAnimatingRef","maxWidth","ensureOffsetBoundary","useCallback","offset","isCloseToEnd","signOfOffset","requireNewOffset","newOffset","nextOffset","current","setValue","interruptAnimation","stopAnimation","lastValue","prevOffset","totalOffset","finalizeAnimation","startPagingAnimation","type","config","configWithDefaults","animated","currentIndex","getValueByDirectionOnAllAdjacentItemsVisible","compensateToValue","getValueByDirectionalPagingOnLoopDisabled","_config","isOriginatedFromGesture","getValueByDirectionalPaging","_configWithDefaults","getValueByIndexPaging","index","distance","wantedToValue","animation","start","finished"],"sources":["usePagingAnimation.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport type {\n CreateScrollAnimation,\n DirectionalPagingAnimationConfig,\n IndexController,\n IndexPagingAnimationConfig,\n PagingAnimationConfig,\n PagingAnimationType,\n PagingDirection,\n StartPagingAnimation,\n} from '../types';\n\nexport interface PagingAnimationParameters {\n createScrollAnimation: CreateScrollAnimation;\n itemWidth: number;\n indexController: IndexController;\n loop: boolean;\n numberOfData: number;\n offsetX: Animated.Value;\n translateX: Animated.Value;\n}\n\nexport interface UsePagingAnimation {\n interruptAnimation: () => void;\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\nfunction toValueCompensator(itemWidth: number) {\n return function (toValue: number, currentOffset: number): number {\n const remainder = Math.abs(currentOffset % itemWidth);\n\n const halfOfItemWidth = Math.abs(itemWidth / 2);\n const compensateVector = remainder > halfOfItemWidth\n ? remainder - itemWidth\n : remainder;\n\n const direction = currentOffset > 0 ? -1 : 1;\n\n return toValue + (direction * compensateVector);\n };\n}\n\nexport default function usePagingAnimation(params: PagingAnimationParameters): UsePagingAnimation {\n const {\n createScrollAnimation,\n itemWidth,\n indexController,\n loop,\n numberOfData,\n offsetX,\n translateX,\n } = params;\n\n const {\n getCurrentIndex,\n lastIndex,\n notifyOffsetHasChanged,\n } = indexController;\n\n const toValueRef = useRef<number>(0);\n const currentOffsetRef = useRef<number>(0);\n\n const isAnimatingRef = useRef<boolean>(false);\n\n const maxWidth = Math.abs(numberOfData * itemWidth);\n\n const ensureOffsetBoundary: (offset: number) => number = useCallback((offset: number) => {\n if (loop) {\n const isCloseToEnd = Math.abs(offset) >= (maxWidth - itemWidth);\n if (isCloseToEnd) {\n const signOfOffset = offset > 0 ? 1 : -1;\n return offset + (-signOfOffset * maxWidth);\n }\n }\n\n return offset % maxWidth;\n }, [itemWidth, loop, maxWidth]);\n\n const requireNewOffset = useCallback((newOffset: number) => {\n const nextOffset = ensureOffsetBoundary(newOffset);\n\n currentOffsetRef.current = nextOffset;\n offsetX.setValue(nextOffset);\n\n toValueRef.current = 0;\n translateX.setValue(0);\n }, [\n ensureOffsetBoundary,\n offsetX,\n translateX,\n ]);\n\n const interruptAnimation = useCallback(() => {\n if (toValueRef.current === 0) {\n // Performance optimization\n return;\n }\n\n translateX.stopAnimation(lastValue => {\n isAnimatingRef.current = false;\n\n const prevOffset = currentOffsetRef.current;\n const totalOffset = prevOffset + lastValue;\n\n notifyOffsetHasChanged(totalOffset);\n\n requireNewOffset(totalOffset);\n });\n }, [requireNewOffset, translateX]);\n\n const finalizeAnimation = useCallback(() => {\n isAnimatingRef.current = false;\n\n const prevOffset = currentOffsetRef.current;\n const toValue = toValueRef.current;\n const totalOffset = prevOffset + toValue;\n\n requireNewOffset(totalOffset);\n }, [requireNewOffset]);\n\n const startPagingAnimation = useCallback((type: PagingAnimationType, config: PagingAnimationConfig) => {\n if (isAnimatingRef.current) {\n return;\n }\n\n const configWithDefaults: PagingAnimationConfig = {\n animated: true,\n ...config,\n };\n\n const currentIndex = getCurrentIndex();\n\n const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);\n const compensateToValue = toValueCompensator(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 wantedToValue = type === 'directional'\n // @ts-ignore\n ? getValueByDirectionalPaging(configWithDefaults)\n // @ts-ignore\n : getValueByIndexPaging(configWithDefaults);\n\n const toValue = compensateToValue(wantedToValue, currentOffsetRef.current);\n\n toValueRef.current = toValue;\n isAnimatingRef.current = true;\n\n if (configWithDefaults.animated) {\n const animation = createScrollAnimation(translateX, toValue);\n\n animation.start(({ finished }) => {\n if (finished) {\n finalizeAnimation();\n }\n });\n } else {\n finalizeAnimation();\n }\n\n notifyOffsetHasChanged(currentOffsetRef.current + toValue);\n }, [\n createScrollAnimation,\n getCurrentIndex,\n finalizeAnimation,\n itemWidth,\n lastIndex,\n loop,\n notifyOffsetHasChanged,\n ]);\n\n return {\n interruptAnimation,\n startPagingAnimation,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AA4BA,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;;AAED,SAASE,kBAAT,CAA4BF,SAA5B,EAA+C;EAC3C,OAAO,UAAUG,OAAV,EAA2BC,aAA3B,EAA0D;IAC7D,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAL,CAASH,aAAa,GAAGJ,SAAzB,CAAlB;IAEA,MAAMQ,eAAe,GAAGF,IAAI,CAACC,GAAL,CAASP,SAAS,GAAG,CAArB,CAAxB;IACA,MAAMS,gBAAgB,GAAGJ,SAAS,GAAGG,eAAZ,GACnBH,SAAS,GAAGL,SADO,GAEnBK,SAFN;IAIA,MAAMJ,SAAS,GAAGG,aAAa,GAAG,CAAhB,GAAoB,CAAC,CAArB,GAAyB,CAA3C;IAEA,OAAOD,OAAO,GAAIF,SAAS,GAAGQ,gBAA9B;EACH,CAXD;AAYH;;AAEc,SAASC,kBAAT,CAA4BC,MAA5B,EAAmF;EAC9F,MAAM;IACFC,qBADE;IAEFZ,SAFE;IAGFa,eAHE;IAIFC,IAJE;IAKFC,YALE;IAMFC,OANE;IAOFC;EAPE,IAQFN,MARJ;EAUA,MAAM;IACFO,eADE;IAEFC,SAFE;IAGFC;EAHE,IAIFP,eAJJ;EAMA,MAAMQ,UAAU,GAAG,IAAAC,aAAA,EAAe,CAAf,CAAnB;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vB,EAAiC;MAC7B,MAAMa,SAAS,GAAG/C,qBAAqB,CAACK,UAAD,EAAad,OAAb,CAAvC;MAEAwD,SAAS,CAACC,KAAV,CAAgB,SAAkB;QAAA,IAAjB;UAAEC;QAAF,CAAiB;;QAC9B,IAAIA,QAAJ,EAAc;UACVpB,iBAAiB;QACpB;MACJ,CAJD;IAKH,CARD,MAQO;MACHA,iBAAiB;IACpB;;IAEDrB,sBAAsB,CAACG,gBAAgB,CAACW,OAAjB,GAA2B/B,OAA5B,CAAtB;EACH,CA7E4B,EA6E1B,CACCS,qBADD,EAECM,eAFD,EAGCuB,iBAHD,EAICzC,SAJD,EAKCmB,SALD,EAMCL,IAND,EAOCM,sBAPD,CA7E0B,CAA7B;EAuFA,OAAO;IACHgB,kBADG;IAEHM;EAFG,CAAP;AAIH;;AAAA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("@fountain-ui/utils");
9
+
10
+ var _default = (0, _utils.logger)('Carousel', {
11
+ enabled: __DEV__,
12
+ format: 'diff'
13
+ });
14
+
15
+ exports.default = _default;
16
+ //# sourceMappingURL=tick.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["logger","enabled","__DEV__","format"],"sources":["tick.ts"],"sourcesContent":["import { logger } from '@fountain-ui/utils';\n\nexport default logger('Carousel', {\n enabled: __DEV__,\n format: 'diff',\n});\n"],"mappings":";;;;;;;AAAA;;eAEe,IAAAA,aAAA,EAAO,UAAP,EAAmB;EAC9BC,OAAO,EAAEC,OADqB;EAE9BC,MAAM,EAAE;AAFsB,CAAnB,C"}
@@ -1 +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 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 interface StartPagingAnimation {\n (direction: PagingDirection, isGesture?: boolean): 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 CarouselInstance {\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 * Get current visible item index.\n */\n getCurrentIndex: GetCurrentIndex;\n}\n"],"mappings":";;;;;AAGA,MAAMA,UAAU,GAAG,CAAC,MAAD,EAAS,MAAT,EAAiB,MAAjB,CAAnB"}
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 getCurrentIndex: GetCurrentIndex;\n lastIndex: number;\n notifyOffsetHasChanged: (offset: number) => void;\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"}