@fountain-ui/lab 2.0.0-beta.11 → 2.0.0-beta.14
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/build/commonjs/Carousel/Carousel.js +142 -0
- package/build/commonjs/Carousel/Carousel.js.map +1 -0
- package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
- package/build/commonjs/Carousel/animation/animationUtils.js +9 -0
- package/build/commonjs/Carousel/animation/animationUtils.js.map +1 -0
- package/build/commonjs/Carousel/animation/createDefaultItemStyle.js +15 -0
- package/build/commonjs/Carousel/animation/createDefaultItemStyle.js.map +1 -0
- package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +20 -0
- package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
- package/build/commonjs/Carousel/animation/index.js +40 -0
- package/build/commonjs/Carousel/animation/index.js.map +1 -0
- package/build/commonjs/Carousel/animation/normalItemStyleFactory.js +27 -0
- package/build/commonjs/Carousel/animation/normalItemStyleFactory.js.map +1 -0
- package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +65 -0
- package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
- package/build/commonjs/Carousel/components/InternalContext.js +29 -0
- package/build/commonjs/Carousel/components/InternalContext.js.map +1 -0
- package/build/commonjs/Carousel/components/ItemView.js +66 -0
- package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
- package/build/commonjs/Carousel/components/RootView.js +86 -0
- package/build/commonjs/Carousel/components/RootView.js.map +1 -0
- package/build/commonjs/Carousel/components/ScrollViewGesture.js +81 -0
- package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -0
- package/build/commonjs/Carousel/components/index.js +40 -0
- package/build/commonjs/Carousel/components/index.js.map +1 -0
- package/build/commonjs/Carousel/hooks/index.js +64 -0
- package/build/commonjs/Carousel/hooks/index.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useAutoplayController.js +58 -0
- package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +23 -0
- package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useIndexController.js +70 -0
- package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useItemInterpolation.js +63 -0
- package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +95 -0
- package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useLoopedData.js +33 -0
- package/build/commonjs/Carousel/hooks/useLoopedData.js.map +1 -0
- package/build/commonjs/Carousel/hooks/usePagingAnimation.js +162 -0
- package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -0
- package/build/commonjs/Carousel/index.js +16 -2
- package/build/commonjs/Carousel/index.js.map +1 -1
- package/build/commonjs/Carousel/types.js +7 -0
- package/build/commonjs/Carousel/types.js.map +1 -0
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +53 -59
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/commonjs/ViewPager/InternalContext.js +17 -0
- package/build/commonjs/ViewPager/InternalContext.js.map +1 -0
- package/build/commonjs/ViewPager/PageStateContext.js +22 -0
- package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
- package/build/commonjs/ViewPager/ViewPagerNative.js +90 -25
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerWeb.js +27 -14
- package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/commonjs/ViewPager/index.js +8 -0
- package/build/commonjs/ViewPager/index.js.map +1 -1
- package/build/commonjs/ViewPager/index.native.js +8 -0
- package/build/commonjs/ViewPager/index.native.js.map +1 -1
- package/build/commonjs/ViewPager/types.js +6 -0
- package/build/commonjs/ViewPager/types.js.map +1 -0
- package/build/commonjs/ViewPager/usePageStore.js +30 -0
- package/build/commonjs/ViewPager/usePageStore.js.map +1 -0
- package/build/commonjs/ViewPager/utils.js +3 -1
- package/build/commonjs/ViewPager/utils.js.map +1 -1
- package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
- package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
- package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
- package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
- package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
- package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
- package/build/commonjs/hooks/index.js +16 -0
- package/build/commonjs/hooks/index.js.map +1 -1
- package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
- package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
- package/build/commonjs/hooks/useIsMounted.js +22 -0
- package/build/commonjs/hooks/useIsMounted.js.map +1 -0
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +1 -1
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/commonjs/index.js +22 -1
- package/build/commonjs/index.js.map +1 -1
- package/build/module/Carousel/Carousel.js +120 -0
- package/build/module/Carousel/Carousel.js.map +1 -0
- package/build/module/Carousel/CarouselProps.js.map +1 -1
- package/build/module/Carousel/animation/animationUtils.js +2 -0
- package/build/module/Carousel/animation/animationUtils.js.map +1 -0
- package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
- package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
- package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
- package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
- package/build/module/Carousel/animation/index.js +5 -0
- package/build/module/Carousel/animation/index.js.map +1 -0
- package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
- package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
- package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
- package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
- package/build/module/Carousel/components/InternalContext.js +19 -0
- package/build/module/Carousel/components/InternalContext.js.map +1 -0
- package/build/module/Carousel/components/ItemView.js +46 -0
- package/build/module/Carousel/components/ItemView.js.map +1 -0
- package/build/module/Carousel/components/RootView.js +65 -0
- package/build/module/Carousel/components/RootView.js.map +1 -0
- package/build/module/Carousel/components/ScrollViewGesture.js +67 -0
- package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
- package/build/module/Carousel/components/index.js +5 -0
- package/build/module/Carousel/components/index.js.map +1 -0
- package/build/module/Carousel/hooks/index.js +8 -0
- package/build/module/Carousel/hooks/index.js.map +1 -0
- package/build/module/Carousel/hooks/useAutoplayController.js +48 -0
- package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
- package/build/module/Carousel/hooks/useDimensionChangeReaction.js +14 -0
- package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
- package/build/module/Carousel/hooks/useIndexController.js +54 -0
- package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
- package/build/module/Carousel/hooks/useItemInterpolation.js +51 -0
- package/build/module/Carousel/hooks/useItemInterpolation.js.map +1 -0
- package/build/module/Carousel/hooks/useItemVisibilityStore.js +87 -0
- package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
- package/build/module/Carousel/hooks/useLoopedData.js +24 -0
- package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
- package/build/module/Carousel/hooks/usePagingAnimation.js +153 -0
- package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -0
- package/build/module/Carousel/index.js +2 -1
- package/build/module/Carousel/index.js.map +1 -1
- package/build/module/Carousel/types.js +3 -0
- package/build/module/Carousel/types.js.map +1 -0
- package/build/module/ViewPager/ChildrenMemoizedPage.js +48 -56
- package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/module/ViewPager/InternalContext.js +7 -0
- package/build/module/ViewPager/InternalContext.js.map +1 -0
- package/build/module/ViewPager/PageStateContext.js +10 -0
- package/build/module/ViewPager/PageStateContext.js.map +1 -0
- package/build/module/ViewPager/ViewPagerNative.js +90 -27
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/module/ViewPager/ViewPagerWeb.js +25 -15
- package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/module/ViewPager/index.js +1 -0
- package/build/module/ViewPager/index.js.map +1 -1
- package/build/module/ViewPager/index.native.js +1 -0
- package/build/module/ViewPager/index.native.js.map +1 -1
- package/build/module/ViewPager/types.js +2 -0
- package/build/module/ViewPager/types.js.map +1 -0
- package/build/module/ViewPager/usePageStore.js +20 -0
- package/build/module/ViewPager/usePageStore.js.map +1 -0
- package/build/module/ViewPager/utils.js +1 -0
- package/build/module/ViewPager/utils.js.map +1 -1
- package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
- package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
- package/build/module/ViewabilityTrackerView/index.js +2 -0
- package/build/module/ViewabilityTrackerView/index.js.map +1 -0
- package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
- package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
- package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
- package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
- package/build/module/hooks/index.js +2 -0
- package/build/module/hooks/index.js.map +1 -1
- package/build/module/hooks/useDeferredExecutor.js +33 -0
- package/build/module/hooks/useDeferredExecutor.js.map +1 -0
- package/build/module/hooks/useIsMounted.js +13 -0
- package/build/module/hooks/useIsMounted.js.map +1 -0
- package/build/module/hooks/useUnstableCollapsibleAppBar.js +1 -1
- package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/module/index.js +2 -0
- package/build/module/index.js.map +1 -1
- package/build/typescript/Carousel/Carousel.d.ts +5 -0
- package/build/typescript/Carousel/CarouselProps.d.ts +33 -48
- package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
- package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
- package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
- package/build/typescript/Carousel/animation/index.d.ts +4 -0
- package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
- package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
- package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
- package/build/typescript/Carousel/components/ItemView.d.ts +9 -0
- package/build/typescript/Carousel/components/RootView.d.ts +16 -0
- package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
- package/build/typescript/Carousel/components/index.d.ts +4 -0
- package/build/typescript/Carousel/hooks/index.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
- package/build/typescript/Carousel/hooks/useItemInterpolation.d.ts +2 -0
- package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
- package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +18 -0
- package/build/typescript/Carousel/index.d.ts +3 -1
- package/build/typescript/Carousel/types.d.ts +79 -0
- package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +1 -1
- package/build/typescript/ViewPager/InternalContext.d.ts +7 -0
- package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
- package/build/typescript/ViewPager/ViewPagerNative.d.ts +2 -2
- package/build/typescript/ViewPager/ViewPagerProps.d.ts +13 -20
- package/build/typescript/ViewPager/ViewPagerWeb.d.ts +2 -2
- package/build/typescript/ViewPager/index.d.ts +3 -1
- package/build/typescript/ViewPager/index.native.d.ts +1 -0
- package/build/typescript/ViewPager/types.d.ts +19 -0
- package/build/typescript/ViewPager/usePageStore.d.ts +2 -0
- package/build/typescript/ViewPager/utils.d.ts +2 -1
- package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
- package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
- package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
- package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
- package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
- package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
- package/build/typescript/hooks/index.d.ts +2 -0
- package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
- package/build/typescript/hooks/useIsMounted.d.ts +4 -0
- package/build/typescript/index.d.ts +2 -0
- package/package.json +4 -19
- package/src/Carousel/Carousel.tsx +152 -0
- package/src/Carousel/CarouselProps.ts +35 -53
- package/src/Carousel/animation/animationUtils.ts +1 -0
- package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
- package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
- package/src/Carousel/animation/index.ts +4 -0
- package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
- package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
- package/src/Carousel/components/InternalContext.ts +33 -0
- package/src/Carousel/components/ItemView.tsx +66 -0
- package/src/Carousel/components/RootView.tsx +79 -0
- package/src/Carousel/components/ScrollViewGesture.tsx +87 -0
- package/src/Carousel/components/index.ts +4 -0
- package/src/Carousel/hooks/index.ts +7 -0
- package/src/Carousel/hooks/useAutoplayController.ts +57 -0
- package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
- package/src/Carousel/hooks/useIndexController.tsx +76 -0
- package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
- package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
- package/src/Carousel/hooks/useLoopedData.ts +26 -0
- package/src/Carousel/hooks/usePagingAnimation.ts +195 -0
- package/src/Carousel/index.ts +4 -2
- package/src/Carousel/types.ts +97 -0
- package/src/ViewPager/ChildrenMemoizedPage.tsx +55 -54
- package/src/ViewPager/InternalContext.ts +13 -0
- package/src/ViewPager/PageStateContext.ts +15 -0
- package/src/ViewPager/ViewPagerNative.tsx +114 -43
- package/src/ViewPager/ViewPagerProps.ts +15 -25
- package/src/ViewPager/ViewPagerWeb.tsx +30 -21
- package/src/ViewPager/index.native.ts +1 -0
- package/src/ViewPager/index.ts +3 -1
- package/src/ViewPager/types.ts +24 -0
- package/src/ViewPager/usePageStore.ts +24 -0
- package/src/ViewPager/utils.tsx +3 -2
- package/src/ViewabilityTrackerView/Viewability.ts +3 -0
- package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
- package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
- package/src/ViewabilityTrackerView/index.ts +2 -0
- package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
- package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useDeferredExecutor.ts +46 -0
- package/src/hooks/useIsMounted.ts +19 -0
- package/src/hooks/useUnstableCollapsibleAppBar.ts +1 -1
- package/src/index.ts +3 -0
- package/build/commonjs/Carousel/CarouselNative.js +0 -72
- package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
- package/build/commonjs/Carousel/CarouselWeb.js +0 -237
- package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
- package/build/commonjs/Carousel/index.native.js.map +0 -1
- package/build/commonjs/Carousel/utils.js +0 -19
- package/build/commonjs/Carousel/utils.js.map +0 -1
- package/build/module/Carousel/CarouselNative.js +0 -54
- package/build/module/Carousel/CarouselNative.js.map +0 -1
- package/build/module/Carousel/CarouselWeb.js +0 -215
- package/build/module/Carousel/CarouselWeb.js.map +0 -1
- package/build/module/Carousel/index.native.js +0 -2
- package/build/module/Carousel/index.native.js.map +0 -1
- package/build/module/Carousel/utils.js +0 -7
- package/build/module/Carousel/utils.js.map +0 -1
- package/build/typescript/Carousel/CarouselNative.d.ts +0 -2
- package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
- package/build/typescript/Carousel/index.native.d.ts +0 -1
- package/build/typescript/Carousel/utils.d.ts +0 -6
- package/src/Carousel/CarouselNative.tsx +0 -67
- package/src/Carousel/CarouselWeb.tsx +0 -222
- package/src/Carousel/index.native.ts +0 -1
- package/src/Carousel/utils.ts +0 -11
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ListRenderItemInfo } from 'react-native';
|
|
1
|
+
import type { RefObject } from 'react';
|
|
3
2
|
import type { ComponentProps } from '@fountain-ui/core';
|
|
3
|
+
import type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, ItemHeight, RenderItem } from './types';
|
|
4
4
|
|
|
5
5
|
export default interface CarouselProps<ItemT = any> extends ComponentProps<{
|
|
6
|
+
ref?: RefObject<CarouselInstance>;
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* If `true`, enable autoplay.
|
|
8
10
|
* @default false
|
|
@@ -16,92 +18,72 @@ export default interface CarouselProps<ItemT = any> extends ComponentProps<{
|
|
|
16
18
|
autoplayInterval?: number;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
21
|
+
* The item style creator function.
|
|
22
|
+
* @default createDefaultItemStyle
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
createItemStyle?: CreateItemStyle;
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
|
-
*
|
|
27
|
+
* The scroll animation creator function.
|
|
28
|
+
* @default createDefaultScrollAnimation
|
|
29
|
+
*/
|
|
30
|
+
createScrollAnimation?: CreateScrollAnimation;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Data for render items.
|
|
25
34
|
*/
|
|
26
35
|
data: ReadonlyArray<ItemT>;
|
|
27
36
|
|
|
28
37
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @default
|
|
38
|
+
* If `true`, carousel will detect its own viewability and control autoplay automatically.
|
|
39
|
+
* @default false
|
|
31
40
|
*/
|
|
32
|
-
|
|
41
|
+
disableSmartAutoplay?: boolean;
|
|
33
42
|
|
|
34
43
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @default 0
|
|
44
|
+
* Index of initial item that should be selected.
|
|
45
|
+
* @default 0
|
|
37
46
|
*/
|
|
38
|
-
|
|
47
|
+
initialIndex?: number;
|
|
39
48
|
|
|
40
49
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
50
|
+
* The item height.
|
|
51
|
+
* For a performance reason, always consider to provide a number value.
|
|
43
52
|
*/
|
|
44
|
-
|
|
53
|
+
itemHeight: ItemHeight;
|
|
45
54
|
|
|
46
55
|
/**
|
|
47
|
-
*
|
|
56
|
+
* The item width.
|
|
48
57
|
*/
|
|
49
|
-
|
|
58
|
+
itemWidth: number;
|
|
50
59
|
|
|
51
60
|
/**
|
|
52
61
|
* Enable infinite loop mode.
|
|
53
62
|
* @default false
|
|
54
63
|
*/
|
|
55
|
-
|
|
64
|
+
loop?: boolean;
|
|
56
65
|
|
|
57
66
|
/**
|
|
58
67
|
* Callback fired when an index is changed.
|
|
59
68
|
*/
|
|
60
|
-
|
|
69
|
+
onIndexChange?: (newIndex: number) => void;
|
|
61
70
|
|
|
62
71
|
/**
|
|
63
72
|
* Takes an item from data and renders it into the list.
|
|
64
73
|
*/
|
|
65
|
-
renderItem:
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Web only. Number of slides to scroll at once.
|
|
69
|
-
* @default 1
|
|
70
|
-
*/
|
|
71
|
-
slidesToScroll?: number;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Web only. Number of slides to display.
|
|
75
|
-
* @default 1
|
|
76
|
-
*/
|
|
77
|
-
slidesToShow?: number;
|
|
74
|
+
renderItem: RenderItem<ItemT>;
|
|
78
75
|
|
|
79
76
|
/**
|
|
80
|
-
*
|
|
77
|
+
* Whether to enable scroll gesture.
|
|
81
78
|
* @default true
|
|
82
79
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Web only. Enable arrows to display.
|
|
87
|
-
* @default true
|
|
88
|
-
*/
|
|
89
|
-
arrows?: boolean;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Web only. Style of arrows
|
|
93
|
-
* @default true
|
|
94
|
-
*/
|
|
95
|
-
arrowsStyle?: object;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Web only. Style of track
|
|
99
|
-
* @default object
|
|
100
|
-
*/
|
|
101
|
-
trackStyle?: object;
|
|
80
|
+
scrollEnabled?: boolean;
|
|
102
81
|
|
|
103
82
|
/**
|
|
104
|
-
*
|
|
83
|
+
* The maximum number of items that can respond to pan gesture events.
|
|
84
|
+
* Due to the nature of the `active` item, it accepts only odd number. (e.g. 1, 3, 5...)
|
|
85
|
+
* 0 means all items will respond to pan gesture events.
|
|
86
|
+
* @default 5
|
|
105
87
|
*/
|
|
106
|
-
|
|
88
|
+
windowSize?: number;
|
|
107
89
|
}> {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const itemInterpolationInputRange = [-1, 0, 1];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Animated, Easing } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default function createDefaultScrollAnimation(
|
|
4
|
+
animatedValue: Animated.Value,
|
|
5
|
+
toValue: number,
|
|
6
|
+
): Animated.CompositeAnimation {
|
|
7
|
+
return Animated.timing(animatedValue, {
|
|
8
|
+
toValue: toValue,
|
|
9
|
+
duration: 350,
|
|
10
|
+
easing: Easing.bezier(0.25, 1, 0.5, 1),
|
|
11
|
+
useNativeDriver: true,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as createDefaultItemStyle } from './createDefaultItemStyle';
|
|
2
|
+
export { default as createDefaultScrollAnimation } from './createDefaultScrollAnimation';
|
|
3
|
+
export { default as normalItemStyleFactory } from './normalItemStyleFactory';
|
|
4
|
+
export { default as parallaxItemStyleFactory } from './parallaxItemStyleFactory';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CreateItemStyle } from '../types';
|
|
2
|
+
import { itemInterpolationInputRange } from './animationUtils';
|
|
3
|
+
|
|
4
|
+
export default function normalItemStyleFactory() {
|
|
5
|
+
const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {
|
|
6
|
+
const translate = itemInterpolation.interpolate({
|
|
7
|
+
inputRange: itemInterpolationInputRange,
|
|
8
|
+
outputRange: [
|
|
9
|
+
-itemWidth,
|
|
10
|
+
0,
|
|
11
|
+
itemWidth,
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return { transform: [{ translateX: translate }] };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return createItemStyle;
|
|
19
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { CreateItemStyle } from '../types';
|
|
2
|
+
import { itemInterpolationInputRange } from './animationUtils';
|
|
3
|
+
|
|
4
|
+
export interface ParallaxAnimationConfig {
|
|
5
|
+
activeItemScale?: number;
|
|
6
|
+
activeItemOpacity?: number;
|
|
7
|
+
adjacentItemScale?: number;
|
|
8
|
+
adjacentItemOpacity?: number;
|
|
9
|
+
scrollingOffset?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const defaultParallaxAnimationConfig: Required<Readonly<ParallaxAnimationConfig>> = {
|
|
13
|
+
activeItemScale: 0.9,
|
|
14
|
+
activeItemOpacity: 1,
|
|
15
|
+
adjacentItemScale: Math.pow(0.9, 2),
|
|
16
|
+
adjacentItemOpacity: 0.5,
|
|
17
|
+
scrollingOffset: 50,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function parallaxItemStyleFactory(config: ParallaxAnimationConfig = defaultParallaxAnimationConfig) {
|
|
21
|
+
const {
|
|
22
|
+
activeItemOpacity,
|
|
23
|
+
activeItemScale,
|
|
24
|
+
adjacentItemOpacity,
|
|
25
|
+
adjacentItemScale,
|
|
26
|
+
scrollingOffset,
|
|
27
|
+
}: Required<ParallaxAnimationConfig> = {
|
|
28
|
+
...config,
|
|
29
|
+
...defaultParallaxAnimationConfig,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {
|
|
33
|
+
const translate = itemInterpolation.interpolate({
|
|
34
|
+
inputRange: itemInterpolationInputRange,
|
|
35
|
+
outputRange: [
|
|
36
|
+
-itemWidth + scrollingOffset,
|
|
37
|
+
0,
|
|
38
|
+
itemWidth - scrollingOffset,
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const zIndex = itemInterpolation.interpolate({
|
|
43
|
+
inputRange: itemInterpolationInputRange,
|
|
44
|
+
outputRange: [0, itemWidth, 0],
|
|
45
|
+
extrapolate: 'clamp',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const scale = itemInterpolation.interpolate({
|
|
49
|
+
inputRange: itemInterpolationInputRange,
|
|
50
|
+
outputRange: [
|
|
51
|
+
adjacentItemScale,
|
|
52
|
+
activeItemScale,
|
|
53
|
+
adjacentItemScale,
|
|
54
|
+
],
|
|
55
|
+
extrapolate: 'clamp',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const opacity = itemInterpolation.interpolate({
|
|
59
|
+
inputRange: itemInterpolationInputRange,
|
|
60
|
+
outputRange: [
|
|
61
|
+
adjacentItemOpacity,
|
|
62
|
+
activeItemOpacity,
|
|
63
|
+
adjacentItemOpacity,
|
|
64
|
+
],
|
|
65
|
+
extrapolate: 'clamp',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
transform: [
|
|
70
|
+
{ translateX: translate },
|
|
71
|
+
{ scale },
|
|
72
|
+
],
|
|
73
|
+
zIndex,
|
|
74
|
+
opacity,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return createItemStyle;
|
|
79
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import type { CreateItemStyle, ItemHeight, ItemVisibilityStore } from '../types';
|
|
4
|
+
|
|
5
|
+
export interface InternalContextValue<ItemT> {
|
|
6
|
+
createItemStyle: CreateItemStyle;
|
|
7
|
+
data: ReadonlyArray<ItemT>;
|
|
8
|
+
globalInterpolation: Animated.AnimatedInterpolation;
|
|
9
|
+
itemHeight: ItemHeight;
|
|
10
|
+
itemWidth: number;
|
|
11
|
+
itemVisibilityStore: ItemVisibilityStore;
|
|
12
|
+
loop: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const mockItemVisibilityStore: ItemVisibilityStore = {
|
|
16
|
+
dispatch: () => void 0,
|
|
17
|
+
subscribe: () => () => void 0,
|
|
18
|
+
removeAllListeners: () => void 0,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const initialValue: Readonly<InternalContextValue<any>> = {
|
|
22
|
+
createItemStyle: () => ({}),
|
|
23
|
+
data: [],
|
|
24
|
+
globalInterpolation: Animated.add(new Animated.Value(0), 0),
|
|
25
|
+
itemHeight: 0,
|
|
26
|
+
itemWidth: 0,
|
|
27
|
+
itemVisibilityStore: mockItemVisibilityStore,
|
|
28
|
+
loop: false,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const InternalContext = createContext<InternalContextValue<any>>(initialValue);
|
|
32
|
+
|
|
33
|
+
export default InternalContext;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import type { ViewProps } from 'react-native';
|
|
4
|
+
import { Animated } from 'react-native';
|
|
5
|
+
import { StyleSheet } from '@fountain-ui/core';
|
|
6
|
+
import { useItemInterpolation } from '../hooks';
|
|
7
|
+
import InternalContext from './InternalContext';
|
|
8
|
+
|
|
9
|
+
export interface ItemViewProps {
|
|
10
|
+
children: (interpolation: Animated.AnimatedInterpolation) => ReactElement | null;
|
|
11
|
+
index: number;
|
|
12
|
+
onLayout?: ViewProps['onLayout'];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function ItemView(props: ItemViewProps) {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
index,
|
|
19
|
+
onLayout,
|
|
20
|
+
} = props;
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
createItemStyle,
|
|
24
|
+
itemHeight,
|
|
25
|
+
itemWidth,
|
|
26
|
+
itemVisibilityStore,
|
|
27
|
+
} = useContext(InternalContext);
|
|
28
|
+
|
|
29
|
+
const [visible, setVisible] = useState(false);
|
|
30
|
+
|
|
31
|
+
const interpolation = useItemInterpolation(index);
|
|
32
|
+
|
|
33
|
+
const itemStyle = useMemo(
|
|
34
|
+
() => createItemStyle(interpolation, itemWidth),
|
|
35
|
+
[createItemStyle, interpolation],
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
return itemVisibilityStore.subscribe(ranges => {
|
|
40
|
+
const nextVisible = ranges.some(([from, to]) => index >= from && index <= to);
|
|
41
|
+
setVisible(nextVisible);
|
|
42
|
+
});
|
|
43
|
+
}, [itemVisibilityStore]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Animated.View
|
|
47
|
+
children={visible ? children(interpolation) : null}
|
|
48
|
+
onLayout={onLayout}
|
|
49
|
+
style={[
|
|
50
|
+
{
|
|
51
|
+
width: itemWidth,
|
|
52
|
+
height: itemHeight !== 'auto' ? itemHeight : undefined,
|
|
53
|
+
},
|
|
54
|
+
styles.absolute,
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
itemStyle,
|
|
57
|
+
]}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const styles = StyleSheet.create({
|
|
63
|
+
absolute: {
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { forwardRef, memo, ReactElement, useState } from 'react';
|
|
2
|
+
import type { View, ViewProps, LayoutChangeEvent } from 'react-native';
|
|
3
|
+
import { Animated } from 'react-native';
|
|
4
|
+
import { StyleSheet } from '@fountain-ui/core';
|
|
5
|
+
import type { ItemHeight, RenderItem } from '../types';
|
|
6
|
+
import ItemView from './ItemView';
|
|
7
|
+
|
|
8
|
+
const styles = StyleSheet.create({
|
|
9
|
+
root: {
|
|
10
|
+
width: '100%',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
},
|
|
13
|
+
horizontal: {
|
|
14
|
+
flexDirection: 'row',
|
|
15
|
+
overflowX: 'hidden',
|
|
16
|
+
overflowY: 'visible',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type RootViewProps<ItemT> = ViewProps & {
|
|
21
|
+
data: ReadonlyArray<ItemT>;
|
|
22
|
+
itemHeight: ItemHeight;
|
|
23
|
+
originalData: ReadonlyArray<ItemT>;
|
|
24
|
+
renderItem: RenderItem<ItemT>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const RootView = forwardRef<View, RootViewProps<any>>(function RootView(props, ref) {
|
|
28
|
+
const {
|
|
29
|
+
data,
|
|
30
|
+
itemHeight,
|
|
31
|
+
originalData,
|
|
32
|
+
renderItem,
|
|
33
|
+
style,
|
|
34
|
+
...otherProps
|
|
35
|
+
} = props;
|
|
36
|
+
|
|
37
|
+
const [maxHeightOfRenderedItems, setMaxHeightOfRenderedItems] = useState(0);
|
|
38
|
+
|
|
39
|
+
const handleItemLayout = (e: LayoutChangeEvent) => {
|
|
40
|
+
const { nativeEvent: { layout: { height } } } = e;
|
|
41
|
+
|
|
42
|
+
const heightInt = Math.round(height);
|
|
43
|
+
if (heightInt > maxHeightOfRenderedItems) {
|
|
44
|
+
setMaxHeightOfRenderedItems(heightInt);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const renderItemView = (item: any, index: number): ReactElement => (
|
|
49
|
+
<ItemView
|
|
50
|
+
key={index}
|
|
51
|
+
index={index}
|
|
52
|
+
onLayout={itemHeight === 'auto' ? handleItemLayout : undefined}
|
|
53
|
+
>
|
|
54
|
+
{(interpolation) => renderItem({
|
|
55
|
+
item,
|
|
56
|
+
index: index % originalData.length,
|
|
57
|
+
interpolation,
|
|
58
|
+
})}
|
|
59
|
+
</ItemView>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const viewStyles = [
|
|
63
|
+
styles.root,
|
|
64
|
+
styles.horizontal,
|
|
65
|
+
{ height: itemHeight === 'auto' ? maxHeightOfRenderedItems : itemHeight },
|
|
66
|
+
style,
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Animated.View
|
|
71
|
+
ref={ref}
|
|
72
|
+
{...otherProps}
|
|
73
|
+
children={data.map(renderItemView)}
|
|
74
|
+
style={viewStyles}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export default memo(RootView);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
import { Animated } from 'react-native';
|
|
4
|
+
import type { PanGestureHandlerStateChangeEvent } from 'react-native-gesture-handler';
|
|
5
|
+
import { PanGestureHandler, State as GestureHandlerState } from 'react-native-gesture-handler';
|
|
6
|
+
import type { AutoplayController, PagingDirection, StartPagingAnimation } from '../types';
|
|
7
|
+
|
|
8
|
+
export interface ScrollViewGestureProps {
|
|
9
|
+
autoplayController: AutoplayController;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
finalizeAnimation: () => void;
|
|
12
|
+
offsetTx: Animated.Value,
|
|
13
|
+
scrollEnabled: boolean;
|
|
14
|
+
startPagingAnimation: StartPagingAnimation;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const SCROLL_TO_ADJACENT_TX_THRESHOLD = 80;
|
|
18
|
+
const SCROLL_TO_ADJACENT_VX_THRESHOLD = 1000;
|
|
19
|
+
|
|
20
|
+
const ACTIVE_OFFSET_ABS_X = 5;
|
|
21
|
+
const activeOffsetX: number[] = [-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X];
|
|
22
|
+
|
|
23
|
+
const endAnimationStates: Readonly<GestureHandlerState[]> = [
|
|
24
|
+
GestureHandlerState.CANCELLED,
|
|
25
|
+
GestureHandlerState.END,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function shouldScrollToAdjacent(translationX: number, velocityX: number): boolean {
|
|
29
|
+
const isSameDirection = translationX * velocityX > 0;
|
|
30
|
+
const isEnoughMovement =
|
|
31
|
+
Math.abs(translationX) >= SCROLL_TO_ADJACENT_TX_THRESHOLD
|
|
32
|
+
|| Math.abs(velocityX) >= SCROLL_TO_ADJACENT_VX_THRESHOLD;
|
|
33
|
+
|
|
34
|
+
return isSameDirection && isEnoughMovement;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default function ScrollViewGesture(props: ScrollViewGestureProps) {
|
|
38
|
+
const {
|
|
39
|
+
autoplayController,
|
|
40
|
+
children,
|
|
41
|
+
finalizeAnimation,
|
|
42
|
+
offsetTx,
|
|
43
|
+
scrollEnabled,
|
|
44
|
+
startPagingAnimation,
|
|
45
|
+
} = props;
|
|
46
|
+
|
|
47
|
+
const { pause: pauseAutoplay, resume: resumeAutoplay } = autoplayController;
|
|
48
|
+
|
|
49
|
+
const handleGestureBegin = useCallback(() => {
|
|
50
|
+
pauseAutoplay();
|
|
51
|
+
|
|
52
|
+
finalizeAnimation();
|
|
53
|
+
}, [finalizeAnimation, pauseAutoplay]);
|
|
54
|
+
|
|
55
|
+
const handleGestureEvent = useCallback(Animated.event(
|
|
56
|
+
[{ nativeEvent: { translationX: offsetTx } }],
|
|
57
|
+
{ useNativeDriver: true },
|
|
58
|
+
), []);
|
|
59
|
+
|
|
60
|
+
const handleHandlerStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {
|
|
61
|
+
const { nativeEvent: { translationX, velocityX, state } } = event;
|
|
62
|
+
|
|
63
|
+
if (endAnimationStates.includes(state)) {
|
|
64
|
+
const direction: PagingDirection = shouldScrollToAdjacent(translationX, velocityX)
|
|
65
|
+
? (translationX < 0 ? 'next' : 'prev')
|
|
66
|
+
: 'stay';
|
|
67
|
+
|
|
68
|
+
startPagingAnimation(
|
|
69
|
+
'directional',
|
|
70
|
+
{ direction: direction, isOriginatedFromGesture: true },
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
resumeAutoplay();
|
|
74
|
+
}
|
|
75
|
+
}, [startPagingAnimation, resumeAutoplay]);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<PanGestureHandler
|
|
79
|
+
activeOffsetX={activeOffsetX}
|
|
80
|
+
children={children}
|
|
81
|
+
enabled={scrollEnabled}
|
|
82
|
+
onBegan={handleGestureBegin}
|
|
83
|
+
onGestureEvent={handleGestureEvent}
|
|
84
|
+
onHandlerStateChange={handleHandlerStateChange}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as useAutoplayController } from './useAutoplayController';
|
|
2
|
+
export { default as useDimensionChangeReaction } from './useDimensionChangeReaction';
|
|
3
|
+
export { default as useIndexController } from './useIndexController';
|
|
4
|
+
export { default as useItemInterpolation } from './useItemInterpolation';
|
|
5
|
+
export { default as useLoopedData } from './useLoopedData';
|
|
6
|
+
export { default as usePagingAnimation } from './usePagingAnimation';
|
|
7
|
+
export { default as useItemVisibilityStore } from './useItemVisibilityStore';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import type { AutoplayController, StartPagingAnimation } from '../types';
|
|
3
|
+
import { useDeferredExecutor } from '../../hooks';
|
|
4
|
+
|
|
5
|
+
export interface AutoplayConfig {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
intervalMillis: number;
|
|
8
|
+
startPagingAnimation: StartPagingAnimation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function useAutoplayController(config: AutoplayConfig): AutoplayController {
|
|
12
|
+
const {
|
|
13
|
+
enabled,
|
|
14
|
+
intervalMillis,
|
|
15
|
+
startPagingAnimation,
|
|
16
|
+
} = config;
|
|
17
|
+
|
|
18
|
+
const paused = useRef<boolean>(false);
|
|
19
|
+
|
|
20
|
+
const executor = useDeferredExecutor();
|
|
21
|
+
|
|
22
|
+
const play = useCallback(() => {
|
|
23
|
+
if (paused.current) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
executor.execute(() => {
|
|
28
|
+
startPagingAnimation(
|
|
29
|
+
'directional',
|
|
30
|
+
{ direction: 'next', isOriginatedFromGesture: false },
|
|
31
|
+
);
|
|
32
|
+
play();
|
|
33
|
+
}, intervalMillis);
|
|
34
|
+
}, [intervalMillis, startPagingAnimation]);
|
|
35
|
+
|
|
36
|
+
const pause = useCallback(() => {
|
|
37
|
+
executor.cancel();
|
|
38
|
+
paused.current = true;
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const resume = useCallback(() => {
|
|
42
|
+
paused.current = false;
|
|
43
|
+
if (enabled) {
|
|
44
|
+
play();
|
|
45
|
+
}
|
|
46
|
+
}, [play, enabled]);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (enabled) {
|
|
50
|
+
resume();
|
|
51
|
+
} else {
|
|
52
|
+
pause();
|
|
53
|
+
}
|
|
54
|
+
}, [enabled]);
|
|
55
|
+
|
|
56
|
+
return { pause, resume };
|
|
57
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Parameters {
|
|
5
|
+
controlledTx: Animated.AnimatedValue;
|
|
6
|
+
currentIndex: number;
|
|
7
|
+
itemWidth: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function useDimensionChangeReaction(params: Parameters) {
|
|
11
|
+
const {
|
|
12
|
+
controlledTx,
|
|
13
|
+
currentIndex,
|
|
14
|
+
itemWidth,
|
|
15
|
+
} = params;
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const newTx = -currentIndex * itemWidth;
|
|
19
|
+
controlledTx.setValue(newTx);
|
|
20
|
+
}, [
|
|
21
|
+
controlledTx,
|
|
22
|
+
currentIndex,
|
|
23
|
+
itemWidth,
|
|
24
|
+
]);
|
|
25
|
+
};
|