@fountain-ui/lab 2.0.0-beta.10 → 2.0.0-beta.13
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 +86 -21
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/commonjs/ViewPager/PageStateContext.js +22 -0
- package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
- package/build/commonjs/ViewPager/ViewPagerNative.js +82 -34
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerWeb.js +35 -26
- 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/utils.js +5 -41
- 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/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 +80 -23
- package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/module/ViewPager/PageStateContext.js +10 -0
- package/build/module/ViewPager/PageStateContext.js.map +1 -0
- package/build/module/ViewPager/ViewPagerNative.js +81 -34
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/module/ViewPager/ViewPagerWeb.js +29 -24
- 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/utils.js +2 -32
- 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/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 +2 -1
- package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
- package/build/typescript/ViewPager/ViewPagerNative.d.ts +4 -1
- package/build/typescript/ViewPager/ViewPagerProps.d.ts +31 -19
- package/build/typescript/ViewPager/ViewPagerWeb.d.ts +4 -1
- package/build/typescript/ViewPager/index.d.ts +2 -1
- package/build/typescript/ViewPager/index.native.d.ts +1 -0
- package/build/typescript/ViewPager/utils.d.ts +3 -19
- 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 +97 -23
- package/src/ViewPager/PageStateContext.ts +15 -0
- package/src/ViewPager/ViewPagerNative.tsx +101 -39
- package/src/ViewPager/ViewPagerProps.ts +33 -19
- package/src/ViewPager/ViewPagerWeb.tsx +38 -29
- package/src/ViewPager/index.native.ts +1 -0
- package/src/ViewPager/index.ts +2 -1
- package/src/ViewPager/utils.tsx +4 -56
- 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/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,41 +1,43 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from 'react';
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
3
4
|
import type { ComponentProps } from '@fountain-ui/core';
|
|
4
5
|
|
|
5
6
|
export type KeyboardDismissMode = 'none' | 'on-drag';
|
|
6
7
|
|
|
7
|
-
export type PageProps =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export type PageProps = PropsWithChildren<ViewProps> & {
|
|
9
|
+
index: number;
|
|
10
|
+
loading: ViewPagerProps['loading'];
|
|
11
|
+
offscreenPageRerenderLimit: number;
|
|
12
|
+
sharedIndex: SharedValue<number>;
|
|
13
|
+
rerenderKey?: ViewPagerProps['pageForceRerenderKey'];
|
|
11
14
|
};
|
|
12
15
|
|
|
13
|
-
export type PageComponent =
|
|
16
|
+
export type PageComponent = ComponentType<PageProps>;
|
|
14
17
|
|
|
15
18
|
export type Loading = 'lazy' | 'eager';
|
|
16
19
|
|
|
17
|
-
export
|
|
20
|
+
export interface ViewPagerInstance {
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
22
|
+
* Function to scroll to a specific page in the ViewPager. Invalid index is ignored.
|
|
23
|
+
* @param index
|
|
20
24
|
*/
|
|
21
|
-
|
|
25
|
+
setPage: (index: number) => void;
|
|
26
|
+
}
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @default false
|
|
26
|
-
*/
|
|
27
|
-
enableVisibleHint?: boolean;
|
|
28
|
+
export default interface ViewPagerProps extends ComponentProps<{
|
|
29
|
+
ref?: Ref<ViewPagerInstance>;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @default false
|
|
32
|
+
* Collection of ViewPager components.
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
+
children?: ReactNode;
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
+
* Index of initial page that should be selected.
|
|
38
|
+
* @default 0
|
|
37
39
|
*/
|
|
38
|
-
|
|
40
|
+
initialPage?: number;
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).
|
|
@@ -43,6 +45,13 @@ export default interface ViewPagerProps extends ComponentProps<{
|
|
|
43
45
|
*/
|
|
44
46
|
loading?: Loading;
|
|
45
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Mobile only. The number of pages that should be re-rendered to either side of the current page.
|
|
50
|
+
* Changing this value after the component mount has no effect.
|
|
51
|
+
* @default 0
|
|
52
|
+
*/
|
|
53
|
+
offscreenPageRerenderLimit?: number;
|
|
54
|
+
|
|
46
55
|
/**
|
|
47
56
|
* Callback fired when an index is changed.
|
|
48
57
|
*/
|
|
@@ -70,4 +79,9 @@ export default interface ViewPagerProps extends ComponentProps<{
|
|
|
70
79
|
* @default 'on-drag'
|
|
71
80
|
*/
|
|
72
81
|
keyboardDismissMode?: KeyboardDismissMode;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Unstable API.
|
|
85
|
+
*/
|
|
86
|
+
UNSTABLE_sharedPage?: SharedValue<number>;
|
|
73
87
|
}> {}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { Children, forwardRef, useCallback, useImperativeHandle } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { StyleSheet } from '@fountain-ui/core';
|
|
3
5
|
import type ViewPagerProps from './ViewPagerProps';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
defaultEnableVisibleHint,
|
|
7
|
-
defaultLoading,
|
|
8
|
-
defaultPageComponent,
|
|
9
|
-
usePageRenderer,
|
|
10
|
-
} from './utils';
|
|
6
|
+
import type { ViewPagerInstance } from './ViewPagerProps';
|
|
7
|
+
import { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';
|
|
11
8
|
|
|
12
9
|
const styles = StyleSheet.create({
|
|
13
10
|
root: {
|
|
@@ -15,38 +12,50 @@ const styles = StyleSheet.create({
|
|
|
15
12
|
overflow: 'auto',
|
|
16
13
|
position: 'relative',
|
|
17
14
|
},
|
|
18
|
-
none: { display: 'none' },
|
|
19
15
|
});
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
const ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {
|
|
22
18
|
const {
|
|
23
19
|
children,
|
|
24
|
-
|
|
25
|
-
enableNeighborPageRerender = defaultEnableNeighborPageRerender,
|
|
26
|
-
index,
|
|
20
|
+
initialPage = defaultInitialPage,
|
|
27
21
|
loading = defaultLoading,
|
|
28
22
|
pageComponent = defaultPageComponent,
|
|
29
23
|
pageForceRerenderKey,
|
|
30
24
|
style,
|
|
25
|
+
UNSTABLE_sharedPage,
|
|
31
26
|
} = props;
|
|
32
27
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
const fallbackSharedPage = useSharedValue<number>(initialPage);
|
|
29
|
+
|
|
30
|
+
const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
|
|
31
|
+
|
|
32
|
+
const setPage = useCallback((newPage: number) => {
|
|
33
|
+
sharedPage.value = newPage;
|
|
34
|
+
}, [sharedPage]);
|
|
35
|
+
|
|
36
|
+
useImperativeHandle(
|
|
37
|
+
ref,
|
|
38
|
+
() => ({ setPage }),
|
|
39
|
+
[setPage],
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const PageComponent = pageComponent;
|
|
41
43
|
|
|
42
44
|
return (
|
|
43
45
|
<View style={[styles.root, style]}>
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
{Children.map(children, (child, index) => (
|
|
47
|
+
<PageComponent
|
|
48
|
+
key={index}
|
|
49
|
+
children={child}
|
|
50
|
+
index={index}
|
|
51
|
+
loading={loading}
|
|
52
|
+
offscreenPageRerenderLimit={0} // All offscreen pages will not be re-rendered
|
|
53
|
+
rerenderKey={pageForceRerenderKey}
|
|
54
|
+
sharedIndex={sharedPage}
|
|
55
|
+
/>
|
|
56
|
+
))}
|
|
50
57
|
</View>
|
|
51
58
|
);
|
|
52
|
-
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export default ViewPager;
|
package/src/ViewPager/index.ts
CHANGED
package/src/ViewPager/utils.tsx
CHANGED
|
@@ -1,62 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ViewPagerProps, { Loading, PageComponent } from './ViewPagerProps';
|
|
1
|
+
import { Loading, PageComponent } from './ViewPagerProps';
|
|
3
2
|
import ChildrenMemoizedPage from './ChildrenMemoizedPage';
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
visited?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface PageRenderOption {
|
|
10
|
-
enableVisibleHint: boolean;
|
|
11
|
-
enableNeighborPageRerender: boolean;
|
|
12
|
-
index: number;
|
|
13
|
-
loading: Loading;
|
|
14
|
-
pageComponent: PageComponent;
|
|
15
|
-
pageForceRerenderKey?: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface PageRenderer {
|
|
19
|
-
(children: ViewPagerProps['children']): React.ReactNode;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const defaultEnableVisibleHint: boolean = false;
|
|
23
|
-
|
|
24
|
-
export const defaultEnableNeighborPageRerender: boolean = false;
|
|
4
|
+
export const defaultInitialPage: number = 0;
|
|
25
5
|
|
|
26
6
|
export const defaultLoading: Loading = 'lazy';
|
|
27
7
|
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
export const usePageRenderer = ({
|
|
31
|
-
enableVisibleHint,
|
|
32
|
-
index: currentIndex,
|
|
33
|
-
loading,
|
|
34
|
-
pageComponent: PageComponent,
|
|
35
|
-
pageForceRerenderKey,
|
|
36
|
-
enableNeighborPageRerender,
|
|
37
|
-
}: PageRenderOption): PageRenderer => {
|
|
38
|
-
const pagesStateRef = React.useRef<Array<PageState>>([]);
|
|
39
|
-
|
|
40
|
-
pagesStateRef.current[currentIndex] = {
|
|
41
|
-
...pagesStateRef.current[currentIndex],
|
|
42
|
-
visited: true,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return (children => React.Children.map(children, (child, index) => {
|
|
46
|
-
const visited = pagesStateRef.current[index]?.visited ?? false;
|
|
47
|
-
const content = (loading === 'eager' || visited) ? child : null;
|
|
8
|
+
export const defaultOffscreenPageRerenderLimit: number = 0;
|
|
48
9
|
|
|
49
|
-
|
|
50
|
-
const isNeighborIndex = index === currentIndex - 1 || index === currentIndex + 1;
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<PageComponent
|
|
54
|
-
key={index}
|
|
55
|
-
children={content}
|
|
56
|
-
isNeighbor={enableNeighborPageRerender && isNeighborIndex}
|
|
57
|
-
isVisible={isVisible}
|
|
58
|
-
rerenderKey={pageForceRerenderKey}
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
61
|
-
}));
|
|
62
|
-
};
|
|
10
|
+
export const defaultPageComponent: PageComponent = ChildrenMemoizedPage;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import useViewabilityTracker from './useViewabilityTracker';
|
|
4
|
+
import type ViewabilityTrackerViewProps from './ViewabilityTrackerViewProps';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default function ViewabilityTrackerView(props: ViewabilityTrackerViewProps) {
|
|
8
|
+
const {
|
|
9
|
+
enabled = true,
|
|
10
|
+
measurementIntervalMillis = 1000,
|
|
11
|
+
onViewabilityChange,
|
|
12
|
+
visiblePercentThreshold = 50,
|
|
13
|
+
...otherProps
|
|
14
|
+
} = props;
|
|
15
|
+
|
|
16
|
+
const viewRef = useRef<View>(null);
|
|
17
|
+
|
|
18
|
+
useViewabilityTracker({
|
|
19
|
+
enabled,
|
|
20
|
+
measurementIntervalMillis,
|
|
21
|
+
onViewabilityChange,
|
|
22
|
+
viewRef,
|
|
23
|
+
visiblePercentThreshold,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<View
|
|
28
|
+
{...otherProps}
|
|
29
|
+
ref={viewRef}
|
|
30
|
+
collapsable={false}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type { OverridableComponentProps } from '@fountain-ui/core';
|
|
3
|
+
import type Viewability from './Viewability';
|
|
4
|
+
|
|
5
|
+
export default interface ViewabilityTrackerViewProps extends OverridableComponentProps<ViewProps, {
|
|
6
|
+
/**
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @default 1000
|
|
13
|
+
*/
|
|
14
|
+
measurementIntervalMillis?: number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
onViewabilityChange?: (viewability: Viewability) => void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @default 50
|
|
23
|
+
*/
|
|
24
|
+
visiblePercentThreshold?: number;
|
|
25
|
+
}> {}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { View } from 'react-native';
|
|
2
|
+
|
|
3
|
+
interface Rect {
|
|
4
|
+
top: number,
|
|
5
|
+
bottom: number;
|
|
6
|
+
left: number;
|
|
7
|
+
right: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ViewabilityDetail {
|
|
11
|
+
visiblePercent: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MeasureViewabilityParameters {
|
|
15
|
+
view: View;
|
|
16
|
+
windowWidth: number;
|
|
17
|
+
windowHeight: number;
|
|
18
|
+
onViewabilityDetailMeasured: (detail: ViewabilityDetail) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const computeRectSize = (rect: Rect): number =>
|
|
22
|
+
(rect.bottom - rect.top) * (rect.right - rect.left);
|
|
23
|
+
|
|
24
|
+
const normalizePagePosition = (value?: number): number =>
|
|
25
|
+
(value != null && Number.isFinite(value)) ? value : Number.MAX_SAFE_INTEGER;
|
|
26
|
+
|
|
27
|
+
const normalizeViewSize = (size: number): number =>
|
|
28
|
+
Number.isFinite(size) && size > 0 ? size : Number.MAX_SAFE_INTEGER;
|
|
29
|
+
|
|
30
|
+
const clamp = (value: number, min: number, max: number): number =>
|
|
31
|
+
Math.min(Math.max(value, min), max);
|
|
32
|
+
|
|
33
|
+
export default function measureViewability({
|
|
34
|
+
view,
|
|
35
|
+
windowWidth,
|
|
36
|
+
windowHeight,
|
|
37
|
+
onViewabilityDetailMeasured,
|
|
38
|
+
}: MeasureViewabilityParameters) {
|
|
39
|
+
view.measure((x, y, width, height, pageX?: number, pageY?: number) => {
|
|
40
|
+
const safePageX = normalizePagePosition(pageX);
|
|
41
|
+
const safePageY = normalizePagePosition(pageY);
|
|
42
|
+
|
|
43
|
+
const visibleRect: Rect = {
|
|
44
|
+
top: clamp(safePageY, 0, windowHeight),
|
|
45
|
+
bottom: clamp(safePageY + height, 0, windowHeight),
|
|
46
|
+
left: clamp(safePageX, 0, windowWidth),
|
|
47
|
+
right: clamp(safePageX + width, 0, windowWidth),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const visibleRectSize = computeRectSize(visibleRect);
|
|
51
|
+
const viewSize = normalizeViewSize(width * height);
|
|
52
|
+
const visiblePercent = Math.round(visibleRectSize / viewSize * 100);
|
|
53
|
+
|
|
54
|
+
onViewabilityDetailMeasured?.({ visiblePercent });
|
|
55
|
+
});
|
|
56
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import type { View } from 'react-native';
|
|
4
|
+
import { useValidWindowDimensions } from '@fountain-ui/core';
|
|
5
|
+
import { useDeferredExecutor } from '../hooks';
|
|
6
|
+
import type { ViewabilityDetail } from './measureViewability';
|
|
7
|
+
import measureViewability from './measureViewability';
|
|
8
|
+
import type Viewability from './Viewability';
|
|
9
|
+
|
|
10
|
+
export interface ViewabilityTrackerConfig {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
measurementIntervalMillis: number;
|
|
13
|
+
onViewabilityChange?: (viewability: Viewability) => void;
|
|
14
|
+
viewRef: RefObject<View>;
|
|
15
|
+
visiblePercentThreshold: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const initialViewability: Readonly<Viewability> = { visible: false };
|
|
19
|
+
|
|
20
|
+
export default function useViewabilityTracker(config: ViewabilityTrackerConfig) {
|
|
21
|
+
const {
|
|
22
|
+
enabled,
|
|
23
|
+
measurementIntervalMillis,
|
|
24
|
+
onViewabilityChange,
|
|
25
|
+
viewRef,
|
|
26
|
+
visiblePercentThreshold,
|
|
27
|
+
} = config;
|
|
28
|
+
|
|
29
|
+
const viewabilityRef = useRef<Viewability>(initialViewability);
|
|
30
|
+
|
|
31
|
+
const executor = useDeferredExecutor();
|
|
32
|
+
|
|
33
|
+
const window = useValidWindowDimensions();
|
|
34
|
+
|
|
35
|
+
const maybeMeasureRecursive = () => {
|
|
36
|
+
if (!enabled) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const mapViewabilityDetailToViewability = (detail: ViewabilityDetail): Viewability => {
|
|
41
|
+
return { visible: detail.visiblePercent >= visiblePercentThreshold };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const isViewabilityEquals = (a: Viewability, b: Viewability): boolean => {
|
|
45
|
+
return a.visible === b.visible;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const dispatchViewabilityChanged = (viewability: Viewability) => {
|
|
49
|
+
executor.execute(() => onViewabilityChange?.(viewability));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const onViewabilityDetailMeasured = (detail: ViewabilityDetail) => {
|
|
53
|
+
const nextViewability = mapViewabilityDetailToViewability(detail);
|
|
54
|
+
|
|
55
|
+
if (!isViewabilityEquals(viewabilityRef.current, nextViewability)) {
|
|
56
|
+
viewabilityRef.current = nextViewability;
|
|
57
|
+
|
|
58
|
+
dispatchViewabilityChanged(nextViewability);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
maybeMeasureRecursive();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const maybeMeasure = () => {
|
|
65
|
+
if (viewRef.current) {
|
|
66
|
+
measureViewability({
|
|
67
|
+
view: viewRef.current,
|
|
68
|
+
windowWidth: window.width,
|
|
69
|
+
windowHeight: window.height,
|
|
70
|
+
onViewabilityDetailMeasured,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
executor.execute(maybeMeasure, measurementIntervalMillis);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (enabled) {
|
|
80
|
+
maybeMeasureRecursive();
|
|
81
|
+
} else {
|
|
82
|
+
executor.cancel();
|
|
83
|
+
}
|
|
84
|
+
}, [enabled]);
|
|
85
|
+
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { default as useDeferredExecutor } from './useDeferredExecutor';
|
|
2
|
+
export { default as useIsMounted } from './useIsMounted';
|
|
1
3
|
export { default as useUnstableCollapsibleAppBar } from './useUnstableCollapsibleAppBar';
|
|
2
4
|
export { default as useUnstableToggleDisplayStyle } from './useUnstableToggleDisplayStyle';
|
|
3
5
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import useIsMounted from './useIsMounted';
|
|
3
|
+
|
|
4
|
+
export interface Runnable {
|
|
5
|
+
(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface DeferredExecute {
|
|
9
|
+
(runnable: Runnable, delay?: number): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DeferredExecutor {
|
|
13
|
+
cancel: () => void;
|
|
14
|
+
execute: DeferredExecute;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function useDeferredExecutor(): DeferredExecutor {
|
|
18
|
+
const isMounted = useIsMounted();
|
|
19
|
+
const timeoutIdRef = useRef<NodeJS.Timer | null>(null);
|
|
20
|
+
|
|
21
|
+
const cancel = useCallback(() => {
|
|
22
|
+
if (timeoutIdRef.current) {
|
|
23
|
+
clearTimeout(timeoutIdRef.current);
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
return cancel;
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
const execute = useCallback<DeferredExecute>((runnable, delay) => {
|
|
32
|
+
if (!isMounted()) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
cancel();
|
|
37
|
+
|
|
38
|
+
if (Number.isFinite(delay)) {
|
|
39
|
+
timeoutIdRef.current = setTimeout(() => runnable(), delay);
|
|
40
|
+
} else {
|
|
41
|
+
runnable();
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
return { cancel, execute };
|
|
46
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface UseIsMounted {
|
|
4
|
+
(): boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default function useIsMounted(): UseIsMounted {
|
|
8
|
+
const mountedRef = useRef<boolean>(false);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
mountedRef.current = true;
|
|
12
|
+
|
|
13
|
+
return () => {
|
|
14
|
+
mountedRef.current = false;
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
return useCallback(() => mountedRef.current, []);
|
|
19
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -19,4 +19,7 @@ export * from './ComicViewer';
|
|
|
19
19
|
export { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';
|
|
20
20
|
export * from './StatusBarProvider';
|
|
21
21
|
|
|
22
|
+
export { default as ViewabilityTrackerView } from './ViewabilityTrackerView';
|
|
23
|
+
export * from './ViewabilityTrackerView';
|
|
24
|
+
|
|
22
25
|
export * from './hooks';
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = Carousel;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
var _reactNativeSnapCarousel = _interopRequireDefault(require("react-native-snap-carousel"));
|
|
13
|
-
|
|
14
|
-
var _utils = require("./utils");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
function Carousel(props) {
|
|
23
|
-
const {
|
|
24
|
-
autoplay = _utils.defaultAutoplay,
|
|
25
|
-
autoplayInterval = _utils.defaultAutoplayInterval,
|
|
26
|
-
centerSlidePadding,
|
|
27
|
-
data,
|
|
28
|
-
inactiveSlideOpacity = _utils.defaultInactiveSlideOpacity,
|
|
29
|
-
inactiveSlideScale = _utils.defaultInactiveSlideScale,
|
|
30
|
-
index,
|
|
31
|
-
infinite = _utils.defaultInfinite,
|
|
32
|
-
onChange,
|
|
33
|
-
renderItem
|
|
34
|
-
} = props;
|
|
35
|
-
const carouselRef = (0, _react.useRef)(null);
|
|
36
|
-
const [sliderWidth, setSliderWidth] = (0, _react.useState)(() => _reactNative.Dimensions.get('window').width);
|
|
37
|
-
const itemWidth = centerSlidePadding !== undefined ? sliderWidth - centerSlidePadding * 2 : sliderWidth;
|
|
38
|
-
(0, _react.useEffect)(() => {
|
|
39
|
-
const carousel = carouselRef.current;
|
|
40
|
-
|
|
41
|
-
if (carousel && index !== carousel.currentIndex) {
|
|
42
|
-
carousel.snapToItem(index, true);
|
|
43
|
-
}
|
|
44
|
-
}, [index]);
|
|
45
|
-
|
|
46
|
-
const handleSnapToItem = newIndex => {
|
|
47
|
-
if (onChange) {
|
|
48
|
-
onChange(newIndex);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
53
|
-
onLayout: event => setSliderWidth(event.nativeEvent.layout.width)
|
|
54
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNativeSnapCarousel.default, {
|
|
55
|
-
autoplay: autoplay,
|
|
56
|
-
autoplayInterval: autoplayInterval,
|
|
57
|
-
data: data,
|
|
58
|
-
horizontal: true,
|
|
59
|
-
inactiveSlideOpacity: inactiveSlideOpacity,
|
|
60
|
-
inactiveSlideScale: inactiveSlideScale,
|
|
61
|
-
itemWidth: itemWidth,
|
|
62
|
-
loop: infinite,
|
|
63
|
-
loopClonesPerSide: 2,
|
|
64
|
-
onSnapToItem: handleSnapToItem,
|
|
65
|
-
ref: carouselRef,
|
|
66
|
-
renderItem: renderItem,
|
|
67
|
-
sliderWidth: sliderWidth
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
;
|
|
72
|
-
//# sourceMappingURL=CarouselNative.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Carousel","props","autoplay","defaultAutoplay","autoplayInterval","defaultAutoplayInterval","centerSlidePadding","data","inactiveSlideOpacity","defaultInactiveSlideOpacity","inactiveSlideScale","defaultInactiveSlideScale","index","infinite","defaultInfinite","onChange","renderItem","carouselRef","useRef","sliderWidth","setSliderWidth","useState","Dimensions","get","width","itemWidth","undefined","useEffect","carousel","current","currentIndex","snapToItem","handleSnapToItem","newIndex","event","nativeEvent","layout"],"sources":["CarouselNative.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { Dimensions, View } from 'react-native';\nimport RNSnapCarousel from 'react-native-snap-carousel';\nimport type CarouselProps from './CarouselProps';\nimport {\n defaultAutoplay,\n defaultAutoplayInterval,\n defaultInactiveSlideOpacity,\n defaultInactiveSlideScale,\n defaultInfinite,\n} from './utils';\n\nexport default function Carousel<ItemT>(props: CarouselProps<ItemT>) {\n const {\n autoplay = defaultAutoplay,\n autoplayInterval = defaultAutoplayInterval,\n centerSlidePadding,\n data,\n inactiveSlideOpacity = defaultInactiveSlideOpacity,\n inactiveSlideScale = defaultInactiveSlideScale,\n index,\n infinite = defaultInfinite,\n onChange,\n renderItem,\n } = props;\n\n const carouselRef = useRef<RNSnapCarousel<ItemT> | null>(null);\n\n const [sliderWidth, setSliderWidth] = useState(() => Dimensions.get('window').width);\n\n const itemWidth = centerSlidePadding !== undefined\n ? sliderWidth - (centerSlidePadding * 2)\n : sliderWidth;\n\n useEffect(() => {\n const carousel = carouselRef.current;\n if (carousel && index !== carousel.currentIndex) {\n carousel.snapToItem(index, true);\n }\n }, [index]);\n\n const handleSnapToItem = (newIndex: number) => {\n if (onChange) {\n onChange(newIndex);\n }\n };\n\n return (\n <View onLayout={(event) => setSliderWidth(event.nativeEvent.layout.width)}>\n <RNSnapCarousel\n autoplay={autoplay}\n autoplayInterval={autoplayInterval}\n data={data}\n horizontal={true}\n inactiveSlideOpacity={inactiveSlideOpacity}\n inactiveSlideScale={inactiveSlideScale}\n itemWidth={itemWidth}\n loop={infinite}\n loopClonesPerSide={2}\n onSnapToItem={handleSnapToItem}\n ref={carouselRef}\n renderItem={renderItem}\n sliderWidth={sliderWidth}\n />\n </View>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;AAQe,SAASA,QAAT,CAAyBC,KAAzB,EAAsD;EACjE,MAAM;IACFC,QAAQ,GAAGC,sBADT;IAEFC,gBAAgB,GAAGC,8BAFjB;IAGFC,kBAHE;IAIFC,IAJE;IAKFC,oBAAoB,GAAGC,kCALrB;IAMFC,kBAAkB,GAAGC,gCANnB;IAOFC,KAPE;IAQFC,QAAQ,GAAGC,sBART;IASFC,QATE;IAUFC;EAVE,IAWFf,KAXJ;EAaA,MAAMgB,WAAW,GAAG,IAAAC,aAAA,EAAqC,IAArC,CAApB;EAEA,MAAM,CAACC,WAAD,EAAcC,cAAd,IAAgC,IAAAC,eAAA,EAAS,MAAMC,uBAAA,CAAWC,GAAX,CAAe,QAAf,EAAyBC,KAAxC,CAAtC;EAEA,MAAMC,SAAS,GAAGnB,kBAAkB,KAAKoB,SAAvB,GACZP,WAAW,GAAIb,kBAAkB,GAAG,CADxB,GAEZa,WAFN;EAIA,IAAAQ,gBAAA,EAAU,MAAM;IACZ,MAAMC,QAAQ,GAAGX,WAAW,CAACY,OAA7B;;IACA,IAAID,QAAQ,IAAIhB,KAAK,KAAKgB,QAAQ,CAACE,YAAnC,EAAiD;MAC7CF,QAAQ,CAACG,UAAT,CAAoBnB,KAApB,EAA2B,IAA3B;IACH;EACJ,CALD,EAKG,CAACA,KAAD,CALH;;EAOA,MAAMoB,gBAAgB,GAAIC,QAAD,IAAsB;IAC3C,IAAIlB,QAAJ,EAAc;MACVA,QAAQ,CAACkB,QAAD,CAAR;IACH;EACJ,CAJD;;EAMA,oBACI,6BAAC,iBAAD;IAAM,QAAQ,EAAGC,KAAD,IAAWd,cAAc,CAACc,KAAK,CAACC,WAAN,CAAkBC,MAAlB,CAAyBZ,KAA1B;EAAzC,gBACI,6BAAC,gCAAD;IACI,QAAQ,EAAEtB,QADd;IAEI,gBAAgB,EAAEE,gBAFtB;IAGI,IAAI,EAAEG,IAHV;IAII,UAAU,EAAE,IAJhB;IAKI,oBAAoB,EAAEC,oBAL1B;IAMI,kBAAkB,EAAEE,kBANxB;IAOI,SAAS,EAAEe,SAPf;IAQI,IAAI,EAAEZ,QARV;IASI,iBAAiB,EAAE,CATvB;IAUI,YAAY,EAAEmB,gBAVlB;IAWI,GAAG,EAAEf,WAXT;IAYI,UAAU,EAAED,UAZhB;IAaI,WAAW,EAAEG;EAbjB,EADJ,CADJ;AAmBH;;AAAA"}
|