react-native-reanimated-carousel 5.0.0-beta.7 → 5.0.0
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.
- package/README.md +60 -28
- package/lib/commonjs/components/Carousel.js +1 -1
- package/lib/commonjs/components/Carousel.js.map +1 -1
- package/lib/commonjs/components/CarouselLayout.js +1 -1
- package/lib/commonjs/components/CarouselLayout.js.map +1 -1
- package/lib/commonjs/components/ItemLayout.js +1 -1
- package/lib/commonjs/components/ItemLayout.js.map +1 -1
- package/lib/commonjs/components/ItemRenderer.js +1 -1
- package/lib/commonjs/components/ItemRenderer.js.map +1 -1
- package/lib/commonjs/components/Pagination/PaginationItem.js +2 -0
- package/lib/commonjs/components/Pagination/PaginationItem.js.map +1 -0
- package/lib/commonjs/components/Pagination/index.js +1 -1
- package/lib/commonjs/components/Pagination/index.js.map +1 -1
- package/lib/commonjs/components/ScrollViewGesture.js +1 -1
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +1 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +1 -1
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +1 -1
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +1 -1
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/public-types.js +2 -0
- package/lib/commonjs/public-types.js.map +1 -0
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/utils/carousel-direction.js +2 -0
- package/lib/commonjs/utils/carousel-direction.js.map +1 -0
- package/lib/commonjs/utils/carousel-math.js +2 -0
- package/lib/commonjs/utils/carousel-math.js.map +1 -0
- package/lib/commonjs/utils/deal-with-animation.js +1 -1
- package/lib/commonjs/utils/deal-with-animation.js.map +1 -1
- package/lib/module/components/Carousel.js +1 -1
- package/lib/module/components/Carousel.js.map +1 -1
- package/lib/module/components/CarouselLayout.js +1 -1
- package/lib/module/components/CarouselLayout.js.map +1 -1
- package/lib/module/components/ItemLayout.js +1 -1
- package/lib/module/components/ItemLayout.js.map +1 -1
- package/lib/module/components/ItemRenderer.js +1 -1
- package/lib/module/components/ItemRenderer.js.map +1 -1
- package/lib/module/components/LazyView.js +1 -1
- package/lib/module/components/LazyView.js.map +1 -1
- package/lib/module/components/Pagination/PaginationItem.js +2 -0
- package/lib/module/components/Pagination/PaginationItem.js.map +1 -0
- package/lib/module/components/Pagination/index.js +1 -1
- package/lib/module/components/Pagination/index.js.map +1 -1
- package/lib/module/components/ScrollViewGesture.js +1 -1
- package/lib/module/components/ScrollViewGesture.js.map +1 -1
- package/lib/module/constants/index.js +1 -1
- package/lib/module/constants/index.js.map +1 -1
- package/lib/module/hooks/useAutoPlay.js +1 -1
- package/lib/module/hooks/useAutoPlay.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +1 -1
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCheckMounted.js +1 -1
- package/lib/module/hooks/useCheckMounted.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +1 -1
- package/lib/module/hooks/useCommonVariables.js.map +1 -1
- package/lib/module/hooks/useInitProps.js +1 -1
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useLayoutConfig.js +1 -1
- package/lib/module/hooks/useLayoutConfig.js.map +1 -1
- package/lib/module/hooks/useOffsetX.js +1 -1
- package/lib/module/hooks/useOffsetX.js.map +1 -1
- package/lib/module/hooks/useOnProgressChange.js +1 -1
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/hooks/usePanGestureProxy.js +1 -1
- package/lib/module/hooks/usePanGestureProxy.js.map +1 -1
- package/lib/module/hooks/usePropsErrorBoundary.js +1 -1
- package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/module/hooks/useUpdateGestureConfig.js +1 -1
- package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -1
- package/lib/module/hooks/useVisibleRanges.js +1 -1
- package/lib/module/hooks/useVisibleRanges.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/layouts/index.js +1 -1
- package/lib/module/layouts/index.js.map +1 -1
- package/lib/module/layouts/normal.js +1 -1
- package/lib/module/layouts/normal.js.map +1 -1
- package/lib/module/layouts/parallax.js +1 -1
- package/lib/module/layouts/parallax.js.map +1 -1
- package/lib/module/layouts/stack.js +1 -1
- package/lib/module/layouts/stack.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/public-types.js +2 -0
- package/lib/module/public-types.js.map +1 -0
- package/lib/module/store/index.js +1 -1
- package/lib/module/store/index.js.map +1 -1
- package/lib/module/types.js +1 -1
- package/lib/module/utils/carousel-direction.js +2 -0
- package/lib/module/utils/carousel-direction.js.map +1 -0
- package/lib/module/utils/carousel-math.js +2 -0
- package/lib/module/utils/carousel-math.js.map +1 -0
- package/lib/module/utils/compute-gesture-translation.js +1 -1
- package/lib/module/utils/compute-gesture-translation.js.map +1 -1
- package/lib/module/utils/compute-offset-if-size-changed.js +1 -1
- package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -1
- package/lib/module/utils/computed-with-auto-fill-data.js +1 -1
- package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -1
- package/lib/module/utils/deal-with-animation.js +1 -1
- package/lib/module/utils/deal-with-animation.js.map +1 -1
- package/lib/module/utils/log.js +1 -1
- package/lib/module/utils/log.js.map +1 -1
- package/lib/module/utils/sanitize-animation-style.js +1 -1
- package/lib/module/utils/sanitize-animation-style.js.map +1 -1
- package/lib/typescript/commonjs/components/Carousel.d.ts +8 -0
- package/lib/typescript/commonjs/components/Carousel.d.ts.map +1 -0
- package/lib/typescript/{components → commonjs/components}/CarouselLayout.d.ts +5 -8
- package/lib/typescript/commonjs/components/CarouselLayout.d.ts.map +1 -0
- package/lib/typescript/{components → commonjs/components}/ItemLayout.d.ts +7 -6
- package/lib/typescript/commonjs/components/ItemLayout.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/ItemRenderer.d.ts +24 -0
- package/lib/typescript/commonjs/components/ItemRenderer.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/LazyView.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Pagination/PaginationItem.d.ts +14 -0
- package/lib/typescript/commonjs/components/Pagination/PaginationItem.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Pagination/index.d.ts +4 -0
- package/lib/typescript/commonjs/components/Pagination/index.d.ts.map +1 -0
- package/lib/typescript/{components → commonjs/components}/ScrollViewGesture.d.ts +3 -4
- package/lib/typescript/commonjs/components/ScrollViewGesture.d.ts.map +1 -0
- package/lib/typescript/commonjs/constants/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useAutoPlay.d.ts +12 -0
- package/lib/typescript/commonjs/hooks/useAutoPlay.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useCarouselController.d.ts +29 -0
- package/lib/typescript/commonjs/hooks/useCarouselController.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useCheckMounted.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useCommonVariables.d.ts +18 -0
- package/lib/typescript/commonjs/hooks/useCommonVariables.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useInitProps.d.ts +25 -0
- package/lib/typescript/commonjs/hooks/useInitProps.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useLayoutConfig.d.ts +8 -0
- package/lib/typescript/commonjs/hooks/useLayoutConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useOffsetX.d.ts +13 -0
- package/lib/typescript/commonjs/hooks/useOffsetX.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useOnProgressChange.d.ts +12 -0
- package/lib/typescript/commonjs/hooks/useOnProgressChange.d.ts.map +1 -0
- package/lib/typescript/{hooks → commonjs/hooks}/usePanGestureProxy.d.ts +3 -2
- package/lib/typescript/commonjs/hooks/usePanGestureProxy.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/usePropsErrorBoundary.d.ts +3 -0
- package/lib/typescript/commonjs/hooks/usePropsErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/useUpdateGestureConfig.d.ts +9 -0
- package/lib/typescript/commonjs/hooks/useUpdateGestureConfig.d.ts.map +1 -0
- package/lib/typescript/{hooks → commonjs/hooks}/useVisibleRanges.d.ts +2 -2
- package/lib/typescript/commonjs/hooks/useVisibleRanges.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +4 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/{layouts → commonjs/layouts}/index.d.ts +0 -1
- package/lib/typescript/commonjs/layouts/index.d.ts.map +1 -0
- package/lib/typescript/{layouts → commonjs/layouts}/normal.d.ts +3 -1
- package/lib/typescript/commonjs/layouts/normal.d.ts.map +1 -0
- package/lib/typescript/commonjs/layouts/parallax.d.ts +27 -0
- package/lib/typescript/commonjs/layouts/parallax.d.ts.map +1 -0
- package/lib/typescript/commonjs/layouts/stack.d.ts +10 -0
- package/lib/typescript/commonjs/layouts/stack.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/public-types.d.ts +161 -0
- package/lib/typescript/commonjs/public-types.d.ts.map +1 -0
- package/lib/typescript/{store → commonjs/store}/index.d.ts +8 -8
- package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +15 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/carousel-direction.d.ts +9 -0
- package/lib/typescript/commonjs/utils/carousel-direction.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/carousel-math.d.ts +28 -0
- package/lib/typescript/commonjs/utils/carousel-math.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/compute-gesture-translation.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/compute-offset-if-size-changed.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/computed-with-auto-fill-data.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/deal-with-animation.d.ts +3 -0
- package/lib/typescript/commonjs/utils/deal-with-animation.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/log.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/sanitize-animation-style.d.ts.map +1 -0
- package/lib/typescript/module/components/Carousel.d.ts +8 -0
- package/lib/typescript/module/components/Carousel.d.ts.map +1 -0
- package/lib/typescript/module/components/CarouselLayout.d.ts +14 -0
- package/lib/typescript/module/components/CarouselLayout.d.ts.map +1 -0
- package/lib/typescript/module/components/ItemLayout.d.ts +21 -0
- package/lib/typescript/module/components/ItemLayout.d.ts.map +1 -0
- package/lib/typescript/module/components/ItemRenderer.d.ts +24 -0
- package/lib/typescript/module/components/ItemRenderer.d.ts.map +1 -0
- package/lib/typescript/module/components/LazyView.d.ts +8 -0
- package/lib/typescript/module/components/LazyView.d.ts.map +1 -0
- package/lib/typescript/module/components/Pagination/PaginationItem.d.ts +14 -0
- package/lib/typescript/module/components/Pagination/PaginationItem.d.ts.map +1 -0
- package/lib/typescript/module/components/Pagination/index.d.ts +4 -0
- package/lib/typescript/module/components/Pagination/index.d.ts.map +1 -0
- package/lib/typescript/module/components/ScrollViewGesture.d.ts +18 -0
- package/lib/typescript/module/components/ScrollViewGesture.d.ts.map +1 -0
- package/lib/typescript/module/constants/index.d.ts +9 -0
- package/lib/typescript/module/constants/index.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useAutoPlay.d.ts +12 -0
- package/lib/typescript/module/hooks/useAutoPlay.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useCarouselController.d.ts +29 -0
- package/lib/typescript/module/hooks/useCarouselController.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useCheckMounted.d.ts +3 -0
- package/lib/typescript/module/hooks/useCheckMounted.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useCommonVariables.d.ts +18 -0
- package/lib/typescript/module/hooks/useCommonVariables.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useInitProps.d.ts +25 -0
- package/lib/typescript/module/hooks/useInitProps.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useLayoutConfig.d.ts +8 -0
- package/lib/typescript/module/hooks/useLayoutConfig.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useOffsetX.d.ts +13 -0
- package/lib/typescript/module/hooks/useOffsetX.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useOnProgressChange.d.ts +12 -0
- package/lib/typescript/module/hooks/useOnProgressChange.d.ts.map +1 -0
- package/lib/typescript/module/hooks/usePanGestureProxy.d.ts +11 -0
- package/lib/typescript/module/hooks/usePanGestureProxy.d.ts.map +1 -0
- package/lib/typescript/module/hooks/usePropsErrorBoundary.d.ts +3 -0
- package/lib/typescript/module/hooks/usePropsErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useUpdateGestureConfig.d.ts +9 -0
- package/lib/typescript/module/hooks/useUpdateGestureConfig.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useVisibleRanges.d.ts +22 -0
- package/lib/typescript/module/hooks/useVisibleRanges.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +4 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/layouts/index.d.ts +10 -0
- package/lib/typescript/module/layouts/index.d.ts.map +1 -0
- package/lib/typescript/module/layouts/normal.d.ts +15 -0
- package/lib/typescript/module/layouts/normal.d.ts.map +1 -0
- package/lib/typescript/module/layouts/parallax.d.ts +27 -0
- package/lib/typescript/module/layouts/parallax.d.ts.map +1 -0
- package/lib/typescript/module/layouts/stack.d.ts +10 -0
- package/lib/typescript/module/layouts/stack.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/public-types.d.ts +161 -0
- package/lib/typescript/module/public-types.d.ts.map +1 -0
- package/lib/typescript/module/store/index.d.ts +35 -0
- package/lib/typescript/module/store/index.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +15 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/lib/typescript/module/utils/carousel-direction.d.ts +9 -0
- package/lib/typescript/module/utils/carousel-direction.d.ts.map +1 -0
- package/lib/typescript/module/utils/carousel-math.d.ts +28 -0
- package/lib/typescript/module/utils/carousel-math.d.ts.map +1 -0
- package/lib/typescript/module/utils/compute-gesture-translation.d.ts +9 -0
- package/lib/typescript/module/utils/compute-gesture-translation.d.ts.map +1 -0
- package/lib/typescript/module/utils/compute-offset-if-size-changed.d.ts +6 -0
- package/lib/typescript/module/utils/compute-offset-if-size-changed.d.ts.map +1 -0
- package/lib/typescript/module/utils/computed-with-auto-fill-data.d.ts +23 -0
- package/lib/typescript/module/utils/computed-with-auto-fill-data.d.ts.map +1 -0
- package/lib/typescript/module/utils/deal-with-animation.d.ts +3 -0
- package/lib/typescript/module/utils/deal-with-animation.d.ts.map +1 -0
- package/lib/typescript/module/utils/log.d.ts +7 -0
- package/lib/typescript/module/utils/log.d.ts.map +1 -0
- package/lib/typescript/module/utils/sanitize-animation-style.d.ts +3 -0
- package/lib/typescript/module/utils/sanitize-animation-style.d.ts.map +1 -0
- package/package.json +34 -7
- package/scripts/codemods/v5.mjs +502 -0
- package/src/components/Carousel.tsx +5 -5
- package/src/components/CarouselLayout.tsx +53 -91
- package/src/components/ItemLayout.tsx +55 -46
- package/src/components/ItemRenderer.tsx +29 -18
- package/src/components/Pagination/PaginationItem.tsx +162 -0
- package/src/components/Pagination/index.tsx +105 -6
- package/src/components/ScrollViewGesture.tsx +92 -177
- package/src/hooks/useAutoPlay.ts +23 -18
- package/src/hooks/useCarouselController.tsx +194 -340
- package/src/hooks/useCommonVariables.ts +159 -71
- package/src/hooks/useInitProps.ts +161 -71
- package/src/hooks/useLayoutConfig.ts +21 -12
- package/src/hooks/useOffsetX.ts +3 -3
- package/src/hooks/useOnProgressChange.ts +23 -48
- package/src/hooks/usePanGestureProxy.ts +2 -2
- package/src/hooks/usePropsErrorBoundary.ts +32 -90
- package/src/hooks/useUpdateGestureConfig.ts +5 -2
- package/src/hooks/useVisibleRanges.tsx +2 -2
- package/src/index.tsx +14 -9
- package/src/layouts/index.tsx +0 -2
- package/src/layouts/normal.ts +14 -4
- package/src/layouts/parallax.ts +32 -59
- package/src/layouts/stack.ts +30 -70
- package/src/public-types.ts +198 -0
- package/src/store/index.tsx +7 -7
- package/src/types.ts +30 -322
- package/src/utils/carousel-direction.ts +39 -0
- package/src/utils/carousel-math.ts +156 -0
- package/src/utils/deal-with-animation.ts +11 -9
- package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +0 -2
- package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +0 -1
- package/lib/commonjs/components/Pagination/Basic/index.js +0 -2
- package/lib/commonjs/components/Pagination/Basic/index.js.map +0 -1
- package/lib/commonjs/components/Pagination/Custom/PaginationItem.js +0 -2
- package/lib/commonjs/components/Pagination/Custom/PaginationItem.js.map +0 -1
- package/lib/commonjs/components/Pagination/Custom/index.js +0 -2
- package/lib/commonjs/components/Pagination/Custom/index.js.map +0 -1
- package/lib/commonjs/utils/compute-offset-if-data-changed.js +0 -2
- package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +0 -1
- package/lib/commonjs/utils/handleroffset-direction.js +0 -2
- package/lib/commonjs/utils/handleroffset-direction.js.map +0 -1
- package/lib/module/components/Pagination/Basic/PaginationItem.js +0 -2
- package/lib/module/components/Pagination/Basic/PaginationItem.js.map +0 -1
- package/lib/module/components/Pagination/Basic/index.js +0 -2
- package/lib/module/components/Pagination/Basic/index.js.map +0 -1
- package/lib/module/components/Pagination/Custom/PaginationItem.js +0 -2
- package/lib/module/components/Pagination/Custom/PaginationItem.js.map +0 -1
- package/lib/module/components/Pagination/Custom/index.js +0 -2
- package/lib/module/components/Pagination/Custom/index.js.map +0 -1
- package/lib/module/utils/compute-offset-if-data-changed.js +0 -2
- package/lib/module/utils/compute-offset-if-data-changed.js.map +0 -1
- package/lib/module/utils/handleroffset-direction.js +0 -2
- package/lib/module/utils/handleroffset-direction.js.map +0 -1
- package/lib/typescript/components/Carousel.d.ts +0 -8
- package/lib/typescript/components/Carousel.d.ts.map +0 -1
- package/lib/typescript/components/CarouselLayout.d.ts.map +0 -1
- package/lib/typescript/components/ItemLayout.d.ts.map +0 -1
- package/lib/typescript/components/ItemRenderer.d.ts +0 -23
- package/lib/typescript/components/ItemRenderer.d.ts.map +0 -1
- package/lib/typescript/components/LazyView.d.ts.map +0 -1
- package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +0 -29
- package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts.map +0 -1
- package/lib/typescript/components/Pagination/Basic/index.d.ts +0 -23
- package/lib/typescript/components/Pagination/Basic/index.d.ts.map +0 -1
- package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts +0 -35
- package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts.map +0 -1
- package/lib/typescript/components/Pagination/Custom/index.d.ts +0 -26
- package/lib/typescript/components/Pagination/Custom/index.d.ts.map +0 -1
- package/lib/typescript/components/Pagination/index.d.ts +0 -5
- package/lib/typescript/components/Pagination/index.d.ts.map +0 -1
- package/lib/typescript/components/ScrollViewGesture.d.ts.map +0 -1
- package/lib/typescript/constants/index.d.ts.map +0 -1
- package/lib/typescript/hooks/useAutoPlay.d.ts +0 -12
- package/lib/typescript/hooks/useAutoPlay.d.ts.map +0 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +0 -28
- package/lib/typescript/hooks/useCarouselController.d.ts.map +0 -1
- package/lib/typescript/hooks/useCheckMounted.d.ts.map +0 -1
- package/lib/typescript/hooks/useCommonVariables.d.ts +0 -13
- package/lib/typescript/hooks/useCommonVariables.d.ts.map +0 -1
- package/lib/typescript/hooks/useInitProps.d.ts +0 -10
- package/lib/typescript/hooks/useInitProps.d.ts.map +0 -1
- package/lib/typescript/hooks/useLayoutConfig.d.ts +0 -8
- package/lib/typescript/hooks/useLayoutConfig.d.ts.map +0 -1
- package/lib/typescript/hooks/useOffsetX.d.ts +0 -13
- package/lib/typescript/hooks/useOffsetX.d.ts.map +0 -1
- package/lib/typescript/hooks/useOnProgressChange.d.ts +0 -11
- package/lib/typescript/hooks/useOnProgressChange.d.ts.map +0 -1
- package/lib/typescript/hooks/usePanGestureProxy.d.ts.map +0 -1
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +0 -5
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +0 -1
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +0 -6
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts.map +0 -1
- package/lib/typescript/hooks/useVisibleRanges.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -7
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/layouts/index.d.ts.map +0 -1
- package/lib/typescript/layouts/normal.d.ts.map +0 -1
- package/lib/typescript/layouts/parallax.d.ts +0 -47
- package/lib/typescript/layouts/parallax.d.ts.map +0 -1
- package/lib/typescript/layouts/stack.d.ts +0 -38
- package/lib/typescript/layouts/stack.d.ts.map +0 -1
- package/lib/typescript/store/index.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -302
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/utils/compute-gesture-translation.d.ts.map +0 -1
- package/lib/typescript/utils/compute-offset-if-data-changed.d.ts +0 -9
- package/lib/typescript/utils/compute-offset-if-data-changed.d.ts.map +0 -1
- package/lib/typescript/utils/compute-offset-if-size-changed.d.ts.map +0 -1
- package/lib/typescript/utils/computed-with-auto-fill-data.d.ts.map +0 -1
- package/lib/typescript/utils/deal-with-animation.d.ts +0 -3
- package/lib/typescript/utils/deal-with-animation.d.ts.map +0 -1
- package/lib/typescript/utils/handleroffset-direction.d.ts +0 -4
- package/lib/typescript/utils/handleroffset-direction.d.ts.map +0 -1
- package/lib/typescript/utils/log.d.ts.map +0 -1
- package/lib/typescript/utils/sanitize-animation-style.d.ts.map +0 -1
- package/src/components/Carousel.test.tsx +0 -1215
- package/src/components/LazyView.test.tsx +0 -61
- package/src/components/Pagination/Basic/PaginationItem.tsx +0 -149
- package/src/components/Pagination/Basic/index.tsx +0 -98
- package/src/components/Pagination/Custom/PaginationItem.tsx +0 -166
- package/src/components/Pagination/Custom/index.tsx +0 -111
- package/src/components/Pagination/Pagination.test.tsx +0 -178
- package/src/components/ScrollViewGesture.test.tsx +0 -155
- package/src/components/issue-899-parallax-reverse-loop.test.tsx +0 -131
- package/src/components/rnr-demo.test.tsx +0 -53
- package/src/hooks/useAutoPlay.test.ts +0 -194
- package/src/hooks/useCarouselController.test.tsx +0 -1158
- package/src/hooks/useCheckMounted.test.ts +0 -47
- package/src/hooks/useCommonVariables.test.tsx +0 -384
- package/src/hooks/useInitProps.test.tsx +0 -134
- package/src/hooks/useLayoutConfig.test.tsx +0 -247
- package/src/hooks/useOffsetX.test.ts +0 -54
- package/src/hooks/useOnProgressChange.test.tsx +0 -270
- package/src/hooks/usePanGestureProxy.test.tsx +0 -368
- package/src/hooks/usePropsErrorBoundary.test.tsx +0 -57
- package/src/hooks/useUpdateGestureConfig.test.ts +0 -89
- package/src/hooks/useVisibleRanges.test.tsx +0 -347
- package/src/layouts/parallax.test.ts +0 -239
- package/src/layouts/stack.test.ts +0 -252
- package/src/store/index.test.tsx +0 -314
- package/src/utils/compute-gesture-translation.test.ts +0 -70
- package/src/utils/compute-offset-if-data-changed.test.ts +0 -133
- package/src/utils/compute-offset-if-data-changed.ts +0 -44
- package/src/utils/compute-offset-if-size-changed.test.ts +0 -78
- package/src/utils/computed-with-auto-fill-data.test.ts +0 -298
- package/src/utils/deal-with-animation.test.ts +0 -181
- package/src/utils/handleroffset-direction.test.ts +0 -124
- package/src/utils/handleroffset-direction.ts +0 -18
- package/src/utils/index.test.ts +0 -90
- package/src/utils/log.test.ts +0 -134
- package/src/utils/sanitize-animation-style.test.ts +0 -40
- /package/lib/typescript/{components → commonjs/components}/LazyView.d.ts +0 -0
- /package/lib/typescript/{constants → commonjs/constants}/index.d.ts +0 -0
- /package/lib/typescript/{hooks → commonjs/hooks}/useCheckMounted.d.ts +0 -0
- /package/lib/typescript/{utils → commonjs/utils}/compute-gesture-translation.d.ts +0 -0
- /package/lib/typescript/{utils → commonjs/utils}/compute-offset-if-size-changed.d.ts +0 -0
- /package/lib/typescript/{utils → commonjs/utils}/computed-with-auto-fill-data.d.ts +0 -0
- /package/lib/typescript/{utils → commonjs/utils}/log.d.ts +0 -0
- /package/lib/typescript/{utils → commonjs/utils}/sanitize-animation-style.d.ts +0 -0
|
@@ -4,74 +4,86 @@ import type { SharedValue } from "react-native-reanimated";
|
|
|
4
4
|
import { useAnimatedReaction, useSharedValue } from "react-native-reanimated";
|
|
5
5
|
import { scheduleOnRN } from "react-native-worklets";
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { InitializedCarouselProps } from "./useInitProps";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getNearestLogicalPage,
|
|
11
|
+
positiveModulo,
|
|
12
|
+
reconcileOffsetAfterDataChange,
|
|
13
|
+
} from "../utils/carousel-math";
|
|
10
14
|
import { computeOffsetIfSizeChanged } from "../utils/compute-offset-if-size-changed";
|
|
11
|
-
import { handlerOffsetDirection } from "../utils/handleroffset-direction";
|
|
12
15
|
|
|
13
|
-
export type
|
|
16
|
+
export type CarouselSizePhase = "pending" | "ready" | "updating";
|
|
14
17
|
|
|
15
|
-
export interface
|
|
18
|
+
export interface CarouselCommonVariables {
|
|
16
19
|
size: number;
|
|
17
20
|
validLength: number;
|
|
18
21
|
handlerOffset: SharedValue<number>;
|
|
19
22
|
resolvedSize: SharedValue<number | null>;
|
|
20
|
-
sizePhase: SharedValue<
|
|
23
|
+
sizePhase: SharedValue<CarouselSizePhase>;
|
|
21
24
|
sizeExplicit: boolean;
|
|
25
|
+
isMoving: SharedValue<boolean>;
|
|
26
|
+
dataRevision: number;
|
|
27
|
+
startMovement: () => void;
|
|
28
|
+
cancelMovement: () => void;
|
|
29
|
+
settleMovement: () => void;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
export function useCommonVariables(
|
|
32
|
+
export function useCommonVariables(
|
|
33
|
+
props: InitializedCarouselProps<unknown>
|
|
34
|
+
): CarouselCommonVariables {
|
|
25
35
|
const {
|
|
26
|
-
|
|
36
|
+
orientation,
|
|
27
37
|
style,
|
|
28
38
|
dataLength,
|
|
29
39
|
defaultIndex,
|
|
30
|
-
|
|
40
|
+
keyExtractor,
|
|
31
41
|
loop,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
itemHeight: explicitItemHeight,
|
|
42
|
+
itemSize,
|
|
43
|
+
rawData,
|
|
44
|
+
rawDataLength,
|
|
36
45
|
} = props;
|
|
46
|
+
const isVertical = orientation === "vertical";
|
|
37
47
|
|
|
38
48
|
const manualSize = React.useMemo(() => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return explicitPageSize;
|
|
49
|
+
if (typeof itemSize === "number" && itemSize > 0) {
|
|
50
|
+
return itemSize;
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
const { width, height } = StyleSheet.flatten(style) || {};
|
|
45
|
-
const candidate =
|
|
54
|
+
const candidate = isVertical ? height : width;
|
|
46
55
|
if (typeof candidate === "number" && candidate > 0) {
|
|
47
56
|
return candidate;
|
|
48
57
|
}
|
|
49
58
|
|
|
50
|
-
// NOTE: `width`/`height` props are deprecated in v5. They are still respected here to
|
|
51
|
-
// maintain backwards compatibility with v4-style usage. Prefer using `style` when both exist.
|
|
52
|
-
const explicitCandidate = vertical ? explicitHeight : explicitWidth;
|
|
53
|
-
if (typeof explicitCandidate === "number" && explicitCandidate > 0) {
|
|
54
|
-
return explicitCandidate;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
59
|
return null;
|
|
58
|
-
}, [
|
|
60
|
+
}, [isVertical, itemSize, style]);
|
|
59
61
|
|
|
60
62
|
const resolvedSize = useSharedValue<number | null>(manualSize);
|
|
61
|
-
const sizePhase = useSharedValue<
|
|
63
|
+
const sizePhase = useSharedValue<CarouselSizePhase>(manualSize ? "ready" : "pending");
|
|
62
64
|
|
|
63
|
-
const defaultHandlerOffsetValue =
|
|
65
|
+
const defaultHandlerOffsetValue =
|
|
66
|
+
manualSize && dataLength > 0 ? -Math.abs(defaultIndex * manualSize) : 0;
|
|
64
67
|
const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
const handlerOffset = props.scrollOffsetValue ?? _handlerOffset;
|
|
69
|
+
const prevDataLength = useSharedValue(rawDataLength);
|
|
70
|
+
const previousRawData = React.useRef(rawData);
|
|
71
|
+
const previousKeyExtractor = React.useRef(keyExtractor);
|
|
72
|
+
const isMoving = useSharedValue(false);
|
|
73
|
+
const pendingDataChange = useSharedValue<{
|
|
74
|
+
previousLength: number;
|
|
75
|
+
currentLength: number;
|
|
76
|
+
retainedIndex: number | null;
|
|
77
|
+
} | null>(null);
|
|
78
|
+
// Start at zero even when a synchronous item size is available. The first
|
|
79
|
+
// size reaction owns initialization and must write the default-index offset
|
|
80
|
+
// into consumer-provided SharedValues as well as the internal value.
|
|
81
|
+
const prevSize = useSharedValue(0);
|
|
82
|
+
const hasInitializedOffset = useSharedValue(false);
|
|
83
|
+
const sizeExplicit = typeof itemSize === "number" && itemSize > 0;
|
|
73
84
|
|
|
74
85
|
const [size, setSize] = React.useState<number>(manualSize ?? 0);
|
|
86
|
+
const [dataRevision, setDataRevision] = React.useState(0);
|
|
75
87
|
|
|
76
88
|
const syncSize = React.useCallback((next: number) => {
|
|
77
89
|
setSize((current) => (current === next ? current : next));
|
|
@@ -95,43 +107,107 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
|
|
|
95
107
|
}
|
|
96
108
|
}, [manualSize, resolvedSize, sizePhase]);
|
|
97
109
|
|
|
110
|
+
React.useEffect(() => {
|
|
111
|
+
const currentSize = resolvedSize.value ?? 0;
|
|
112
|
+
if (currentSize <= 0 || dataLength <= 0 || hasInitializedOffset.value) return;
|
|
113
|
+
|
|
114
|
+
handlerOffset.value = -(defaultIndex * currentSize);
|
|
115
|
+
prevSize.value = currentSize;
|
|
116
|
+
hasInitializedOffset.value = true;
|
|
117
|
+
}, [dataLength, defaultIndex, handlerOffset, hasInitializedOffset, prevSize, resolvedSize]);
|
|
118
|
+
|
|
119
|
+
const reconcileDataChange = React.useCallback(
|
|
120
|
+
(previousLength: number, currentLength: number, retainedIndex?: number) => {
|
|
121
|
+
const currentSize = resolvedSize.value ?? 0;
|
|
122
|
+
if (currentSize <= 0) return;
|
|
123
|
+
|
|
124
|
+
handlerOffset.value = reconcileOffsetAfterDataChange({
|
|
125
|
+
offset: handlerOffset.value,
|
|
126
|
+
itemSize: currentSize,
|
|
127
|
+
previousCount: previousLength,
|
|
128
|
+
nextCount: currentLength,
|
|
129
|
+
defaultIndex,
|
|
130
|
+
loop,
|
|
131
|
+
retainedIndex,
|
|
132
|
+
});
|
|
133
|
+
setDataRevision((revision) => revision + 1);
|
|
134
|
+
},
|
|
135
|
+
[defaultIndex, handlerOffset, loop, resolvedSize]
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const startMovement = React.useCallback(() => {
|
|
139
|
+
isMoving.value = true;
|
|
140
|
+
}, [isMoving]);
|
|
141
|
+
|
|
142
|
+
const finishMovement = React.useCallback(() => {
|
|
143
|
+
isMoving.value = false;
|
|
144
|
+
const pending = pendingDataChange.value;
|
|
145
|
+
if (!pending) return;
|
|
146
|
+
|
|
147
|
+
pendingDataChange.value = null;
|
|
148
|
+
reconcileDataChange(
|
|
149
|
+
pending.previousLength,
|
|
150
|
+
pending.currentLength,
|
|
151
|
+
pending.retainedIndex ?? undefined
|
|
152
|
+
);
|
|
153
|
+
}, [isMoving, pendingDataChange, reconcileDataChange]);
|
|
154
|
+
|
|
98
155
|
/**
|
|
99
156
|
* When data changes, we need to compute new index for handlerOffset
|
|
100
157
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
handlerOffset: handlerOffset.value,
|
|
130
|
-
});
|
|
158
|
+
React.useEffect(() => {
|
|
159
|
+
const previousLength = prevDataLength.value;
|
|
160
|
+
const previousItems = previousRawData.current;
|
|
161
|
+
const dataChanged =
|
|
162
|
+
previousLength !== rawDataLength ||
|
|
163
|
+
previousItems.length !== rawData.length ||
|
|
164
|
+
previousItems.some((item, index) => !Object.is(item, rawData[index]));
|
|
165
|
+
|
|
166
|
+
previousRawData.current = rawData;
|
|
167
|
+
const extractorForPreviousData = previousKeyExtractor.current ?? keyExtractor;
|
|
168
|
+
previousKeyExtractor.current = keyExtractor;
|
|
169
|
+
|
|
170
|
+
if (!dataChanged) return;
|
|
171
|
+
|
|
172
|
+
let retainedIndex: number | undefined;
|
|
173
|
+
if (keyExtractor && extractorForPreviousData && previousLength > 0 && rawDataLength > 0) {
|
|
174
|
+
const currentSize = resolvedSize.value ?? 0;
|
|
175
|
+
const pendingIndex = pendingDataChange.value?.retainedIndex;
|
|
176
|
+
const previousIndex =
|
|
177
|
+
typeof pendingIndex === "number"
|
|
178
|
+
? pendingIndex
|
|
179
|
+
: positiveModulo(getNearestLogicalPage(handlerOffset.value, currentSize), previousLength);
|
|
180
|
+
if (previousIndex < previousItems.length) {
|
|
181
|
+
const selectedKey = extractorForPreviousData(previousItems[previousIndex], previousIndex);
|
|
182
|
+
const matchingIndex = rawData.findIndex(
|
|
183
|
+
(item, index) => keyExtractor(item, index) === selectedKey
|
|
184
|
+
);
|
|
185
|
+
if (matchingIndex >= 0) retainedIndex = matchingIndex;
|
|
131
186
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
prevDataLength.value = rawDataLength;
|
|
190
|
+
if (isMoving.value) {
|
|
191
|
+
pendingDataChange.value = {
|
|
192
|
+
previousLength: pendingDataChange.value?.previousLength ?? previousLength,
|
|
193
|
+
currentLength: rawDataLength,
|
|
194
|
+
retainedIndex: retainedIndex ?? null,
|
|
195
|
+
};
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
reconcileDataChange(previousLength, rawDataLength, retainedIndex);
|
|
200
|
+
}, [
|
|
201
|
+
handlerOffset,
|
|
202
|
+
isMoving,
|
|
203
|
+
keyExtractor,
|
|
204
|
+
pendingDataChange,
|
|
205
|
+
prevDataLength,
|
|
206
|
+
rawData,
|
|
207
|
+
rawDataLength,
|
|
208
|
+
reconcileDataChange,
|
|
209
|
+
resolvedSize,
|
|
210
|
+
]);
|
|
135
211
|
|
|
136
212
|
/**
|
|
137
213
|
* When size changes, we need to compute new index for handlerOffset
|
|
@@ -146,8 +222,15 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
|
|
|
146
222
|
|
|
147
223
|
sizePhase.value = previousSize > 0 ? "updating" : sizePhase.value;
|
|
148
224
|
|
|
149
|
-
if (
|
|
150
|
-
|
|
225
|
+
if (dataLength <= 0) {
|
|
226
|
+
prevSize.value = currentSize;
|
|
227
|
+
sizePhase.value = "ready";
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (previousSize <= 0 || !hasInitializedOffset.value) {
|
|
232
|
+
handlerOffset.value = -(defaultIndex * currentSize);
|
|
233
|
+
hasInitializedOffset.value = true;
|
|
151
234
|
} else {
|
|
152
235
|
handlerOffset.value = computeOffsetIfSizeChanged({
|
|
153
236
|
handlerOffset: handlerOffset.value,
|
|
@@ -159,7 +242,7 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
|
|
|
159
242
|
prevSize.value = currentSize;
|
|
160
243
|
sizePhase.value = "ready";
|
|
161
244
|
},
|
|
162
|
-
[defaultIndex, resolvedSize, sizePhase]
|
|
245
|
+
[dataLength, defaultIndex, hasInitializedOffset, resolvedSize, sizePhase]
|
|
163
246
|
);
|
|
164
247
|
|
|
165
248
|
return {
|
|
@@ -169,5 +252,10 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
|
|
|
169
252
|
resolvedSize,
|
|
170
253
|
sizePhase,
|
|
171
254
|
sizeExplicit,
|
|
255
|
+
isMoving,
|
|
256
|
+
dataRevision,
|
|
257
|
+
startMovement,
|
|
258
|
+
cancelMovement: finishMovement,
|
|
259
|
+
settleMovement: finishMovement,
|
|
172
260
|
};
|
|
173
261
|
}
|
|
@@ -1,87 +1,177 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { I18nManager } from "react-native";
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
+
import { Easing } from "../constants";
|
|
5
|
+
import type { CarouselAnimation, CarouselProps } from "../types";
|
|
6
|
+
import { type CarouselDirectionSign, getCarouselDirectionSign } from "../utils/carousel-direction";
|
|
4
7
|
import { computedFillDataWithAutoFillData } from "../utils/computed-with-auto-fill-data";
|
|
5
8
|
|
|
6
|
-
type
|
|
9
|
+
type CarouselSnapMode = NonNullable<CarouselProps<unknown>["snapMode"]>;
|
|
7
10
|
|
|
8
|
-
export type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export type InitializedCarouselProps<Item> = Omit<
|
|
12
|
+
CarouselProps<Item>,
|
|
13
|
+
| "autoplay"
|
|
14
|
+
| "autoplayDirection"
|
|
15
|
+
| "autoplayInterval"
|
|
16
|
+
| "data"
|
|
17
|
+
| "defaultIndex"
|
|
18
|
+
| "loop"
|
|
19
|
+
| "orientation"
|
|
20
|
+
| "overscrollEnabled"
|
|
21
|
+
| "scrollEnabled"
|
|
22
|
+
| "snapMode"
|
|
23
|
+
| "style"
|
|
24
|
+
> & {
|
|
25
|
+
autoplay: boolean;
|
|
26
|
+
autoplayDirection: "forward" | "backward";
|
|
27
|
+
autoplayInterval: number;
|
|
28
|
+
data: Item[];
|
|
29
|
+
defaultIndex: number;
|
|
30
|
+
loop: boolean;
|
|
31
|
+
orientation: "horizontal" | "vertical";
|
|
32
|
+
overscrollEnabled: boolean;
|
|
33
|
+
scrollEnabled: boolean;
|
|
34
|
+
snapMode: CarouselSnapMode;
|
|
35
|
+
style: NonNullable<CarouselProps<Item>["style"]>;
|
|
36
|
+
animation: CarouselAnimation;
|
|
37
|
+
rawData: Item[];
|
|
38
|
+
dataLength: number;
|
|
39
|
+
rawDataLength: number;
|
|
40
|
+
autoFillData: true;
|
|
41
|
+
directionSign: CarouselDirectionSign;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function useInitProps<Item>(props: CarouselProps<Item>): InitializedCarouselProps<Item> {
|
|
45
|
+
validateStaticProps(props);
|
|
46
|
+
|
|
47
|
+
const rawData = props.data ?? [];
|
|
48
|
+
const requestedDefaultIndex = props.defaultIndex ?? 0;
|
|
49
|
+
const loop = props.loop ?? false;
|
|
50
|
+
const autoplay = props.autoplay ?? false;
|
|
51
|
+
const autoplayInterval = props.autoplayInterval ?? 3000;
|
|
52
|
+
const autoplayDirection = props.autoplayDirection ?? "forward";
|
|
53
|
+
const orientation = props.orientation ?? "horizontal";
|
|
54
|
+
const directionSign = getCarouselDirectionSign({
|
|
55
|
+
isRTL: I18nManager.isRTL,
|
|
56
|
+
orientation,
|
|
57
|
+
});
|
|
58
|
+
const scrollEnabled = props.scrollEnabled ?? true;
|
|
59
|
+
const snapMode = props.snapMode ?? "page";
|
|
60
|
+
const overscrollEnabled = props.overscrollEnabled ?? true;
|
|
61
|
+
const style = props.style ?? {};
|
|
62
|
+
const animation: CarouselAnimation = props.animation ?? {
|
|
63
|
+
type: "timing",
|
|
64
|
+
duration: 500,
|
|
65
|
+
easing: Easing.easeOutQuart,
|
|
16
66
|
};
|
|
17
67
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
}, [rawData, loop, autoFillData]);
|
|
52
|
-
|
|
53
|
-
const dataLength = data.length;
|
|
54
|
-
const rawDataLength = rawData.length;
|
|
55
|
-
|
|
56
|
-
if (props.mode === "vertical-stack" || props.mode === "horizontal-stack") {
|
|
57
|
-
if (!props.modeConfig) props.modeConfig = {};
|
|
58
|
-
|
|
59
|
-
props.modeConfig.showLength = props.modeConfig?.showLength ?? dataLength - 1;
|
|
68
|
+
const defaultIndexState = React.useRef<{
|
|
69
|
+
consumed: boolean;
|
|
70
|
+
requested: number;
|
|
71
|
+
resolved: number;
|
|
72
|
+
warned: boolean;
|
|
73
|
+
} | null>(null);
|
|
74
|
+
|
|
75
|
+
if (!defaultIndexState.current) {
|
|
76
|
+
if (rawData.length > 0) {
|
|
77
|
+
assertValidDefaultIndex(requestedDefaultIndex, rawData.length);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
defaultIndexState.current = {
|
|
81
|
+
consumed: rawData.length > 0,
|
|
82
|
+
requested: requestedDefaultIndex,
|
|
83
|
+
resolved: rawData.length > 0 ? requestedDefaultIndex : 0,
|
|
84
|
+
warned: false,
|
|
85
|
+
};
|
|
86
|
+
} else if (!defaultIndexState.current.consumed && rawData.length > 0) {
|
|
87
|
+
const pendingIndex = defaultIndexState.current.requested;
|
|
88
|
+
defaultIndexState.current.consumed = true;
|
|
89
|
+
|
|
90
|
+
if (isValidDefaultIndex(pendingIndex, rawData.length)) {
|
|
91
|
+
defaultIndexState.current.resolved = pendingIndex;
|
|
92
|
+
} else {
|
|
93
|
+
defaultIndexState.current.resolved = 0;
|
|
94
|
+
if (__DEV__ && !defaultIndexState.current.warned) {
|
|
95
|
+
console.warn(
|
|
96
|
+
`[react-native-reanimated-carousel] Ignored defaultIndex ${pendingIndex} because it is outside the first non-empty data set.`
|
|
97
|
+
);
|
|
98
|
+
defaultIndexState.current.warned = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
60
101
|
}
|
|
61
102
|
|
|
103
|
+
const defaultIndex = defaultIndexState.current.resolved;
|
|
104
|
+
const data = React.useMemo(
|
|
105
|
+
() =>
|
|
106
|
+
computedFillDataWithAutoFillData({
|
|
107
|
+
loop,
|
|
108
|
+
autoFillData: true,
|
|
109
|
+
data: rawData,
|
|
110
|
+
dataLength: rawData.length,
|
|
111
|
+
}),
|
|
112
|
+
[loop, rawData]
|
|
113
|
+
);
|
|
114
|
+
|
|
62
115
|
return {
|
|
63
116
|
...props,
|
|
117
|
+
autoplay,
|
|
118
|
+
autoplayDirection,
|
|
119
|
+
autoplayInterval,
|
|
64
120
|
defaultIndex,
|
|
65
|
-
autoFillData,
|
|
66
|
-
// Fill data with autoFillData
|
|
67
|
-
data,
|
|
68
|
-
// Length of fill data
|
|
69
|
-
dataLength,
|
|
70
|
-
// Raw data that has not been processed
|
|
71
|
-
rawData,
|
|
72
|
-
// Length of raw data
|
|
73
|
-
rawDataLength,
|
|
74
121
|
loop,
|
|
75
|
-
|
|
76
|
-
autoPlayInterval,
|
|
77
|
-
scrollAnimationDuration,
|
|
78
|
-
style,
|
|
79
|
-
pagingEnabled,
|
|
80
|
-
snapEnabled,
|
|
122
|
+
orientation,
|
|
81
123
|
overscrollEnabled,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
124
|
+
scrollEnabled,
|
|
125
|
+
snapMode,
|
|
126
|
+
style,
|
|
127
|
+
animation,
|
|
128
|
+
data,
|
|
129
|
+
rawData,
|
|
130
|
+
dataLength: data.length,
|
|
131
|
+
rawDataLength: rawData.length,
|
|
132
|
+
autoFillData: true,
|
|
133
|
+
directionSign,
|
|
86
134
|
};
|
|
87
135
|
}
|
|
136
|
+
|
|
137
|
+
function validateStaticProps<Item>(props: CarouselProps<Item>) {
|
|
138
|
+
if (props.layout && props.itemAnimation) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"[react-native-reanimated-carousel] `layout` and `itemAnimation` are mutually exclusive."
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (props.itemSize !== undefined && (!Number.isFinite(props.itemSize) || props.itemSize <= 0)) {
|
|
145
|
+
throw new Error("[react-native-reanimated-carousel] itemSize must be a positive number.");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (
|
|
149
|
+
props.autoplayInterval !== undefined &&
|
|
150
|
+
(!Number.isFinite(props.autoplayInterval) || props.autoplayInterval < 0)
|
|
151
|
+
) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
"[react-native-reanimated-carousel] autoplayInterval must be a non-negative number."
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (
|
|
158
|
+
props.renderWindowSize !== undefined &&
|
|
159
|
+
(!Number.isInteger(props.renderWindowSize) || props.renderWindowSize <= 0)
|
|
160
|
+
) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
"[react-native-reanimated-carousel] renderWindowSize must be a positive integer."
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isValidDefaultIndex(defaultIndex: number, dataLength: number) {
|
|
168
|
+
return Number.isInteger(defaultIndex) && defaultIndex >= 0 && defaultIndex < dataLength;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function assertValidDefaultIndex(defaultIndex: number, dataLength: number) {
|
|
172
|
+
if (!isValidDefaultIndex(defaultIndex, dataLength)) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`[react-native-reanimated-carousel] defaultIndex must be an integer between 0 and ${dataLength - 1}.`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import type { TInitializeCarouselProps } from "./useInitProps";
|
|
4
|
-
|
|
5
|
-
import type { TAnimationStyle } from "../components/ItemLayout";
|
|
6
3
|
import { Layouts } from "../layouts";
|
|
4
|
+
import type { CarouselItemAnimation } from "../types";
|
|
5
|
+
import type { InitializedCarouselProps } from "./useInitProps";
|
|
7
6
|
|
|
8
|
-
type
|
|
7
|
+
type LayoutConfigOptions<Item> = InitializedCarouselProps<Item> & { size: number };
|
|
9
8
|
|
|
10
|
-
export function useLayoutConfig<
|
|
11
|
-
const {
|
|
9
|
+
export function useLayoutConfig<Item>(options: LayoutConfigOptions<Item>): CarouselItemAnimation {
|
|
10
|
+
const { dataLength, directionSign, layout, orientation, size } = options;
|
|
11
|
+
const isVertical = orientation === "vertical";
|
|
12
12
|
|
|
13
13
|
return React.useMemo(() => {
|
|
14
|
-
const baseConfig = { size,
|
|
15
|
-
switch (
|
|
14
|
+
const baseConfig = { size, isVertical, directionSign };
|
|
15
|
+
switch (layout?.type) {
|
|
16
16
|
case "parallax":
|
|
17
|
-
return Layouts.parallax(baseConfig,
|
|
17
|
+
return Layouts.parallax(baseConfig, layout);
|
|
18
18
|
case "horizontal-stack":
|
|
19
|
-
return Layouts.horizontalStack(
|
|
19
|
+
return Layouts.horizontalStack(
|
|
20
|
+
{
|
|
21
|
+
...layout,
|
|
22
|
+
visibleCount: layout.visibleCount ?? Math.max(0, dataLength - 1),
|
|
23
|
+
},
|
|
24
|
+
directionSign
|
|
25
|
+
);
|
|
20
26
|
case "vertical-stack":
|
|
21
|
-
return Layouts.verticalStack(
|
|
27
|
+
return Layouts.verticalStack({
|
|
28
|
+
...layout,
|
|
29
|
+
visibleCount: layout.visibleCount ?? Math.max(0, dataLength - 1),
|
|
30
|
+
});
|
|
22
31
|
default:
|
|
23
32
|
return Layouts.normal(baseConfig);
|
|
24
33
|
}
|
|
25
|
-
}, [
|
|
34
|
+
}, [dataLength, directionSign, isVertical, layout, size]);
|
|
26
35
|
}
|
package/src/hooks/useOffsetX.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SharedValue } from "react-native-reanimated";
|
|
2
2
|
import { Extrapolation, interpolate, useDerivedValue } from "react-native-reanimated";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { VisibleRangesValue } from "./useVisibleRanges";
|
|
5
5
|
|
|
6
|
-
export interface
|
|
6
|
+
export interface OffsetOptions {
|
|
7
7
|
index: number;
|
|
8
8
|
size: number;
|
|
9
9
|
handlerOffset: SharedValue<number>;
|
|
@@ -13,7 +13,7 @@ export interface IOpts {
|
|
|
13
13
|
loop?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const useOffsetX = (opts:
|
|
16
|
+
export const useOffsetX = (opts: OffsetOptions, visibleRanges: VisibleRangesValue) => {
|
|
17
17
|
const {
|
|
18
18
|
handlerOffset,
|
|
19
19
|
index,
|