@fountain-ui/lab 2.0.0-beta.12 → 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 (69) hide show
  1. package/build/commonjs/Carousel/Carousel.js +12 -7
  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/parallaxItemStyleFactory.js +13 -13
  5. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -1
  6. package/build/commonjs/Carousel/components/InternalContext.js.map +1 -1
  7. package/build/commonjs/Carousel/components/ItemView.js +4 -2
  8. package/build/commonjs/Carousel/components/ItemView.js.map +1 -1
  9. package/build/commonjs/Carousel/components/RootView.js +21 -3
  10. package/build/commonjs/Carousel/components/RootView.js.map +1 -1
  11. package/build/commonjs/Carousel/components/ScrollViewGesture.js +12 -7
  12. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -1
  13. package/build/commonjs/Carousel/hooks/useAutoplayController.js +4 -1
  14. package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -1
  15. package/build/commonjs/Carousel/hooks/usePagingAnimation.js +57 -19
  16. package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -1
  17. package/build/commonjs/Carousel/types.js.map +1 -1
  18. package/build/commonjs/ViewPager/ViewPagerNative.js +45 -17
  19. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  20. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  21. package/build/commonjs/ViewPager/ViewPagerWeb.js +7 -7
  22. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  23. package/build/module/Carousel/Carousel.js +12 -7
  24. package/build/module/Carousel/Carousel.js.map +1 -1
  25. package/build/module/Carousel/CarouselProps.js.map +1 -1
  26. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +13 -13
  27. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -1
  28. package/build/module/Carousel/components/InternalContext.js.map +1 -1
  29. package/build/module/Carousel/components/ItemView.js +4 -2
  30. package/build/module/Carousel/components/ItemView.js.map +1 -1
  31. package/build/module/Carousel/components/RootView.js +22 -4
  32. package/build/module/Carousel/components/RootView.js.map +1 -1
  33. package/build/module/Carousel/components/ScrollViewGesture.js +12 -7
  34. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -1
  35. package/build/module/Carousel/hooks/useAutoplayController.js +4 -1
  36. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -1
  37. package/build/module/Carousel/hooks/usePagingAnimation.js +57 -19
  38. package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -1
  39. package/build/module/Carousel/types.js.map +1 -1
  40. package/build/module/ViewPager/ViewPagerNative.js +45 -17
  41. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  42. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  43. package/build/module/ViewPager/ViewPagerWeb.js +8 -8
  44. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  45. package/build/typescript/Carousel/CarouselProps.d.ts +4 -3
  46. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +5 -5
  47. package/build/typescript/Carousel/components/InternalContext.d.ts +2 -2
  48. package/build/typescript/Carousel/components/ItemView.d.ts +2 -0
  49. package/build/typescript/Carousel/components/RootView.d.ts +4 -4
  50. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +1 -1
  51. package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +3 -3
  52. package/build/typescript/Carousel/types.d.ts +25 -3
  53. package/build/typescript/ViewPager/ViewPagerNative.d.ts +1 -1
  54. package/build/typescript/ViewPager/ViewPagerProps.d.ts +1 -1
  55. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +1 -1
  56. package/package.json +2 -2
  57. package/src/Carousel/Carousel.tsx +7 -6
  58. package/src/Carousel/CarouselProps.ts +4 -3
  59. package/src/Carousel/animation/parallaxItemStyleFactory.ts +23 -23
  60. package/src/Carousel/components/InternalContext.ts +2 -2
  61. package/src/Carousel/components/ItemView.tsx +12 -2
  62. package/src/Carousel/components/RootView.tsx +19 -6
  63. package/src/Carousel/components/ScrollViewGesture.tsx +15 -8
  64. package/src/Carousel/hooks/useAutoplayController.ts +4 -1
  65. package/src/Carousel/hooks/usePagingAnimation.ts +70 -23
  66. package/src/Carousel/types.ts +33 -3
  67. package/src/ViewPager/ViewPagerNative.tsx +49 -16
  68. package/src/ViewPager/ViewPagerProps.ts +1 -1
  69. package/src/ViewPager/ViewPagerWeb.tsx +8 -8
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","Animated","PanGestureHandler","State","GestureHandlerState","SCROLL_TO_ADJACENT_TX_THRESHOLD","SCROLL_TO_ADJACENT_VX_THRESHOLD","ACTIVE_OFFSET_ABS_X","activeOffsetX","endAnimationStates","CANCELLED","END","shouldScrollToAdjacent","translationX","velocityX","Math","abs","ScrollViewGesture","props","autoplayController","children","finalizeAnimation","offsetTx","scrollEnabled","startAnimation","pause","pauseAutoplay","resume","resumeAutoplay","handleGestureBegin","handleGestureEvent","event","nativeEvent","useNativeDriver","handleHandlerStateChange","state","includes","userDirection"],"sources":["ScrollViewGesture.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport React, { useCallback } from 'react';\nimport { Animated } from 'react-native';\nimport type { PanGestureHandlerStateChangeEvent } from 'react-native-gesture-handler';\nimport { PanGestureHandler, State as GestureHandlerState } from 'react-native-gesture-handler';\nimport type { AutoplayController, PagingDirection, StartPagingAnimation } from '../types';\n\nexport interface ScrollViewGestureProps {\n autoplayController: AutoplayController;\n children: ReactNode;\n finalizeAnimation: () => void;\n offsetTx: Animated.Value,\n scrollEnabled: boolean;\n startAnimation: StartPagingAnimation;\n}\n\nconst SCROLL_TO_ADJACENT_TX_THRESHOLD = 60;\nconst SCROLL_TO_ADJACENT_VX_THRESHOLD = 500;\n\nconst ACTIVE_OFFSET_ABS_X = 5;\nconst activeOffsetX: number[] = [-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X];\n\nconst endAnimationStates: Readonly<GestureHandlerState[]> = [\n GestureHandlerState.CANCELLED,\n GestureHandlerState.END,\n];\n\nfunction shouldScrollToAdjacent(translationX: number, velocityX: number): boolean {\n return Math.abs(translationX) >= SCROLL_TO_ADJACENT_TX_THRESHOLD\n || Math.abs(velocityX) >= SCROLL_TO_ADJACENT_VX_THRESHOLD;\n}\n\nexport default function ScrollViewGesture(props: ScrollViewGestureProps) {\n const {\n autoplayController,\n children,\n finalizeAnimation,\n offsetTx,\n scrollEnabled,\n startAnimation,\n } = props;\n\n const { pause: pauseAutoplay, resume: resumeAutoplay } = autoplayController;\n\n const handleGestureBegin = useCallback(() => {\n pauseAutoplay();\n\n finalizeAnimation();\n }, [finalizeAnimation, pauseAutoplay]);\n\n const handleGestureEvent = useCallback(Animated.event(\n [{ nativeEvent: { translationX: offsetTx } }],\n { useNativeDriver: true },\n ), []);\n\n const handleHandlerStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {\n const { nativeEvent: { translationX, velocityX, state } } = event;\n\n if (endAnimationStates.includes(state)) {\n const userDirection: PagingDirection = shouldScrollToAdjacent(translationX, velocityX)\n ? (translationX < 0 ? 'next' : 'prev')\n : 'stay';\n\n startAnimation(userDirection, true);\n\n resumeAutoplay();\n }\n }, [startAnimation, resumeAutoplay]);\n\n return (\n <PanGestureHandler\n activeOffsetX={activeOffsetX}\n children={children}\n enabled={scrollEnabled}\n onBegan={handleGestureBegin}\n onGestureEvent={handleGestureEvent}\n onHandlerStateChange={handleHandlerStateChange}\n />\n );\n}\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,iBAAT,EAA4BC,KAAK,IAAIC,mBAArC,QAAgE,8BAAhE;AAYA,MAAMC,+BAA+B,GAAG,EAAxC;AACA,MAAMC,+BAA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AsB,CAACC,YAAD,EAAeC,SAAf,CAAtB,GAChCD,YAAY,GAAG,CAAf,GAAmB,MAAnB,GAA4B,MADI,GAEjC,MAFN;MAIAW,cAAc,CAACa,aAAD,EAAgB,IAAhB,CAAd;MAEAT,cAAc;IACjB;EACJ,CAZ2C,EAYzC,CAACJ,cAAD,EAAiBI,cAAjB,CAZyC,CAA5C;EAcA,oBACI,oBAAC,iBAAD;IACI,aAAa,EAAEpB,aADnB;IAEI,QAAQ,EAAEY,QAFd;IAGI,OAAO,EAAEG,aAHb;IAII,OAAO,EAAEM,kBAJb;IAKI,cAAc,EAAEC,kBALpB;IAMI,oBAAoB,EAAEI;EAN1B,EADJ;AAUH"}
1
+ {"version":3,"names":["React","useCallback","Animated","PanGestureHandler","State","GestureHandlerState","SCROLL_TO_ADJACENT_TX_THRESHOLD","SCROLL_TO_ADJACENT_VX_THRESHOLD","ACTIVE_OFFSET_ABS_X","activeOffsetX","endAnimationStates","CANCELLED","END","shouldScrollToAdjacent","translationX","velocityX","isSameDirection","isEnoughMovement","Math","abs","ScrollViewGesture","props","autoplayController","children","finalizeAnimation","offsetTx","scrollEnabled","startPagingAnimation","pause","pauseAutoplay","resume","resumeAutoplay","handleGestureBegin","handleGestureEvent","event","nativeEvent","useNativeDriver","handleHandlerStateChange","state","includes","direction","isOriginatedFromGesture"],"sources":["ScrollViewGesture.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport React, { useCallback } from 'react';\nimport { Animated } from 'react-native';\nimport type { PanGestureHandlerStateChangeEvent } from 'react-native-gesture-handler';\nimport { PanGestureHandler, State as GestureHandlerState } from 'react-native-gesture-handler';\nimport type { AutoplayController, PagingDirection, StartPagingAnimation } from '../types';\n\nexport interface ScrollViewGestureProps {\n autoplayController: AutoplayController;\n children: ReactNode;\n finalizeAnimation: () => void;\n offsetTx: Animated.Value,\n scrollEnabled: boolean;\n startPagingAnimation: StartPagingAnimation;\n}\n\nconst SCROLL_TO_ADJACENT_TX_THRESHOLD = 80;\nconst SCROLL_TO_ADJACENT_VX_THRESHOLD = 1000;\n\nconst ACTIVE_OFFSET_ABS_X = 5;\nconst activeOffsetX: number[] = [-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X];\n\nconst endAnimationStates: Readonly<GestureHandlerState[]> = [\n GestureHandlerState.CANCELLED,\n GestureHandlerState.END,\n];\n\nfunction shouldScrollToAdjacent(translationX: number, velocityX: number): boolean {\n const isSameDirection = translationX * velocityX > 0;\n const isEnoughMovement =\n Math.abs(translationX) >= SCROLL_TO_ADJACENT_TX_THRESHOLD\n || Math.abs(velocityX) >= SCROLL_TO_ADJACENT_VX_THRESHOLD;\n\n return isSameDirection && isEnoughMovement;\n}\n\nexport default function ScrollViewGesture(props: ScrollViewGestureProps) {\n const {\n autoplayController,\n children,\n finalizeAnimation,\n offsetTx,\n scrollEnabled,\n startPagingAnimation,\n } = props;\n\n const { pause: pauseAutoplay, resume: resumeAutoplay } = autoplayController;\n\n const handleGestureBegin = useCallback(() => {\n pauseAutoplay();\n\n finalizeAnimation();\n }, [finalizeAnimation, pauseAutoplay]);\n\n const handleGestureEvent = useCallback(Animated.event(\n [{ nativeEvent: { translationX: offsetTx } }],\n { useNativeDriver: true },\n ), []);\n\n const handleHandlerStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {\n const { nativeEvent: { translationX, velocityX, state } } = event;\n\n if (endAnimationStates.includes(state)) {\n const direction: PagingDirection = shouldScrollToAdjacent(translationX, velocityX)\n ? (translationX < 0 ? 'next' : 'prev')\n : 'stay';\n\n startPagingAnimation(\n 'directional',\n { direction: direction, isOriginatedFromGesture: true },\n );\n\n resumeAutoplay();\n }\n }, [startPagingAnimation, resumeAutoplay]);\n\n return (\n <PanGestureHandler\n activeOffsetX={activeOffsetX}\n children={children}\n enabled={scrollEnabled}\n onBegan={handleGestureBegin}\n onGestureEvent={handleGestureEvent}\n onHandlerStateChange={handleHandlerStateChange}\n />\n );\n}\n"],"mappings":"AACA,OAAOA,KAA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CAAD,EAGnC,EAHmC,CAAtC;EAKA,MAAMC,wBAAwB,GAAGpC,WAAW,CAAEiC,KAAD,IAA8C;IACvF,MAAM;MAAEC,WAAW,EAAE;QAAErB,YAAF;QAAgBC,SAAhB;QAA2BuB;MAA3B;IAAf,IAAsDJ,KAA5D;;IAEA,IAAIxB,kBAAkB,CAAC6B,QAAnB,CAA4BD,KAA5B,CAAJ,EAAwC;MACpC,MAAME,SAA0B,GAAG3B,sBAAsB,CAACC,YAAD,EAAeC,SAAf,CAAtB,GAC5BD,YAAY,GAAG,CAAf,GAAmB,MAAnB,GAA4B,MADA,GAE7B,MAFN;MAIAa,oBAAoB,CAChB,aADgB,EAEhB;QAAEa,SAAS,EAAEA,SAAb;QAAwBC,uBAAuB,EAAE;MAAjD,CAFgB,CAApB;MAKAV,cAAc;IACjB;EACJ,CAf2C,EAezC,CAACJ,oBAAD,EAAuBI,cAAvB,CAfyC,CAA5C;EAiBA,oBACI,oBAAC,iBAAD;IACI,aAAa,EAAEtB,aADnB;IAEI,QAAQ,EAAEc,QAFd;IAGI,OAAO,EAAEG,aAHb;IAII,OAAO,EAAEM,kBAJb;IAKI,cAAc,EAAEC,kBALpB;IAMI,oBAAoB,EAAEI;EAN1B,EADJ;AAUH"}
@@ -14,7 +14,10 @@ export default function useAutoplayController(config) {
14
14
  }
15
15
 
16
16
  executor.execute(() => {
17
- startPagingAnimation('next', false);
17
+ startPagingAnimation('directional', {
18
+ direction: 'next',
19
+ isOriginatedFromGesture: false
20
+ });
18
21
  play();
19
22
  }, intervalMillis);
20
23
  }, [intervalMillis, startPagingAnimation]);
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useRef","useDeferredExecutor","useAutoplayController","config","enabled","intervalMillis","startPagingAnimation","paused","executor","play","current","execute","pause","cancel","resume"],"sources":["useAutoplayController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { AutoplayController, StartPagingAnimation } from '../types';\nimport { useDeferredExecutor } from '../../hooks';\n\nexport interface AutoplayConfig {\n enabled: boolean;\n intervalMillis: number;\n startPagingAnimation: StartPagingAnimation;\n}\n\nexport default function useAutoplayController(config: AutoplayConfig): AutoplayController {\n const {\n enabled,\n intervalMillis,\n startPagingAnimation,\n } = config;\n\n const paused = useRef<boolean>(false);\n\n const executor = useDeferredExecutor();\n\n const play = useCallback(() => {\n if (paused.current) {\n return;\n }\n\n executor.execute(() => {\n startPagingAnimation('next', false);\n play();\n }, intervalMillis);\n }, [intervalMillis, startPagingAnimation]);\n\n const pause = useCallback(() => {\n executor.cancel();\n paused.current = true;\n }, []);\n\n const resume = useCallback(() => {\n paused.current = false;\n if (enabled) {\n play();\n }\n }, [play, enabled]);\n\n useEffect(() => {\n if (enabled) {\n resume();\n } else {\n pause();\n }\n }, [enabled]);\n\n return { pause, resume };\n};\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,QAA+C,OAA/C;AAEA,SAASC,mBAAT,QAAoC,aAApC;AAQA,eAAe,SAASC,qBAAT,CAA+BC,MAA/B,EAA2E;EACtF,MAAM;IACFC,OADE;IAEFC,cAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,MAAMI,MAAM,GAAGP,MAAM,CAAU,KAAV,CAArB;EAEA,MAAMQ,QAAQ,GAAGP,mBAAmB,EAApC;EAEA,MAAMQ,IAAI,GAAGX,WAAW,CAAC,MAAM;IAC3B,IAAIS,MAAM,CAACG,OAAX,EAAoB;MAChB;IACH;;IAEDF,QAAQ,CAACG,OAAT,CAAiB,MAAM;MACnBL,oBAAoB,CAAC,MAAD,EAAS,KAAT,CAApB;MACAG,IAAI;IACP,CAHD,EAGGJ,cAHH;EAIH,CATuB,EASrB,CAACA,cAAD,EAAiBC,oBAAjB,CATqB,CAAxB;EAWA,MAAMM,KAAK,GAAGd,WAAW,CAAC,MAAM;IAC5BU,QAAQ,CAACK,MAAT;IACAN,MAAM,CAACG,OAAP,GAAiB,IAAjB;EACH,CAHwB,EAGtB,EAHsB,CAAzB;EAKA,MAAMI,MAAM,GAAGhB,WAAW,CAAC,MAAM;IAC7BS,MAAM,CAACG,OAAP,GAAiB,KAAjB;;IACA,IAAIN,OAAJ,EAAa;MACTK,IAAI;IACP;EACJ,CALyB,EAKvB,CAACA,IAAD,EAAOL,OAAP,CALuB,CAA1B;EAOAL,SAAS,CAAC,MAAM;IACZ,IAAIK,OAAJ,EAAa;MACTU,MAAM;IACT,CAFD,MAEO;MACHF,KAAK;IACR;EACJ,CANQ,EAMN,CAACR,OAAD,CANM,CAAT;EAQA,OAAO;IAAEQ,KAAF;IAASE;EAAT,CAAP;AACH;AAAA"}
1
+ {"version":3,"names":["useCallback","useEffect","useRef","useDeferredExecutor","useAutoplayController","config","enabled","intervalMillis","startPagingAnimation","paused","executor","play","current","execute","direction","isOriginatedFromGesture","pause","cancel","resume"],"sources":["useAutoplayController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport type { AutoplayController, StartPagingAnimation } from '../types';\nimport { useDeferredExecutor } from '../../hooks';\n\nexport interface AutoplayConfig {\n enabled: boolean;\n intervalMillis: number;\n startPagingAnimation: StartPagingAnimation;\n}\n\nexport default function useAutoplayController(config: AutoplayConfig): AutoplayController {\n const {\n enabled,\n intervalMillis,\n startPagingAnimation,\n } = config;\n\n const paused = useRef<boolean>(false);\n\n const executor = useDeferredExecutor();\n\n const play = useCallback(() => {\n if (paused.current) {\n return;\n }\n\n executor.execute(() => {\n startPagingAnimation(\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,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,QAA+C,OAA/C;AAEA,SAASC,mBAAT,QAAoC,aAApC;AAQA,eAAe,SAASC,qBAAT,CAA+BC,MAA/B,EAA2E;EACtF,MAAM;IACFC,OADE;IAEFC,cAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,MAAMI,MAAM,GAAGP,MAAM,CAAU,KAAV,CAArB;EAEA,MAAMQ,QAAQ,GAAGP,mBAAmB,EAApC;EAEA,MAAMQ,IAAI,GAAGX,WAAW,CAAC,MAAM;IAC3B,IAAIS,MAAM,CAACG,OAAX,EAAoB;MAChB;IACH;;IAEDF,QAAQ,CAACG,OAAT,CAAiB,MAAM;MACnBL,oBAAoB,CAChB,aADgB,EAEhB;QAAEM,SAAS,EAAE,MAAb;QAAqBC,uBAAuB,EAAE;MAA9C,CAFgB,CAApB;MAIAJ,IAAI;IACP,CAND,EAMGJ,cANH;EAOH,CAZuB,EAYrB,CAACA,cAAD,EAAiBC,oBAAjB,CAZqB,CAAxB;EAcA,MAAMQ,KAAK,GAAGhB,WAAW,CAAC,MAAM;IAC5BU,QAAQ,CAACO,MAAT;IACAR,MAAM,CAACG,OAAP,GAAiB,IAAjB;EACH,CAHwB,EAGtB,EAHsB,CAAzB;EAKA,MAAMM,MAAM,GAAGlB,WAAW,CAAC,MAAM;IAC7BS,MAAM,CAACG,OAAP,GAAiB,KAAjB;;IACA,IAAIN,OAAJ,EAAa;MACTK,IAAI;IACP;EACJ,CALyB,EAKvB,CAACA,IAAD,EAAOL,OAAP,CALuB,CAA1B;EAOAL,SAAS,CAAC,MAAM;IACZ,IAAIK,OAAJ,EAAa;MACTY,MAAM;IACT,CAFD,MAEO;MACHF,KAAK;IACR;EACJ,CANQ,EAMN,CAACV,OAAD,CANM,CAAT;EAQA,OAAO;IAAEU,KAAF;IAASE;EAAT,CAAP;AACH;AAAA"}
@@ -16,7 +16,7 @@ function directionToValue(itemWidth) {
16
16
  };
17
17
  }
18
18
 
19
- export default function usePagingAnimation(config) {
19
+ export default function usePagingAnimation(params) {
20
20
  const {
21
21
  controlledTx,
22
22
  createScrollAnimation,
@@ -26,7 +26,7 @@ export default function usePagingAnimation(config) {
26
26
  loop,
27
27
  numberOfData,
28
28
  offsetTx
29
- } = config;
29
+ } = params;
30
30
  const animationRef = useRef(null);
31
31
  const toValueRef = useRef(0);
32
32
  const globalInterpolation = useMemo(() => Animated.add(controlledTx, offsetTx), [controlledTx, offsetTx]);
@@ -76,39 +76,77 @@ export default function usePagingAnimation(config) {
76
76
  stopUnfinishedSnapAnimation();
77
77
  resetBoundary();
78
78
  }, [controlledTx]);
79
- const startAnimation = useCallback(function (direction) {
80
- let isGesture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
81
- const getToValueByDirection = directionToValue(itemWidth);
79
+ const startPagingAnimation = useCallback((type, config) => {
80
+ const configWithDefaults = {
81
+ animated: true,
82
+ ...config
83
+ };
82
84
  const currentIndex = getCurrentIndex();
85
+ const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);
86
+
87
+ const getValueByDirectionalPagingOnLoopDisabled = _config => {
88
+ const {
89
+ direction,
90
+ isOriginatedFromGesture
91
+ } = _config;
83
92
 
84
- const computeToValueOnNoLoop = () => {
85
93
  if (currentIndex === 0 && direction === 'prev') {
86
- return isGesture ? getToValueByDirection('stay') : -lastIndex * itemWidth; // last position
94
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : -lastIndex * itemWidth; // last position
87
95
  } else if (currentIndex === lastIndex && direction === 'next') {
88
- return isGesture ? getToValueByDirection('stay') : lastIndex * itemWidth; // first position
96
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : lastIndex * itemWidth; // first position
89
97
  }
90
98
 
91
- return getToValueByDirection(direction);
99
+ return getValueByDirectionOnAllAdjacentItemsVisible(direction);
92
100
  };
93
101
 
94
- const toValue = loop ? getToValueByDirection(direction) : computeToValueOnNoLoop();
95
- const animation = createScrollAnimation(offsetTx, toValue);
96
- animationRef.current = animation;
97
- toValueRef.current = toValue;
98
- animation.start(_ref => {
102
+ const getValueByDirectionalPaging = _config => {
103
+ const _configWithDefaults = {
104
+ isOriginatedFromGesture: false,
105
+ ..._config
106
+ };
107
+ return loop ? getValueByDirectionOnAllAdjacentItemsVisible(_configWithDefaults.direction) : getValueByDirectionalPagingOnLoopDisabled(_configWithDefaults);
108
+ };
109
+
110
+ const getValueByIndexPaging = _ref => {
99
111
  let {
100
- finished
112
+ index
101
113
  } = _ref;
102
114
 
103
- if (finished) {
104
- finalizeAnimation();
115
+ if (index < 0 || index > lastIndex || index === currentIndex) {
116
+ // no animation if index is invalid or equals to current index
117
+ return 0;
105
118
  }
106
- });
119
+
120
+ const distance = Math.abs(currentIndex - index) * itemWidth;
121
+ const direction = index > currentIndex ? -1 : 1;
122
+ return distance * direction;
123
+ };
124
+
125
+ const toValue = type === 'directional' // @ts-ignore
126
+ ? getValueByDirectionalPaging(configWithDefaults) // @ts-ignore
127
+ : getValueByIndexPaging(configWithDefaults);
128
+ toValueRef.current = toValue;
129
+
130
+ if (configWithDefaults.animated) {
131
+ const animation = createScrollAnimation(offsetTx, toValue);
132
+ animationRef.current = animation;
133
+ animation.start(_ref2 => {
134
+ let {
135
+ finished
136
+ } = _ref2;
137
+
138
+ if (finished) {
139
+ finalizeAnimation();
140
+ }
141
+ });
142
+ } else {
143
+ finalizeAnimation();
144
+ }
107
145
  }, [createScrollAnimation, getCurrentIndex, finalizeAnimation, itemWidth, lastIndex, loop]);
108
146
  return {
109
147
  globalInterpolation,
110
148
  finalizeAnimation,
111
- startAnimation
149
+ startPagingAnimation
112
150
  };
113
151
  }
114
152
  ;
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useMemo","useRef","Animated","Platform","directionToValue","itemWidth","direction","usePagingAnimation","config","controlledTx","createScrollAnimation","getCurrentIndex","lastIndex","loop","numberOfData","offsetTx","animationRef","toValueRef","globalInterpolation","add","subscriptionId","addListener","value","currentTx","maxWidth","Math","abs","round","setValue","removeListener","finalizeAnimation","stopUnfinishedSnapAnimation","current","stop","resetBoundary","setOffset","flattenOffset","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,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,OAAjC,EAA0CC,MAA1C,QAAwD,OAAxD;AACA,SAASC,QAAT,EAAmBC,QAAnB,QAAmC,cAAnC;;AAoBA,SAASC,gBAAT,CAA0BC,SAA1B,EAA6C;EACzC,OAAO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;;MACD,OAAOoC,qBAAqB,CAACnC,SAAD,CAA5B;IACH,CAXD;;IAaA,MAAMsC,OAAO,GAAG/B,IAAI,GAAG4B,qBAAqB,CAACnC,SAAD,CAAxB,GAAsCqC,sBAAsB,EAAhF;IACA,MAAME,SAAS,GAAGnC,qBAAqB,CAACK,QAAD,EAAW6B,OAAX,CAAvC;IAEA5B,YAAY,CAACgB,OAAb,GAAuBa,SAAvB;IACA5B,UAAU,CAACe,OAAX,GAAqBY,OAArB;IAEAC,SAAS,CAACC,KAAV,CAAgB,QAAkB;MAAA,IAAjB;QAAEC;MAAF,CAAiB;;MAC9B,IAAIA,QAAJ,EAAc;QACVjB,iBAAiB;MACpB;IACJ,CAJD;EAKH,CA7BiC,EA6B/B,CACCpB,qBADD,EAECC,eAFD,EAGCmB,iBAHD,EAICzB,SAJD,EAKCO,SALD,EAMCC,IAND,CA7B+B,CAAlC;EAsCA,OAAO;IACHK,mBADG;IAEHY,iBAFG;IAGHS;EAHG,CAAP;AAKH;AAAA"}
1
+ {"version":3,"names":["useCallback","useEffect","useMemo","useRef","Animated","Platform","directionToValue","itemWidth","direction","usePagingAnimation","params","controlledTx","createScrollAnimation","getCurrentIndex","lastIndex","loop","numberOfData","offsetTx","animationRef","toValueRef","globalInterpolation","add","subscriptionId","addListener","value","currentTx","maxWidth","Math","abs","round","setValue","removeListener","finalizeAnimation","stopUnfinishedSnapAnimation","current","stop","resetBoundary","setOffset","flattenOffset","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,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,OAAjC,EAA0CC,MAA1C,QAAwD,OAAxD;AACA,SAASC,QAAT,EAAmBC,QAAnB,QAAmC,cAAnC;;AA6BA,SAASC,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,eAAe,SAASE,kBAAT,CAA4BC,MAA5B,EAAmF;EAC9F,MAAM;IACFC,YADE;IAEFC,qBAFE;IAGFC,eAHE;IAIFN,SAJE;IAKFO,SALE;IAMFC,IANE;IAOFC,YAPE;IAQFC;EARE,IASFP,MATJ;EAWA,MAAMQ,YAAY,GAAGf,MAAM,CAAqC,IAArC,CAA3B;EACA,MAAMgB,UAAU,GAAGhB,MAAM,CAAS,CAAT,CAAzB;EAEA,MAAMiB,mBAAmB,GAAGlB,OAAO,CAC/B,MAAME,QAAQ,CAACiB,GAAT,CAAaV,YAAb,EAA2BM,QAA3B,CADyB,EAE/B,CAACN,YAAD,EAAeM,QAAf,CAF+B,CAAnC;EAKAhB,SAAS,CAAC,MAAM;IACZ,MAAMqB,cAAc,GAAGX,YAAY,CAACY,WAAb,CAA0BC,KAAD,IAAW;MACvD,MAAMC,SAAS,GAAGD,KAAK,CAACA,KAAxB,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AS,GAAG8C,KAAK,GAAGR,YAAR,GAAuB,CAAC,CAAxB,GAA4B,CAA9C;MAEA,OAAOS,QAAQ,GAAG/C,SAAlB;IACH,CAVD;;IAYA,MAAMgD,OAAO,GAAGd,IAAI,KAAK,aAAT,CACZ;IADY,EAEVS,2BAA2B,CAACP,kBAAD,CAFjB,CAGZ;IAHY,EAIVS,qBAAqB,CAACT,kBAAD,CAJ3B;IAMAzB,UAAU,CAACe,OAAX,GAAqBsB,OAArB;;IAEA,IAAIZ,kBAAkB,CAACC,QAAvB,EAAiC;MAC7B,MAAMY,SAAS,GAAG7C,qBAAqB,CAACK,QAAD,EAAWuC,OAAX,CAAvC;MACAtC,YAAY,CAACgB,OAAb,GAAuBuB,SAAvB;MACAA,SAAS,CAACC,KAAV,CAAgB,SAAkB;QAAA,IAAjB;UAAEC;QAAF,CAAiB;;QAC9B,IAAIA,QAAJ,EAAc;UACV3B,iBAAiB;QACpB;MACJ,CAJD;IAKH,CARD,MAQO;MACHA,iBAAiB;IACpB;EACJ,CAnEuC,EAmErC,CACCpB,qBADD,EAECC,eAFD,EAGCmB,iBAHD,EAICzB,SAJD,EAKCO,SALD,EAMCC,IAND,CAnEqC,CAAxC;EA4EA,OAAO;IACHK,mBADG;IAEHY,iBAFG;IAGHS;EAHG,CAAP;AAKH;AAAA"}
@@ -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 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"}
@@ -14,17 +14,35 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
14
14
  pageForceRerenderKey,
15
15
  scrollEnabled = true,
16
16
  style,
17
- UNSTABLE_sharedIndex
17
+ UNSTABLE_sharedPage
18
18
  } = props;
19
- const fallbackSharedIndex = useSharedValue(initialPage);
20
- const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
19
+ const fallbackSharedPage = useSharedValue(initialPage);
20
+ const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
21
+ const desiredPageRef = useRef(NaN);
21
22
  const pagerRef = useRef(null);
22
23
  const animationFrameRef = useRef(NaN);
23
- const setPage = useCallback(newIndex => {
24
+ const setPage = useCallback(newPage => {
25
+ if (!Number.isInteger(newPage)) {
26
+ return;
27
+ }
28
+
24
29
  animationFrameRef.current = requestAnimationFrame(() => {
25
30
  var _pagerRef$current;
26
31
 
27
- (_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newIndex);
32
+ if (Number.isFinite(desiredPageRef.current)) {
33
+ if (sharedPage.value === desiredPageRef.current) {
34
+ // end of state machine. clear desired page.
35
+ desiredPageRef.current = NaN;
36
+ return;
37
+ }
38
+
39
+ if (newPage === desiredPageRef.current) {
40
+ return;
41
+ }
42
+ }
43
+
44
+ desiredPageRef.current = newPage;
45
+ (_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newPage);
28
46
  });
29
47
  }, []);
30
48
  useEffect(() => {
@@ -34,21 +52,31 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
34
52
  }
35
53
  };
36
54
  }, []);
37
- useAnimatedReaction(() => sharedIndex.value, result => {
55
+ useAnimatedReaction(() => sharedPage.value, result => {
38
56
  runOnJS(setPage)(result);
39
57
  }, [setPage]);
40
58
  const handlePageSelected = useCallback(e => {
41
- const currentIndex = sharedIndex.value;
42
- const nextIndex = e.nativeEvent.position;
59
+ if (Number.isFinite(desiredPageRef.current)) {
60
+ // onPageSelected is called from outer controlling mechanism
61
+ // e.g. sharedPage.value is changed, setPage() is called
62
+ // Due to the onPageSelected bug,
63
+ // we don't trust the value from event, (e.nativeEvent.position)
64
+ // other than that trust the value from desiredPageRef.
65
+ const desiredPage = desiredPageRef.current;
43
66
 
44
- if (currentIndex === nextIndex) {
45
- return;
46
- }
47
-
48
- sharedIndex.value = nextIndex;
67
+ if (sharedPage.value === desiredPage) {
68
+ // end of state machine. clear desired page.
69
+ desiredPageRef.current = NaN;
70
+ } else {
71
+ sharedPage.value = desiredPage;
72
+ }
49
73
 
50
- if (onChange) {
51
- onChange(nextIndex);
74
+ onChange === null || onChange === void 0 ? void 0 : onChange(desiredPage);
75
+ } else {
76
+ const trustfulNextPage = e.nativeEvent.position;
77
+ desiredPageRef.current = trustfulNextPage;
78
+ sharedPage.value = trustfulNextPage;
79
+ onChange === null || onChange === void 0 ? void 0 : onChange(trustfulNextPage);
52
80
  }
53
81
  }, [onChange]);
54
82
  useImperativeHandle(ref, () => ({
@@ -57,7 +85,7 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
57
85
  const PageComponent = pageComponent;
58
86
  return /*#__PURE__*/React.createElement(RNViewPager, {
59
87
  ref: pagerRef,
60
- initialPage: initialPage,
88
+ initialPage: sharedPage.value,
61
89
  keyboardDismissMode: keyboardDismissMode,
62
90
  onPageSelected: handlePageSelected,
63
91
  pageMargin: 8,
@@ -70,7 +98,7 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
70
98
  loading: loading,
71
99
  offscreenPageRerenderLimit: offscreenPageRerenderLimit,
72
100
  rerenderKey: pageForceRerenderKey,
73
- sharedIndex: sharedIndex
101
+ sharedIndex: sharedPage
74
102
  })));
75
103
  });
76
104
  export default ViewPager;
@@ -1 +1 @@
1
- {"version":3,"names":["React","Children","forwardRef","useCallback","useEffect","useImperativeHandle","useRef","RNViewPager","runOnJS","useAnimatedReaction","useSharedValue","defaultInitialPage","defaultLoading","defaultOffscreenPageRerenderLimit","defaultPageComponent","ViewPager","props","ref","children","initialPage","keyboardDismissMode","loading","offscreenPageRerenderLimit","onChange","pageComponent","pageForceRerenderKey","scrollEnabled","style","UNSTABLE_sharedIndex","fallbackSharedIndex","sharedIndex","pagerRef","animationFrameRef","NaN","setPage","newIndex","current","requestAnimationFrame","cancelAnimationFrame","value","result","handlePageSelected","e","currentIndex","nextIndex","nativeEvent","position","PageComponent","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_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSharedValue<number>(initialPage);\n\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n\n const pagerRef = useRef<RNViewPager | null>(null);\n\n const animationFrameRef = useRef<number>(NaN);\n\n const setPage = useCallback((newIndex: number) => {\n animationFrameRef.current = requestAnimationFrame(() => {\n pagerRef.current?.setPage(newIndex);\n });\n }, []);\n\n useEffect(() => {\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current);\n }\n };\n }, []);\n\n useAnimatedReaction(\n () => sharedIndex.value,\n (result) => {\n runOnJS(setPage)(result);\n },\n [setPage],\n );\n\n const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {\n const currentIndex = sharedIndex.value;\n const nextIndex = e.nativeEvent.position;\n\n if (currentIndex === nextIndex) {\n return;\n }\n\n sharedIndex.value = nextIndex;\n\n if (onChange) {\n onChange(nextIndex);\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={initialPage}\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={sharedIndex}\n />\n ))}\n </RNViewPager>\n );\n});\n\nexport default ViewPager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,WAAtC,EAAmDC,SAAnD,EAA8DC,mBAA9D,EAAmFC,MAAnF,QAAiG,OAAjG;AAEA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,SAASC,OAAT,EAAkBC,mBAAlB,EAAuCC,cAAvC,QAA6D,yBAA7D;AAGA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,iCAA7C,EAAgFC,oBAAhF,QAA4G,SAA5G;AAEA,MAAMC,SAAS,gBAAGb,UAAU,CAAoC,SAASa,SAAT,CAAmBC,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGR,kBAFZ;IAGFS,mBAAmB,GAAG,SAHpB;IAIFC,OAAO,GAAGT,cAJR;IAKFU,0BAA0B,GAAGT,iCAL3B;IAMFU,QANE;IAOFC,aAAa,GAAGV,oBAPd;IAQFW,oBARE;IASFC,aAAa,GAAG,IATd;IAUFC,KAVE;IAWFC;EAXE,IAYFZ,KAZJ;EAcA,MAAMa,mBAAmB,GAAGnB,cAAc,CAASS,WAAT,CAA1C;EAEA,MAAMW,WAAW,GAAGF,oBAAoB,IAAIC,mBAA5C;EAEA,MAAME,QAAQ,GAAGzB,MAAM,CAAqB,IAArB,CAAvB;EAEA,MAAM0B,iBAAiB,GAAG1B,MAAM,CAAS2B,GAAT,CAAhC;EAEA,MAAMC,OAAO,GAAG/B,WAAW,CAAEgC,QAAD,IAAsB;IAC9CH,iBAAiB,CAACI,OAAlB,GAA4BC,q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B,QAAb,EAAuB,CAAC+B,KAAD,EAAQC,KAAR,kBACpB,oBAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,OAAO,EAAE7B,OAJb;IAKI,0BAA0B,EAAEC,0BALhC;IAMI,WAAW,EAAEG,oBANjB;IAOI,WAAW,EAAEK;EAPjB,EADH,CATL,CADJ;AAuBH,CA3F2B,CAA5B;AA6FA,eAAef,SAAf"}
1
+ {"version":3,"names":["React","Children","forwardRef","useCallback","useEffect","useImperativeHandle","useRef","RNViewPager","runOnJS","useAnimatedReaction","useSharedValue","defaultInitialPage","defaultLoading","defaultOffscreenPageRerenderLimit","defaultPageComponent","ViewPager","props","ref","children","initialPage","keyboardDismissMode","loading","offscreenPageRerenderLimit","onChange","pageComponent","pageForceRerenderKey","scrollEnabled","style","UNSTABLE_sharedPage","fallbackSharedPage","sharedPage","desiredPageRef","NaN","pagerRef","animationFrameRef","setPage","newPage","Number","isInteger","current","requestAnimationFrame","isFinite","value","cancelAnimationFrame","result","handlePageSelected","e","desiredPage","trustfulNextPage","nativeEvent","position","PageComponent","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,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,WAAtC,EAAmDC,SAAnD,EAA8DC,mBAA9D,EAAmFC,MAAnF,QAAiG,OAAjG;AAEA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,SAASC,OAAT,EAAkBC,mBAAlB,EAAuCC,cAAvC,QAA6D,yBAA7D;AAGA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,iCAA7C,EAAgFC,oBAAhF,QAA4G,SAA5G;AAEA,MAAMC,SAAS,gBAAGb,UAAU,CAAoC,SAASa,SAAT,CAAmBC,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGR,kBAFZ;IAGFS,mBAAmB,GAAG,SAHpB;IAIFC,OAAO,GAAGT,cAJR;IAKFU,0BAA0B,GAAGT,iCAL3B;IAMFU,QANE;IAOFC,aAAa,GAAGV,oBAPd;IAQFW,oBARE;IASFC,aAAa,GAAG,IATd;IAUFC,KAVE;IAWFC;EAXE,IAYFZ,KAZJ;EAcA,MAAMa,kBAAkB,GAAGnB,cAAc,CAASS,WAAT,CAAzC;EAEA,MAAMW,UAAU,GAAGF,mBAAmB,IAAIC,kBAA1C;EAEA,MAAME,cAAc,GAAGzB,MAAM,CAAS0B,GAAT,CAA7B;EAEA,MAAMC,QAAQ,GAAG3B,MAAM,CAAqB,IAArB,CAAvB;EAEA,MAAM4B,iBAAiB,GAAG5B,M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"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_sharedIndex?: SharedValue<number>;\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":""}
@@ -1,4 +1,4 @@
1
- import React, { Children, forwardRef, useImperativeHandle, useCallback } from 'react';
1
+ import React, { Children, forwardRef, useCallback, useImperativeHandle } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import { useSharedValue } from 'react-native-reanimated';
4
4
  import { StyleSheet } from '@fountain-ui/core';
@@ -18,13 +18,13 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
18
18
  pageComponent = defaultPageComponent,
19
19
  pageForceRerenderKey,
20
20
  style,
21
- UNSTABLE_sharedIndex
21
+ UNSTABLE_sharedPage
22
22
  } = props;
23
- const fallbackSharedIndex = useSharedValue(initialPage);
24
- const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
25
- const setPage = useCallback(newIndex => {
26
- sharedIndex.value = newIndex;
27
- }, [sharedIndex]);
23
+ const fallbackSharedPage = useSharedValue(initialPage);
24
+ const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
25
+ const setPage = useCallback(newPage => {
26
+ sharedPage.value = newPage;
27
+ }, [sharedPage]);
28
28
  useImperativeHandle(ref, () => ({
29
29
  setPage
30
30
  }), [setPage]);
@@ -39,7 +39,7 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
39
39
  offscreenPageRerenderLimit: 0 // All offscreen pages will not be re-rendered
40
40
  ,
41
41
  rerenderKey: pageForceRerenderKey,
42
- sharedIndex: sharedIndex
42
+ sharedIndex: sharedPage
43
43
  })));
44
44
  });
45
45
  export default ViewPager;
@@ -1 +1 @@
1
- {"version":3,"names":["React","Children","forwardRef","useImperativeHandle","useCallback","View","useSharedValue","StyleSheet","defaultInitialPage","defaultLoading","defaultPageComponent","styles","create","root","overflow","position","ViewPager","props","ref","children","initialPage","loading","pageComponent","pageForceRerenderKey","style","UNSTABLE_sharedIndex","fallbackSharedIndex","sharedIndex","setPage","newIndex","value","PageComponent","map","child","index"],"sources":["ViewPagerWeb.tsx"],"sourcesContent":["import React, { Children, forwardRef, useImperativeHandle, useCallback } from 'react';\nimport { View } from 'react-native';\nimport { useSharedValue } from 'react-native-reanimated';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './ViewPagerProps';\nimport { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';\n\nconst styles = StyleSheet.create({\n root: {\n // @ts-ignore\n overflow: 'auto',\n position: 'relative',\n },\n});\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n loading = defaultLoading,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n style,\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSharedValue<number>(initialPage);\n\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n\n const setPage = useCallback((newIndex: number) => {\n sharedIndex.value = newIndex;\n }, [sharedIndex]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const PageComponent = pageComponent;\n\n return (\n <View style={[styles.root, style]}>\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n loading={loading}\n offscreenPageRerenderLimit={0} // All offscreen pages will not be re-rendered\n rerenderKey={pageForceRerenderKey}\n sharedIndex={sharedIndex}\n />\n ))}\n </View>\n );\n});\n\nexport default ViewPager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,mBAAtC,EAA2DC,WAA3D,QAA8E,OAA9E;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,SAASC,cAAT,QAA+B,yBAA/B;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAGA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,oBAA7C,QAAyE,SAAzE;AAEA,MAAMC,MAAM,GAAGJ,UAAU,CAACK,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IACF;IACAC,QAAQ,EAAE,MAFR;IAGFC,QAAQ,EAAE;EAHR;AADuB,CAAlB,CAAf;AAQA,MAAMC,SAAS,gBAAGd,UAAU,CAAoC,SAASc,SAAT,CAAmBC,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGZ,kBAFZ;IAGFa,OAAO,GAAGZ,cAHR;IAIFa,aAAa,GAAGZ,oBAJd;IAKFa,oBALE;IAMFC,KANE;IAOFC;EAPE,IAQFR,KARJ;EAUA,MAAMS,mBAAmB,GAAGpB,cAAc,CAASc,WAAT,CAA1C;EAEA,MAAMO,WAAW,GAAGF,oBAAoB,IAAIC,mBAA5C;EAEA,MAAME,OAAO,GAAGxB,WAAW,CAAEyB,QAAD,IAAsB;IAC9CF,WAAW,CAACG,KAAZ,GAAoBD,QAApB;EACH,CAF0B,EAExB,CAACF,WAAD,CAFwB,CAA3B;EAIAxB,mBAAmB,CACfe,GADe,EAEf,OAAO;IAAEU;EAAF,CAAP,CAFe,EAGf,CAACA,OAAD,CAHe,CAAnB;EAMA,MAAMG,aAAa,GAAGT,aAAtB;EAEA,oBACI,oBAAC,IAAD;IAAM,KAAK,EAAE,CAACX,MAAM,CAACE,IAAR,EAAcW,KAAd;EAAb,GACKvB,QAAQ,CAAC+B,GAAT,CAAab,QAAb,EAAuB,CAACc,KAAD,EAAQC,KAAR,kBACpB,oBAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,OAAO,EAAEb,OAJb;IAKI,0BAA0B,EAAE,CALhC,CAKmC;IALnC;IAMI,WAAW,EAAEE,oBANjB;IAOI,WAAW,EAAEI;EAPjB,EADH,CADL,CADJ;AAeH,CA1C2B,CAA5B;AA4CA,eAAeX,SAAf"}
1
+ {"version":3,"names":["React","Children","forwardRef","useCallback","useImperativeHandle","View","useSharedValue","StyleSheet","defaultInitialPage","defaultLoading","defaultPageComponent","styles","create","root","overflow","position","ViewPager","props","ref","children","initialPage","loading","pageComponent","pageForceRerenderKey","style","UNSTABLE_sharedPage","fallbackSharedPage","sharedPage","setPage","newPage","value","PageComponent","map","child","index"],"sources":["ViewPagerWeb.tsx"],"sourcesContent":["import React, { Children, forwardRef, useCallback, useImperativeHandle } from 'react';\nimport { View } from 'react-native';\nimport { useSharedValue } from 'react-native-reanimated';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './ViewPagerProps';\nimport { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';\n\nconst styles = StyleSheet.create({\n root: {\n // @ts-ignore\n overflow: 'auto',\n position: 'relative',\n },\n});\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n loading = defaultLoading,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n style,\n UNSTABLE_sharedPage,\n } = props;\n\n const fallbackSharedPage = useSharedValue<number>(initialPage);\n\n const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;\n\n const setPage = useCallback((newPage: number) => {\n sharedPage.value = newPage;\n }, [sharedPage]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const PageComponent = pageComponent;\n\n return (\n <View style={[styles.root, style]}>\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n loading={loading}\n offscreenPageRerenderLimit={0} // All offscreen pages will not be re-rendered\n rerenderKey={pageForceRerenderKey}\n sharedIndex={sharedPage}\n />\n ))}\n </View>\n );\n});\n\nexport default ViewPager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,WAAtC,EAAmDC,mBAAnD,QAA8E,OAA9E;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,SAASC,cAAT,QAA+B,yBAA/B;AACA,SAASC,UAAT,QAA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,CADL,CADJ;AAeH,CA1C2B,CAA5B;AA4CA,eAAeX,SAAf"}
@@ -1,6 +1,6 @@
1
1
  import type { RefObject } from 'react';
2
2
  import type { ComponentProps } from '@fountain-ui/core';
3
- import type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, RenderItem } from './types';
3
+ import type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, ItemHeight, RenderItem } from './types';
4
4
  export default interface CarouselProps<ItemT = any> extends ComponentProps<{
5
5
  ref?: RefObject<CarouselInstance>;
6
6
  /**
@@ -38,9 +38,10 @@ export default interface CarouselProps<ItemT = any> extends ComponentProps<{
38
38
  */
39
39
  initialIndex?: number;
40
40
  /**
41
- * The item width.
41
+ * The item height.
42
+ * For a performance reason, always consider to provide a number value.
42
43
  */
43
- itemHeight: number;
44
+ itemHeight: ItemHeight;
44
45
  /**
45
46
  * The item width.
46
47
  */
@@ -1,9 +1,9 @@
1
1
  import type { CreateItemStyle } from '../types';
2
2
  export interface ParallaxAnimationConfig {
3
- parallaxActiveItemScale?: number;
4
- parallaxActiveItemOpacity?: number;
5
- parallaxAdjacentItemScale?: number;
6
- parallaxAdjacentItemOpacity?: number;
7
- parallaxScrollingOffset?: number;
3
+ activeItemScale?: number;
4
+ activeItemOpacity?: number;
5
+ adjacentItemScale?: number;
6
+ adjacentItemOpacity?: number;
7
+ scrollingOffset?: number;
8
8
  }
9
9
  export default function parallaxItemStyleFactory(config?: ParallaxAnimationConfig): CreateItemStyle;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { Animated } from 'react-native';
3
- import type { CreateItemStyle, ItemVisibilityStore } from '../types';
3
+ import type { CreateItemStyle, ItemHeight, ItemVisibilityStore } from '../types';
4
4
  export interface InternalContextValue<ItemT> {
5
5
  createItemStyle: CreateItemStyle;
6
6
  data: ReadonlyArray<ItemT>;
7
7
  globalInterpolation: Animated.AnimatedInterpolation;
8
- itemHeight: number;
8
+ itemHeight: ItemHeight;
9
9
  itemWidth: number;
10
10
  itemVisibilityStore: ItemVisibilityStore;
11
11
  loop: boolean;
@@ -1,7 +1,9 @@
1
1
  import type { ReactElement } from 'react';
2
+ import type { ViewProps } from 'react-native';
2
3
  import { Animated } from 'react-native';
3
4
  export interface ItemViewProps {
4
5
  children: (interpolation: Animated.AnimatedInterpolation) => ReactElement | null;
5
6
  index: number;
7
+ onLayout?: ViewProps['onLayout'];
6
8
  }
7
9
  export default function ItemView(props: ItemViewProps): JSX.Element;
@@ -1,15 +1,15 @@
1
1
  import React from 'react';
2
- import type { ViewProps, View } from 'react-native';
3
- import type { RenderItem } from '../types';
2
+ import type { View, ViewProps } from 'react-native';
3
+ import type { ItemHeight, RenderItem } from '../types';
4
4
  export declare type RootViewProps<ItemT> = ViewProps & {
5
5
  data: ReadonlyArray<ItemT>;
6
- itemHeight: number;
6
+ itemHeight: ItemHeight;
7
7
  originalData: ReadonlyArray<ItemT>;
8
8
  renderItem: RenderItem<ItemT>;
9
9
  };
10
10
  declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<ViewProps & {
11
11
  data: readonly any[];
12
- itemHeight: number;
12
+ itemHeight: ItemHeight;
13
13
  originalData: readonly any[];
14
14
  renderItem: RenderItem<any>;
15
15
  } & React.RefAttributes<View>>>;
@@ -7,6 +7,6 @@ export interface ScrollViewGestureProps {
7
7
  finalizeAnimation: () => void;
8
8
  offsetTx: Animated.Value;
9
9
  scrollEnabled: boolean;
10
- startAnimation: StartPagingAnimation;
10
+ startPagingAnimation: StartPagingAnimation;
11
11
  }
12
12
  export default function ScrollViewGesture(props: ScrollViewGestureProps): JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { Animated } from 'react-native';
2
2
  import type { CreateScrollAnimation, GetCurrentIndex, StartPagingAnimation } from '../types';
3
- export interface PagingAnimationConfig {
3
+ export interface PagingAnimationParameters {
4
4
  controlledTx: Animated.Value;
5
5
  createScrollAnimation: CreateScrollAnimation;
6
6
  getCurrentIndex: GetCurrentIndex;
@@ -13,6 +13,6 @@ export interface PagingAnimationConfig {
13
13
  export interface UsePagingAnimation {
14
14
  finalizeAnimation: () => void;
15
15
  globalInterpolation: Animated.AnimatedInterpolation;
16
- startAnimation: StartPagingAnimation;
16
+ startPagingAnimation: StartPagingAnimation;
17
17
  }
18
- export default function usePagingAnimation(config: PagingAnimationConfig): UsePagingAnimation;
18
+ export default function usePagingAnimation(params: PagingAnimationParameters): UsePagingAnimation;