@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,314 @@
|
|
|
1
|
+
import { act, render } from "@testing-library/react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
|
|
5
|
+
import { ICommonVariables } from "../hooks/useCommonVariables";
|
|
6
|
+
import { GlobalStateContext, GlobalStateProvider, IContext, useGlobalState } from "./index";
|
|
7
|
+
|
|
8
|
+
const createSharedValue = <T,>(initial: T) => ({ value: initial });
|
|
9
|
+
|
|
10
|
+
describe("GlobalStateProvider", () => {
|
|
11
|
+
const mockProps = {
|
|
12
|
+
width: 300,
|
|
13
|
+
height: 200,
|
|
14
|
+
data: [1, 2, 3],
|
|
15
|
+
renderItem: () => <Text>Item</Text>,
|
|
16
|
+
} as any;
|
|
17
|
+
|
|
18
|
+
const mockCommon = {
|
|
19
|
+
size: 300,
|
|
20
|
+
validLength: 3,
|
|
21
|
+
handlerOffset: createSharedValue(0),
|
|
22
|
+
resolvedSize: createSharedValue<number | null>(300),
|
|
23
|
+
sizePhase: createSharedValue("ready" as const),
|
|
24
|
+
} as ICommonVariables;
|
|
25
|
+
|
|
26
|
+
const mockValue: Pick<IContext, "props" | "common"> = {
|
|
27
|
+
props: mockProps,
|
|
28
|
+
common: mockCommon,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
it("should render children correctly", () => {
|
|
32
|
+
const { getByText } = render(
|
|
33
|
+
<GlobalStateProvider value={mockValue}>
|
|
34
|
+
<Text>Test Child</Text>
|
|
35
|
+
</GlobalStateProvider>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(getByText("Test Child")).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should provide context value with layout methods", () => {
|
|
42
|
+
let contextValue: any;
|
|
43
|
+
|
|
44
|
+
const TestComponent = () => {
|
|
45
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
46
|
+
return <Text>Test</Text>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
render(
|
|
50
|
+
<GlobalStateProvider value={mockValue}>
|
|
51
|
+
<TestComponent />
|
|
52
|
+
</GlobalStateProvider>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(contextValue).toHaveProperty("props");
|
|
56
|
+
expect(contextValue).toHaveProperty("common");
|
|
57
|
+
expect(contextValue).toHaveProperty("layout");
|
|
58
|
+
expect(contextValue.layout).toHaveProperty("containerSize");
|
|
59
|
+
expect(contextValue.layout).toHaveProperty("itemDimensions");
|
|
60
|
+
expect(contextValue.layout).toHaveProperty("updateItemDimensions");
|
|
61
|
+
expect(contextValue.layout).toHaveProperty("updateContainerSize");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should initialize containerSize with default values", () => {
|
|
65
|
+
let contextValue: any;
|
|
66
|
+
|
|
67
|
+
const TestComponent = () => {
|
|
68
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
69
|
+
return <Text>Test</Text>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
render(
|
|
73
|
+
<GlobalStateProvider value={mockValue}>
|
|
74
|
+
<TestComponent />
|
|
75
|
+
</GlobalStateProvider>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(contextValue.layout.containerSize.value).toEqual({ width: 0, height: 0 });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should initialize itemDimensions with empty object", () => {
|
|
82
|
+
let contextValue: any;
|
|
83
|
+
|
|
84
|
+
const TestComponent = () => {
|
|
85
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
86
|
+
return <Text>Test</Text>;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
render(
|
|
90
|
+
<GlobalStateProvider value={mockValue}>
|
|
91
|
+
<TestComponent />
|
|
92
|
+
</GlobalStateProvider>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(contextValue.layout.itemDimensions.value).toEqual({});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should provide updateItemDimensions function", () => {
|
|
99
|
+
let contextValue: any;
|
|
100
|
+
|
|
101
|
+
const TestComponent = () => {
|
|
102
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
103
|
+
return <Text>Test</Text>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
render(
|
|
107
|
+
<GlobalStateProvider value={mockValue}>
|
|
108
|
+
<TestComponent />
|
|
109
|
+
</GlobalStateProvider>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(typeof contextValue.layout.updateItemDimensions).toBe("function");
|
|
113
|
+
|
|
114
|
+
act(() => {
|
|
115
|
+
contextValue.layout.updateItemDimensions(0, { width: 100, height: 50 });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(contextValue.layout.itemDimensions.value).toEqual({
|
|
119
|
+
0: { width: 100, height: 50 },
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should provide updateContainerSize function", () => {
|
|
124
|
+
let contextValue: any;
|
|
125
|
+
|
|
126
|
+
const TestComponent = () => {
|
|
127
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
128
|
+
return <Text>Test</Text>;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
render(
|
|
132
|
+
<GlobalStateProvider value={mockValue}>
|
|
133
|
+
<TestComponent />
|
|
134
|
+
</GlobalStateProvider>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
expect(typeof contextValue.layout.updateContainerSize).toBe("function");
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
contextValue.layout.updateContainerSize({ width: 400, height: 300 });
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(contextValue.layout.containerSize.value).toEqual({ width: 400, height: 300 });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should merge props and common with layout", () => {
|
|
147
|
+
let contextValue: any;
|
|
148
|
+
|
|
149
|
+
const TestComponent = () => {
|
|
150
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
151
|
+
return <Text>Test</Text>;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
render(
|
|
155
|
+
<GlobalStateProvider value={mockValue}>
|
|
156
|
+
<TestComponent />
|
|
157
|
+
</GlobalStateProvider>
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
expect(contextValue.props).toEqual(mockProps);
|
|
161
|
+
expect(contextValue.common).toEqual(mockCommon);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should handle multiple children", () => {
|
|
165
|
+
const { getByText } = render(
|
|
166
|
+
<GlobalStateProvider value={mockValue}>
|
|
167
|
+
<Text>First Child</Text>
|
|
168
|
+
<Text>Second Child</Text>
|
|
169
|
+
</GlobalStateProvider>
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(getByText("First Child")).toBeTruthy();
|
|
173
|
+
expect(getByText("Second Child")).toBeTruthy();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("should handle updateItemDimensions with multiple items", () => {
|
|
177
|
+
let contextValue: any;
|
|
178
|
+
|
|
179
|
+
const TestComponent = () => {
|
|
180
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
181
|
+
return <Text>Test</Text>;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
render(
|
|
185
|
+
<GlobalStateProvider value={mockValue}>
|
|
186
|
+
<TestComponent />
|
|
187
|
+
</GlobalStateProvider>
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
act(() => {
|
|
191
|
+
contextValue.layout.updateItemDimensions(0, { width: 100, height: 50 });
|
|
192
|
+
contextValue.layout.updateItemDimensions(1, { width: 120, height: 60 });
|
|
193
|
+
contextValue.layout.updateItemDimensions(2, { width: 90, height: 45 });
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(contextValue.layout.itemDimensions.value).toEqual({
|
|
197
|
+
0: { width: 100, height: 50 },
|
|
198
|
+
1: { width: 120, height: 60 },
|
|
199
|
+
2: { width: 90, height: 45 },
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("useGlobalState", () => {
|
|
205
|
+
const mockValue: Pick<IContext, "props" | "common"> = {
|
|
206
|
+
props: { width: 300, data: [1, 2, 3], renderItem: () => <Text>Item</Text> } as any,
|
|
207
|
+
common: {
|
|
208
|
+
size: 300,
|
|
209
|
+
validLength: 3,
|
|
210
|
+
handlerOffset: createSharedValue(0),
|
|
211
|
+
resolvedSize: createSharedValue<number | null>(300),
|
|
212
|
+
sizePhase: createSharedValue("ready" as const),
|
|
213
|
+
} as ICommonVariables,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
it("should return context value when used within provider", () => {
|
|
217
|
+
let hookResult: any;
|
|
218
|
+
|
|
219
|
+
const TestComponent = () => {
|
|
220
|
+
hookResult = useGlobalState();
|
|
221
|
+
return <Text>Test</Text>;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
render(
|
|
225
|
+
<GlobalStateProvider value={mockValue}>
|
|
226
|
+
<TestComponent />
|
|
227
|
+
</GlobalStateProvider>
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
expect(hookResult).toHaveProperty("props");
|
|
231
|
+
expect(hookResult).toHaveProperty("common");
|
|
232
|
+
expect(hookResult).toHaveProperty("layout");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("should provide expected hook functionality", () => {
|
|
236
|
+
let hookResult: any;
|
|
237
|
+
|
|
238
|
+
const TestComponent = () => {
|
|
239
|
+
hookResult = useGlobalState();
|
|
240
|
+
return <Text>Test</Text>;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const mockValue: Pick<IContext, "props" | "common"> = {
|
|
244
|
+
props: { width: 300, data: [1, 2, 3], renderItem: () => <Text>Item</Text> } as any,
|
|
245
|
+
common: { size: 300, validLength: 3 } as ICommonVariables,
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
render(
|
|
249
|
+
<GlobalStateProvider value={mockValue}>
|
|
250
|
+
<TestComponent />
|
|
251
|
+
</GlobalStateProvider>
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(hookResult).toHaveProperty("props");
|
|
255
|
+
expect(hookResult).toHaveProperty("common");
|
|
256
|
+
expect(hookResult).toHaveProperty("layout");
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("should return the same context value as directly accessing context", () => {
|
|
260
|
+
let hookResult: any;
|
|
261
|
+
let contextResult: any;
|
|
262
|
+
|
|
263
|
+
const TestComponent = () => {
|
|
264
|
+
hookResult = useGlobalState();
|
|
265
|
+
contextResult = React.useContext(GlobalStateContext);
|
|
266
|
+
return <Text>Test</Text>;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
render(
|
|
270
|
+
<GlobalStateProvider value={mockValue}>
|
|
271
|
+
<TestComponent />
|
|
272
|
+
</GlobalStateProvider>
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
expect(hookResult).toBe(contextResult);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("should provide all expected properties", () => {
|
|
279
|
+
let hookResult: any;
|
|
280
|
+
|
|
281
|
+
const TestComponent = () => {
|
|
282
|
+
hookResult = useGlobalState();
|
|
283
|
+
return <Text>Test</Text>;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
render(
|
|
287
|
+
<GlobalStateProvider value={mockValue}>
|
|
288
|
+
<TestComponent />
|
|
289
|
+
</GlobalStateProvider>
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
expect(hookResult.props).toEqual(mockValue.props);
|
|
293
|
+
expect(hookResult.common).toEqual(mockValue.common);
|
|
294
|
+
expect(hookResult.layout).toHaveProperty("containerSize");
|
|
295
|
+
expect(hookResult.layout).toHaveProperty("itemDimensions");
|
|
296
|
+
expect(hookResult.layout).toHaveProperty("updateItemDimensions");
|
|
297
|
+
expect(hookResult.layout).toHaveProperty("updateContainerSize");
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe("GlobalStateContext", () => {
|
|
302
|
+
it("should have default empty context value", () => {
|
|
303
|
+
let contextValue: any;
|
|
304
|
+
|
|
305
|
+
const TestComponent = () => {
|
|
306
|
+
contextValue = React.useContext(GlobalStateContext);
|
|
307
|
+
return <Text>Test</Text>;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
render(<TestComponent />);
|
|
311
|
+
|
|
312
|
+
expect(contextValue).toEqual({});
|
|
313
|
+
});
|
|
314
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { SharedValue, useSharedValue } from "react-native-reanimated";
|
|
4
|
+
import type { ICommonVariables } from "../hooks/useCommonVariables";
|
|
5
|
+
import type { TInitializeCarouselProps } from "../hooks/useInitProps";
|
|
6
|
+
import type { SizeResolver } from "../utils/size-resolver";
|
|
7
|
+
|
|
8
|
+
type ItemDimensions = Record<number, { width: number; height: number }>;
|
|
9
|
+
|
|
10
|
+
export interface IContext {
|
|
11
|
+
props: TInitializeCarouselProps<any>;
|
|
12
|
+
common: ICommonVariables;
|
|
13
|
+
/** Per-item size resolver (uniform or variable). */
|
|
14
|
+
sizeResolver: SizeResolver;
|
|
15
|
+
layout: {
|
|
16
|
+
containerSize: SharedValue<{ width: number; height: number }>;
|
|
17
|
+
updateContainerSize: (dimensions: { width: number; height: number }) => void;
|
|
18
|
+
itemDimensions: SharedValue<ItemDimensions>;
|
|
19
|
+
updateItemDimensions: (index: number, dimensions: { width: number; height: number }) => void;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const GlobalStateContext = React.createContext<IContext>({} as IContext);
|
|
24
|
+
|
|
25
|
+
export const GlobalStateProvider = ({
|
|
26
|
+
children,
|
|
27
|
+
value,
|
|
28
|
+
}: {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
value: Pick<IContext, "props" | "common" | "sizeResolver">;
|
|
31
|
+
}) => {
|
|
32
|
+
const containerSize = useSharedValue<{ width: number; height: number }>({ width: 0, height: 0 });
|
|
33
|
+
const itemDimensions = useSharedValue<ItemDimensions>({});
|
|
34
|
+
|
|
35
|
+
const updateItemDimensions = (index: number, dimensions: { width: number; height: number }) => {
|
|
36
|
+
"worklet";
|
|
37
|
+
|
|
38
|
+
itemDimensions.value = { ...itemDimensions.value, [index]: dimensions };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const updateContainerSize = (dimensions: { width: number; height: number }) => {
|
|
42
|
+
"worklet";
|
|
43
|
+
containerSize.value = dimensions;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<GlobalStateContext.Provider
|
|
48
|
+
value={{
|
|
49
|
+
...value,
|
|
50
|
+
layout: { containerSize, itemDimensions, updateItemDimensions, updateContainerSize },
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{children}
|
|
54
|
+
</GlobalStateContext.Provider>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const useGlobalState = () => {
|
|
59
|
+
const context = React.useContext(GlobalStateContext);
|
|
60
|
+
|
|
61
|
+
if (!context) {
|
|
62
|
+
throw new Error("useGlobalState must be used within a GlobalStateProvider");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return context;
|
|
66
|
+
};
|