@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,149 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import type { AccessibilityRole, AccessibilityState, ViewStyle } from "react-native";
|
|
4
|
+
import { Pressable, View } from "react-native";
|
|
5
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
6
|
+
import Animated, {
|
|
7
|
+
Extrapolation,
|
|
8
|
+
interpolate,
|
|
9
|
+
useAnimatedReaction,
|
|
10
|
+
useAnimatedStyle,
|
|
11
|
+
} from "react-native-reanimated";
|
|
12
|
+
import { scheduleOnRN } from "react-native-worklets";
|
|
13
|
+
|
|
14
|
+
export type DotStyle = Omit<ViewStyle, "width" | "height"> & {
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type PaginationItemAccessibilityOverrides = {
|
|
20
|
+
accessibilityLabel?: string;
|
|
21
|
+
accessibilityHint?: string;
|
|
22
|
+
accessibilityRole?: AccessibilityRole;
|
|
23
|
+
accessibilityState?: AccessibilityState;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const PaginationItem: React.FC<
|
|
27
|
+
PropsWithChildren<{
|
|
28
|
+
index: number;
|
|
29
|
+
count: number;
|
|
30
|
+
size?: number;
|
|
31
|
+
animValue: SharedValue<number>;
|
|
32
|
+
horizontal?: boolean;
|
|
33
|
+
dotStyle?: DotStyle;
|
|
34
|
+
activeDotStyle?: DotStyle;
|
|
35
|
+
onPress: () => void;
|
|
36
|
+
accessibilityLabel?: string;
|
|
37
|
+
accessibilityHint?: string;
|
|
38
|
+
accessibilityRole?: AccessibilityRole;
|
|
39
|
+
accessibilityState?: AccessibilityState;
|
|
40
|
+
}>
|
|
41
|
+
> = (props) => {
|
|
42
|
+
const {
|
|
43
|
+
animValue,
|
|
44
|
+
dotStyle,
|
|
45
|
+
activeDotStyle,
|
|
46
|
+
index,
|
|
47
|
+
count,
|
|
48
|
+
size,
|
|
49
|
+
horizontal,
|
|
50
|
+
children,
|
|
51
|
+
onPress,
|
|
52
|
+
accessibilityLabel,
|
|
53
|
+
accessibilityHint,
|
|
54
|
+
accessibilityRole,
|
|
55
|
+
accessibilityState,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
const defaultDotSize = 10;
|
|
59
|
+
|
|
60
|
+
const sizes = {
|
|
61
|
+
width: size || dotStyle?.width || defaultDotSize,
|
|
62
|
+
height: size || dotStyle?.height || defaultDotSize,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* TODO: Keep this for future implementation
|
|
67
|
+
* Used to change the size of the active dot with animation
|
|
68
|
+
*/
|
|
69
|
+
// const animatedSize = {
|
|
70
|
+
// width: activeDotStyle?.width,
|
|
71
|
+
// height: activeDotStyle?.height,
|
|
72
|
+
// };
|
|
73
|
+
|
|
74
|
+
const width = sizes.width;
|
|
75
|
+
const height = sizes.height;
|
|
76
|
+
|
|
77
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
78
|
+
const resolvedAccessibilityLabel = accessibilityLabel ?? `Slide ${index + 1} of ${count}`;
|
|
79
|
+
const resolvedAccessibilityHint =
|
|
80
|
+
accessibilityHint ?? (isSelected ? "" : `Go to ${resolvedAccessibilityLabel}`);
|
|
81
|
+
const resolvedAccessibilityRole = accessibilityRole ?? "button";
|
|
82
|
+
const resolvedAccessibilityState = accessibilityState ?? { selected: isSelected };
|
|
83
|
+
|
|
84
|
+
useAnimatedReaction(
|
|
85
|
+
() => animValue.value,
|
|
86
|
+
(value) => {
|
|
87
|
+
scheduleOnRN(setIsSelected, value === index);
|
|
88
|
+
},
|
|
89
|
+
[animValue, index]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const animStyle = useAnimatedStyle(() => {
|
|
93
|
+
const size = horizontal ? height : width;
|
|
94
|
+
let inputRange = [index - 1, index, index + 1];
|
|
95
|
+
let outputRange = [-size, 0, size];
|
|
96
|
+
|
|
97
|
+
if (index === 0 && animValue?.value > count - 1) {
|
|
98
|
+
inputRange = [count - 1, count, count + 1];
|
|
99
|
+
outputRange = [-size, 0, size];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
transform: [
|
|
104
|
+
{
|
|
105
|
+
translateX: interpolate(animValue?.value, inputRange, outputRange, Extrapolation.CLAMP),
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
}, [animValue, index, count, horizontal]);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<Pressable
|
|
113
|
+
onPress={onPress}
|
|
114
|
+
accessibilityLabel={resolvedAccessibilityLabel}
|
|
115
|
+
accessibilityRole={resolvedAccessibilityRole}
|
|
116
|
+
accessibilityHint={resolvedAccessibilityHint}
|
|
117
|
+
accessibilityState={resolvedAccessibilityState}
|
|
118
|
+
>
|
|
119
|
+
<View
|
|
120
|
+
style={[
|
|
121
|
+
{
|
|
122
|
+
width,
|
|
123
|
+
height,
|
|
124
|
+
overflow: "hidden",
|
|
125
|
+
transform: [
|
|
126
|
+
{
|
|
127
|
+
rotateZ: horizontal ? "90deg" : "0deg",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
dotStyle,
|
|
132
|
+
]}
|
|
133
|
+
>
|
|
134
|
+
<Animated.View
|
|
135
|
+
style={[
|
|
136
|
+
{
|
|
137
|
+
backgroundColor: "black",
|
|
138
|
+
flex: 1,
|
|
139
|
+
},
|
|
140
|
+
animStyle,
|
|
141
|
+
activeDotStyle,
|
|
142
|
+
]}
|
|
143
|
+
>
|
|
144
|
+
{children}
|
|
145
|
+
</Animated.View>
|
|
146
|
+
</View>
|
|
147
|
+
</Pressable>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type StyleProp, View, type ViewStyle } from "react-native";
|
|
2
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
3
|
+
|
|
4
|
+
import React from "react";
|
|
5
|
+
import type { DotStyle, PaginationItemAccessibilityOverrides } from "./PaginationItem";
|
|
6
|
+
import { PaginationItem } from "./PaginationItem";
|
|
7
|
+
|
|
8
|
+
export interface BasicProps<T> {
|
|
9
|
+
progress: SharedValue<number>;
|
|
10
|
+
horizontal?: boolean;
|
|
11
|
+
data: Array<T>;
|
|
12
|
+
renderItem?: (item: T, index: number) => React.ReactNode;
|
|
13
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
14
|
+
dotStyle?: DotStyle;
|
|
15
|
+
activeDotStyle?: DotStyle;
|
|
16
|
+
size?: number;
|
|
17
|
+
onPress?: (index: number) => void;
|
|
18
|
+
carouselName?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional accessibility overrides for each pagination item.
|
|
21
|
+
* Use this to fully control screen reader announcements per dot.
|
|
22
|
+
*/
|
|
23
|
+
paginationItemAccessibility?: (
|
|
24
|
+
index: number,
|
|
25
|
+
length: number
|
|
26
|
+
) => PaginationItemAccessibilityOverrides;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Basic = <T extends {}>(props: BasicProps<T>) => {
|
|
30
|
+
const {
|
|
31
|
+
activeDotStyle,
|
|
32
|
+
dotStyle,
|
|
33
|
+
progress,
|
|
34
|
+
horizontal = true,
|
|
35
|
+
data,
|
|
36
|
+
size,
|
|
37
|
+
containerStyle,
|
|
38
|
+
renderItem,
|
|
39
|
+
onPress,
|
|
40
|
+
carouselName,
|
|
41
|
+
paginationItemAccessibility,
|
|
42
|
+
} = props;
|
|
43
|
+
|
|
44
|
+
if (
|
|
45
|
+
typeof size === "string" ||
|
|
46
|
+
typeof dotStyle?.width === "string" ||
|
|
47
|
+
typeof dotStyle?.height === "string"
|
|
48
|
+
)
|
|
49
|
+
throw new Error("size/width/height must be a number");
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<View
|
|
53
|
+
style={[
|
|
54
|
+
{
|
|
55
|
+
justifyContent: "space-between",
|
|
56
|
+
alignSelf: "center",
|
|
57
|
+
},
|
|
58
|
+
horizontal
|
|
59
|
+
? {
|
|
60
|
+
flexDirection: "row",
|
|
61
|
+
}
|
|
62
|
+
: {
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
},
|
|
65
|
+
containerStyle,
|
|
66
|
+
]}
|
|
67
|
+
>
|
|
68
|
+
{data.map((item, index) => {
|
|
69
|
+
const defaultAccessibilityLabel = carouselName
|
|
70
|
+
? `Slide ${index + 1} of ${data.length} - ${carouselName}`
|
|
71
|
+
: `Slide ${index + 1} of ${data.length}`;
|
|
72
|
+
const accessibilityOverrides = paginationItemAccessibility?.(index, data.length) ?? {};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<PaginationItem
|
|
76
|
+
key={index}
|
|
77
|
+
index={index}
|
|
78
|
+
size={size}
|
|
79
|
+
count={data.length}
|
|
80
|
+
dotStyle={dotStyle}
|
|
81
|
+
animValue={progress}
|
|
82
|
+
horizontal={!horizontal}
|
|
83
|
+
activeDotStyle={activeDotStyle}
|
|
84
|
+
onPress={() => onPress?.(index)}
|
|
85
|
+
accessibilityLabel={
|
|
86
|
+
accessibilityOverrides.accessibilityLabel ?? defaultAccessibilityLabel
|
|
87
|
+
}
|
|
88
|
+
accessibilityHint={accessibilityOverrides.accessibilityHint}
|
|
89
|
+
accessibilityRole={accessibilityOverrides.accessibilityRole}
|
|
90
|
+
accessibilityState={accessibilityOverrides.accessibilityState}
|
|
91
|
+
>
|
|
92
|
+
{renderItem?.(item, index)}
|
|
93
|
+
</PaginationItem>
|
|
94
|
+
);
|
|
95
|
+
})}
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import type { AccessibilityRole, AccessibilityState } from "react-native";
|
|
4
|
+
import { Pressable } from "react-native";
|
|
5
|
+
import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
|
|
6
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
7
|
+
import Animated, {
|
|
8
|
+
Extrapolation,
|
|
9
|
+
interpolate,
|
|
10
|
+
interpolateColor,
|
|
11
|
+
useAnimatedStyle,
|
|
12
|
+
useSharedValue,
|
|
13
|
+
useDerivedValue,
|
|
14
|
+
useAnimatedReaction,
|
|
15
|
+
} from "react-native-reanimated";
|
|
16
|
+
import { scheduleOnRN } from "react-native-worklets";
|
|
17
|
+
|
|
18
|
+
type AnimatedDefaultStyle = ViewStyle | ImageStyle | TextStyle;
|
|
19
|
+
|
|
20
|
+
export type PaginationItemAccessibilityOverrides = {
|
|
21
|
+
accessibilityLabel?: string;
|
|
22
|
+
accessibilityHint?: string;
|
|
23
|
+
accessibilityRole?: AccessibilityRole;
|
|
24
|
+
accessibilityState?: AccessibilityState;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type DotStyle = Omit<ViewStyle, "width" | "height" | "backgroundColor" | "borderRadius"> & {
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
backgroundColor?: string;
|
|
31
|
+
borderRadius?: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const PaginationItem: React.FC<
|
|
35
|
+
PropsWithChildren<{
|
|
36
|
+
index: number;
|
|
37
|
+
count: number;
|
|
38
|
+
size?: number;
|
|
39
|
+
animValue: SharedValue<number>;
|
|
40
|
+
horizontal?: boolean;
|
|
41
|
+
dotStyle?: DotStyle;
|
|
42
|
+
activeDotStyle?: DotStyle;
|
|
43
|
+
onPress: () => void;
|
|
44
|
+
customReanimatedStyle?: (
|
|
45
|
+
progress: number,
|
|
46
|
+
index: number,
|
|
47
|
+
length: number
|
|
48
|
+
) => AnimatedDefaultStyle;
|
|
49
|
+
accessibilityLabel?: string;
|
|
50
|
+
accessibilityHint?: string;
|
|
51
|
+
accessibilityRole?: AccessibilityRole;
|
|
52
|
+
accessibilityState?: AccessibilityState;
|
|
53
|
+
}>
|
|
54
|
+
> = (props) => {
|
|
55
|
+
const defaultDotSize = 10;
|
|
56
|
+
const {
|
|
57
|
+
animValue,
|
|
58
|
+
dotStyle,
|
|
59
|
+
activeDotStyle,
|
|
60
|
+
index,
|
|
61
|
+
count,
|
|
62
|
+
size,
|
|
63
|
+
horizontal,
|
|
64
|
+
children,
|
|
65
|
+
customReanimatedStyle,
|
|
66
|
+
onPress,
|
|
67
|
+
accessibilityLabel,
|
|
68
|
+
accessibilityHint,
|
|
69
|
+
accessibilityRole,
|
|
70
|
+
accessibilityState,
|
|
71
|
+
} = props;
|
|
72
|
+
const customReanimatedStyleRef = useSharedValue<AnimatedDefaultStyle>({});
|
|
73
|
+
const handleCustomAnimation = (progress: number) => {
|
|
74
|
+
customReanimatedStyleRef.value = customReanimatedStyle?.(progress, index, count) ?? {};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
78
|
+
const resolvedAccessibilityLabel = accessibilityLabel ?? `Slide ${index + 1} of ${count}`;
|
|
79
|
+
const resolvedAccessibilityHint =
|
|
80
|
+
accessibilityHint ?? (isSelected ? "" : `Go to ${resolvedAccessibilityLabel}`);
|
|
81
|
+
const resolvedAccessibilityRole = accessibilityRole ?? "button";
|
|
82
|
+
const resolvedAccessibilityState = accessibilityState ?? { selected: isSelected };
|
|
83
|
+
|
|
84
|
+
useDerivedValue(() => {
|
|
85
|
+
scheduleOnRN(handleCustomAnimation, animValue?.value);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
useAnimatedReaction(
|
|
89
|
+
() => animValue.value,
|
|
90
|
+
(value) => {
|
|
91
|
+
scheduleOnRN(setIsSelected, value === index);
|
|
92
|
+
},
|
|
93
|
+
[animValue, index]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const animStyle = useAnimatedStyle((): AnimatedDefaultStyle => {
|
|
97
|
+
const {
|
|
98
|
+
width = size || defaultDotSize,
|
|
99
|
+
height = size || defaultDotSize,
|
|
100
|
+
borderRadius,
|
|
101
|
+
backgroundColor = "#FFF",
|
|
102
|
+
...restDotStyle
|
|
103
|
+
} = dotStyle ?? {};
|
|
104
|
+
const {
|
|
105
|
+
width: activeWidth = width,
|
|
106
|
+
height: activeHeight = height,
|
|
107
|
+
borderRadius: activeBorderRadius,
|
|
108
|
+
backgroundColor: activeBackgroundColor = "#000",
|
|
109
|
+
...restActiveDotStyle
|
|
110
|
+
} = activeDotStyle ?? {};
|
|
111
|
+
let val = Math.abs(animValue?.value - index);
|
|
112
|
+
if (index === 0 && animValue?.value > count - 1) val = Math.abs(animValue?.value - count);
|
|
113
|
+
|
|
114
|
+
const inputRange = [0, 1, 2];
|
|
115
|
+
const restStyle = (val === 0 ? restActiveDotStyle : restDotStyle) ?? {};
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
width: interpolate(val, inputRange, [activeWidth, width, width], Extrapolation.CLAMP),
|
|
119
|
+
height: interpolate(val, inputRange, [activeHeight, height, height], Extrapolation.CLAMP),
|
|
120
|
+
borderRadius: interpolate(
|
|
121
|
+
val,
|
|
122
|
+
inputRange,
|
|
123
|
+
[activeBorderRadius ?? borderRadius ?? 0, borderRadius ?? 0, borderRadius ?? 0],
|
|
124
|
+
Extrapolation.CLAMP
|
|
125
|
+
),
|
|
126
|
+
backgroundColor: interpolateColor(val, inputRange, [
|
|
127
|
+
activeBackgroundColor,
|
|
128
|
+
backgroundColor,
|
|
129
|
+
backgroundColor,
|
|
130
|
+
]),
|
|
131
|
+
...restStyle,
|
|
132
|
+
...(customReanimatedStyleRef.value ?? {}),
|
|
133
|
+
transform: [
|
|
134
|
+
...(restStyle?.transform ?? []),
|
|
135
|
+
...(customReanimatedStyleRef.value?.transform ?? []),
|
|
136
|
+
] as AnimatedDefaultStyle["transform"],
|
|
137
|
+
};
|
|
138
|
+
}, [animValue, index, count, horizontal, dotStyle, activeDotStyle, customReanimatedStyle]);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<Pressable
|
|
142
|
+
onPress={onPress}
|
|
143
|
+
accessibilityLabel={resolvedAccessibilityLabel}
|
|
144
|
+
accessibilityRole={resolvedAccessibilityRole}
|
|
145
|
+
accessibilityHint={resolvedAccessibilityHint}
|
|
146
|
+
accessibilityState={resolvedAccessibilityState}
|
|
147
|
+
>
|
|
148
|
+
<Animated.View
|
|
149
|
+
style={[
|
|
150
|
+
{
|
|
151
|
+
overflow: "hidden",
|
|
152
|
+
transform: [
|
|
153
|
+
{
|
|
154
|
+
rotateZ: horizontal ? "90deg" : "0deg",
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
dotStyle,
|
|
159
|
+
animStyle,
|
|
160
|
+
]}
|
|
161
|
+
>
|
|
162
|
+
{children}
|
|
163
|
+
</Animated.View>
|
|
164
|
+
</Pressable>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ImageStyle, StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
5
|
+
|
|
6
|
+
import type { DotStyle, PaginationItemAccessibilityOverrides } from "./PaginationItem";
|
|
7
|
+
import { PaginationItem } from "./PaginationItem";
|
|
8
|
+
|
|
9
|
+
export interface ShapeProps<T extends {}> {
|
|
10
|
+
progress: SharedValue<number>;
|
|
11
|
+
horizontal?: boolean;
|
|
12
|
+
data: Array<T>;
|
|
13
|
+
renderItem?: (item: T, index: number) => React.ReactNode;
|
|
14
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
15
|
+
dotStyle?: DotStyle;
|
|
16
|
+
activeDotStyle?: DotStyle;
|
|
17
|
+
size?: number;
|
|
18
|
+
onPress?: (index: number) => void;
|
|
19
|
+
customReanimatedStyle?: (progress: number, index: number, length: number) => AnimatedDefaultStyle;
|
|
20
|
+
carouselName?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional accessibility overrides for each pagination item.
|
|
23
|
+
* Use this to fully control screen reader announcements per dot.
|
|
24
|
+
*/
|
|
25
|
+
paginationItemAccessibility?: (
|
|
26
|
+
index: number,
|
|
27
|
+
length: number
|
|
28
|
+
) => PaginationItemAccessibilityOverrides;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type AnimatedDefaultStyle = ViewStyle | ImageStyle | TextStyle;
|
|
32
|
+
|
|
33
|
+
export const Custom = <T extends {}>(props: ShapeProps<T>) => {
|
|
34
|
+
const {
|
|
35
|
+
activeDotStyle,
|
|
36
|
+
dotStyle,
|
|
37
|
+
progress,
|
|
38
|
+
horizontal = true,
|
|
39
|
+
data,
|
|
40
|
+
size,
|
|
41
|
+
containerStyle,
|
|
42
|
+
renderItem,
|
|
43
|
+
onPress,
|
|
44
|
+
customReanimatedStyle,
|
|
45
|
+
carouselName,
|
|
46
|
+
paginationItemAccessibility,
|
|
47
|
+
} = props;
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
typeof size === "string" ||
|
|
51
|
+
typeof dotStyle?.width === "string" ||
|
|
52
|
+
typeof dotStyle?.height === "string" ||
|
|
53
|
+
typeof activeDotStyle?.width === "string" ||
|
|
54
|
+
typeof activeDotStyle?.height === "string"
|
|
55
|
+
)
|
|
56
|
+
throw new Error("size/width/height must be a number");
|
|
57
|
+
|
|
58
|
+
const maxItemWidth = Math.max(size ?? 0, dotStyle?.width ?? 0, activeDotStyle?.width ?? 0);
|
|
59
|
+
const maxItemHeight = Math.max(size ?? 0, dotStyle?.height ?? 0, activeDotStyle?.height ?? 0);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View
|
|
63
|
+
style={[
|
|
64
|
+
{
|
|
65
|
+
justifyContent: "space-between",
|
|
66
|
+
alignSelf: "center",
|
|
67
|
+
minWidth: maxItemWidth,
|
|
68
|
+
minHeight: maxItemHeight,
|
|
69
|
+
},
|
|
70
|
+
horizontal
|
|
71
|
+
? {
|
|
72
|
+
flexDirection: "row",
|
|
73
|
+
}
|
|
74
|
+
: {
|
|
75
|
+
flexDirection: "column",
|
|
76
|
+
},
|
|
77
|
+
containerStyle,
|
|
78
|
+
]}
|
|
79
|
+
>
|
|
80
|
+
{data.map((item, index) => {
|
|
81
|
+
const defaultAccessibilityLabel = carouselName
|
|
82
|
+
? `Slide ${index + 1} of ${data.length} - ${carouselName}`
|
|
83
|
+
: `Slide ${index + 1} of ${data.length}`;
|
|
84
|
+
const accessibilityOverrides = paginationItemAccessibility?.(index, data.length) ?? {};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<PaginationItem
|
|
88
|
+
key={index}
|
|
89
|
+
index={index}
|
|
90
|
+
size={size}
|
|
91
|
+
count={data.length}
|
|
92
|
+
dotStyle={dotStyle}
|
|
93
|
+
animValue={progress}
|
|
94
|
+
horizontal={!horizontal}
|
|
95
|
+
activeDotStyle={activeDotStyle}
|
|
96
|
+
customReanimatedStyle={customReanimatedStyle}
|
|
97
|
+
onPress={() => onPress?.(index)}
|
|
98
|
+
accessibilityLabel={
|
|
99
|
+
accessibilityOverrides.accessibilityLabel ?? defaultAccessibilityLabel
|
|
100
|
+
}
|
|
101
|
+
accessibilityHint={accessibilityOverrides.accessibilityHint}
|
|
102
|
+
accessibilityRole={accessibilityOverrides.accessibilityRole}
|
|
103
|
+
accessibilityState={accessibilityOverrides.accessibilityState}
|
|
104
|
+
>
|
|
105
|
+
{renderItem?.(item, index)}
|
|
106
|
+
</PaginationItem>
|
|
107
|
+
);
|
|
108
|
+
})}
|
|
109
|
+
</View>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { act, fireEvent, render } from "@testing-library/react-native";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import { Pagination } from ".";
|
|
6
|
+
|
|
7
|
+
jest.mock("react-native-worklets", () => ({
|
|
8
|
+
scheduleOnRN: (fn: (...args: unknown[]) => void, ...args: unknown[]) => fn(...args),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
// Use fake timers so the reanimated mapper's mockedRequestAnimationFrame
|
|
12
|
+
// (a setTimeout-based RAF) doesn't fire outside of act().
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.useFakeTimers();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.useRealTimers();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("Pagination.Basic", () => {
|
|
22
|
+
it("throws when size/dot width/height are non-number", () => {
|
|
23
|
+
const Test = () => {
|
|
24
|
+
const progress = useSharedValue(0);
|
|
25
|
+
return (
|
|
26
|
+
<Pagination.Basic
|
|
27
|
+
data={[1, 2]}
|
|
28
|
+
progress={progress}
|
|
29
|
+
// @ts-expect-error intentional invalid type
|
|
30
|
+
size={"12px"}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
expect(() => render(<Test />)).toThrow("size/width/height must be a number");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders dots and calls onPress", async () => {
|
|
39
|
+
const handlePress = jest.fn();
|
|
40
|
+
const Test = () => {
|
|
41
|
+
const progress = useSharedValue(0);
|
|
42
|
+
return (
|
|
43
|
+
<Pagination.Basic
|
|
44
|
+
data={[1, 2, 3]}
|
|
45
|
+
progress={progress}
|
|
46
|
+
onPress={handlePress}
|
|
47
|
+
carouselName="Demo"
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const { UNSAFE_root } = render(<Test />);
|
|
53
|
+
await act(async () => {
|
|
54
|
+
jest.advanceTimersByTime(100);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const buttons = UNSAFE_root.findAll(
|
|
58
|
+
(node) =>
|
|
59
|
+
node?.props?.accessibilityRole === "button" &&
|
|
60
|
+
typeof node?.props?.accessibilityLabel === "string" &&
|
|
61
|
+
node.props.accessibilityLabel.startsWith("Slide ")
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const uniqueByLabel = Array.from(
|
|
65
|
+
new Map(buttons.map((b) => [b.props.accessibilityLabel, b])).values()
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(uniqueByLabel).toHaveLength(3);
|
|
69
|
+
|
|
70
|
+
await act(async () => {
|
|
71
|
+
fireEvent.press(uniqueByLabel[1]);
|
|
72
|
+
jest.advanceTimersByTime(100);
|
|
73
|
+
});
|
|
74
|
+
expect(handlePress).toHaveBeenCalledWith(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("does not include undefined in default accessibilityLabel when carouselName is omitted", async () => {
|
|
78
|
+
const Test = () => {
|
|
79
|
+
const progress = useSharedValue(0);
|
|
80
|
+
return <Pagination.Basic data={[1, 2]} progress={progress} />;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const { UNSAFE_root } = render(<Test />);
|
|
84
|
+
await act(async () => {
|
|
85
|
+
jest.advanceTimersByTime(100);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const buttons = UNSAFE_root.findAll(
|
|
89
|
+
(node) =>
|
|
90
|
+
node?.props?.accessibilityRole === "button" &&
|
|
91
|
+
typeof node?.props?.accessibilityLabel === "string" &&
|
|
92
|
+
node.props.accessibilityLabel.startsWith("Slide ")
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const uniqueByLabel = Array.from(
|
|
96
|
+
new Map(buttons.map((b) => [b.props.accessibilityLabel, b])).values()
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(uniqueByLabel[0].props.accessibilityLabel).toBe("Slide 1 of 2");
|
|
100
|
+
expect(uniqueByLabel[0].props.accessibilityLabel).not.toContain("undefined");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("Pagination.Custom", () => {
|
|
105
|
+
it("throws when any size-related prop is non-number", () => {
|
|
106
|
+
const Test = () => {
|
|
107
|
+
const progress = useSharedValue(0);
|
|
108
|
+
return (
|
|
109
|
+
<Pagination.Custom
|
|
110
|
+
data={[1]}
|
|
111
|
+
progress={progress}
|
|
112
|
+
// @ts-expect-error intentional invalid type
|
|
113
|
+
activeDotStyle={{ width: "10px" }}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
expect(() => render(<Test />)).toThrow("size/width/height must be a number");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("uses max item dimensions for container min sizes", async () => {
|
|
122
|
+
const Test = () => {
|
|
123
|
+
const progress = useSharedValue(0);
|
|
124
|
+
return (
|
|
125
|
+
<Pagination.Custom
|
|
126
|
+
data={[1, 2]}
|
|
127
|
+
progress={progress}
|
|
128
|
+
size={12}
|
|
129
|
+
dotStyle={{ width: 14, height: 8 }}
|
|
130
|
+
activeDotStyle={{ width: 16, height: 20 }}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const { UNSAFE_root } = render(<Test />);
|
|
136
|
+
await act(async () => {
|
|
137
|
+
jest.advanceTimersByTime(100);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// @ts-expect-error
|
|
141
|
+
const container = UNSAFE_root.findByType(View);
|
|
142
|
+
const flattened = Array.isArray(container.props.style)
|
|
143
|
+
? Object.assign({}, ...container.props.style.filter(Boolean))
|
|
144
|
+
: container.props.style;
|
|
145
|
+
|
|
146
|
+
expect(flattened.minWidth).toBe(16);
|
|
147
|
+
expect(flattened.minHeight).toBe(20);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("allows overriding pagination item accessibility props", async () => {
|
|
151
|
+
const Test = () => {
|
|
152
|
+
const progress = useSharedValue(0);
|
|
153
|
+
return (
|
|
154
|
+
<Pagination.Custom
|
|
155
|
+
data={[1, 2]}
|
|
156
|
+
progress={progress}
|
|
157
|
+
paginationItemAccessibility={(index: number, length: number) => ({
|
|
158
|
+
accessibilityLabel: `Page ${index + 1}/${length}`,
|
|
159
|
+
accessibilityHint: `Jump to ${index + 1}`,
|
|
160
|
+
accessibilityRole: "link",
|
|
161
|
+
})}
|
|
162
|
+
/>
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const { UNSAFE_root } = render(<Test />);
|
|
167
|
+
await act(async () => {
|
|
168
|
+
jest.advanceTimersByTime(100);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const item = UNSAFE_root.find(
|
|
172
|
+
(node) =>
|
|
173
|
+
node?.props?.accessibilityLabel === "Page 1/2" && node?.props?.accessibilityRole === "link"
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
expect(item.props.accessibilityHint).toBe("Jump to 1");
|
|
177
|
+
});
|
|
178
|
+
});
|