@leonsilicon/react-native-reanimated-carousel 0.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/LICENSE +21 -0
- package/README.md +652 -0
- package/lib/commonjs/components/Carousel.js +2 -0
- package/lib/commonjs/components/Carousel.js.map +1 -0
- package/lib/commonjs/components/CarouselLayout.js +2 -0
- package/lib/commonjs/components/CarouselLayout.js.map +1 -0
- package/lib/commonjs/components/ItemLayout.js +2 -0
- package/lib/commonjs/components/ItemLayout.js.map +1 -0
- package/lib/commonjs/components/ItemRenderer.js +2 -0
- package/lib/commonjs/components/ItemRenderer.js.map +1 -0
- package/lib/commonjs/components/LazyView.js +2 -0
- package/lib/commonjs/components/LazyView.js.map +1 -0
- package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +2 -0
- package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +1 -0
- package/lib/commonjs/components/Pagination/Basic/index.js +2 -0
- package/lib/commonjs/components/Pagination/Basic/index.js.map +1 -0
- package/lib/commonjs/components/Pagination/Custom/PaginationItem.js +2 -0
- package/lib/commonjs/components/Pagination/Custom/PaginationItem.js.map +1 -0
- package/lib/commonjs/components/Pagination/Custom/index.js +2 -0
- package/lib/commonjs/components/Pagination/Custom/index.js.map +1 -0
- package/lib/commonjs/components/Pagination/index.js +2 -0
- package/lib/commonjs/components/Pagination/index.js.map +1 -0
- package/lib/commonjs/components/ScrollViewGesture.js +2 -0
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
- package/lib/commonjs/constants/index.js +2 -0
- package/lib/commonjs/constants/index.js.map +1 -0
- package/lib/commonjs/hooks/useAutoPlay.js +2 -0
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -0
- package/lib/commonjs/hooks/useCarouselController.js +2 -0
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -0
- package/lib/commonjs/hooks/useCheckMounted.js +2 -0
- package/lib/commonjs/hooks/useCheckMounted.js.map +1 -0
- package/lib/commonjs/hooks/useCommonVariables.js +2 -0
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -0
- package/lib/commonjs/hooks/useInitProps.js +2 -0
- package/lib/commonjs/hooks/useInitProps.js.map +1 -0
- package/lib/commonjs/hooks/useLayoutConfig.js +2 -0
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -0
- package/lib/commonjs/hooks/useOffsetX.js +2 -0
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -0
- package/lib/commonjs/hooks/useOnProgressChange.js +2 -0
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -0
- package/lib/commonjs/hooks/usePanGestureProxy.js +2 -0
- package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +2 -0
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -0
- package/lib/commonjs/hooks/useSizeResolver.js +2 -0
- package/lib/commonjs/hooks/useSizeResolver.js.map +1 -0
- package/lib/commonjs/hooks/useUpdateGestureConfig.js +2 -0
- package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/commonjs/hooks/useVisibleRanges.js +2 -0
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -0
- package/lib/commonjs/index.js +2 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/layouts/index.js +2 -0
- package/lib/commonjs/layouts/index.js.map +1 -0
- package/lib/commonjs/layouts/normal.js +2 -0
- package/lib/commonjs/layouts/normal.js.map +1 -0
- package/lib/commonjs/layouts/parallax.js +2 -0
- package/lib/commonjs/layouts/parallax.js.map +1 -0
- package/lib/commonjs/layouts/stack.js +2 -0
- package/lib/commonjs/layouts/stack.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/store/index.js +2 -0
- package/lib/commonjs/store/index.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/compute-gesture-translation.js +2 -0
- package/lib/commonjs/utils/compute-gesture-translation.js.map +1 -0
- package/lib/commonjs/utils/compute-offset-if-data-changed.js +2 -0
- package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +1 -0
- package/lib/commonjs/utils/compute-offset-if-size-changed.js +2 -0
- package/lib/commonjs/utils/compute-offset-if-size-changed.js.map +1 -0
- package/lib/commonjs/utils/compute-offset-if-sizes-changed.js +2 -0
- package/lib/commonjs/utils/compute-offset-if-sizes-changed.js.map +1 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js +2 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/commonjs/utils/deal-with-animation.js +2 -0
- package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
- package/lib/commonjs/utils/handleroffset-direction.js +2 -0
- package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
- package/lib/commonjs/utils/log.js +2 -0
- package/lib/commonjs/utils/log.js.map +1 -0
- package/lib/commonjs/utils/sanitize-animation-style.js +2 -0
- package/lib/commonjs/utils/sanitize-animation-style.js.map +1 -0
- package/lib/commonjs/utils/size-resolver.js +2 -0
- package/lib/commonjs/utils/size-resolver.js.map +1 -0
- package/lib/module/components/Carousel.js +2 -0
- package/lib/module/components/Carousel.js.map +1 -0
- package/lib/module/components/CarouselLayout.js +2 -0
- package/lib/module/components/CarouselLayout.js.map +1 -0
- package/lib/module/components/ItemLayout.js +2 -0
- package/lib/module/components/ItemLayout.js.map +1 -0
- package/lib/module/components/ItemRenderer.js +2 -0
- package/lib/module/components/ItemRenderer.js.map +1 -0
- package/lib/module/components/LazyView.js +2 -0
- package/lib/module/components/LazyView.js.map +1 -0
- package/lib/module/components/Pagination/Basic/PaginationItem.js +2 -0
- package/lib/module/components/Pagination/Basic/PaginationItem.js.map +1 -0
- package/lib/module/components/Pagination/Basic/index.js +2 -0
- package/lib/module/components/Pagination/Basic/index.js.map +1 -0
- package/lib/module/components/Pagination/Custom/PaginationItem.js +2 -0
- package/lib/module/components/Pagination/Custom/PaginationItem.js.map +1 -0
- package/lib/module/components/Pagination/Custom/index.js +2 -0
- package/lib/module/components/Pagination/Custom/index.js.map +1 -0
- package/lib/module/components/Pagination/index.js +2 -0
- package/lib/module/components/Pagination/index.js.map +1 -0
- package/lib/module/components/ScrollViewGesture.js +2 -0
- package/lib/module/components/ScrollViewGesture.js.map +1 -0
- package/lib/module/constants/index.js +2 -0
- package/lib/module/constants/index.js.map +1 -0
- package/lib/module/hooks/useAutoPlay.js +2 -0
- package/lib/module/hooks/useAutoPlay.js.map +1 -0
- package/lib/module/hooks/useCarouselController.js +2 -0
- package/lib/module/hooks/useCarouselController.js.map +1 -0
- package/lib/module/hooks/useCheckMounted.js +2 -0
- package/lib/module/hooks/useCheckMounted.js.map +1 -0
- package/lib/module/hooks/useCommonVariables.js +2 -0
- package/lib/module/hooks/useCommonVariables.js.map +1 -0
- package/lib/module/hooks/useInitProps.js +2 -0
- package/lib/module/hooks/useInitProps.js.map +1 -0
- package/lib/module/hooks/useLayoutConfig.js +2 -0
- package/lib/module/hooks/useLayoutConfig.js.map +1 -0
- package/lib/module/hooks/useOffsetX.js +2 -0
- package/lib/module/hooks/useOffsetX.js.map +1 -0
- package/lib/module/hooks/useOnProgressChange.js +2 -0
- package/lib/module/hooks/useOnProgressChange.js.map +1 -0
- package/lib/module/hooks/usePanGestureProxy.js +2 -0
- package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
- package/lib/module/hooks/usePropsErrorBoundary.js +2 -0
- package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -0
- package/lib/module/hooks/useSizeResolver.js +2 -0
- package/lib/module/hooks/useSizeResolver.js.map +1 -0
- package/lib/module/hooks/useUpdateGestureConfig.js +2 -0
- package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/module/hooks/useVisibleRanges.js +2 -0
- package/lib/module/hooks/useVisibleRanges.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/layouts/index.js +2 -0
- package/lib/module/layouts/index.js.map +1 -0
- package/lib/module/layouts/normal.js +2 -0
- package/lib/module/layouts/normal.js.map +1 -0
- package/lib/module/layouts/parallax.js +2 -0
- package/lib/module/layouts/parallax.js.map +1 -0
- package/lib/module/layouts/stack.js +2 -0
- package/lib/module/layouts/stack.js.map +1 -0
- package/lib/module/store/index.js +2 -0
- package/lib/module/store/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/compute-gesture-translation.js +2 -0
- package/lib/module/utils/compute-gesture-translation.js.map +1 -0
- package/lib/module/utils/compute-offset-if-data-changed.js +2 -0
- package/lib/module/utils/compute-offset-if-data-changed.js.map +1 -0
- package/lib/module/utils/compute-offset-if-size-changed.js +2 -0
- package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -0
- package/lib/module/utils/compute-offset-if-sizes-changed.js +2 -0
- package/lib/module/utils/compute-offset-if-sizes-changed.js.map +1 -0
- package/lib/module/utils/computed-with-auto-fill-data.js +2 -0
- package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/module/utils/deal-with-animation.js +2 -0
- package/lib/module/utils/deal-with-animation.js.map +1 -0
- package/lib/module/utils/handleroffset-direction.js +2 -0
- package/lib/module/utils/handleroffset-direction.js.map +1 -0
- package/lib/module/utils/log.js +2 -0
- package/lib/module/utils/log.js.map +1 -0
- package/lib/module/utils/sanitize-animation-style.js +2 -0
- package/lib/module/utils/sanitize-animation-style.js.map +1 -0
- package/lib/module/utils/size-resolver.js +2 -0
- package/lib/module/utils/size-resolver.js.map +1 -0
- package/lib/typescript/components/Carousel.d.ts +8 -0
- package/lib/typescript/components/Carousel.d.ts.map +1 -0
- package/lib/typescript/components/CarouselLayout.d.ts +6 -0
- package/lib/typescript/components/CarouselLayout.d.ts.map +1 -0
- package/lib/typescript/components/ItemLayout.d.ts +15 -0
- package/lib/typescript/components/ItemLayout.d.ts.map +1 -0
- package/lib/typescript/components/ItemRenderer.d.ts +24 -0
- package/lib/typescript/components/ItemRenderer.d.ts.map +1 -0
- package/lib/typescript/components/LazyView.d.ts +8 -0
- package/lib/typescript/components/LazyView.d.ts.map +1 -0
- package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +29 -0
- package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts.map +1 -0
- package/lib/typescript/components/Pagination/Basic/index.d.ts +23 -0
- package/lib/typescript/components/Pagination/Basic/index.d.ts.map +1 -0
- package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts +35 -0
- package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts.map +1 -0
- package/lib/typescript/components/Pagination/Custom/index.d.ts +26 -0
- package/lib/typescript/components/Pagination/Custom/index.d.ts.map +1 -0
- package/lib/typescript/components/Pagination/index.d.ts +5 -0
- package/lib/typescript/components/Pagination/index.d.ts.map +1 -0
- package/lib/typescript/components/ScrollViewGesture.d.ts +19 -0
- package/lib/typescript/components/ScrollViewGesture.d.ts.map +1 -0
- package/lib/typescript/constants/index.d.ts +9 -0
- package/lib/typescript/constants/index.d.ts.map +1 -0
- package/lib/typescript/hooks/useAutoPlay.d.ts +12 -0
- package/lib/typescript/hooks/useAutoPlay.d.ts.map +1 -0
- package/lib/typescript/hooks/useCarouselController.d.ts +28 -0
- package/lib/typescript/hooks/useCarouselController.d.ts.map +1 -0
- package/lib/typescript/hooks/useCheckMounted.d.ts +3 -0
- package/lib/typescript/hooks/useCheckMounted.d.ts.map +1 -0
- package/lib/typescript/hooks/useCommonVariables.d.ts +13 -0
- package/lib/typescript/hooks/useCommonVariables.d.ts.map +1 -0
- package/lib/typescript/hooks/useInitProps.d.ts +17 -0
- package/lib/typescript/hooks/useInitProps.d.ts.map +1 -0
- package/lib/typescript/hooks/useLayoutConfig.d.ts +10 -0
- package/lib/typescript/hooks/useLayoutConfig.d.ts.map +1 -0
- package/lib/typescript/hooks/useOffsetX.d.ts +24 -0
- package/lib/typescript/hooks/useOffsetX.d.ts.map +1 -0
- package/lib/typescript/hooks/useOnProgressChange.d.ts +14 -0
- package/lib/typescript/hooks/useOnProgressChange.d.ts.map +1 -0
- package/lib/typescript/hooks/usePanGestureProxy.d.ts +10 -0
- package/lib/typescript/hooks/usePanGestureProxy.d.ts.map +1 -0
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +5 -0
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/hooks/useSizeResolver.d.ts +27 -0
- package/lib/typescript/hooks/useSizeResolver.d.ts.map +1 -0
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +6 -0
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts.map +1 -0
- package/lib/typescript/hooks/useVisibleRanges.d.ts +23 -0
- package/lib/typescript/hooks/useVisibleRanges.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/layouts/index.d.ts +11 -0
- package/lib/typescript/layouts/index.d.ts.map +1 -0
- package/lib/typescript/layouts/normal.d.ts +16 -0
- package/lib/typescript/layouts/normal.d.ts.map +1 -0
- package/lib/typescript/layouts/parallax.d.ts +50 -0
- package/lib/typescript/layouts/parallax.d.ts.map +1 -0
- package/lib/typescript/layouts/stack.d.ts +38 -0
- package/lib/typescript/layouts/stack.d.ts.map +1 -0
- package/lib/typescript/store/index.d.ts +38 -0
- package/lib/typescript/store/index.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +326 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils/compute-gesture-translation.d.ts +9 -0
- package/lib/typescript/utils/compute-gesture-translation.d.ts.map +1 -0
- package/lib/typescript/utils/compute-offset-if-data-changed.d.ts +9 -0
- package/lib/typescript/utils/compute-offset-if-data-changed.d.ts.map +1 -0
- package/lib/typescript/utils/compute-offset-if-size-changed.d.ts +6 -0
- package/lib/typescript/utils/compute-offset-if-size-changed.d.ts.map +1 -0
- package/lib/typescript/utils/compute-offset-if-sizes-changed.d.ts +14 -0
- package/lib/typescript/utils/compute-offset-if-sizes-changed.d.ts.map +1 -0
- package/lib/typescript/utils/computed-with-auto-fill-data.d.ts +23 -0
- package/lib/typescript/utils/computed-with-auto-fill-data.d.ts.map +1 -0
- package/lib/typescript/utils/deal-with-animation.d.ts +3 -0
- package/lib/typescript/utils/deal-with-animation.d.ts.map +1 -0
- package/lib/typescript/utils/handleroffset-direction.d.ts +4 -0
- package/lib/typescript/utils/handleroffset-direction.d.ts.map +1 -0
- package/lib/typescript/utils/log.d.ts +7 -0
- package/lib/typescript/utils/log.d.ts.map +1 -0
- package/lib/typescript/utils/sanitize-animation-style.d.ts +3 -0
- package/lib/typescript/utils/sanitize-animation-style.d.ts.map +1 -0
- package/lib/typescript/utils/size-resolver.d.ts +87 -0
- package/lib/typescript/utils/size-resolver.d.ts.map +1 -0
- package/package.json +151 -0
- package/src/components/Carousel.test.tsx +1153 -0
- package/src/components/Carousel.tsx +35 -0
- package/src/components/CarouselLayout.tsx +231 -0
- package/src/components/ItemLayout.tsx +217 -0
- package/src/components/ItemRenderer.tsx +114 -0
- package/src/components/LazyView.test.tsx +61 -0
- package/src/components/LazyView.tsx +14 -0
- package/src/components/Pagination/Basic/PaginationItem.tsx +149 -0
- package/src/components/Pagination/Basic/index.tsx +98 -0
- package/src/components/Pagination/Custom/PaginationItem.tsx +166 -0
- package/src/components/Pagination/Custom/index.tsx +111 -0
- package/src/components/Pagination/Pagination.test.tsx +178 -0
- package/src/components/Pagination/index.tsx +7 -0
- package/src/components/ScrollViewGesture.tsx +577 -0
- package/src/components/rnr-demo.test.tsx +53 -0
- package/src/constants/index.ts +11 -0
- package/src/hooks/useAutoPlay.test.ts +194 -0
- package/src/hooks/useAutoPlay.ts +58 -0
- package/src/hooks/useCarouselController.test.tsx +1158 -0
- package/src/hooks/useCarouselController.tsx +525 -0
- package/src/hooks/useCheckMounted.test.ts +47 -0
- package/src/hooks/useCheckMounted.ts +14 -0
- package/src/hooks/useCommonVariables.test.tsx +384 -0
- package/src/hooks/useCommonVariables.ts +202 -0
- package/src/hooks/useInitProps.test.tsx +134 -0
- package/src/hooks/useInitProps.ts +111 -0
- package/src/hooks/useLayoutConfig.test.tsx +247 -0
- package/src/hooks/useLayoutConfig.ts +30 -0
- package/src/hooks/useOffsetX.test.ts +110 -0
- package/src/hooks/useOffsetX.ts +109 -0
- package/src/hooks/useOnProgressChange.test.tsx +207 -0
- package/src/hooks/useOnProgressChange.ts +105 -0
- package/src/hooks/usePanGestureProxy.test.tsx +368 -0
- package/src/hooks/usePanGestureProxy.ts +144 -0
- package/src/hooks/usePropsErrorBoundary.ts +138 -0
- package/src/hooks/useSizeResolver.test.tsx +112 -0
- package/src/hooks/useSizeResolver.ts +106 -0
- package/src/hooks/useUpdateGestureConfig.test.ts +89 -0
- package/src/hooks/useUpdateGestureConfig.ts +14 -0
- package/src/hooks/useVisibleRanges.test.tsx +366 -0
- package/src/hooks/useVisibleRanges.tsx +123 -0
- package/src/index.tsx +13 -0
- package/src/layouts/index.tsx +12 -0
- package/src/layouts/normal.ts +32 -0
- package/src/layouts/parallax.test.ts +239 -0
- package/src/layouts/parallax.ts +83 -0
- package/src/layouts/stack.test.ts +252 -0
- package/src/layouts/stack.ts +306 -0
- package/src/store/index.test.tsx +314 -0
- package/src/store/index.tsx +66 -0
- package/src/types.ts +348 -0
- package/src/utils/compute-gesture-translation.test.ts +70 -0
- package/src/utils/compute-gesture-translation.ts +29 -0
- package/src/utils/compute-offset-if-data-changed.test.ts +133 -0
- package/src/utils/compute-offset-if-data-changed.ts +44 -0
- package/src/utils/compute-offset-if-size-changed.test.ts +78 -0
- package/src/utils/compute-offset-if-size-changed.ts +14 -0
- package/src/utils/compute-offset-if-sizes-changed.test.ts +74 -0
- package/src/utils/compute-offset-if-sizes-changed.ts +44 -0
- package/src/utils/computed-with-auto-fill-data.test.ts +298 -0
- package/src/utils/computed-with-auto-fill-data.ts +92 -0
- package/src/utils/deal-with-animation.test.ts +181 -0
- package/src/utils/deal-with-animation.ts +17 -0
- package/src/utils/handleroffset-direction.test.ts +124 -0
- package/src/utils/handleroffset-direction.ts +18 -0
- package/src/utils/index.test.ts +90 -0
- package/src/utils/log.test.ts +134 -0
- package/src/utils/log.ts +12 -0
- package/src/utils/sanitize-animation-style.test.ts +40 -0
- package/src/utils/sanitize-animation-style.ts +20 -0
- package/src/utils/size-resolver.test.ts +193 -0
- package/src/utils/size-resolver.ts +216 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
5
|
+
|
|
6
|
+
import { useInitProps } from "./useInitProps";
|
|
7
|
+
|
|
8
|
+
import type { TCarouselProps } from "../types";
|
|
9
|
+
|
|
10
|
+
describe("useInitProps", () => {
|
|
11
|
+
const defaultData = [1, 2, 3, 4];
|
|
12
|
+
const defaultProps: TCarouselProps<number> = {
|
|
13
|
+
data: defaultData,
|
|
14
|
+
width: 300,
|
|
15
|
+
height: 200,
|
|
16
|
+
renderItem: ({ item: _item }) => <Text>Item</Text>,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
it("should initialize with default values", () => {
|
|
20
|
+
const { result } = renderHook(() => useInitProps(defaultProps));
|
|
21
|
+
|
|
22
|
+
expect(result.current).toEqual(
|
|
23
|
+
expect.objectContaining({
|
|
24
|
+
defaultIndex: 0,
|
|
25
|
+
loop: true,
|
|
26
|
+
autoPlayInterval: 1000,
|
|
27
|
+
scrollAnimationDuration: 500,
|
|
28
|
+
width: 300,
|
|
29
|
+
height: 200,
|
|
30
|
+
enabled: true,
|
|
31
|
+
autoFillData: true,
|
|
32
|
+
pagingEnabled: true,
|
|
33
|
+
snapEnabled: true,
|
|
34
|
+
overscrollEnabled: true,
|
|
35
|
+
data: defaultData,
|
|
36
|
+
rawData: defaultData,
|
|
37
|
+
dataLength: 4,
|
|
38
|
+
rawDataLength: 4,
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should handle custom values", () => {
|
|
44
|
+
const customProps: TCarouselProps<number> = {
|
|
45
|
+
...defaultProps,
|
|
46
|
+
defaultIndex: 2,
|
|
47
|
+
loop: false,
|
|
48
|
+
autoPlayInterval: 2000,
|
|
49
|
+
scrollAnimationDuration: 300,
|
|
50
|
+
enabled: false,
|
|
51
|
+
autoFillData: false,
|
|
52
|
+
pagingEnabled: false,
|
|
53
|
+
snapEnabled: false,
|
|
54
|
+
overscrollEnabled: false,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const { result } = renderHook(() => useInitProps(customProps));
|
|
58
|
+
|
|
59
|
+
expect(result.current).toEqual(
|
|
60
|
+
expect.objectContaining({
|
|
61
|
+
...customProps,
|
|
62
|
+
data: defaultData,
|
|
63
|
+
rawData: defaultData,
|
|
64
|
+
dataLength: 4,
|
|
65
|
+
rawDataLength: 4,
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
it("should handle stack mode configuration", () => {
|
|
70
|
+
const stackProps: TCarouselProps<number> = {
|
|
71
|
+
...defaultProps,
|
|
72
|
+
mode: "horizontal-stack",
|
|
73
|
+
modeConfig: {
|
|
74
|
+
showLength: 3,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const { result } = renderHook(() => useInitProps(stackProps));
|
|
79
|
+
|
|
80
|
+
expect(result.current.modeConfig).toBeDefined();
|
|
81
|
+
if (result.current.modeConfig && "showLength" in result.current.modeConfig)
|
|
82
|
+
expect(result.current.modeConfig.showLength).toBe(3); // dataLength - 1
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should handle empty data array", () => {
|
|
86
|
+
const props: TCarouselProps<number> = {
|
|
87
|
+
...defaultProps,
|
|
88
|
+
data: [],
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const { result } = renderHook(() => useInitProps(props));
|
|
92
|
+
|
|
93
|
+
expect(result.current.dataLength).toBe(0);
|
|
94
|
+
expect(result.current.rawDataLength).toBe(0);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should round width and height values", () => {
|
|
98
|
+
const props: TCarouselProps<number> = {
|
|
99
|
+
...defaultProps,
|
|
100
|
+
width: 300.6,
|
|
101
|
+
height: 200.4,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const { result } = renderHook(() => useInitProps(props));
|
|
105
|
+
|
|
106
|
+
expect(result.current.width).toBe(301);
|
|
107
|
+
expect(result.current.height).toBe(200);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should handle enableSnap property", () => {
|
|
111
|
+
const props: TCarouselProps<number> = {
|
|
112
|
+
...defaultProps,
|
|
113
|
+
enableSnap: false,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const { result } = renderHook(() => useInitProps(props));
|
|
117
|
+
|
|
118
|
+
expect(result.current.snapEnabled).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
it("should handle vertical-stack mode", () => {
|
|
121
|
+
const props: TCarouselProps<number> = {
|
|
122
|
+
...defaultProps,
|
|
123
|
+
mode: "vertical-stack",
|
|
124
|
+
modeConfig: {
|
|
125
|
+
showLength: 3,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const { result } = renderHook(() => useInitProps(props));
|
|
130
|
+
expect(result.current.modeConfig).toBeDefined();
|
|
131
|
+
if (result.current.modeConfig && "showLength" in result.current.modeConfig)
|
|
132
|
+
expect(result.current.modeConfig.showLength).toBe(3); // dataLength - 1
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import type { TCarouselProps } from "../types";
|
|
4
|
+
import { computedFillDataWithAutoFillData } from "../utils/computed-with-auto-fill-data";
|
|
5
|
+
|
|
6
|
+
type TGetRequiredProps<P extends keyof TCarouselProps> = Record<P, Required<TCarouselProps>[P]>;
|
|
7
|
+
|
|
8
|
+
export type TInitializeCarouselProps<T> = TCarouselProps<T> &
|
|
9
|
+
TGetRequiredProps<
|
|
10
|
+
"defaultIndex" | "loop" | "scrollAnimationDuration" | "autoPlayInterval" | "autoFillData"
|
|
11
|
+
> & {
|
|
12
|
+
// Raw data that has not been processed
|
|
13
|
+
rawData: T[];
|
|
14
|
+
dataLength: number;
|
|
15
|
+
rawDataLength: number;
|
|
16
|
+
/**
|
|
17
|
+
* Axis-aware item-size getter — `getItemHeight` when vertical, otherwise
|
|
18
|
+
* `getItemWidth`. Undefined unless the user supplied the matching prop.
|
|
19
|
+
*/
|
|
20
|
+
getItemSize?: (index: number) => number;
|
|
21
|
+
/** `true` when variable-size mode is active (`getItemSize` is set). */
|
|
22
|
+
variableSize: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function useInitProps<T>(props: TCarouselProps<T>): TInitializeCarouselProps<T> {
|
|
26
|
+
const {
|
|
27
|
+
defaultIndex = 0,
|
|
28
|
+
data: rawData = [],
|
|
29
|
+
loop = true,
|
|
30
|
+
autoPlayInterval: _autoPlayInterval = 1000,
|
|
31
|
+
scrollAnimationDuration = 500,
|
|
32
|
+
style = {},
|
|
33
|
+
autoFillData = true,
|
|
34
|
+
// switchers
|
|
35
|
+
enabled = true,
|
|
36
|
+
pagingEnabled = true,
|
|
37
|
+
overscrollEnabled = true,
|
|
38
|
+
snapEnabled = props.enableSnap ?? true,
|
|
39
|
+
width: _width,
|
|
40
|
+
height: _height,
|
|
41
|
+
itemWidth: _itemWidth,
|
|
42
|
+
itemHeight: _itemHeight,
|
|
43
|
+
getItemWidth,
|
|
44
|
+
getItemHeight,
|
|
45
|
+
vertical,
|
|
46
|
+
} = props;
|
|
47
|
+
|
|
48
|
+
const width = typeof _width === "number" ? Math.round(_width) : undefined;
|
|
49
|
+
const height = typeof _height === "number" ? Math.round(_height) : undefined;
|
|
50
|
+
const itemWidth = typeof _itemWidth === "number" && _itemWidth > 0 ? _itemWidth : undefined;
|
|
51
|
+
const itemHeight = typeof _itemHeight === "number" && _itemHeight > 0 ? _itemHeight : undefined;
|
|
52
|
+
const autoPlayInterval = Math.max(_autoPlayInterval, 0);
|
|
53
|
+
|
|
54
|
+
// Axis-aware variable-size getter. When `getItemWidth`/`getItemHeight` is
|
|
55
|
+
// provided for the active axis, variable-size mode is enabled downstream.
|
|
56
|
+
const getItemSize = vertical ? getItemHeight : getItemWidth;
|
|
57
|
+
const variableSize = typeof getItemSize === "function";
|
|
58
|
+
|
|
59
|
+
// autoFillData duplicates data assuming a single page size; it produces
|
|
60
|
+
// incorrect totals once items differ in size. Disable it silently in
|
|
61
|
+
// variable-size mode (`usePropsErrorBoundary` warns the user).
|
|
62
|
+
const effectiveAutoFillData = variableSize ? false : autoFillData;
|
|
63
|
+
|
|
64
|
+
const data = React.useMemo<T[]>(() => {
|
|
65
|
+
return computedFillDataWithAutoFillData<T>({
|
|
66
|
+
loop,
|
|
67
|
+
autoFillData: effectiveAutoFillData,
|
|
68
|
+
data: rawData,
|
|
69
|
+
dataLength: rawData.length,
|
|
70
|
+
});
|
|
71
|
+
}, [rawData, loop, effectiveAutoFillData]);
|
|
72
|
+
|
|
73
|
+
const dataLength = data.length;
|
|
74
|
+
const rawDataLength = rawData.length;
|
|
75
|
+
|
|
76
|
+
if (props.mode === "vertical-stack" || props.mode === "horizontal-stack") {
|
|
77
|
+
if (!props.modeConfig) props.modeConfig = {};
|
|
78
|
+
|
|
79
|
+
props.modeConfig.showLength = props.modeConfig?.showLength ?? dataLength - 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
...props,
|
|
84
|
+
defaultIndex,
|
|
85
|
+
autoFillData: effectiveAutoFillData,
|
|
86
|
+
// Fill data with autoFillData
|
|
87
|
+
data,
|
|
88
|
+
// Length of fill data
|
|
89
|
+
dataLength,
|
|
90
|
+
// Raw data that has not been processed
|
|
91
|
+
rawData,
|
|
92
|
+
// Length of raw data
|
|
93
|
+
rawDataLength,
|
|
94
|
+
loop,
|
|
95
|
+
enabled,
|
|
96
|
+
autoPlayInterval,
|
|
97
|
+
scrollAnimationDuration,
|
|
98
|
+
style,
|
|
99
|
+
pagingEnabled,
|
|
100
|
+
snapEnabled,
|
|
101
|
+
overscrollEnabled,
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
itemWidth,
|
|
105
|
+
itemHeight,
|
|
106
|
+
getItemWidth,
|
|
107
|
+
getItemHeight,
|
|
108
|
+
getItemSize,
|
|
109
|
+
variableSize,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
5
|
+
|
|
6
|
+
import { useLayoutConfig } from "./useLayoutConfig";
|
|
7
|
+
|
|
8
|
+
describe("useLayoutConfig", () => {
|
|
9
|
+
const defaultProps = {
|
|
10
|
+
size: 300,
|
|
11
|
+
vertical: false,
|
|
12
|
+
};
|
|
13
|
+
it("should return normal layout by default", () => {
|
|
14
|
+
const { result } = renderHook(() =>
|
|
15
|
+
useLayoutConfig({
|
|
16
|
+
...defaultProps,
|
|
17
|
+
data: [],
|
|
18
|
+
renderItem: () => <View />,
|
|
19
|
+
loop: false,
|
|
20
|
+
autoFillData: false,
|
|
21
|
+
defaultIndex: 0,
|
|
22
|
+
autoPlayInterval: 0,
|
|
23
|
+
scrollAnimationDuration: 0,
|
|
24
|
+
width: 0,
|
|
25
|
+
height: 0,
|
|
26
|
+
rawData: [],
|
|
27
|
+
dataLength: 0,
|
|
28
|
+
rawDataLength: 0,
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(result.current).toBeDefined();
|
|
33
|
+
expect(typeof result.current).toBe("function");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should handle parallax mode", () => {
|
|
37
|
+
const props = {
|
|
38
|
+
...defaultProps,
|
|
39
|
+
mode: "parallax" as const,
|
|
40
|
+
modeConfig: {
|
|
41
|
+
parallaxScrollingScale: 0.9,
|
|
42
|
+
parallaxScrollingOffset: 50,
|
|
43
|
+
parallaxAdjacentItemScale: 0.8,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const { result } = renderHook(() =>
|
|
48
|
+
useLayoutConfig({
|
|
49
|
+
...props,
|
|
50
|
+
data: [],
|
|
51
|
+
renderItem: () => <View />,
|
|
52
|
+
loop: false,
|
|
53
|
+
autoFillData: false,
|
|
54
|
+
defaultIndex: 0,
|
|
55
|
+
autoPlayInterval: 0,
|
|
56
|
+
scrollAnimationDuration: 0,
|
|
57
|
+
width: 0,
|
|
58
|
+
height: 0,
|
|
59
|
+
rawData: [],
|
|
60
|
+
dataLength: 0,
|
|
61
|
+
rawDataLength: 0,
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
const style = result.current(0); // Test with offset 0
|
|
65
|
+
|
|
66
|
+
expect(style.transform).toBeDefined();
|
|
67
|
+
expect(style.transform).toContainEqual({ translateX: 0 });
|
|
68
|
+
expect(style.transform).toContainEqual({ scale: 0.9 });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should handle horizontal-stack mode", () => {
|
|
72
|
+
const props = {
|
|
73
|
+
...defaultProps,
|
|
74
|
+
mode: "horizontal-stack" as const,
|
|
75
|
+
modeConfig: {
|
|
76
|
+
snapDirection: "left" as const,
|
|
77
|
+
showLength: 3,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const { result } = renderHook(() =>
|
|
82
|
+
useLayoutConfig({
|
|
83
|
+
...props,
|
|
84
|
+
data: [],
|
|
85
|
+
renderItem: () => <View />,
|
|
86
|
+
loop: false,
|
|
87
|
+
autoFillData: false,
|
|
88
|
+
defaultIndex: 0,
|
|
89
|
+
autoPlayInterval: 0,
|
|
90
|
+
scrollAnimationDuration: 0,
|
|
91
|
+
width: 0,
|
|
92
|
+
height: 0,
|
|
93
|
+
rawData: [],
|
|
94
|
+
dataLength: 0,
|
|
95
|
+
rawDataLength: 0,
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
const style = result.current(0); // Test with offset 0
|
|
99
|
+
|
|
100
|
+
expect(style.transform).toBeDefined();
|
|
101
|
+
expect(style.zIndex).toBeDefined();
|
|
102
|
+
expect(style.opacity).toBeDefined();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should handle vertical-stack mode", () => {
|
|
106
|
+
const props = {
|
|
107
|
+
...defaultProps,
|
|
108
|
+
mode: "vertical-stack" as const,
|
|
109
|
+
modeConfig: {
|
|
110
|
+
snapDirection: "left" as const,
|
|
111
|
+
showLength: 3,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const { result } = renderHook(() =>
|
|
116
|
+
useLayoutConfig({
|
|
117
|
+
...props,
|
|
118
|
+
data: [],
|
|
119
|
+
renderItem: () => <View />,
|
|
120
|
+
loop: false,
|
|
121
|
+
autoFillData: false,
|
|
122
|
+
defaultIndex: 0,
|
|
123
|
+
autoPlayInterval: 0,
|
|
124
|
+
scrollAnimationDuration: 0,
|
|
125
|
+
width: 0,
|
|
126
|
+
height: 0,
|
|
127
|
+
rawData: [],
|
|
128
|
+
dataLength: 0,
|
|
129
|
+
rawDataLength: 0,
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
const style = result.current(0); // Test with offset 0
|
|
133
|
+
|
|
134
|
+
expect(style.transform).toBeDefined();
|
|
135
|
+
expect(style.zIndex).toBeDefined();
|
|
136
|
+
expect(style.opacity).toBeDefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should handle vertical orientation", () => {
|
|
140
|
+
const props = {
|
|
141
|
+
...defaultProps,
|
|
142
|
+
vertical: true,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const { result } = renderHook(() =>
|
|
146
|
+
useLayoutConfig({
|
|
147
|
+
...props,
|
|
148
|
+
data: [],
|
|
149
|
+
renderItem: () => <View />,
|
|
150
|
+
loop: false,
|
|
151
|
+
autoFillData: false,
|
|
152
|
+
defaultIndex: 0,
|
|
153
|
+
autoPlayInterval: 0,
|
|
154
|
+
scrollAnimationDuration: 0,
|
|
155
|
+
width: 0,
|
|
156
|
+
height: 0,
|
|
157
|
+
rawData: [],
|
|
158
|
+
dataLength: 0,
|
|
159
|
+
rawDataLength: 0,
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
const style = result.current(0); // Test with offset 0
|
|
163
|
+
|
|
164
|
+
expect(style.transform).toBeDefined();
|
|
165
|
+
expect(style.transform).toContainEqual({ translateY: 0 });
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should handle different offsets", () => {
|
|
169
|
+
const { result } = renderHook(() =>
|
|
170
|
+
useLayoutConfig({
|
|
171
|
+
...defaultProps,
|
|
172
|
+
data: [],
|
|
173
|
+
renderItem: () => <View />,
|
|
174
|
+
loop: false,
|
|
175
|
+
autoFillData: false,
|
|
176
|
+
defaultIndex: 0,
|
|
177
|
+
autoPlayInterval: 0,
|
|
178
|
+
scrollAnimationDuration: 0,
|
|
179
|
+
width: 0,
|
|
180
|
+
height: 0,
|
|
181
|
+
rawData: [],
|
|
182
|
+
dataLength: 0,
|
|
183
|
+
rawDataLength: 0,
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const style1 = result.current(-1); // Previous item
|
|
188
|
+
const style2 = result.current(0); // Current item
|
|
189
|
+
const style3 = result.current(1); // Next item
|
|
190
|
+
|
|
191
|
+
expect(style1.transform).toContainEqual({ translateX: -300 });
|
|
192
|
+
expect(style2.transform).toContainEqual({ translateX: 0 });
|
|
193
|
+
expect(style3.transform).toContainEqual({ translateX: 300 });
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("should memoize layout function", () => {
|
|
197
|
+
const { result, rerender } = renderHook(() =>
|
|
198
|
+
useLayoutConfig({
|
|
199
|
+
...defaultProps,
|
|
200
|
+
data: [],
|
|
201
|
+
renderItem: () => <View />,
|
|
202
|
+
loop: false,
|
|
203
|
+
autoFillData: false,
|
|
204
|
+
defaultIndex: 0,
|
|
205
|
+
autoPlayInterval: 0,
|
|
206
|
+
scrollAnimationDuration: 0,
|
|
207
|
+
width: 0,
|
|
208
|
+
height: 0,
|
|
209
|
+
rawData: [],
|
|
210
|
+
dataLength: 0,
|
|
211
|
+
rawDataLength: 0,
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
const firstResult = result.current;
|
|
215
|
+
|
|
216
|
+
rerender();
|
|
217
|
+
expect(result.current).toBe(firstResult);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("should update layout when props change", () => {
|
|
221
|
+
const { result, rerender } = renderHook(
|
|
222
|
+
(props) =>
|
|
223
|
+
useLayoutConfig({
|
|
224
|
+
...props,
|
|
225
|
+
data: [],
|
|
226
|
+
renderItem: () => <View />,
|
|
227
|
+
loop: false,
|
|
228
|
+
autoFillData: false,
|
|
229
|
+
defaultIndex: 0,
|
|
230
|
+
autoPlayInterval: 0,
|
|
231
|
+
scrollAnimationDuration: 0,
|
|
232
|
+
width: 0,
|
|
233
|
+
height: 0,
|
|
234
|
+
rawData: [],
|
|
235
|
+
dataLength: 0,
|
|
236
|
+
rawDataLength: 0,
|
|
237
|
+
}),
|
|
238
|
+
{
|
|
239
|
+
initialProps: defaultProps,
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
const firstResult = result.current;
|
|
243
|
+
|
|
244
|
+
rerender({ ...defaultProps, size: 400 });
|
|
245
|
+
expect(result.current).not.toBe(firstResult);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import type { TInitializeCarouselProps } from "./useInitProps";
|
|
4
|
+
|
|
5
|
+
import type { TAnimationStyle } from "../components/ItemLayout";
|
|
6
|
+
import { Layouts } from "../layouts";
|
|
7
|
+
import type { SizeResolver } from "../utils/size-resolver";
|
|
8
|
+
|
|
9
|
+
type TLayoutConfigOpts<T> = TInitializeCarouselProps<T> & {
|
|
10
|
+
size: number;
|
|
11
|
+
sizeResolver?: SizeResolver;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function useLayoutConfig<T>(opts: TLayoutConfigOpts<T>): TAnimationStyle {
|
|
15
|
+
const { size, vertical, sizeResolver } = opts as Required<TLayoutConfigOpts<T>>;
|
|
16
|
+
|
|
17
|
+
return React.useMemo(() => {
|
|
18
|
+
const baseConfig = { size, vertical, sizeResolver };
|
|
19
|
+
switch (opts.mode) {
|
|
20
|
+
case "parallax":
|
|
21
|
+
return Layouts.parallax(baseConfig, opts.modeConfig);
|
|
22
|
+
case "horizontal-stack":
|
|
23
|
+
return Layouts.horizontalStack(opts.modeConfig);
|
|
24
|
+
case "vertical-stack":
|
|
25
|
+
return Layouts.verticalStack(opts.modeConfig);
|
|
26
|
+
default:
|
|
27
|
+
return Layouts.normal(baseConfig);
|
|
28
|
+
}
|
|
29
|
+
}, [opts.mode, opts.modeConfig, size, vertical, sizeResolver]);
|
|
30
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
2
|
+
|
|
3
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
4
|
+
|
|
5
|
+
import { buildPrefixSum, createVariableSizeResolver } from "../utils/size-resolver";
|
|
6
|
+
|
|
7
|
+
import type { IOpts } from "./useOffsetX";
|
|
8
|
+
import { useOffsetX } from "./useOffsetX";
|
|
9
|
+
import type { IVisibleRanges } from "./useVisibleRanges";
|
|
10
|
+
|
|
11
|
+
describe("useSharedValue", () => {
|
|
12
|
+
it("should return the correct values", async () => {
|
|
13
|
+
const hook = renderHook(() => {
|
|
14
|
+
const range = useSharedValue({
|
|
15
|
+
negativeRange: [7, 9],
|
|
16
|
+
positiveRange: [0, 3],
|
|
17
|
+
}) as IVisibleRanges;
|
|
18
|
+
const inputs: Array<{
|
|
19
|
+
config: IOpts;
|
|
20
|
+
range: IVisibleRanges;
|
|
21
|
+
}> = Array.from({ length: 10 }).map((_, index) => ({
|
|
22
|
+
config: {
|
|
23
|
+
dataLength: 10,
|
|
24
|
+
handlerOffset: useSharedValue(-0),
|
|
25
|
+
index,
|
|
26
|
+
loop: false,
|
|
27
|
+
size: 393,
|
|
28
|
+
},
|
|
29
|
+
range,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
return inputs.map((input) => {
|
|
33
|
+
const { config, range } = input;
|
|
34
|
+
|
|
35
|
+
return useOffsetX(config, range);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const expected = hook.result.current.map((v) => v.value).slice();
|
|
40
|
+
|
|
41
|
+
expect(expected).toMatchInlineSnapshot(`
|
|
42
|
+
[
|
|
43
|
+
0,
|
|
44
|
+
393,
|
|
45
|
+
786,
|
|
46
|
+
1179,
|
|
47
|
+
9007199254740991,
|
|
48
|
+
9007199254740991,
|
|
49
|
+
9007199254740991,
|
|
50
|
+
2751,
|
|
51
|
+
3144,
|
|
52
|
+
3537,
|
|
53
|
+
]
|
|
54
|
+
`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("useOffsetX (variable size)", () => {
|
|
59
|
+
it("returns cumulative offsets in non-loop mode when resolver is supplied", () => {
|
|
60
|
+
const widths = [80, 150, 220, 100, 300, 100, 120, 200, 90, 180];
|
|
61
|
+
const built = buildPrefixSum(widths.length, (i) => widths[i]);
|
|
62
|
+
|
|
63
|
+
const hook = renderHook(() => {
|
|
64
|
+
const range = useSharedValue({
|
|
65
|
+
negativeRange: [7, 9],
|
|
66
|
+
positiveRange: [0, 3],
|
|
67
|
+
}) as IVisibleRanges;
|
|
68
|
+
const sizes = useSharedValue(built.sizes);
|
|
69
|
+
const prefix = useSharedValue(built.prefix);
|
|
70
|
+
const total = useSharedValue(built.total);
|
|
71
|
+
const count = useSharedValue(widths.length);
|
|
72
|
+
const resolver = createVariableSizeResolver({ sizes, prefix, total, count });
|
|
73
|
+
|
|
74
|
+
const inputs: Array<{ config: IOpts; range: IVisibleRanges }> = Array.from({
|
|
75
|
+
length: 10,
|
|
76
|
+
}).map((_, index) => ({
|
|
77
|
+
config: {
|
|
78
|
+
dataLength: 10,
|
|
79
|
+
handlerOffset: useSharedValue(-0),
|
|
80
|
+
index,
|
|
81
|
+
loop: false,
|
|
82
|
+
size: 0, // unused once resolver is supplied
|
|
83
|
+
resolver,
|
|
84
|
+
},
|
|
85
|
+
range,
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
return inputs.map(({ config, range }) => useOffsetX(config, range));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const expected = hook.result.current.map((v) => v.value);
|
|
92
|
+
|
|
93
|
+
// Items 0..3 are in the positive range, so they get their cumulative
|
|
94
|
+
// offsets. Items 4..6 are out of the visible window — sentinel.
|
|
95
|
+
// Items 7..9 are in the negative range, so they get their cumulative
|
|
96
|
+
// offsets too.
|
|
97
|
+
expect(expected).toEqual([
|
|
98
|
+
0,
|
|
99
|
+
80,
|
|
100
|
+
230,
|
|
101
|
+
450,
|
|
102
|
+
Number.MAX_SAFE_INTEGER,
|
|
103
|
+
Number.MAX_SAFE_INTEGER,
|
|
104
|
+
Number.MAX_SAFE_INTEGER,
|
|
105
|
+
built.prefix[7],
|
|
106
|
+
built.prefix[8],
|
|
107
|
+
built.prefix[9],
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
});
|