@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,368 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import type { PanGesture, PanGestureHandler, TapGesture } from "react-native-gesture-handler";
|
|
4
|
+
import {
|
|
5
|
+
Gesture,
|
|
6
|
+
GestureDetector,
|
|
7
|
+
GestureHandlerRootView,
|
|
8
|
+
State,
|
|
9
|
+
} from "react-native-gesture-handler";
|
|
10
|
+
|
|
11
|
+
import { cleanup, render } from "@testing-library/react-native";
|
|
12
|
+
import { fireGestureHandler, getByGestureTestId } from "react-native-gesture-handler/jest-utils";
|
|
13
|
+
|
|
14
|
+
import { usePanGestureProxy } from "./usePanGestureProxy";
|
|
15
|
+
|
|
16
|
+
beforeEach(cleanup);
|
|
17
|
+
|
|
18
|
+
const mockedEventHandlers = () => {
|
|
19
|
+
return {
|
|
20
|
+
begin: jest.fn(),
|
|
21
|
+
start: jest.fn(),
|
|
22
|
+
active: jest.fn(),
|
|
23
|
+
end: jest.fn(),
|
|
24
|
+
fail: jest.fn(),
|
|
25
|
+
cancel: jest.fn(),
|
|
26
|
+
finish: jest.fn(),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const mockedEventHandlersFromUser = () => {
|
|
31
|
+
return {
|
|
32
|
+
begin: jest.fn(),
|
|
33
|
+
start: jest.fn(),
|
|
34
|
+
active: jest.fn(),
|
|
35
|
+
end: jest.fn(),
|
|
36
|
+
fail: jest.fn(),
|
|
37
|
+
cancel: jest.fn(),
|
|
38
|
+
finish: jest.fn(),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe("Using RNGH v2 gesture API", () => {
|
|
43
|
+
interface SingleHandlerProps {
|
|
44
|
+
handlers: ReturnType<typeof mockedEventHandlers>;
|
|
45
|
+
handlersFromUser: ReturnType<typeof mockedEventHandlers>;
|
|
46
|
+
treatStartAsUpdate?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function SingleHandler({ handlers, handlersFromUser, treatStartAsUpdate }: SingleHandlerProps) {
|
|
50
|
+
const pan = usePanGestureProxy({
|
|
51
|
+
onConfigurePanGesture: (gesture: PanGesture) => {
|
|
52
|
+
// This is user's customizations
|
|
53
|
+
gesture
|
|
54
|
+
.onBegin(handlersFromUser.begin)
|
|
55
|
+
.onUpdate(handlersFromUser.active)
|
|
56
|
+
.onEnd(handlersFromUser.end)
|
|
57
|
+
.onFinalize(handlers.finish)
|
|
58
|
+
.withTestId("pan");
|
|
59
|
+
},
|
|
60
|
+
onGestureStart: treatStartAsUpdate ? handlers.active : handlers.start,
|
|
61
|
+
onGestureUpdate: handlers.active,
|
|
62
|
+
onGestureEnd: handlers.end,
|
|
63
|
+
options: { enabled: true },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<GestureHandlerRootView>
|
|
68
|
+
<GestureDetector gesture={pan}>
|
|
69
|
+
<Text>v2 API test</Text>
|
|
70
|
+
</GestureDetector>
|
|
71
|
+
</GestureHandlerRootView>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface RacingHandlersProps {
|
|
76
|
+
tapHandlers: ReturnType<typeof mockedEventHandlers>;
|
|
77
|
+
panHandlers: ReturnType<typeof mockedEventHandlers>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function RacingHandlers({ tapHandlers, panHandlers }: RacingHandlersProps) {
|
|
81
|
+
const tap = Gesture.Tap().onBegin(tapHandlers.begin).onEnd(tapHandlers.end).withTestId("tap");
|
|
82
|
+
|
|
83
|
+
const pan = usePanGestureProxy({
|
|
84
|
+
onConfigurePanGesture: (_: PanGesture) => {
|
|
85
|
+
_.onBegin(panHandlers.begin).onFinalize(panHandlers.finish).withTestId("pan");
|
|
86
|
+
},
|
|
87
|
+
onGestureStart: panHandlers.start,
|
|
88
|
+
onGestureUpdate: panHandlers.active,
|
|
89
|
+
onGestureEnd: panHandlers.end,
|
|
90
|
+
options: { enabled: true },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<GestureHandlerRootView>
|
|
95
|
+
<GestureDetector gesture={Gesture.Race(tap, pan)}>
|
|
96
|
+
<Text>v2 API test</Text>
|
|
97
|
+
</GestureDetector>
|
|
98
|
+
</GestureHandlerRootView>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
it("sends events to handlers", () => {
|
|
103
|
+
const tapHandlers = mockedEventHandlers();
|
|
104
|
+
const panHandlers = mockedEventHandlers();
|
|
105
|
+
render(<RacingHandlers tapHandlers={tapHandlers} panHandlers={panHandlers} />);
|
|
106
|
+
|
|
107
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
108
|
+
{ state: State.BEGAN },
|
|
109
|
+
{ state: State.ACTIVE },
|
|
110
|
+
{ state: State.END },
|
|
111
|
+
]);
|
|
112
|
+
expect(panHandlers.begin).toBeCalledWith(expect.objectContaining({ state: State.BEGAN }));
|
|
113
|
+
expect(panHandlers.finish).toBeCalled();
|
|
114
|
+
expect(tapHandlers.begin).not.toBeCalled();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("sends events with additional data to handlers", () => {
|
|
118
|
+
const panHandlers = mockedEventHandlers();
|
|
119
|
+
const panHandlersFromUser = mockedEventHandlersFromUser();
|
|
120
|
+
render(
|
|
121
|
+
<SingleHandler
|
|
122
|
+
handlers={panHandlers}
|
|
123
|
+
handlersFromUser={panHandlersFromUser}
|
|
124
|
+
treatStartAsUpdate
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
128
|
+
{ state: State.BEGAN, translationX: 0 },
|
|
129
|
+
{ state: State.ACTIVE, translationX: 10 },
|
|
130
|
+
{ translationX: 20 },
|
|
131
|
+
{ translationX: 20 },
|
|
132
|
+
{ state: State.END, translationX: 30 },
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
expect(panHandlersFromUser.begin).toBeCalledTimes(1);
|
|
136
|
+
expect(panHandlersFromUser.active).toBeCalledTimes(2);
|
|
137
|
+
expect(panHandlersFromUser.end).toBeCalledTimes(1);
|
|
138
|
+
|
|
139
|
+
expect(panHandlers.active).toBeCalledTimes(3);
|
|
140
|
+
expect(panHandlers.active).toHaveBeenLastCalledWith(
|
|
141
|
+
expect.objectContaining({ translationX: 20 })
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("does not include console.error in the output", () => {
|
|
146
|
+
// if react-native-gesture-handler detects that some handlers are
|
|
147
|
+
// workletized and some are not, it will log an error to the
|
|
148
|
+
// console. We'd like to make sure that this doesn't happen.
|
|
149
|
+
|
|
150
|
+
// The error that would be shown looks like:
|
|
151
|
+
// [react-native-gesture-handler] Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.scheduleOnRN(true)' modifier on the gesture explicitly to run all callbacks on the JS thread.
|
|
152
|
+
|
|
153
|
+
const panHandlers = mockedEventHandlers();
|
|
154
|
+
const panHandlersFromUser = mockedEventHandlersFromUser();
|
|
155
|
+
|
|
156
|
+
jest.spyOn(console, "error");
|
|
157
|
+
|
|
158
|
+
render(
|
|
159
|
+
<SingleHandler
|
|
160
|
+
handlers={panHandlers}
|
|
161
|
+
handlersFromUser={panHandlersFromUser}
|
|
162
|
+
treatStartAsUpdate
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
166
|
+
{ state: State.BEGAN },
|
|
167
|
+
{ state: State.ACTIVE },
|
|
168
|
+
{ state: State.END },
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
expect(console.error).not.toBeCalled();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("Event list validation", () => {
|
|
176
|
+
interface SingleHandlerProps {
|
|
177
|
+
handlers: ReturnType<typeof mockedEventHandlers>;
|
|
178
|
+
handlersFromUser: ReturnType<typeof mockedEventHandlers>;
|
|
179
|
+
treatStartAsUpdate?: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function SingleHandler({ handlers, handlersFromUser, treatStartAsUpdate }: SingleHandlerProps) {
|
|
183
|
+
const pan = usePanGestureProxy({
|
|
184
|
+
onConfigurePanGesture: (_: PanGesture) => {
|
|
185
|
+
_.onBegin(handlersFromUser.begin)
|
|
186
|
+
.onUpdate(handlersFromUser.active)
|
|
187
|
+
.onEnd(handlersFromUser.end)
|
|
188
|
+
.onFinalize(handlers.finish)
|
|
189
|
+
.withTestId("pan");
|
|
190
|
+
},
|
|
191
|
+
onGestureStart: treatStartAsUpdate ? handlers.active : handlers.start,
|
|
192
|
+
onGestureUpdate: handlers.active,
|
|
193
|
+
onGestureEnd: handlers.end,
|
|
194
|
+
options: { enabled: true },
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<GestureHandlerRootView>
|
|
199
|
+
<GestureDetector gesture={pan}>
|
|
200
|
+
<Text>v2 API test</Text>
|
|
201
|
+
</GestureDetector>
|
|
202
|
+
</GestureHandlerRootView>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
it("throws error when oldState doesn't correspond to previous event's state", () => {
|
|
207
|
+
const panHandlers = mockedEventHandlers();
|
|
208
|
+
const panHandlersFromUser = mockedEventHandlersFromUser();
|
|
209
|
+
render(<SingleHandler handlers={panHandlers} handlersFromUser={panHandlersFromUser} />);
|
|
210
|
+
|
|
211
|
+
expect(() => {
|
|
212
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
213
|
+
{ oldState: State.UNDETERMINED, state: State.BEGAN, x: 0, y: 10 },
|
|
214
|
+
{ oldState: State.UNDETERMINED, state: State.ACTIVE, x: 1, y: 11 },
|
|
215
|
+
]);
|
|
216
|
+
}).toThrow("when state changes, oldState should be the same as previous event' state");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it.each([[State.END], [State.FAILED], [State.CANCELLED]])(
|
|
220
|
+
"correctly handles events ending with state %s",
|
|
221
|
+
(lastState) => {
|
|
222
|
+
const panHandlers = mockedEventHandlers();
|
|
223
|
+
const panHandlersFromUser = mockedEventHandlersFromUser();
|
|
224
|
+
render(<SingleHandler handlers={panHandlers} handlersFromUser={panHandlersFromUser} />);
|
|
225
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
226
|
+
{ state: State.BEGAN },
|
|
227
|
+
{ state: State.ACTIVE },
|
|
228
|
+
{ state: lastState },
|
|
229
|
+
]);
|
|
230
|
+
|
|
231
|
+
expect(panHandlersFromUser.begin).toBeCalledTimes(1);
|
|
232
|
+
expect(panHandlersFromUser.active).toBeCalledTimes(0);
|
|
233
|
+
expect(panHandlersFromUser.end).toBeCalledTimes(1);
|
|
234
|
+
|
|
235
|
+
if (lastState === State.END) expect(panHandlers.end).toBeCalled();
|
|
236
|
+
else expect(panHandlers.finish).toBeCalledWith(expect.any(Object), false);
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe("Filling event list with defaults", () => {
|
|
242
|
+
interface RacingTapAndPanProps {
|
|
243
|
+
handlers: ReturnType<typeof mockedEventHandlers>;
|
|
244
|
+
treatStartAsUpdate?: boolean;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function RacingTapAndPan({ handlers, treatStartAsUpdate }: RacingTapAndPanProps) {
|
|
248
|
+
const tap = Gesture.Tap().onBegin(handlers.begin).onEnd(handlers.end).withTestId("tap");
|
|
249
|
+
|
|
250
|
+
const pan = usePanGestureProxy({
|
|
251
|
+
onConfigurePanGesture: (_: PanGesture) => {
|
|
252
|
+
_.onBegin(handlers.begin).onFinalize(handlers.finish).withTestId("pan");
|
|
253
|
+
},
|
|
254
|
+
onGestureStart: treatStartAsUpdate ? handlers.active : handlers.start,
|
|
255
|
+
onGestureUpdate: handlers.active,
|
|
256
|
+
onGestureEnd: handlers.end,
|
|
257
|
+
options: { enabled: true },
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
<GestureHandlerRootView>
|
|
262
|
+
<GestureDetector gesture={Gesture.Exclusive(pan, tap)}>
|
|
263
|
+
<Text>v2 API test</Text>
|
|
264
|
+
</GestureDetector>
|
|
265
|
+
</GestureHandlerRootView>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
it("fills oldState if not passed", () => {
|
|
270
|
+
const handlers = mockedEventHandlers();
|
|
271
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
272
|
+
fireGestureHandler<PanGestureHandler>(getByGestureTestId("pan"), [
|
|
273
|
+
{ state: State.BEGAN },
|
|
274
|
+
{ state: State.ACTIVE },
|
|
275
|
+
{ state: State.ACTIVE },
|
|
276
|
+
{ state: State.ACTIVE },
|
|
277
|
+
{ state: State.END },
|
|
278
|
+
]);
|
|
279
|
+
|
|
280
|
+
expect(handlers.begin).toBeCalledWith(
|
|
281
|
+
expect.objectContaining({ oldState: State.UNDETERMINED })
|
|
282
|
+
);
|
|
283
|
+
expect(handlers.active).nthCalledWith(1, expect.objectContaining({ oldState: State.BEGAN }));
|
|
284
|
+
expect(handlers.active).lastCalledWith(
|
|
285
|
+
expect.not.objectContaining({ oldState: expect.anything() })
|
|
286
|
+
);
|
|
287
|
+
expect(handlers.end).toBeCalledWith(expect.objectContaining({ oldState: State.ACTIVE }), true);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("fills missing ACTIVE states", () => {
|
|
291
|
+
const panHandlers = mockedEventHandlers();
|
|
292
|
+
render(<RacingTapAndPan handlers={panHandlers} treatStartAsUpdate />);
|
|
293
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
294
|
+
{ state: State.BEGAN, x: 0, y: 10 },
|
|
295
|
+
{ state: State.ACTIVE, x: 1, y: 11 },
|
|
296
|
+
{ x: 2, y: 12 },
|
|
297
|
+
{ x: 3, y: 13 },
|
|
298
|
+
{ state: State.END, x: 4, y: 14 },
|
|
299
|
+
]);
|
|
300
|
+
|
|
301
|
+
expect(panHandlers.active).toBeCalledTimes(3);
|
|
302
|
+
expect(panHandlers.active).toHaveBeenLastCalledWith(expect.objectContaining({ x: 3, y: 13 }));
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("fills BEGIN and END events for discrete handlers", () => {
|
|
306
|
+
const handlers = mockedEventHandlers();
|
|
307
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
308
|
+
fireGestureHandler<TapGesture>(getByGestureTestId("tap"), [{ x: 5 }]);
|
|
309
|
+
expect(handlers.begin).toBeCalledTimes(1);
|
|
310
|
+
expect(handlers.end).toBeCalledTimes(1);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("with FAILED event, fills BEGIN event for discrete handlers", () => {
|
|
314
|
+
const handlers = mockedEventHandlers();
|
|
315
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
316
|
+
fireGestureHandler<TapGesture>(getByGestureTestId("tap"), [{ state: State.FAILED }]);
|
|
317
|
+
expect(handlers.begin).toBeCalledTimes(1);
|
|
318
|
+
expect(handlers.end).toBeCalledTimes(1);
|
|
319
|
+
expect(handlers.end).toBeCalledWith(expect.anything(), false);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("uses event data from first event in filled BEGIN, ACTIVE events", () => {
|
|
323
|
+
const handlers = mockedEventHandlers();
|
|
324
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
325
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [{ x: 120 }]);
|
|
326
|
+
expect(handlers.begin).toBeCalledWith(expect.objectContaining({ x: 120 }));
|
|
327
|
+
expect(handlers.active).toHaveBeenNthCalledWith(1, expect.objectContaining({ x: 120 }));
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("uses event data from last event in filled END events", () => {
|
|
331
|
+
const handlers = mockedEventHandlers();
|
|
332
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
333
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [{ x: 120, state: State.FAILED }]);
|
|
334
|
+
expect(handlers.begin).toBeCalledTimes(1);
|
|
335
|
+
expect(handlers.active).toBeCalledTimes(1);
|
|
336
|
+
expect(handlers.end).toBeCalledWith(expect.objectContaining({ x: 120 }), false);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("uses event data filled events", () => {
|
|
340
|
+
const handlers = mockedEventHandlers();
|
|
341
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
342
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"), [
|
|
343
|
+
{ x: 5, y: 15 },
|
|
344
|
+
{ x: 6, y: 16 },
|
|
345
|
+
{ x: 7, y: 17 },
|
|
346
|
+
]);
|
|
347
|
+
expect(handlers.begin).toBeCalledWith(expect.objectContaining({ x: 5, y: 15 }));
|
|
348
|
+
expect(handlers.active).toBeCalledTimes(3);
|
|
349
|
+
expect(handlers.end).toBeCalledWith(expect.objectContaining({ x: 7, y: 17 }), true);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("fills BEGIN and END events when they're not present, for discrete handlers", () => {
|
|
353
|
+
const handlers = mockedEventHandlers();
|
|
354
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
355
|
+
fireGestureHandler<TapGesture>(getByGestureTestId("tap"));
|
|
356
|
+
expect(handlers.begin).toBeCalledTimes(1);
|
|
357
|
+
expect(handlers.end).toHaveBeenCalledTimes(1);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("fills BEGIN, ACTIVE and END events when they're not present, for continuous handlers", () => {
|
|
361
|
+
const handlers = mockedEventHandlers();
|
|
362
|
+
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
|
|
363
|
+
fireGestureHandler<PanGesture>(getByGestureTestId("pan"));
|
|
364
|
+
expect(handlers.begin).toBeCalledTimes(1);
|
|
365
|
+
expect(handlers.active).toBeCalledTimes(1);
|
|
366
|
+
expect(handlers.end).toHaveBeenCalledTimes(1);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
GestureStateChangeEvent,
|
|
4
|
+
GestureUpdateEvent,
|
|
5
|
+
PanGesture,
|
|
6
|
+
PanGestureHandlerEventPayload,
|
|
7
|
+
} from "react-native-gesture-handler";
|
|
8
|
+
import { Gesture } from "react-native-gesture-handler";
|
|
9
|
+
|
|
10
|
+
import type { GestureConfig } from "./useUpdateGestureConfig";
|
|
11
|
+
import { useUpdateGestureConfig } from "./useUpdateGestureConfig";
|
|
12
|
+
|
|
13
|
+
export const usePanGestureProxy = (customization: {
|
|
14
|
+
onConfigurePanGesture?: (gesture: PanGesture) => void;
|
|
15
|
+
onGestureStart: (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => void;
|
|
16
|
+
onGestureUpdate: (event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => void;
|
|
17
|
+
onGestureEnd: (
|
|
18
|
+
event: GestureStateChangeEvent<PanGestureHandlerEventPayload>,
|
|
19
|
+
success: boolean
|
|
20
|
+
) => void;
|
|
21
|
+
options?: GestureConfig;
|
|
22
|
+
}) => {
|
|
23
|
+
const {
|
|
24
|
+
onConfigurePanGesture,
|
|
25
|
+
onGestureStart,
|
|
26
|
+
onGestureUpdate,
|
|
27
|
+
onGestureEnd,
|
|
28
|
+
options = {},
|
|
29
|
+
} = customization;
|
|
30
|
+
|
|
31
|
+
const gesture = useMemo(() => {
|
|
32
|
+
const gesture = Gesture.Pan().withTestId("rnrc-gesture-handler");
|
|
33
|
+
|
|
34
|
+
// Save the original gesture callbacks
|
|
35
|
+
const originalGestures = {
|
|
36
|
+
onBegin: gesture.onBegin,
|
|
37
|
+
onStart: gesture.onStart,
|
|
38
|
+
onUpdate: gesture.onUpdate,
|
|
39
|
+
onEnd: gesture.onEnd,
|
|
40
|
+
onFinalize: gesture.onFinalize,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Save the user defined gesture callbacks
|
|
44
|
+
const userDefinedConflictGestures: {
|
|
45
|
+
onBegin?: Parameters<(typeof gesture)["onBegin"]>[0];
|
|
46
|
+
onStart?: Parameters<(typeof gesture)["onStart"]>[0];
|
|
47
|
+
onUpdate?: Parameters<(typeof gesture)["onUpdate"]>[0];
|
|
48
|
+
onEnd?: Parameters<(typeof gesture)["onEnd"]>[0];
|
|
49
|
+
onFinalize?: Parameters<(typeof gesture)["onFinalize"]>[0];
|
|
50
|
+
} = {
|
|
51
|
+
onBegin: undefined,
|
|
52
|
+
onStart: undefined,
|
|
53
|
+
onUpdate: undefined,
|
|
54
|
+
onEnd: undefined,
|
|
55
|
+
onFinalize: undefined,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const fakeOnBegin: typeof gesture.onBegin = (cb) => {
|
|
59
|
+
// Using fakeOnBegin to save the user defined callback
|
|
60
|
+
userDefinedConflictGestures.onBegin = cb;
|
|
61
|
+
return gesture;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const fakeOnStart: typeof gesture.onStart = (cb) => {
|
|
65
|
+
// Using fakeOnStart to save the user defined callback
|
|
66
|
+
userDefinedConflictGestures.onStart = cb;
|
|
67
|
+
return gesture;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const fakeOnUpdate: typeof gesture.onUpdate = (cb) => {
|
|
71
|
+
// Using fakeOnUpdate to save the user defined callback
|
|
72
|
+
userDefinedConflictGestures.onUpdate = cb;
|
|
73
|
+
return gesture;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const fakeOnEnd: typeof gesture.onEnd = (cb) => {
|
|
77
|
+
// Using fakeOnEnd to save the user defined callback
|
|
78
|
+
userDefinedConflictGestures.onEnd = cb;
|
|
79
|
+
return gesture;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const fakeOnFinalize: typeof gesture.onFinalize = (cb) => {
|
|
83
|
+
// Using fakeOnFinalize to save the user defined callback
|
|
84
|
+
userDefinedConflictGestures.onFinalize = cb;
|
|
85
|
+
return gesture;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Setup the fake callbacks
|
|
89
|
+
gesture.onBegin = fakeOnBegin;
|
|
90
|
+
gesture.onStart = fakeOnStart;
|
|
91
|
+
gesture.onUpdate = fakeOnUpdate;
|
|
92
|
+
gesture.onEnd = fakeOnEnd;
|
|
93
|
+
gesture.onFinalize = fakeOnFinalize;
|
|
94
|
+
|
|
95
|
+
if (onConfigurePanGesture)
|
|
96
|
+
// Get the gesture with the user defined configuration
|
|
97
|
+
onConfigurePanGesture(gesture);
|
|
98
|
+
|
|
99
|
+
// Restore the original callbacks
|
|
100
|
+
gesture.onBegin = originalGestures.onBegin;
|
|
101
|
+
gesture.onStart = originalGestures.onStart;
|
|
102
|
+
gesture.onUpdate = originalGestures.onUpdate;
|
|
103
|
+
gesture.onEnd = originalGestures.onEnd;
|
|
104
|
+
gesture.onFinalize = originalGestures.onFinalize;
|
|
105
|
+
|
|
106
|
+
// Setup the original callbacks with the user defined callbacks
|
|
107
|
+
gesture
|
|
108
|
+
.onBegin((e) => {
|
|
109
|
+
"worklet";
|
|
110
|
+
|
|
111
|
+
if (userDefinedConflictGestures.onBegin) userDefinedConflictGestures.onBegin(e);
|
|
112
|
+
})
|
|
113
|
+
.onStart((e) => {
|
|
114
|
+
"worklet";
|
|
115
|
+
onGestureStart(e);
|
|
116
|
+
|
|
117
|
+
if (userDefinedConflictGestures.onStart) userDefinedConflictGestures.onStart(e);
|
|
118
|
+
})
|
|
119
|
+
.onUpdate((e) => {
|
|
120
|
+
"worklet";
|
|
121
|
+
onGestureUpdate(e);
|
|
122
|
+
|
|
123
|
+
if (userDefinedConflictGestures.onUpdate) userDefinedConflictGestures.onUpdate(e);
|
|
124
|
+
})
|
|
125
|
+
.onEnd((e, success) => {
|
|
126
|
+
"worklet";
|
|
127
|
+
onGestureEnd(e, success);
|
|
128
|
+
|
|
129
|
+
if (userDefinedConflictGestures.onEnd) userDefinedConflictGestures.onEnd(e, success);
|
|
130
|
+
})
|
|
131
|
+
.onFinalize((e, success) => {
|
|
132
|
+
"worklet";
|
|
133
|
+
|
|
134
|
+
if (userDefinedConflictGestures.onFinalize)
|
|
135
|
+
userDefinedConflictGestures.onFinalize(e, success);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return gesture;
|
|
139
|
+
}, [onGestureStart, onGestureUpdate, onGestureEnd, onConfigurePanGesture]);
|
|
140
|
+
|
|
141
|
+
useUpdateGestureConfig(gesture, options);
|
|
142
|
+
|
|
143
|
+
return gesture;
|
|
144
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
|
|
4
|
+
import type { TCarouselProps } from "../types";
|
|
5
|
+
|
|
6
|
+
export function usePropsErrorBoundary(props: TCarouselProps & { dataLength: number }) {
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
const { defaultIndex, dataLength: viewCount } = props;
|
|
9
|
+
|
|
10
|
+
if (typeof defaultIndex === "number" && viewCount > 0) {
|
|
11
|
+
if (defaultIndex < 0 || defaultIndex >= viewCount) {
|
|
12
|
+
throw new Error("DefaultIndex must be in the range of data length.");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (__DEV__) {
|
|
17
|
+
const {
|
|
18
|
+
style,
|
|
19
|
+
vertical,
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
itemWidth,
|
|
23
|
+
itemHeight,
|
|
24
|
+
contentContainerStyle,
|
|
25
|
+
getItemWidth,
|
|
26
|
+
getItemHeight,
|
|
27
|
+
autoFillData,
|
|
28
|
+
} = props;
|
|
29
|
+
|
|
30
|
+
// Variable-size mode: sanity-check the first few indices to catch
|
|
31
|
+
// common mistakes (returning 0, undefined, NaN).
|
|
32
|
+
const axisGetter = vertical ? getItemHeight : getItemWidth;
|
|
33
|
+
if (typeof axisGetter === "function" && viewCount > 0 && !warnedRefs.getItemSize) {
|
|
34
|
+
const sample = Math.min(viewCount, 5);
|
|
35
|
+
for (let i = 0; i < sample; i++) {
|
|
36
|
+
const value = axisGetter(i);
|
|
37
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
38
|
+
console.warn(
|
|
39
|
+
`[react-native-reanimated-carousel] ${
|
|
40
|
+
vertical ? "getItemHeight" : "getItemWidth"
|
|
41
|
+
}(${i}) returned ${String(
|
|
42
|
+
value
|
|
43
|
+
)}. Each item must report a positive, finite size; non-positive values are clamped to 0 and break snapping.`
|
|
44
|
+
);
|
|
45
|
+
warnedRefs.getItemSize = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof axisGetter === "function" && autoFillData && !warnedRefs.autoFillVariable) {
|
|
52
|
+
console.warn(
|
|
53
|
+
"[react-native-reanimated-carousel] `autoFillData` is ignored when `getItemWidth`/`getItemHeight` is set. autoFillData duplicates data assuming uniform item size, which conflicts with variable-size layouts. Pre-duplicate your data array if you need a short loopable list."
|
|
54
|
+
);
|
|
55
|
+
warnedRefs.autoFillVariable = true;
|
|
56
|
+
}
|
|
57
|
+
const { width: styleWidth, height: styleHeight } = StyleSheet.flatten(style) || {};
|
|
58
|
+
|
|
59
|
+
// Deprecation warnings for width/height props
|
|
60
|
+
if (typeof width === "number" && !warnedRefs.width) {
|
|
61
|
+
console.warn(
|
|
62
|
+
"[react-native-reanimated-carousel] The `width` prop is deprecated. Please use `style={{ width: ... }}` instead."
|
|
63
|
+
);
|
|
64
|
+
warnedRefs.width = true;
|
|
65
|
+
}
|
|
66
|
+
if (typeof height === "number" && !warnedRefs.height) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"[react-native-reanimated-carousel] The `height` prop is deprecated. Please use `style={{ height: ... }}` instead."
|
|
69
|
+
);
|
|
70
|
+
warnedRefs.height = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Conflict warning for contentContainerStyle
|
|
74
|
+
const { opacity, transform } = StyleSheet.flatten(contentContainerStyle) || {};
|
|
75
|
+
if ((opacity !== undefined || transform !== undefined) && !warnedRefs.conflict) {
|
|
76
|
+
console.warn(
|
|
77
|
+
"[react-native-reanimated-carousel] Do not set 'opacity' or 'transform' on 'contentContainerStyle' as it may conflict with animations."
|
|
78
|
+
);
|
|
79
|
+
warnedRefs.conflict = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Updated missing size warnings
|
|
83
|
+
const hasHorizontalContainerSize =
|
|
84
|
+
typeof styleWidth === "number" || typeof width === "number";
|
|
85
|
+
const hasVerticalContainerSize =
|
|
86
|
+
typeof styleHeight === "number" || typeof height === "number";
|
|
87
|
+
|
|
88
|
+
if (!vertical && !hasHorizontalContainerSize && !warnedRefs.horizontal) {
|
|
89
|
+
console.warn(
|
|
90
|
+
"[react-native-reanimated-carousel] Horizontal mode did not specify `width` in `style`, will fall back to automatic measurement mode."
|
|
91
|
+
);
|
|
92
|
+
warnedRefs.horizontal = true;
|
|
93
|
+
}
|
|
94
|
+
if (vertical && !hasVerticalContainerSize && !warnedRefs.vertical) {
|
|
95
|
+
console.warn(
|
|
96
|
+
"[react-native-reanimated-carousel] Vertical mode did not specify `height` in `style`, will fall back to automatic measurement mode."
|
|
97
|
+
);
|
|
98
|
+
warnedRefs.vertical = true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Page-size guidance (common pitfall): setting itemWidth/itemHeight without container size.
|
|
102
|
+
if (
|
|
103
|
+
!vertical &&
|
|
104
|
+
typeof itemWidth === "number" &&
|
|
105
|
+
!hasHorizontalContainerSize &&
|
|
106
|
+
!warnedRefs.itemWidth
|
|
107
|
+
) {
|
|
108
|
+
console.warn(
|
|
109
|
+
"[react-native-reanimated-carousel] `itemWidth` sets the snapping page size, not the container width. Consider setting container width via `style` (e.g. `style={{ width: '100%' }}` or `flex: 1`)."
|
|
110
|
+
);
|
|
111
|
+
warnedRefs.itemWidth = true;
|
|
112
|
+
}
|
|
113
|
+
if (
|
|
114
|
+
vertical &&
|
|
115
|
+
typeof itemHeight === "number" &&
|
|
116
|
+
!hasVerticalContainerSize &&
|
|
117
|
+
!warnedRefs.itemHeight
|
|
118
|
+
) {
|
|
119
|
+
console.warn(
|
|
120
|
+
"[react-native-reanimated-carousel] `itemHeight` sets the snapping page size, not the container height. Consider setting container height via `style` (e.g. `style={{ height: '100%' }}` or `flex: 1`)."
|
|
121
|
+
);
|
|
122
|
+
warnedRefs.itemHeight = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, [props]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const warnedRefs: { [key: string]: boolean } = {
|
|
129
|
+
horizontal: false,
|
|
130
|
+
vertical: false,
|
|
131
|
+
width: false,
|
|
132
|
+
height: false,
|
|
133
|
+
conflict: false,
|
|
134
|
+
itemWidth: false,
|
|
135
|
+
itemHeight: false,
|
|
136
|
+
getItemSize: false,
|
|
137
|
+
autoFillVariable: false,
|
|
138
|
+
};
|