@fountain-ui/lab 2.0.0-beta.16 → 2.0.0-beta.19

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 (58) hide show
  1. package/build/commonjs/Carousel/Carousel.js +11 -20
  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/components/ItemView.js +2 -2
  5. package/build/commonjs/Carousel/components/ItemView.js.map +1 -1
  6. package/build/commonjs/Carousel/components/ScrollViewGesture.js +4 -3
  7. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -1
  8. package/build/commonjs/Carousel/hooks/index.js +3 -3
  9. package/build/commonjs/Carousel/hooks/index.js.map +1 -1
  10. package/build/commonjs/Carousel/hooks/useIndexController.js +28 -21
  11. package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -1
  12. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +3 -3
  13. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -1
  14. package/build/commonjs/Carousel/hooks/{usePagingAnimation.js → usePagingAnimator.js} +44 -22
  15. package/build/commonjs/Carousel/hooks/usePagingAnimator.js.map +1 -0
  16. package/build/commonjs/Carousel/types.js +1 -1
  17. package/build/commonjs/Carousel/types.js.map +1 -1
  18. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +1 -1
  19. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  20. package/build/module/Carousel/Carousel.js +13 -19
  21. package/build/module/Carousel/Carousel.js.map +1 -1
  22. package/build/module/Carousel/CarouselProps.js.map +1 -1
  23. package/build/module/Carousel/components/ItemView.js +2 -2
  24. package/build/module/Carousel/components/ItemView.js.map +1 -1
  25. package/build/module/Carousel/components/ScrollViewGesture.js +4 -3
  26. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -1
  27. package/build/module/Carousel/hooks/index.js +1 -1
  28. package/build/module/Carousel/hooks/index.js.map +1 -1
  29. package/build/module/Carousel/hooks/useIndexController.js +28 -22
  30. package/build/module/Carousel/hooks/useIndexController.js.map +1 -1
  31. package/build/module/Carousel/hooks/useItemVisibilityStore.js +3 -3
  32. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -1
  33. package/build/module/Carousel/hooks/{usePagingAnimation.js → usePagingAnimator.js} +43 -22
  34. package/build/module/Carousel/hooks/usePagingAnimator.js.map +1 -0
  35. package/build/module/Carousel/types.js +1 -1
  36. package/build/module/Carousel/types.js.map +1 -1
  37. package/build/module/ViewPager/ChildrenMemoizedPage.js +1 -1
  38. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  39. package/build/typescript/Carousel/CarouselProps.d.ts +2 -2
  40. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +1 -1
  41. package/build/typescript/Carousel/hooks/index.d.ts +1 -1
  42. package/build/typescript/Carousel/hooks/useIndexController.d.ts +3 -1
  43. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +2 -5
  44. package/build/typescript/Carousel/hooks/{usePagingAnimation.d.ts → usePagingAnimator.d.ts} +6 -5
  45. package/build/typescript/Carousel/types.d.ts +14 -4
  46. package/package.json +2 -2
  47. package/src/Carousel/Carousel.tsx +12 -20
  48. package/src/Carousel/CarouselProps.ts +9 -2
  49. package/src/Carousel/components/ItemView.tsx +2 -2
  50. package/src/Carousel/components/ScrollViewGesture.tsx +8 -4
  51. package/src/Carousel/hooks/index.ts +1 -1
  52. package/src/Carousel/hooks/useIndexController.tsx +29 -26
  53. package/src/Carousel/hooks/useItemVisibilityStore.ts +5 -9
  54. package/src/Carousel/hooks/{usePagingAnimation.ts → usePagingAnimator.ts} +48 -29
  55. package/src/Carousel/types.ts +17 -4
  56. package/src/ViewPager/ChildrenMemoizedPage.tsx +1 -1
  57. package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +0 -1
  58. package/build/module/Carousel/hooks/usePagingAnimation.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useMemo","useRef","Animated","directionToValue","itemWidth","direction","toValueCompensator","toValue","currentOffset","remainder","Math","abs","halfOfItemWidth","compensateVector","usePagingAnimator","config","createScrollAnimation","indexController","initialIndex","loop","numberOfData","getCurrentIndex","lastIndex","notifyScrollStateHasChanged","initialOffsetX","accumulativeOffsetX","Value","current","animationOffsetX","gestureTranslationX","globalInterpolation","add","toValueRef","currentOffsetRef","isAnimatingRef","maxWidth","ensureOffsetBoundary","offset","isCloseToEnd","signOfOffset","requireNewOffset","newOffset","nextOffset","setValue","interruptAnimation","stopAnimation","lastValue","prevOffset","totalOffset","state","finalizeAnimation","startPagingAnimation","type","configWithDefaults","animated","currentIndex","getValueByDirectionOnAllAdjacentItemsVisible","compensateToValue","getValueByDirectionalPagingOnLoopDisabled","_config","isOriginatedFromGesture","getValueByDirectionalPaging","_configWithDefaults","getValueByIndexPaging","index","distance","wantedToValue","lastGestureTranslationX","Number","isFinite","animation","start","finished"],"sources":["usePagingAnimator.ts"],"sourcesContent":["import { useCallback, useMemo, 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 PagingAnimatorConfig {\n createScrollAnimation: CreateScrollAnimation;\n itemWidth: number;\n indexController: IndexController;\n initialIndex: number;\n loop: boolean;\n numberOfData: number;\n}\n\nexport interface PagingAnimator {\n gestureTranslationX: Animated.Value;\n globalInterpolation: Animated.AnimatedInterpolation;\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 usePagingAnimator(config: PagingAnimatorConfig): PagingAnimator {\n const {\n createScrollAnimation,\n itemWidth,\n indexController,\n initialIndex,\n loop,\n numberOfData,\n } = config;\n\n const {\n getCurrentIndex,\n lastIndex,\n notifyScrollStateHasChanged,\n } = indexController;\n\n const initialOffsetX = itemWidth * initialIndex;\n const accumulativeOffsetX = useRef(new Animated.Value(initialOffsetX)).current;\n const animationOffsetX = useRef(new Animated.Value(0)).current;\n const gestureTranslationX = useRef(new Animated.Value(0)).current;\n\n const globalInterpolation = useMemo(() => {\n return Animated.add(\n Animated.add(accumulativeOffsetX, animationOffsetX),\n gestureTranslationX,\n );\n }, []);\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 accumulativeOffsetX.setValue(nextOffset);\n\n toValueRef.current = 0;\n animationOffsetX.setValue(0);\n }, [\n ensureOffsetBoundary,\n ]);\n\n const interruptAnimation = useCallback(() => {\n if (!isAnimatingRef.current) {\n return;\n }\n\n animationOffsetX.stopAnimation(lastValue => {\n isAnimatingRef.current = false;\n\n const prevOffset = currentOffsetRef.current;\n const totalOffset = prevOffset + lastValue;\n\n requireNewOffset(totalOffset);\n\n notifyScrollStateHasChanged({ offset: totalOffset, state: 'interrupted' });\n });\n }, [\n notifyScrollStateHasChanged,\n requireNewOffset,\n ]);\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\n notifyScrollStateHasChanged({ offset: totalOffset, state: 'idle' });\n }, [\n notifyScrollStateHasChanged,\n requireNewOffset,\n ]);\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 notifyScrollStateHasChanged({\n offset: currentOffsetRef.current + toValue,\n state: 'dragging',\n });\n\n const lastGestureTranslationX: number = configWithDefaults.lastGestureTranslationX ?? 0;\n if (Number.isFinite(lastGestureTranslationX)) {\n animationOffsetX.setValue(lastGestureTranslationX);\n gestureTranslationX.setValue(0);\n }\n\n if (configWithDefaults.animated) {\n const animation = createScrollAnimation(animationOffsetX, toValue);\n\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 notifyScrollStateHasChanged,\n ]);\n\n return {\n gestureTranslationX,\n globalInterpolation,\n interruptAnimation,\n startPagingAnimation,\n };\n};\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,OAAtB,EAA+BC,MAA/B,QAA6C,OAA7C;AACA,SAASC,QAAT,QAAyB,cAAzB;;AA4BA,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,SAASE,kBAAT,CAA4BF,SAA5B,EAA+C;EAC3C,OAAO,UAAUG,OAAV,EAA2BC,aAA3B,EAA0D;IAC7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,CAACL,OAAX,GAAqBpB,OAArB;IACA2B,cAAc,CAACP,OAAf,GAAyB,IAAzB;IAEAJ,2BAA2B,CAAC;MACxBc,MAAM,EAAEJ,gBAAgB,CAACN,OAAjB,GAA2BpB,OADX;MAExB0C,KAAK,EAAE;IAFiB,CAAD,CAA3B;IAKA,MAAMkB,uBAA+B,GAAGd,kBAAkB,CAACc,uBAAnB,IAA8C,CAAtF;;IACA,IAAIC,MAAM,CAACC,QAAP,CAAgBF,uBAAhB,CAAJ,EAA8C;MAC1CvC,gBAAgB,CAACe,QAAjB,CAA0BwB,uBAA1B;MACAtC,mBAAmB,CAACc,QAApB,CAA6B,CAA7B;IACH;;IAED,IAAIU,kBAAkB,CAACC,QAAvB,EAAiC;MAC7B,MAAMgB,SAAS,GAAGtD,qBAAqB,CAACY,gBAAD,EAAmBrB,OAAnB,CAAvC;MAEA+D,SAAS,CAACC,KAAV,CAAgB,SAAkB;QAAA,IAAjB;UAAEC;QAAF,CAAiB;;QAC9B,IAAIA,QAAJ,EAAc;UACVtB,iBAAiB;QACpB;MACJ,CAJD;IAKH,CARD,MAQO;MACHA,iBAAiB;IACpB;EACJ,CAtFuC,EAsFrC,CACClC,qBADD,EAECK,eAFD,EAGC6B,iBAHD,EAIC9C,SAJD,EAKCkB,SALD,EAMCH,IAND,EAOCI,2BAPD,CAtFqC,CAAxC;EAgGA,OAAO;IACHM,mBADG;IAEHC,mBAFG;IAGHc,kBAHG;IAIHO;EAJG,CAAP;AAMH;AAAA"}
@@ -1,4 +1,4 @@
1
1
  const directions = ['next', 'prev', 'stay'];
2
- const animationStates = ['started', 'finished', 'interrupted'];
2
+ const scrollStates = ['idle', 'dragging', 'interrupted'];
3
3
  export {};
4
4
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["directions","animationStates"],"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\nconst animationStates = ['started', 'finished', 'interrupted'] as const;\n\nexport type AnimationState = (typeof animationStates)[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 notifyAnimationState: (state: AnimationState) => void;\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;AAIA,MAAMC,eAAe,GAAG,CAAC,SAAD,EAAY,UAAZ,EAAwB,aAAxB,CAAxB"}
1
+ {"version":3,"names":["directions","scrollStates"],"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\nconst scrollStates = ['idle', 'dragging', 'interrupted'] as const;\n\nexport type ScrollState = (typeof scrollStates)[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 OnIndexChange {\n (itemIndex: number): void;\n}\n\nexport interface OnPositionChange {\n (position: number): void;\n}\n\nexport interface ScrollStateChangeEvent {\n offset: number;\n state: ScrollState;\n}\n\nexport interface IndexController {\n getCurrentIndex: GetCurrentIndex;\n lastIndex: number;\n notifyScrollStateHasChanged: (event: ScrollStateChangeEvent) => void;\n}\n\nexport type PagingAnimationType = 'directional' | 'index';\n\nexport interface BasePagingAnimationConfig {\n animated?: boolean;\n lastGestureTranslationX?: number;\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;AAIA,MAAMC,YAAY,GAAG,CAAC,MAAD,EAAS,UAAT,EAAqB,aAArB,CAArB"}
@@ -95,6 +95,6 @@ export default /*#__PURE__*/memo(Page, (prevProps, nextProps) => {
95
95
  return false;
96
96
  }
97
97
 
98
- return prevProps.index !== nextProps.index;
98
+ return prevProps.index === nextProps.index;
99
99
  });
100
100
  //# sourceMappingURL=ChildrenMemoizedPage.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","memo","useCallback","useContext","useEffect","useMemo","useReducer","useRef","useState","Platform","View","StyleSheet","PageStateContext","InternalContext","styles","create","fill","width","height","none","display","Page","props","index","initialPage","children","loading","offscreenPageRerenderLimit","pageStore","computePageDescription","page","activeIndex","isActive","shouldRerender","becomeNeighbor","initialState","active","loaded","pageStateRef","forceRender","s","current","content","subscribe","newPage","currentState","newState","contextValue","style","OS","absoluteFill","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from 'react';\nimport { Platform, View } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { PageProps } from './types';\nimport PageStateContext from './PageStateContext';\nimport InternalContext from './InternalContext';\n\nconst styles = StyleSheet.create({\n fill: { width: '100%', height: '100%' },\n none: { display: 'none' },\n});\n\ninterface InternalPageDescription {\n isActive: boolean;\n becomeNeighbor: boolean;\n}\n\ninterface InternalPageState {\n active: boolean;\n loaded: boolean;\n}\n\nfunction Page(props: PageProps) {\n const {\n index,\n initialPage,\n children,\n loading,\n offscreenPageRerenderLimit,\n } = props;\n\n const { pageStore } = useContext(InternalContext);\n\n const computePageDescription: (page: number) => InternalPageDescription = useCallback((page: number) => {\n const activeIndex = page;\n\n const isActive = index === activeIndex;\n\n const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n const becomeNeighbor = shouldRerender && !isActive;\n\n return { isActive, becomeNeighbor };\n }, [index]);\n\n const [initialState] = useState<InternalPageState>(() => {\n const { isActive, becomeNeighbor } = computePageDescription(initialPage);\n\n if (loading === 'eager') {\n return { active: isActive, loaded: true };\n }\n\n return { active: isActive, loaded: isActive || becomeNeighbor };\n });\n\n // `Bailing out of a state update` is not working as expected.\n const pageStateRef = useRef<InternalPageState>(initialState);\n const [, forceRender] = useReducer((s) => s + 1, 0);\n\n const { active, loaded } = pageStateRef.current;\n\n const content = loaded ? children : null;\n\n useEffect(() => {\n return pageStore.subscribe(newPage => {\n const { isActive, becomeNeighbor } = computePageDescription(newPage);\n\n const currentState = pageStateRef.current;\n\n const newState: InternalPageState = {\n active: isActive,\n loaded: isActive || becomeNeighbor ? true : currentState.loaded,\n };\n\n if (\n currentState.active !== newState.active\n || currentState.loaded !== newState.loaded\n ) {\n pageStateRef.current = newState;\n\n forceRender();\n }\n });\n }, [pageStore, computePageDescription]);\n\n const contextValue = useMemo(() => ({\n isActive: active,\n }), [active]);\n\n const style = Platform.OS === 'web'\n ? (active ? StyleSheet.absoluteFill : styles.none)\n : styles.fill;\n\n return (\n <View\n collapsable={false}\n style={style}\n >\n <PageStateContext.Provider value={contextValue}>\n {content}\n </PageStateContext.Provider>\n </View>\n );\n}\n\nexport default memo(Page, (prevProps, nextProps) => {\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.index !== nextProps.index;\n});\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,IAAhB,EAAsBC,WAAtB,EAAmCC,UAAnC,EAA+CC,SAA/C,EAA0DC,OAA1D,EAAmEC,UAAnE,EAA+EC,MAA/E,EAAuFC,QAAvF,QAAuG,OAAvG;AACA,SAASC,QAAT,EAAmBC,IAAnB,QAA+B,cAA/B;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,MAAMC,MAAM,GAAGH,UAAU,CAACI,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IAAEC,KAAK,EAAE,MAAT;IAAiBC,MAAM,EAAE;EAAzB,CADuB;EAE7BC,IAAI,EAAE;IAAEC,OAAO,EAAE;EAAX;AAFuB,CAAlB,CAAf;;AAeA,SAASC,IAAT,CAAcC,KAAd,EAAgC;EAC5B,MAAM;IACFC,KADE;IAEFC,WAFE;IAGFC,QAHE;IAIFC,OAJE;IAKFC;EALE,IAMFL,KANJ;EAQA,MAAM;IAAEM;EAAF,IAAgBzB,UAAU,CAACU,eAAD,CAAhC;EAEA,MAAMgB,sBAAiE,GAAG3B,WAAW,CAAE4B,IAAD,IAAkB;IACpG,MAAMC,WAAW,GAAGD,IAApB;IAEA,MAAME,QAAQ,GAAGT,KAAK,KAAKQ,WAA3B;IAEA,MAAME,cAAc,GAAGV,KAAK,IAAIQ,WAAW,GAAGJ,0BAAvB,IAChBJ,KAAK,I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AjC,IACGS,YAAY,CAACR,MAAb,KAAwBS,QAAQ,CAACT,MAFxC,EAGE;QACEC,YAAY,CAACG,OAAb,GAAuBK,QAAvB;QAEAP,WAAW;MACd;IACJ,CAlBM,CAAP;EAmBH,CApBQ,EAoBN,CAACX,SAAD,EAAYC,sBAAZ,CApBM,CAAT;EAsBA,MAAMkB,YAAY,GAAG1C,OAAO,CAAC,OAAO;IAChC2B,QAAQ,EAAEI;EADsB,CAAP,CAAD,EAExB,CAACA,MAAD,CAFwB,CAA5B;EAIA,MAAMY,KAAK,GAAGvC,QAAQ,CAACwC,EAAT,KAAgB,KAAhB,GACPb,MAAM,GAAGzB,UAAU,CAACuC,YAAd,GAA6BpC,MAAM,CAACK,IADnC,GAERL,MAAM,CAACE,IAFb;EAIA,oBACI,oBAAC,IAAD;IACI,WAAW,EAAE,KADjB;IAEI,KAAK,EAAEgC;EAFX,gBAII,oBAAC,gBAAD,CAAkB,QAAlB;IAA2B,KAAK,EAAED;EAAlC,GACKL,OADL,CAJJ,CADJ;AAUH;;AAED,4BAAezC,IAAI,CAACoB,IAAD,EAAO,CAAC8B,SAAD,EAAYC,SAAZ,KAA0B;EAChD,IAAID,SAAS,CAACE,WAAV,KAA0BD,SAAS,CAACC,WAAxC,EAAqD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOF,SAAS,CAAC5B,KAAV,KAAoB6B,SAAS,CAAC7B,KAArC;AACH,CANkB,CAAnB"}
1
+ {"version":3,"names":["React","memo","useCallback","useContext","useEffect","useMemo","useReducer","useRef","useState","Platform","View","StyleSheet","PageStateContext","InternalContext","styles","create","fill","width","height","none","display","Page","props","index","initialPage","children","loading","offscreenPageRerenderLimit","pageStore","computePageDescription","page","activeIndex","isActive","shouldRerender","becomeNeighbor","initialState","active","loaded","pageStateRef","forceRender","s","current","content","subscribe","newPage","currentState","newState","contextValue","style","OS","absoluteFill","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from 'react';\nimport { Platform, View } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { PageProps } from './types';\nimport PageStateContext from './PageStateContext';\nimport InternalContext from './InternalContext';\n\nconst styles = StyleSheet.create({\n fill: { width: '100%', height: '100%' },\n none: { display: 'none' },\n});\n\ninterface InternalPageDescription {\n isActive: boolean;\n becomeNeighbor: boolean;\n}\n\ninterface InternalPageState {\n active: boolean;\n loaded: boolean;\n}\n\nfunction Page(props: PageProps) {\n const {\n index,\n initialPage,\n children,\n loading,\n offscreenPageRerenderLimit,\n } = props;\n\n const { pageStore } = useContext(InternalContext);\n\n const computePageDescription: (page: number) => InternalPageDescription = useCallback((page: number) => {\n const activeIndex = page;\n\n const isActive = index === activeIndex;\n\n const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n const becomeNeighbor = shouldRerender && !isActive;\n\n return { isActive, becomeNeighbor };\n }, [index]);\n\n const [initialState] = useState<InternalPageState>(() => {\n const { isActive, becomeNeighbor } = computePageDescription(initialPage);\n\n if (loading === 'eager') {\n return { active: isActive, loaded: true };\n }\n\n return { active: isActive, loaded: isActive || becomeNeighbor };\n });\n\n // `Bailing out of a state update` is not working as expected.\n const pageStateRef = useRef<InternalPageState>(initialState);\n const [, forceRender] = useReducer((s) => s + 1, 0);\n\n const { active, loaded } = pageStateRef.current;\n\n const content = loaded ? children : null;\n\n useEffect(() => {\n return pageStore.subscribe(newPage => {\n const { isActive, becomeNeighbor } = computePageDescription(newPage);\n\n const currentState = pageStateRef.current;\n\n const newState: InternalPageState = {\n active: isActive,\n loaded: isActive || becomeNeighbor ? true : currentState.loaded,\n };\n\n if (\n currentState.active !== newState.active\n || currentState.loaded !== newState.loaded\n ) {\n pageStateRef.current = newState;\n\n forceRender();\n }\n });\n }, [pageStore, computePageDescription]);\n\n const contextValue = useMemo(() => ({\n isActive: active,\n }), [active]);\n\n const style = Platform.OS === 'web'\n ? (active ? StyleSheet.absoluteFill : styles.none)\n : styles.fill;\n\n return (\n <View\n collapsable={false}\n style={style}\n >\n <PageStateContext.Provider value={contextValue}>\n {content}\n </PageStateContext.Provider>\n </View>\n );\n}\n\nexport default memo(Page, (prevProps, nextProps) => {\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.index === nextProps.index;\n});\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,IAAhB,EAAsBC,WAAtB,EAAmCC,UAAnC,EAA+CC,SAA/C,EAA0DC,OAA1D,EAAmEC,UAAnE,EAA+EC,MAA/E,EAAuFC,QAAvF,QAAuG,OAAvG;AACA,SAASC,QAAT,EAAmBC,IAAnB,QAA+B,cAA/B;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,MAAMC,MAAM,GAAGH,UAAU,CAACI,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IAAEC,KAAK,EAAE,MAAT;IAAiBC,MAAM,EAAE;EAAzB,CADuB;EAE7BC,IAAI,EAAE;IAAEC,OAAO,EAAE;EAAX;AAFuB,CAAlB,CAAf;;AAeA,SAASC,IAAT,CAAcC,KAAd,EAAgC;EAC5B,MAAM;IACFC,KADE;IAEFC,WAFE;IAGFC,QAHE;IAIFC,OAJE;IAKFC;EALE,IAMFL,KANJ;EAQA,MAAM;IAAEM;EAAF,IAAgBzB,UAAU,CAACU,eAAD,CAAhC;EAEA,MAAMgB,sBAAiE,GAAG3B,WAAW,CAAE4B,IAAD,IAAkB;IACpG,MAAMC,WAAW,GAAGD,IAApB;IAEA,MAAME,QAAQ,GAAGT,KAAK,KAAKQ,WAA3B;IAEA,MAAME,cAAc,GAAGV,KAAK,IAAIQ,WAAW,GAAGJ,0BAAvB,IAChBJ,KAAK,IAAIQ,WAAW,GAAGJ,0BAD9B;IAGA,MAAMO,cAAc,GAAG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xC,EAGE;QACEC,YAAY,CAACG,OAAb,GAAuBK,QAAvB;QAEAP,WAAW;MACd;IACJ,CAlBM,CAAP;EAmBH,CApBQ,EAoBN,CAACX,SAAD,EAAYC,sBAAZ,CApBM,CAAT;EAsBA,MAAMkB,YAAY,GAAG1C,OAAO,CAAC,OAAO;IAChC2B,QAAQ,EAAEI;EADsB,CAAP,CAAD,EAExB,CAACA,MAAD,CAFwB,CAA5B;EAIA,MAAMY,KAAK,GAAGvC,QAAQ,CAACwC,EAAT,KAAgB,KAAhB,GACPb,MAAM,GAAGzB,UAAU,CAACuC,YAAd,GAA6BpC,MAAM,CAACK,IADnC,GAERL,MAAM,CAACE,IAFb;EAIA,oBACI,oBAAC,IAAD;IACI,WAAW,EAAE,KADjB;IAEI,KAAK,EAAEgC;EAFX,gBAII,oBAAC,gBAAD,CAAkB,QAAlB;IAA2B,KAAK,EAAED;EAAlC,GACKL,OADL,CAJJ,CADJ;AAUH;;AAED,4BAAezC,IAAI,CAACoB,IAAD,EAAO,CAAC8B,SAAD,EAAYC,SAAZ,KAA0B;EAChD,IAAID,SAAS,CAACE,WAAV,KAA0BD,SAAS,CAACC,WAAxC,EAAqD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOF,SAAS,CAAC5B,KAAV,KAAoB6B,SAAS,CAAC7B,KAArC;AACH,CANkB,CAAnB"}
@@ -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, ItemHeight, RenderItem } from './types';
3
+ import type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, ItemHeight, OnIndexChange, RenderItem } from './types';
4
4
  export default interface CarouselProps<ItemT = any> extends ComponentProps<{
5
5
  ref?: RefObject<CarouselInstance>;
6
6
  /**
@@ -54,7 +54,7 @@ export default interface CarouselProps<ItemT = any> extends ComponentProps<{
54
54
  /**
55
55
  * Callback fired when an index is changed.
56
56
  */
57
- onIndexChange?: (newIndex: number) => void;
57
+ onIndexChange?: OnIndexChange;
58
58
  /**
59
59
  * Takes an item from data and renders it into the list.
60
60
  */
@@ -4,8 +4,8 @@ import type { AutoplayController, StartPagingAnimation } from '../types';
4
4
  export interface ScrollViewGestureProps {
5
5
  autoplayController: AutoplayController;
6
6
  children: ReactNode;
7
+ gestureTranslationX: Animated.Value;
7
8
  interruptAnimation: () => void;
8
- translateX: Animated.Value;
9
9
  scrollEnabled: boolean;
10
10
  startPagingAnimation: StartPagingAnimation;
11
11
  }
@@ -1,5 +1,5 @@
1
1
  export { default as useAutoplayController } from './useAutoplayController';
2
2
  export { default as useIndexController } from './useIndexController';
3
3
  export { default as useLoopedData } from './useLoopedData';
4
- export { default as usePagingAnimation } from './usePagingAnimation';
4
+ export { default as usePagingAnimator } from './usePagingAnimator';
5
5
  export { default as useItemVisibilityStore } from './useItemVisibilityStore';
@@ -2,7 +2,9 @@ import type { IndexController } from '../types';
2
2
  export interface UseIndexControllerParameters {
3
3
  initialIndex: number;
4
4
  itemWidth: number;
5
+ numberOfData: number;
5
6
  numberOfOriginalData: number;
6
- onIndexChange?: (newIndex: number) => void;
7
+ onIndexChange?: (itemIndex: number) => void;
8
+ onPositionChange?: (position: number) => void;
7
9
  }
8
10
  export default function useIndexController(params: UseIndexControllerParameters): IndexController;
@@ -1,10 +1,7 @@
1
- import type { ItemVisibilityStore } from '../types';
1
+ import type { ItemVisibilityStore, OnPositionChange } from '../types';
2
2
  export interface Parameters {
3
3
  initialIndex: number;
4
4
  numberOfData: number;
5
5
  windowSize: number;
6
6
  }
7
- export interface OnIndexChange {
8
- (newIndex: number): void;
9
- }
10
- export default function useItemVisibilityStore(params: Parameters): [ItemVisibilityStore, OnIndexChange];
7
+ export default function useItemVisibilityStore(params: Parameters): [ItemVisibilityStore, OnPositionChange];
@@ -1,16 +1,17 @@
1
1
  import { Animated } from 'react-native';
2
2
  import type { CreateScrollAnimation, IndexController, StartPagingAnimation } from '../types';
3
- export interface PagingAnimationParameters {
3
+ export interface PagingAnimatorConfig {
4
4
  createScrollAnimation: CreateScrollAnimation;
5
5
  itemWidth: number;
6
6
  indexController: IndexController;
7
+ initialIndex: number;
7
8
  loop: boolean;
8
9
  numberOfData: number;
9
- offsetX: Animated.Value;
10
- translateX: Animated.Value;
11
10
  }
12
- export interface UsePagingAnimation {
11
+ export interface PagingAnimator {
12
+ gestureTranslationX: Animated.Value;
13
+ globalInterpolation: Animated.AnimatedInterpolation;
13
14
  interruptAnimation: () => void;
14
15
  startPagingAnimation: StartPagingAnimation;
15
16
  }
16
- export default function usePagingAnimation(params: PagingAnimationParameters): UsePagingAnimation;
17
+ export default function usePagingAnimator(config: PagingAnimatorConfig): PagingAnimator;
@@ -2,8 +2,8 @@ import type { ReactElement } from 'react';
2
2
  import type { Animated, ViewProps } from 'react-native';
3
3
  declare const directions: readonly ["next", "prev", "stay"];
4
4
  export declare type PagingDirection = (typeof directions)[number];
5
- declare const animationStates: readonly ["started", "finished", "interrupted"];
6
- export declare type AnimationState = (typeof animationStates)[number];
5
+ declare const scrollStates: readonly ["idle", "dragging", "interrupted"];
6
+ export declare type ScrollState = (typeof scrollStates)[number];
7
7
  export declare type ItemHeight = number | 'auto';
8
8
  export interface RenderItem<T> {
9
9
  (info: {
@@ -21,15 +21,25 @@ export interface CreateItemStyle {
21
21
  export interface GetCurrentIndex {
22
22
  (): number;
23
23
  }
24
+ export interface OnIndexChange {
25
+ (itemIndex: number): void;
26
+ }
27
+ export interface OnPositionChange {
28
+ (position: number): void;
29
+ }
30
+ export interface ScrollStateChangeEvent {
31
+ offset: number;
32
+ state: ScrollState;
33
+ }
24
34
  export interface IndexController {
25
35
  getCurrentIndex: GetCurrentIndex;
26
36
  lastIndex: number;
27
- notifyAnimationState: (state: AnimationState) => void;
28
- notifyOffsetHasChanged: (offset: number) => void;
37
+ notifyScrollStateHasChanged: (event: ScrollStateChangeEvent) => void;
29
38
  }
30
39
  export declare type PagingAnimationType = 'directional' | 'index';
31
40
  export interface BasePagingAnimationConfig {
32
41
  animated?: boolean;
42
+ lastGestureTranslationX?: number;
33
43
  }
34
44
  export interface DirectionalPagingAnimationConfig extends BasePagingAnimationConfig {
35
45
  direction: PagingDirection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fountain-ui/lab",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.19",
4
4
  "private": false,
5
5
  "author": "Fountain-UI Team",
6
6
  "description": "Incubator for Fountain-UI React components.",
@@ -70,5 +70,5 @@
70
70
  "publishConfig": {
71
71
  "access": "public"
72
72
  },
73
- "gitHead": "44c50a4474a3bca589e8cedd3ff476927e12061c"
73
+ "gitHead": "d18fb7ba86bc8aa042122e5321b9c26381bd5d5f"
74
74
  }
@@ -1,5 +1,4 @@
1
- import React, { forwardRef, memo, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
2
- import { Animated } from 'react-native';
1
+ import React, { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
3
2
  import ViewabilityTrackerView from '../ViewabilityTrackerView';
4
3
  import type CarouselProps from './CarouselProps';
5
4
  import type { CarouselInstance } from './types';
@@ -8,7 +7,7 @@ import {
8
7
  useIndexController,
9
8
  useItemVisibilityStore,
10
9
  useLoopedData,
11
- usePagingAnimation,
10
+ usePagingAnimator,
12
11
  } from './hooks';
13
12
  import { createDefaultItemStyle, createDefaultScrollAnimation } from './animation';
14
13
  import { InternalContext, RootView, ScrollViewGesture } from './components';
@@ -25,7 +24,7 @@ const Carousel = forwardRef<CarouselInstance, CarouselProps>(function Carousel(p
25
24
  itemHeight,
26
25
  itemWidth,
27
26
  loop = false,
28
- onIndexChange: onIndexChangeProp,
27
+ onIndexChange,
29
28
  renderItem,
30
29
  scrollEnabled = true,
31
30
  style,
@@ -34,42 +33,35 @@ const Carousel = forwardRef<CarouselInstance, CarouselProps>(function Carousel(p
34
33
 
35
34
  const data = useLoopedData(originalData, loop);
36
35
 
37
- const initialTx = itemWidth * initialIndex;
38
- const offsetX = useRef(new Animated.Value(initialTx)).current;
39
- const translateX = useRef(new Animated.Value(0)).current;
40
- const globalInterpolation = Animated.add(offsetX, translateX);
41
-
42
- const [itemVisibilityStore, onIndexChange] = useItemVisibilityStore({
36
+ const [itemVisibilityStore, onPositionChange] = useItemVisibilityStore({
43
37
  initialIndex,
44
38
  numberOfData: data.length,
45
39
  windowSize,
46
40
  });
47
41
 
48
- const handleIndexChange = useCallback((newIndex: number) => {
49
- onIndexChange(newIndex);
50
- onIndexChangeProp?.(newIndex);
51
- }, [onIndexChange, onIndexChangeProp]);
52
-
53
42
  const indexController = useIndexController({
54
43
  initialIndex,
55
44
  itemWidth,
45
+ numberOfData: data.length,
56
46
  numberOfOriginalData: originalData.length,
57
- onIndexChange: handleIndexChange,
47
+ onIndexChange,
48
+ onPositionChange,
58
49
  });
59
50
 
60
51
  const { getCurrentIndex } = indexController;
61
52
 
62
53
  const {
54
+ gestureTranslationX,
55
+ globalInterpolation,
63
56
  interruptAnimation,
64
57
  startPagingAnimation,
65
- } = usePagingAnimation({
58
+ } = usePagingAnimator({
66
59
  createScrollAnimation,
67
60
  itemWidth,
68
61
  indexController,
62
+ initialIndex,
69
63
  loop,
70
64
  numberOfData: data.length,
71
- offsetX,
72
- translateX,
73
65
  });
74
66
 
75
67
  const autoplayController = useAutoplayController({
@@ -122,8 +114,8 @@ const Carousel = forwardRef<CarouselInstance, CarouselProps>(function Carousel(p
122
114
  >
123
115
  <ScrollViewGesture
124
116
  autoplayController={autoplayController}
117
+ gestureTranslationX={gestureTranslationX}
125
118
  interruptAnimation={interruptAnimation}
126
- translateX={translateX}
127
119
  scrollEnabled={scrollEnabled}
128
120
  startPagingAnimation={startPagingAnimation}
129
121
  >
@@ -1,6 +1,13 @@
1
1
  import type { RefObject } from 'react';
2
2
  import type { ComponentProps } from '@fountain-ui/core';
3
- import type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, ItemHeight, RenderItem } from './types';
3
+ import type {
4
+ CarouselInstance,
5
+ CreateItemStyle,
6
+ CreateScrollAnimation,
7
+ ItemHeight,
8
+ OnIndexChange,
9
+ RenderItem,
10
+ } from './types';
4
11
 
5
12
  export default interface CarouselProps<ItemT = any> extends ComponentProps<{
6
13
  ref?: RefObject<CarouselInstance>;
@@ -66,7 +73,7 @@ export default interface CarouselProps<ItemT = any> extends ComponentProps<{
66
73
  /**
67
74
  * Callback fired when an index is changed.
68
75
  */
69
- onIndexChange?: (newIndex: number) => void;
76
+ onIndexChange?: OnIndexChange;
70
77
 
71
78
  /**
72
79
  * Takes an item from data and renders it into the list.
@@ -32,7 +32,7 @@ export default function ItemView(props: ItemViewProps) {
32
32
 
33
33
  const itemStyle = useMemo(
34
34
  () => createItemStyle(interpolation, itemWidth),
35
- [createItemStyle, interpolation],
35
+ [createItemStyle, interpolation, itemWidth],
36
36
  );
37
37
 
38
38
  useEffect(() => {
@@ -40,7 +40,7 @@ export default function ItemView(props: ItemViewProps) {
40
40
  const nextVisible = ranges.some(([from, to]) => index >= from && index <= to);
41
41
  setVisible(nextVisible);
42
42
  });
43
- }, [itemVisibilityStore]);
43
+ }, [index, itemVisibilityStore]);
44
44
 
45
45
  return (
46
46
  <Animated.View
@@ -8,8 +8,8 @@ import type { AutoplayController, PagingDirection, StartPagingAnimation } from '
8
8
  export interface ScrollViewGestureProps {
9
9
  autoplayController: AutoplayController;
10
10
  children: ReactNode;
11
+ gestureTranslationX: Animated.Value,
11
12
  interruptAnimation: () => void;
12
- translateX: Animated.Value,
13
13
  scrollEnabled: boolean;
14
14
  startPagingAnimation: StartPagingAnimation;
15
15
  }
@@ -40,7 +40,7 @@ export default function ScrollViewGesture(props: ScrollViewGestureProps) {
40
40
  autoplayController,
41
41
  children,
42
42
  interruptAnimation,
43
- translateX,
43
+ gestureTranslationX,
44
44
  scrollEnabled,
45
45
  startPagingAnimation,
46
46
  } = props;
@@ -54,7 +54,7 @@ export default function ScrollViewGesture(props: ScrollViewGestureProps) {
54
54
  }, [interruptAnimation, pauseAutoplay]);
55
55
 
56
56
  const handleGestureEvent = useCallback(Animated.event(
57
- [{ nativeEvent: { translationX: translateX } }],
57
+ [{ nativeEvent: { translationX: gestureTranslationX } }],
58
58
  { useNativeDriver: true },
59
59
  ), []);
60
60
 
@@ -68,7 +68,11 @@ export default function ScrollViewGesture(props: ScrollViewGestureProps) {
68
68
 
69
69
  startPagingAnimation(
70
70
  'directional',
71
- { direction: direction, isOriginatedFromGesture: true },
71
+ {
72
+ direction: direction,
73
+ isOriginatedFromGesture: true,
74
+ lastGestureTranslationX: translationX,
75
+ },
72
76
  );
73
77
 
74
78
  resumeAutoplay();
@@ -1,5 +1,5 @@
1
1
  export { default as useAutoplayController } from './useAutoplayController';
2
2
  export { default as useIndexController } from './useIndexController';
3
3
  export { default as useLoopedData } from './useLoopedData';
4
- export { default as usePagingAnimation } from './usePagingAnimation';
4
+ export { default as usePagingAnimator } from './usePagingAnimator';
5
5
  export { default as useItemVisibilityStore } from './useItemVisibilityStore';
@@ -1,54 +1,57 @@
1
- import React, { useCallback, useRef } from 'react';
1
+ import { useCallback } from 'react';
2
+ import { useImperativeState } from '@fountain-ui/core';
2
3
  import { mod } from '@fountain-ui/utils';
3
- import type { AnimationState, IndexController } from '../types';
4
+ import type { IndexController, ScrollStateChangeEvent } from '../types';
4
5
 
5
6
  export interface UseIndexControllerParameters {
6
7
  initialIndex: number;
7
8
  itemWidth: number;
9
+ numberOfData: number;
8
10
  numberOfOriginalData: number;
9
- onIndexChange?: (newIndex: number) => void;
11
+ onIndexChange?: (itemIndex: number) => void;
12
+ onPositionChange?: (position: number) => void;
10
13
  }
11
14
 
12
15
  export default function useIndexController(params: UseIndexControllerParameters): IndexController {
13
16
  const {
14
17
  initialIndex,
15
18
  itemWidth,
19
+ numberOfData,
16
20
  numberOfOriginalData,
17
21
  onIndexChange,
22
+ onPositionChange,
18
23
  } = params;
19
24
 
20
- const currentIndexRef = useRef<number>(initialIndex);
21
- const indexChangedRef = useRef<boolean>(false);
25
+ const currentIndex = useImperativeState(initialIndex);
26
+ const currentPosition = useImperativeState(initialIndex);
22
27
 
23
- const getCurrentIndex = useCallback(() => currentIndexRef.current, []);
28
+ const notifyScrollStateHasChanged = useCallback(({ offset, state }: ScrollStateChangeEvent) => {
29
+ const normalized = -Math.round(offset / itemWidth);
30
+ const index = Math.floor(mod(normalized, numberOfOriginalData));
31
+ const position = Math.floor(mod(normalized, numberOfData));
24
32
 
25
- const notifyAnimationState = useCallback((state: AnimationState) => {
26
- if (state === 'finished' || state === 'interrupted') {
27
- if (indexChangedRef.current) {
28
- onIndexChange?.(getCurrentIndex());
33
+ if (state === 'idle' || state === 'interrupted') {
34
+ if (currentIndex.hasChanged()) {
35
+ onIndexChange?.(currentIndex.get());
36
+ }
37
+ if (currentPosition.hasChanged()) {
38
+ onPositionChange?.(currentPosition.get());
29
39
  }
30
40
  }
41
+
42
+ currentIndex.set(index);
43
+ currentPosition.set(position);
31
44
  }, [
32
- getCurrentIndex,
45
+ itemWidth,
46
+ numberOfData,
47
+ numberOfOriginalData,
33
48
  onIndexChange,
49
+ onPositionChange,
34
50
  ]);
35
51
 
36
- const notifyOffsetHasChanged = useCallback((offset: number) => {
37
- const roundedOffset = Math.round(offset / itemWidth) * itemWidth;
38
-
39
- // To prevent floating point problem, make sure index is integer type.
40
- const nextIndex = Math.floor(mod((-roundedOffset / itemWidth), numberOfOriginalData));
41
-
42
- if (nextIndex !== currentIndexRef.current) {
43
- currentIndexRef.current = nextIndex;
44
- indexChangedRef.current = true;
45
- }
46
- }, [itemWidth, numberOfOriginalData]);
47
-
48
52
  return {
49
- getCurrentIndex,
53
+ getCurrentIndex: currentIndex.get,
50
54
  lastIndex: numberOfOriginalData - 1,
51
- notifyAnimationState,
52
- notifyOffsetHasChanged,
55
+ notifyScrollStateHasChanged,
53
56
  };
54
57
  };
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { mod } from '@fountain-ui/utils';
3
- import type { ItemVisibilityStore, VisibleIndexRanges } from '../types';
3
+ import type { ItemVisibilityStore, OnPositionChange, VisibleIndexRanges } from '../types';
4
4
 
5
5
  export interface Parameters {
6
6
  initialIndex: number;
@@ -8,10 +8,6 @@ export interface Parameters {
8
8
  windowSize: number;
9
9
  }
10
10
 
11
- export interface OnIndexChange {
12
- (newIndex: number): void;
13
- }
14
-
15
11
  class SimpleItemVisibilityStore implements ItemVisibilityStore {
16
12
 
17
13
  private store: VisibleIndexRanges;
@@ -82,7 +78,7 @@ function makeVisibleIndexRanges(numberOfData: number, windowSize: number, index:
82
78
  ];
83
79
  }
84
80
 
85
- export default function useItemVisibilityStore(params: Parameters): [ItemVisibilityStore, OnIndexChange] {
81
+ export default function useItemVisibilityStore(params: Parameters): [ItemVisibilityStore, OnPositionChange] {
86
82
  const {
87
83
  initialIndex,
88
84
  numberOfData,
@@ -95,8 +91,8 @@ export default function useItemVisibilityStore(params: Parameters): [ItemVisibil
95
91
 
96
92
  const store = useRef(new SimpleItemVisibilityStore(initialRange)).current;
97
93
 
98
- const onIndexChange: OnIndexChange = useCallback((newIndex) => {
99
- const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, newIndex);
94
+ const onPositionChange: OnPositionChange = useCallback((position) => {
95
+ const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, position);
100
96
 
101
97
  store.dispatch(newRanges);
102
98
  }, [numberOfData, windowSize]);
@@ -107,5 +103,5 @@ export default function useItemVisibilityStore(params: Parameters): [ItemVisibil
107
103
  };
108
104
  }, []);
109
105
 
110
- return [store, onIndexChange];
106
+ return [store, onPositionChange];
111
107
  };