@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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useIsMounted;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
function useIsMounted() {
|
|
11
|
+
const mountedRef = (0, _react.useRef)(false);
|
|
12
|
+
(0, _react.useEffect)(() => {
|
|
13
|
+
mountedRef.current = true;
|
|
14
|
+
return () => {
|
|
15
|
+
mountedRef.current = false;
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
return (0, _react.useCallback)(() => mountedRef.current, []);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
;
|
|
22
|
+
//# sourceMappingURL=useIsMounted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useIsMounted","mountedRef","useRef","useEffect","current","useCallback"],"sources":["useIsMounted.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport interface UseIsMounted {\n (): boolean;\n}\n\nexport default function useIsMounted(): UseIsMounted {\n const mountedRef = useRef<boolean>(false);\n\n useEffect(() => {\n mountedRef.current = true;\n\n return () => {\n mountedRef.current = false;\n };\n }, []);\n\n return useCallback(() => mountedRef.current, []);\n};\n"],"mappings":";;;;;;;AAAA;;AAMe,SAASA,YAAT,GAAsC;EACjD,MAAMC,UAAU,GAAG,IAAAC,aAAA,EAAgB,KAAhB,CAAnB;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACZF,UAAU,CAACG,OAAX,GAAqB,IAArB;IAEA,OAAO,MAAM;MACTH,UAAU,CAACG,OAAX,GAAqB,KAArB;IACH,CAFD;EAGH,CAND,EAMG,EANH;EAQA,OAAO,IAAAC,kBAAA,EAAY,MAAMJ,UAAU,CAACG,OAA7B,EAAsC,EAAtC,CAAP;AACH;;AAAA"}
|
|
@@ -181,7 +181,7 @@ function useUnstableCollapsibleAppBar() {
|
|
|
181
181
|
duration: ANIMATION_DURATION_MILLIS
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
|
-
}, []);
|
|
184
|
+
}, [appBarHeight]);
|
|
185
185
|
const hasCollapsible = collapsibleToolbarHeight > 0;
|
|
186
186
|
const appBarStyle = [animatedStyle, {
|
|
187
187
|
paddingTop: safeAreaInsets.top
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","Platform","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","useRef","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","appBarHeight","onAppBarLayout","useHeight","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","useElevationStyle","animatedStyle","useAnimatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","withTiming","duration","savedOffsetY","scrollHandler","useAnimatedScrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n const transform = [{ translateY: translateY.value }];\n\n if (Platform.OS === 'web') {\n return {\n transform,\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform,\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n }, [\n /**\n * FIXME: Consider add `elevationStyle` to dependencies.\n */\n ]);\n\n const indexRef = useRef<number>(0);\n const offsetsRef = useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n }, []);\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAOA;;AACA;;AACA;;AACA;;;;AA+BA,MAAMA,cAAiC,GAAG;EACtCC,qBAAqB,EAAE;AADe,CAA1C;AAIA,MAAMC,yBAAyB,GAAG,GAAlC;AAEA,MAAMC,uBAAuB,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhD;;AAEA,SAASC,6BAAT,CAAuCC,KAAvC,EAAsD;EAClD,MAAMC,kBAAkB,GAAG,IAAAC,aAAA,EAAO,CAAC,CAAD,EAAI,CAAJ,CAAP,CAA3B;EAEAD,kBAAkB,CAACE,OAAnB,CAA2BC,KAA3B;EACAH,kBAAkB,CAAC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GAAG,EAAEH,cAAc,GAAGjD,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;;AAAA"}
|
|
1
|
+
{"version":3,"names":["defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","Platform","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","useRef","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","appBarHeight","onAppBarLayout","useHeight","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","useElevationStyle","animatedStyle","useAnimatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","withTiming","duration","savedOffsetY","scrollHandler","useAnimatedScrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n const transform = [{ translateY: translateY.value }];\n\n if (Platform.OS === 'web') {\n return {\n transform,\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform,\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n }, [\n /**\n * FIXME: Consider add `elevationStyle` to dependencies.\n */\n ]);\n\n const indexRef = useRef<number>(0);\n const offsetsRef = useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n }, [appBarHeight]);\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAOA;;AACA;;AACA;;AACA;;;;AA+BA,MAAMA,cAAiC,GAAG;EACtCC,qBAAqB,EAAE;AADe,CAA1C;AAIA,MAAMC,yBAAyB,GAAG,GAAlC;AAEA,MAAMC,uBAAuB,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhD;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,EAGhBH,cAAc,GAAGxD,MAAM,CAAC4D,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHvC,OAFG;IAGHb,cAHG;IAIHI,0BAJG;IAKHiC,QAAQ,EAAEJ,aALP;IAMHN,mBANG;IAOH8B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAGjD,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;;AAAA"}
|
package/build/commonjs/index.js
CHANGED
|
@@ -11,7 +11,8 @@ var _exportNames = {
|
|
|
11
11
|
ViewPager: true,
|
|
12
12
|
ComicViewer: true,
|
|
13
13
|
StatusBarProvider: true,
|
|
14
|
-
useStatusBarContext: true
|
|
14
|
+
useStatusBarContext: true,
|
|
15
|
+
ViewabilityTrackerView: true
|
|
15
16
|
};
|
|
16
17
|
Object.defineProperty(exports, "BottomSheet", {
|
|
17
18
|
enumerable: true,
|
|
@@ -55,6 +56,12 @@ Object.defineProperty(exports, "ViewPager", {
|
|
|
55
56
|
return _ViewPager.default;
|
|
56
57
|
}
|
|
57
58
|
});
|
|
59
|
+
Object.defineProperty(exports, "ViewabilityTrackerView", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () {
|
|
62
|
+
return _ViewabilityTrackerView.default;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
58
65
|
Object.defineProperty(exports, "useStatusBarContext", {
|
|
59
66
|
enumerable: true,
|
|
60
67
|
get: function () {
|
|
@@ -160,6 +167,20 @@ Object.keys(_StatusBarProvider).forEach(function (key) {
|
|
|
160
167
|
});
|
|
161
168
|
});
|
|
162
169
|
|
|
170
|
+
var _ViewabilityTrackerView = _interopRequireWildcard(require("./ViewabilityTrackerView"));
|
|
171
|
+
|
|
172
|
+
Object.keys(_ViewabilityTrackerView).forEach(function (key) {
|
|
173
|
+
if (key === "default" || key === "__esModule") return;
|
|
174
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
175
|
+
if (key in exports && exports[key] === _ViewabilityTrackerView[key]) return;
|
|
176
|
+
Object.defineProperty(exports, key, {
|
|
177
|
+
enumerable: true,
|
|
178
|
+
get: function () {
|
|
179
|
+
return _ViewabilityTrackerView[key];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
163
184
|
var _hooks = require("./hooks");
|
|
164
185
|
|
|
165
186
|
Object.keys(_hooks).forEach(function (key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as BottomSheet } from './BottomSheet';\nexport * from './BottomSheet';\n\nexport { default as Carousel } from './Carousel';\nexport * from './Carousel';\n\nexport { default as DateTimePicker } from './DateTimePicker';\nexport * from './DateTimePicker';\n\nexport { default as FlipCard } from './FlipCard';\nexport * from './FlipCard';\n\nexport { default as ViewPager } from './ViewPager';\nexport * from './ViewPager';\n\nexport { default as ComicViewer } from './ComicViewer';\nexport * from './ComicViewer';\n\nexport { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';\nexport * from './StatusBarProvider';\n\nexport * from './hooks';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as BottomSheet } from './BottomSheet';\nexport * from './BottomSheet';\n\nexport { default as Carousel } from './Carousel';\nexport * from './Carousel';\n\nexport { default as DateTimePicker } from './DateTimePicker';\nexport * from './DateTimePicker';\n\nexport { default as FlipCard } from './FlipCard';\nexport * from './FlipCard';\n\nexport { default as ViewPager } from './ViewPager';\nexport * from './ViewPager';\n\nexport { default as ComicViewer } from './ComicViewer';\nexport * from './ComicViewer';\n\nexport { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';\nexport * from './StatusBarProvider';\n\nexport { default as ViewabilityTrackerView } from './ViewabilityTrackerView';\nexport * from './ViewabilityTrackerView';\n\nexport * from './hooks';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import ViewabilityTrackerView from '../ViewabilityTrackerView';
|
|
4
|
+
import { useAutoplayController, useDimensionChangeReaction, useIndexController, useItemVisibilityStore, useLoopedData, usePagingAnimation } from './hooks';
|
|
5
|
+
import { createDefaultItemStyle, createDefaultScrollAnimation } from './animation';
|
|
6
|
+
import { InternalContext, RootView, ScrollViewGesture } from './components';
|
|
7
|
+
const Carousel = /*#__PURE__*/forwardRef(function Carousel(props, ref) {
|
|
8
|
+
const {
|
|
9
|
+
autoplay = false,
|
|
10
|
+
autoplayInterval = 3000,
|
|
11
|
+
createItemStyle = createDefaultItemStyle,
|
|
12
|
+
createScrollAnimation = createDefaultScrollAnimation,
|
|
13
|
+
data: originalData,
|
|
14
|
+
disableSmartAutoplay = false,
|
|
15
|
+
initialIndex = 0,
|
|
16
|
+
itemHeight,
|
|
17
|
+
itemWidth,
|
|
18
|
+
loop = false,
|
|
19
|
+
onIndexChange,
|
|
20
|
+
renderItem,
|
|
21
|
+
scrollEnabled = true,
|
|
22
|
+
style,
|
|
23
|
+
windowSize = 5
|
|
24
|
+
} = props;
|
|
25
|
+
const data = useLoopedData(originalData, loop);
|
|
26
|
+
const initialTx = itemWidth * initialIndex;
|
|
27
|
+
const controlledTx = useRef(new Animated.Value(initialTx)).current;
|
|
28
|
+
const offsetTx = useRef(new Animated.Value(0)).current;
|
|
29
|
+
const {
|
|
30
|
+
currentIndex,
|
|
31
|
+
getCurrentIndex,
|
|
32
|
+
lastIndex,
|
|
33
|
+
monitorElement
|
|
34
|
+
} = useIndexController({
|
|
35
|
+
controlledTx,
|
|
36
|
+
initialIndex,
|
|
37
|
+
itemWidth,
|
|
38
|
+
numberOfOriginalData: originalData.length,
|
|
39
|
+
onIndexChange
|
|
40
|
+
});
|
|
41
|
+
const itemVisibilityStore = useItemVisibilityStore({
|
|
42
|
+
currentIndex,
|
|
43
|
+
numberOfData: data.length,
|
|
44
|
+
windowSize
|
|
45
|
+
});
|
|
46
|
+
const {
|
|
47
|
+
finalizeAnimation,
|
|
48
|
+
globalInterpolation,
|
|
49
|
+
startPagingAnimation
|
|
50
|
+
} = usePagingAnimation({
|
|
51
|
+
controlledTx,
|
|
52
|
+
createScrollAnimation,
|
|
53
|
+
getCurrentIndex,
|
|
54
|
+
itemWidth,
|
|
55
|
+
lastIndex,
|
|
56
|
+
loop,
|
|
57
|
+
numberOfData: data.length,
|
|
58
|
+
offsetTx
|
|
59
|
+
});
|
|
60
|
+
const autoplayController = useAutoplayController({
|
|
61
|
+
enabled: autoplay,
|
|
62
|
+
intervalMillis: autoplayInterval,
|
|
63
|
+
startPagingAnimation
|
|
64
|
+
});
|
|
65
|
+
useDimensionChangeReaction({
|
|
66
|
+
controlledTx,
|
|
67
|
+
currentIndex,
|
|
68
|
+
itemWidth
|
|
69
|
+
});
|
|
70
|
+
useImperativeHandle(ref, () => ({
|
|
71
|
+
getCurrentIndex,
|
|
72
|
+
next: () => startPagingAnimation('directional', {
|
|
73
|
+
direction: 'next'
|
|
74
|
+
}),
|
|
75
|
+
prev: () => startPagingAnimation('directional', {
|
|
76
|
+
direction: 'prev'
|
|
77
|
+
}),
|
|
78
|
+
scrollTo: option => startPagingAnimation('index', option)
|
|
79
|
+
}), [startPagingAnimation, getCurrentIndex]);
|
|
80
|
+
const contextValue = useMemo(() => ({
|
|
81
|
+
createItemStyle,
|
|
82
|
+
data,
|
|
83
|
+
globalInterpolation,
|
|
84
|
+
itemHeight,
|
|
85
|
+
itemWidth,
|
|
86
|
+
itemVisibilityStore,
|
|
87
|
+
loop
|
|
88
|
+
}), [createItemStyle, data, globalInterpolation, itemHeight, itemWidth, itemVisibilityStore, loop]);
|
|
89
|
+
return /*#__PURE__*/React.createElement(InternalContext.Provider, {
|
|
90
|
+
value: contextValue
|
|
91
|
+
}, monitorElement, /*#__PURE__*/React.createElement(ViewabilityTrackerView, {
|
|
92
|
+
enabled: autoplay && !disableSmartAutoplay,
|
|
93
|
+
measurementIntervalMillis: Math.max(3000, autoplayInterval),
|
|
94
|
+
onViewabilityChange: _ref => {
|
|
95
|
+
let {
|
|
96
|
+
visible
|
|
97
|
+
} = _ref;
|
|
98
|
+
|
|
99
|
+
if (visible) {
|
|
100
|
+
autoplayController.resume();
|
|
101
|
+
} else {
|
|
102
|
+
autoplayController.pause();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, /*#__PURE__*/React.createElement(ScrollViewGesture, {
|
|
106
|
+
autoplayController: autoplayController,
|
|
107
|
+
finalizeAnimation: finalizeAnimation,
|
|
108
|
+
offsetTx: offsetTx,
|
|
109
|
+
scrollEnabled: scrollEnabled,
|
|
110
|
+
startPagingAnimation: startPagingAnimation
|
|
111
|
+
}, /*#__PURE__*/React.createElement(RootView, {
|
|
112
|
+
data: data,
|
|
113
|
+
itemHeight: itemHeight,
|
|
114
|
+
originalData: originalData,
|
|
115
|
+
renderItem: renderItem,
|
|
116
|
+
style: style
|
|
117
|
+
}))));
|
|
118
|
+
});
|
|
119
|
+
export default /*#__PURE__*/memo(Carousel);
|
|
120
|
+
//# sourceMappingURL=Carousel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","memo","useImperativeHandle","useMemo","useRef","Animated","ViewabilityTrackerView","useAutoplayController","useDimensionChangeReaction","useIndexController","useItemVisibilityStore","useLoopedData","usePagingAnimation","createDefaultItemStyle","createDefaultScrollAnimation","InternalContext","RootView","ScrollViewGesture","Carousel","props","ref","autoplay","autoplayInterval","createItemStyle","createScrollAnimation","data","originalData","disableSmartAutoplay","initialIndex","itemHeight","itemWidth","loop","onIndexChange","renderItem","scrollEnabled","style","windowSize","initialTx","controlledTx","Value","current","offsetTx","currentIndex","getCurrentIndex","lastIndex","monitorElement","numberOfOriginalData","length","itemVisibilityStore","numberOfData","finalizeAnimation","globalInterpolation","startPagingAnimation","autoplayController","enabled","intervalMillis","next","direction","prev","scrollTo","option","contextValue","Math","max","visible","resume","pause"],"sources":["Carousel.tsx"],"sourcesContent":["import React, { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport ViewabilityTrackerView from '../ViewabilityTrackerView';\nimport type CarouselProps from './CarouselProps';\nimport type { CarouselInstance } from './types';\nimport {\n useAutoplayController,\n useDimensionChangeReaction,\n useIndexController,\n useItemVisibilityStore,\n useLoopedData,\n usePagingAnimation,\n} from './hooks';\nimport { createDefaultItemStyle, createDefaultScrollAnimation } from './animation';\nimport { InternalContext, RootView, ScrollViewGesture } from './components';\n\nconst Carousel = forwardRef<CarouselInstance, CarouselProps>(function Carousel(props, ref) {\n const {\n autoplay = false,\n autoplayInterval = 3000,\n createItemStyle = createDefaultItemStyle,\n createScrollAnimation = createDefaultScrollAnimation,\n data: originalData,\n disableSmartAutoplay = false,\n initialIndex = 0,\n itemHeight,\n itemWidth,\n loop = false,\n onIndexChange,\n renderItem,\n scrollEnabled = true,\n style,\n windowSize = 5,\n } = props;\n\n const data = useLoopedData(originalData, loop);\n\n const initialTx = itemWidth * initialIndex;\n const controlledTx = useRef(new Animated.Value(initialTx)).current;\n const offsetTx = useRef(new Animated.Value(0)).current;\n\n const {\n currentIndex,\n getCurrentIndex,\n lastIndex,\n monitorElement,\n } = useIndexController({\n controlledTx,\n initialIndex,\n itemWidth,\n numberOfOriginalData: originalData.length,\n onIndexChange,\n });\n\n const itemVisibilityStore = useItemVisibilityStore({\n currentIndex,\n numberOfData: data.length,\n windowSize,\n });\n\n const {\n finalizeAnimation,\n globalInterpolation,\n startPagingAnimation,\n } = usePagingAnimation({\n controlledTx,\n createScrollAnimation,\n getCurrentIndex,\n itemWidth,\n lastIndex,\n loop,\n numberOfData: data.length,\n offsetTx,\n });\n\n const autoplayController = useAutoplayController({\n enabled: autoplay,\n intervalMillis: autoplayInterval,\n startPagingAnimation,\n });\n\n useDimensionChangeReaction({\n controlledTx,\n currentIndex,\n itemWidth,\n });\n\n useImperativeHandle(\n ref,\n () => ({\n getCurrentIndex,\n next: () => startPagingAnimation('directional', { direction: 'next' }),\n prev: () => startPagingAnimation('directional', { direction: 'prev' }),\n scrollTo: (option) => startPagingAnimation('index', option),\n }),\n [startPagingAnimation, getCurrentIndex],\n );\n\n const contextValue = useMemo(() => ({\n createItemStyle,\n data,\n globalInterpolation,\n itemHeight,\n itemWidth,\n itemVisibilityStore,\n loop,\n }), [\n createItemStyle,\n data,\n globalInterpolation,\n itemHeight,\n itemWidth,\n itemVisibilityStore,\n loop,\n ]);\n\n return (\n <InternalContext.Provider value={contextValue}>\n {monitorElement}\n\n <ViewabilityTrackerView\n enabled={autoplay && !disableSmartAutoplay}\n measurementIntervalMillis={Math.max(3000, autoplayInterval)}\n onViewabilityChange={({ visible }) => {\n if (visible) {\n autoplayController.resume();\n } else {\n autoplayController.pause();\n }\n }}\n >\n <ScrollViewGesture\n autoplayController={autoplayController}\n finalizeAnimation={finalizeAnimation}\n offsetTx={offsetTx}\n scrollEnabled={scrollEnabled}\n startPagingAnimation={startPagingAnimation}\n >\n <RootView\n data={data}\n itemHeight={itemHeight}\n originalData={originalData}\n renderItem={renderItem}\n style={style}\n />\n </ScrollViewGesture>\n </ViewabilityTrackerView>\n </InternalContext.Provider>\n );\n});\n\nexport default memo(Carousel);\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,IAA5B,EAAkCC,mBAAlC,EAAuDC,OAAvD,EAAgEC,MAAhE,QAA8E,OAA9E;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,OAAOC,sBAAP,MAAmC,2BAAnC;AAGA,SACIC,qBADJ,EAEIC,0BAFJ,EAGIC,kBAHJ,EAIIC,sBAJJ,EAKIC,aALJ,EAMIC,kBANJ,QAOO,SAPP;AAQA,SAASC,sBAAT,EAAiCC,4BAAjC,QAAqE,aAArE;AACA,SAASC,eAAT,EAA0BC,QAA1B,EAAoCC,iBAApC,QAA6D,cAA7D;AAEA,MAAMC,QAAQ,gBAAGlB,UAAU,CAAkC,SAASkB,QAAT,CAAkBC,KAAlB,EAAyBC,GAAzB,EAA8B;EACvF,MAAM;IACFC,QAAQ,GAAG,KADT;IAEFC,gBAAgB,GAAG,IAFjB;IAGFC,eAAe,GAAGV,sBAHhB;IAIFW,qBAAqB,GAAGV,4BAJtB;IAKFW,IAAI,EAAEC,YALJ;IAMFC,oBAAoB,GAAG,KANrB;IAOFC,YAAY,GAAG,CAPb;IAQFC,UARE;IASFC,SATE;IAUFC,IAAI,GAAG,KAVL;IAWFC,aAXE;IAYFC,UAZE;IAaFC,aAAa,GAAG,IAbd;IAcFC,KAdE;IAeFC,UAAU,GAAG;EAfX,IAgBFjB,KAhBJ;EAkBA,MAAMM,IAAI,GAAGd,aAAa,CAACe,YAAD,EAAeK,IAAf,CAA1B;E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H,CArI0B,CAA3B;AAuIA,4BAAelC,IAAI,CAACiB,QAAD,CAAnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["CarouselProps.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"names":[],"sources":["CarouselProps.ts"],"sourcesContent":["import type { RefObject } from 'react';\nimport type { ComponentProps } from '@fountain-ui/core';\nimport type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, ItemHeight, RenderItem } from './types';\n\nexport default interface CarouselProps<ItemT = any> extends ComponentProps<{\n ref?: RefObject<CarouselInstance>;\n\n /**\n * If `true`, enable autoplay.\n * @default false\n */\n autoplay?: boolean;\n\n /**\n * Delay in ms until navigating to the next item.\n * @default 3000\n */\n autoplayInterval?: number;\n\n /**\n * The item style creator function.\n * @default createDefaultItemStyle\n */\n createItemStyle?: CreateItemStyle;\n\n /**\n * The scroll animation creator function.\n * @default createDefaultScrollAnimation\n */\n createScrollAnimation?: CreateScrollAnimation;\n\n /**\n * Data for render items.\n */\n data: ReadonlyArray<ItemT>;\n\n /**\n * If `true`, carousel will detect its own viewability and control autoplay automatically.\n * @default false\n */\n disableSmartAutoplay?: boolean;\n\n /**\n * Index of initial item that should be selected.\n * @default 0\n */\n initialIndex?: number;\n\n /**\n * The item height.\n * For a performance reason, always consider to provide a number value.\n */\n itemHeight: ItemHeight;\n\n /**\n * The item width.\n */\n itemWidth: number;\n\n /**\n * Enable infinite loop mode.\n * @default false\n */\n loop?: boolean;\n\n /**\n * Callback fired when an index is changed.\n */\n onIndexChange?: (newIndex: number) => void;\n\n /**\n * Takes an item from data and renders it into the list.\n */\n renderItem: RenderItem<ItemT>;\n\n /**\n * Whether to enable scroll gesture.\n * @default true\n */\n scrollEnabled?: boolean;\n\n /**\n * The maximum number of items that can respond to pan gesture events.\n * Due to the nature of the `active` item, it accepts only odd number. (e.g. 1, 3, 5...)\n * 0 means all items will respond to pan gesture events.\n * @default 5\n */\n windowSize?: number;\n}> {}\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["itemInterpolationInputRange"],"sources":["animationUtils.ts"],"sourcesContent":["export const itemInterpolationInputRange = [-1, 0, 1];\n"],"mappings":"AAAA,OAAO,MAAMA,2BAA2B,GAAG,CAAC,CAAC,CAAF,EAAK,CAAL,EAAQ,CAAR,CAApC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["normalItemStyleFactory"],"sources":["createDefaultItemStyle.ts"],"sourcesContent":["import normalItemStyleFactory from './normalItemStyleFactory';\n\nexport default normalItemStyleFactory();\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,0BAAnC;AAEA,eAAeA,sBAAsB,EAArC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Animated, Easing } from 'react-native';
|
|
2
|
+
export default function createDefaultScrollAnimation(animatedValue, toValue) {
|
|
3
|
+
return Animated.timing(animatedValue, {
|
|
4
|
+
toValue: toValue,
|
|
5
|
+
duration: 350,
|
|
6
|
+
easing: Easing.bezier(0.25, 1, 0.5, 1),
|
|
7
|
+
useNativeDriver: true
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
;
|
|
11
|
+
//# sourceMappingURL=createDefaultScrollAnimation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Animated","Easing","createDefaultScrollAnimation","animatedValue","toValue","timing","duration","easing","bezier","useNativeDriver"],"sources":["createDefaultScrollAnimation.ts"],"sourcesContent":["import { Animated, Easing } from 'react-native';\n\nexport default function createDefaultScrollAnimation(\n animatedValue: Animated.Value,\n toValue: number,\n): Animated.CompositeAnimation {\n return Animated.timing(animatedValue, {\n toValue: toValue,\n duration: 350,\n easing: Easing.bezier(0.25, 1, 0.5, 1),\n useNativeDriver: true,\n });\n};\n"],"mappings":"AAAA,SAASA,QAAT,EAAmBC,MAAnB,QAAiC,cAAjC;AAEA,eAAe,SAASC,4BAAT,CACXC,aADW,EAEXC,OAFW,EAGgB;EAC3B,OAAOJ,QAAQ,CAACK,MAAT,CAAgBF,aAAhB,EAA+B;IAClCC,OAAO,EAAEA,OADyB;IAElCE,QAAQ,EAAE,GAFwB;IAGlCC,MAAM,EAAEN,MAAM,CAACO,MAAP,CAAc,IAAd,EAAoB,CAApB,EAAuB,GAAvB,EAA4B,CAA5B,CAH0B;IAIlCC,eAAe,EAAE;EAJiB,CAA/B,CAAP;AAMH;AAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
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';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["default","createDefaultItemStyle","createDefaultScrollAnimation","normalItemStyleFactory","parallaxItemStyleFactory"],"sources":["index.ts"],"sourcesContent":["export { default as createDefaultItemStyle } from './createDefaultItemStyle';\nexport { default as createDefaultScrollAnimation } from './createDefaultScrollAnimation';\nexport { default as normalItemStyleFactory } from './normalItemStyleFactory';\nexport { default as parallaxItemStyleFactory } from './parallaxItemStyleFactory';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,sBAApB,QAAkD,0BAAlD;AACA,SAASD,OAAO,IAAIE,4BAApB,QAAwD,gCAAxD;AACA,SAASF,OAAO,IAAIG,sBAApB,QAAkD,0BAAlD;AACA,SAASH,OAAO,IAAII,wBAApB,QAAoD,4BAApD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { itemInterpolationInputRange } from './animationUtils';
|
|
2
|
+
export default function normalItemStyleFactory() {
|
|
3
|
+
const createItemStyle = (itemInterpolation, itemWidth) => {
|
|
4
|
+
const translate = itemInterpolation.interpolate({
|
|
5
|
+
inputRange: itemInterpolationInputRange,
|
|
6
|
+
outputRange: [-itemWidth, 0, itemWidth]
|
|
7
|
+
});
|
|
8
|
+
return {
|
|
9
|
+
transform: [{
|
|
10
|
+
translateX: translate
|
|
11
|
+
}]
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return createItemStyle;
|
|
16
|
+
}
|
|
17
|
+
;
|
|
18
|
+
//# sourceMappingURL=normalItemStyleFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["itemInterpolationInputRange","normalItemStyleFactory","createItemStyle","itemInterpolation","itemWidth","translate","interpolate","inputRange","outputRange","transform","translateX"],"sources":["normalItemStyleFactory.ts"],"sourcesContent":["import type { CreateItemStyle } from '../types';\nimport { itemInterpolationInputRange } from './animationUtils';\n\nexport default function normalItemStyleFactory() {\n const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {\n const translate = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n -itemWidth,\n 0,\n itemWidth,\n ],\n });\n\n return { transform: [{ translateX: translate }] };\n };\n\n return createItemStyle;\n};\n"],"mappings":"AACA,SAASA,2BAAT,QAA4C,kBAA5C;AAEA,eAAe,SAASC,sBAAT,GAAkC;EAC7C,MAAMC,eAAgC,GAAG,CAACC,iBAAD,EAAoBC,SAApB,KAAkC;IACvE,MAAMC,SAAS,GAAGF,iBAAiB,CAACG,WAAlB,CAA8B;MAC5CC,UAAU,EAAEP,2BADgC;MAE5CQ,WAAW,EAAE,CACT,CAACJ,SADQ,EAET,CAFS,EAGTA,SAHS;IAF+B,CAA9B,CAAlB;IASA,OAAO;MAAEK,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEL;MAAd,CAAD;IAAb,CAAP;EACH,CAXD;;EAaA,OAAOH,eAAP;AACH;AAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { itemInterpolationInputRange } from './animationUtils';
|
|
2
|
+
const defaultParallaxAnimationConfig = {
|
|
3
|
+
activeItemScale: 0.9,
|
|
4
|
+
activeItemOpacity: 1,
|
|
5
|
+
adjacentItemScale: Math.pow(0.9, 2),
|
|
6
|
+
adjacentItemOpacity: 0.5,
|
|
7
|
+
scrollingOffset: 50
|
|
8
|
+
};
|
|
9
|
+
export default function parallaxItemStyleFactory() {
|
|
10
|
+
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultParallaxAnimationConfig;
|
|
11
|
+
const {
|
|
12
|
+
activeItemOpacity,
|
|
13
|
+
activeItemScale,
|
|
14
|
+
adjacentItemOpacity,
|
|
15
|
+
adjacentItemScale,
|
|
16
|
+
scrollingOffset
|
|
17
|
+
} = { ...config,
|
|
18
|
+
...defaultParallaxAnimationConfig
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const createItemStyle = (itemInterpolation, itemWidth) => {
|
|
22
|
+
const translate = itemInterpolation.interpolate({
|
|
23
|
+
inputRange: itemInterpolationInputRange,
|
|
24
|
+
outputRange: [-itemWidth + scrollingOffset, 0, itemWidth - scrollingOffset]
|
|
25
|
+
});
|
|
26
|
+
const zIndex = itemInterpolation.interpolate({
|
|
27
|
+
inputRange: itemInterpolationInputRange,
|
|
28
|
+
outputRange: [0, itemWidth, 0],
|
|
29
|
+
extrapolate: 'clamp'
|
|
30
|
+
});
|
|
31
|
+
const scale = itemInterpolation.interpolate({
|
|
32
|
+
inputRange: itemInterpolationInputRange,
|
|
33
|
+
outputRange: [adjacentItemScale, activeItemScale, adjacentItemScale],
|
|
34
|
+
extrapolate: 'clamp'
|
|
35
|
+
});
|
|
36
|
+
const opacity = itemInterpolation.interpolate({
|
|
37
|
+
inputRange: itemInterpolationInputRange,
|
|
38
|
+
outputRange: [adjacentItemOpacity, activeItemOpacity, adjacentItemOpacity],
|
|
39
|
+
extrapolate: 'clamp'
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
transform: [{
|
|
43
|
+
translateX: translate
|
|
44
|
+
}, {
|
|
45
|
+
scale
|
|
46
|
+
}],
|
|
47
|
+
zIndex,
|
|
48
|
+
opacity
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return createItemStyle;
|
|
53
|
+
}
|
|
54
|
+
;
|
|
55
|
+
//# sourceMappingURL=parallaxItemStyleFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["itemInterpolationInputRange","defaultParallaxAnimationConfig","activeItemScale","activeItemOpacity","adjacentItemScale","Math","pow","adjacentItemOpacity","scrollingOffset","parallaxItemStyleFactory","config","createItemStyle","itemInterpolation","itemWidth","translate","interpolate","inputRange","outputRange","zIndex","extrapolate","scale","opacity","transform","translateX"],"sources":["parallaxItemStyleFactory.ts"],"sourcesContent":["import type { CreateItemStyle } from '../types';\nimport { itemInterpolationInputRange } from './animationUtils';\n\nexport interface ParallaxAnimationConfig {\n activeItemScale?: number;\n activeItemOpacity?: number;\n adjacentItemScale?: number;\n adjacentItemOpacity?: number;\n scrollingOffset?: number;\n}\n\nconst defaultParallaxAnimationConfig: Required<Readonly<ParallaxAnimationConfig>> = {\n activeItemScale: 0.9,\n activeItemOpacity: 1,\n adjacentItemScale: Math.pow(0.9, 2),\n adjacentItemOpacity: 0.5,\n scrollingOffset: 50,\n};\n\nexport default function parallaxItemStyleFactory(config: ParallaxAnimationConfig = defaultParallaxAnimationConfig) {\n const {\n activeItemOpacity,\n activeItemScale,\n adjacentItemOpacity,\n adjacentItemScale,\n scrollingOffset,\n }: Required<ParallaxAnimationConfig> = {\n ...config,\n ...defaultParallaxAnimationConfig,\n };\n\n const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {\n const translate = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n -itemWidth + scrollingOffset,\n 0,\n itemWidth - scrollingOffset,\n ],\n });\n\n const zIndex = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [0, itemWidth, 0],\n extrapolate: 'clamp',\n });\n\n const scale = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n adjacentItemScale,\n activeItemScale,\n adjacentItemScale,\n ],\n extrapolate: 'clamp',\n });\n\n const opacity = itemInterpolation.interpolate({\n inputRange: itemInterpolationInputRange,\n outputRange: [\n adjacentItemOpacity,\n activeItemOpacity,\n adjacentItemOpacity,\n ],\n extrapolate: 'clamp',\n });\n\n return {\n transform: [\n { translateX: translate },\n { scale },\n ],\n zIndex,\n opacity,\n };\n };\n\n return createItemStyle;\n};\n"],"mappings":"AACA,SAASA,2BAAT,QAA4C,kBAA5C;AAUA,MAAMC,8BAA2E,GAAG;EAChFC,eAAe,EAAE,GAD+D;EAEhFC,iBAAiB,EAAE,CAF6D;EAGhFC,iBAAiB,EAAEC,IAAI,CAACC,GAAL,CAAS,GAAT,EAAc,CAAd,CAH6D;EAIhFC,mBAAmB,EAAE,GAJ2D;EAKhFC,eAAe,EAAE;AAL+D,CAApF;AAQA,eAAe,SAASC,wBAAT,GAAoG;EAAA,IAAlEC,MAAkE,uEAAhCT,8BAAgC;EAC/G,MAAM;IACFE,iBADE;IAEFD,eAFE;IAGFK,mBAHE;IAIFH,iBAJE;IAKFI;EALE,IAMiC,EACnC,GAAGE,MADgC;IAEnC,GAAGT;EAFgC,CANvC;;EAWA,MAAMU,eAAgC,GAAG,CAACC,iBAAD,EAAoBC,SAApB,KAAkC;IACvE,MAAMC,SAAS,GAAGF,iBAAiB,CAACG,WAAlB,CAA8B;MAC5CC,UAAU,EAAEhB,2BADgC;MAE5CiB,WAAW,EAAE,CACT,CAACJ,SAAD,GAAaL,eADJ,EAET,CAFS,EAGTK,SAAS,GAAGL,eAHH;IAF+B,CAA9B,CAAlB;IASA,MAAMU,MAAM,GAAGN,iBAAiB,CAACG,WAAlB,CAA8B;MACzCC,UAAU,EAAEhB,2BAD6B;MAEzCiB,WAAW,EAAE,CAAC,CAAD,EAAIJ,SAAJ,EAAe,CAAf,CAF4B;MAGzCM,WAAW,EAAE;IAH4B,CAA9B,CAAf;IAMA,MAAMC,KAAK,GAAGR,iBAAiB,CAACG,WAAlB,CAA8B;MACxCC,UAAU,EAAEhB,2BAD4B;MAExCiB,WAAW,EAAE,CACTb,iBADS,EAETF,eAFS,EAGTE,iBAHS,CAF2B;MAOxCe,WAAW,EAAE;IAP2B,CAA9B,CAAd;IAUA,MAAME,OAAO,GAAGT,iBAAiB,CAACG,WAAlB,CAA8B;MAC1CC,UAAU,EAAEhB,2BAD8B;MAE1CiB,WAAW,EAAE,CACTV,mBADS,EAETJ,iBAFS,EAGTI,mBAHS,CAF6B;MAO1CY,WAAW,EAAE;IAP6B,CAA9B,CAAhB;IAUA,OAAO;MACHG,SAAS,EAAE,CACP;QAAEC,UAAU,EAAET;MAAd,CADO,EAEP;QAAEM;MAAF,CAFO,CADR;MAKHF,MALG;MAMHG;IANG,CAAP;EAQH,CA5CD;;EA8CA,OAAOV,eAAP;AACH;AAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
const mockItemVisibilityStore = {
|
|
4
|
+
dispatch: () => void 0,
|
|
5
|
+
subscribe: () => () => void 0,
|
|
6
|
+
removeAllListeners: () => void 0
|
|
7
|
+
};
|
|
8
|
+
const initialValue = {
|
|
9
|
+
createItemStyle: () => ({}),
|
|
10
|
+
data: [],
|
|
11
|
+
globalInterpolation: Animated.add(new Animated.Value(0), 0),
|
|
12
|
+
itemHeight: 0,
|
|
13
|
+
itemWidth: 0,
|
|
14
|
+
itemVisibilityStore: mockItemVisibilityStore,
|
|
15
|
+
loop: false
|
|
16
|
+
};
|
|
17
|
+
const InternalContext = /*#__PURE__*/createContext(initialValue);
|
|
18
|
+
export default InternalContext;
|
|
19
|
+
//# sourceMappingURL=InternalContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","Animated","mockItemVisibilityStore","dispatch","subscribe","removeAllListeners","initialValue","createItemStyle","data","globalInterpolation","add","Value","itemHeight","itemWidth","itemVisibilityStore","loop","InternalContext"],"sources":["InternalContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { Animated } from 'react-native';\nimport type { CreateItemStyle, ItemHeight, ItemVisibilityStore } from '../types';\n\nexport interface InternalContextValue<ItemT> {\n createItemStyle: CreateItemStyle;\n data: ReadonlyArray<ItemT>;\n globalInterpolation: Animated.AnimatedInterpolation;\n itemHeight: ItemHeight;\n itemWidth: number;\n itemVisibilityStore: ItemVisibilityStore;\n loop: boolean;\n}\n\nconst mockItemVisibilityStore: ItemVisibilityStore = {\n dispatch: () => void 0,\n subscribe: () => () => void 0,\n removeAllListeners: () => void 0,\n};\n\nconst initialValue: Readonly<InternalContextValue<any>> = {\n createItemStyle: () => ({}),\n data: [],\n globalInterpolation: Animated.add(new Animated.Value(0), 0),\n itemHeight: 0,\n itemWidth: 0,\n itemVisibilityStore: mockItemVisibilityStore,\n loop: false,\n};\n\nconst InternalContext = createContext<InternalContextValue<any>>(initialValue);\n\nexport default InternalContext;\n"],"mappings":"AAAA,SAASA,aAAT,QAA8B,OAA9B;AACA,SAASC,QAAT,QAAyB,cAAzB;AAaA,MAAMC,uBAA4C,GAAG;EACjDC,QAAQ,EAAE,MAAM,KAAK,CAD4B;EAEjDC,SAAS,EAAE,MAAM,MAAM,KAAK,CAFqB;EAGjDC,kBAAkB,EAAE,MAAM,KAAK;AAHkB,CAArD;AAMA,MAAMC,YAAiD,GAAG;EACtDC,eAAe,EAAE,OAAO,EAAP,CADqC;EAEtDC,IAAI,EAAE,EAFgD;EAGtDC,mBAAmB,EAAER,QAAQ,CAACS,GAAT,CAAa,IAAIT,QAAQ,CAACU,KAAb,CAAmB,CAAnB,CAAb,EAAoC,CAApC,CAHiC;EAItDC,UAAU,EAAE,CAJ0C;EAKtDC,SAAS,EAAE,CAL2C;EAMtDC,mBAAmB,EAAEZ,uBANiC;EAOtDa,IAAI,EAAE;AAPgD,CAA1D;AAUA,MAAMC,eAAe,gBAAGhB,aAAa,CAA4BM,YAA5B,CAArC;AAEA,eAAeU,eAAf"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import { StyleSheet } from '@fountain-ui/core';
|
|
4
|
+
import { useItemInterpolation } from '../hooks';
|
|
5
|
+
import InternalContext from './InternalContext';
|
|
6
|
+
export default function ItemView(props) {
|
|
7
|
+
const {
|
|
8
|
+
children,
|
|
9
|
+
index,
|
|
10
|
+
onLayout
|
|
11
|
+
} = props;
|
|
12
|
+
const {
|
|
13
|
+
createItemStyle,
|
|
14
|
+
itemHeight,
|
|
15
|
+
itemWidth,
|
|
16
|
+
itemVisibilityStore
|
|
17
|
+
} = useContext(InternalContext);
|
|
18
|
+
const [visible, setVisible] = useState(false);
|
|
19
|
+
const interpolation = useItemInterpolation(index);
|
|
20
|
+
const itemStyle = useMemo(() => createItemStyle(interpolation, itemWidth), [createItemStyle, interpolation]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
return itemVisibilityStore.subscribe(ranges => {
|
|
23
|
+
const nextVisible = ranges.some(_ref => {
|
|
24
|
+
let [from, to] = _ref;
|
|
25
|
+
return index >= from && index <= to;
|
|
26
|
+
});
|
|
27
|
+
setVisible(nextVisible);
|
|
28
|
+
});
|
|
29
|
+
}, [itemVisibilityStore]);
|
|
30
|
+
return /*#__PURE__*/React.createElement(Animated.View, {
|
|
31
|
+
children: visible ? children(interpolation) : null,
|
|
32
|
+
onLayout: onLayout,
|
|
33
|
+
style: [{
|
|
34
|
+
width: itemWidth,
|
|
35
|
+
height: itemHeight !== 'auto' ? itemHeight : undefined
|
|
36
|
+
}, styles.absolute, // @ts-ignore
|
|
37
|
+
itemStyle]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
;
|
|
41
|
+
const styles = StyleSheet.create({
|
|
42
|
+
absolute: {
|
|
43
|
+
position: 'absolute'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=ItemView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useContext","useEffect","useMemo","useState","Animated","StyleSheet","useItemInterpolation","InternalContext","ItemView","props","children","index","onLayout","createItemStyle","itemHeight","itemWidth","itemVisibilityStore","visible","setVisible","interpolation","itemStyle","subscribe","ranges","nextVisible","some","from","to","width","height","undefined","styles","absolute","create","position"],"sources":["ItemView.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useMemo, useState } from 'react';\nimport type { ViewProps } from 'react-native';\nimport { Animated } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport { useItemInterpolation } from '../hooks';\nimport InternalContext from './InternalContext';\n\nexport interface ItemViewProps {\n children: (interpolation: Animated.AnimatedInterpolation) => ReactElement | null;\n index: number;\n onLayout?: ViewProps['onLayout'];\n}\n\nexport default function ItemView(props: ItemViewProps) {\n const {\n children,\n index,\n onLayout,\n } = props;\n\n const {\n createItemStyle,\n itemHeight,\n itemWidth,\n itemVisibilityStore,\n } = useContext(InternalContext);\n\n const [visible, setVisible] = useState(false);\n\n const interpolation = useItemInterpolation(index);\n\n const itemStyle = useMemo(\n () => createItemStyle(interpolation, itemWidth),\n [createItemStyle, interpolation],\n );\n\n useEffect(() => {\n return itemVisibilityStore.subscribe(ranges => {\n const nextVisible = ranges.some(([from, to]) => index >= from && index <= to);\n setVisible(nextVisible);\n });\n }, [itemVisibilityStore]);\n\n return (\n <Animated.View\n children={visible ? children(interpolation) : null}\n onLayout={onLayout}\n style={[\n {\n width: itemWidth,\n height: itemHeight !== 'auto' ? itemHeight : undefined,\n },\n styles.absolute,\n // @ts-ignore\n itemStyle,\n ]}\n />\n );\n};\n\nconst styles = StyleSheet.create({\n absolute: {\n position: 'absolute',\n },\n});\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,SAA5B,EAAuCC,OAAvC,EAAg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,MAAM,CAACC,QALJ,EAMH;IACAX,SAPG;EAHX,EADJ;AAeH;AAAA;AAED,MAAMU,MAAM,GAAGzB,UAAU,CAAC2B,MAAX,CAAkB;EAC7BD,QAAQ,EAAE;IACNE,QAAQ,EAAE;EADJ;AADmB,CAAlB,CAAf"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef, memo, useState } from 'react';
|
|
4
|
+
import { Animated } from 'react-native';
|
|
5
|
+
import { StyleSheet } from '@fountain-ui/core';
|
|
6
|
+
import ItemView from './ItemView';
|
|
7
|
+
const styles = StyleSheet.create({
|
|
8
|
+
root: {
|
|
9
|
+
width: '100%',
|
|
10
|
+
justifyContent: 'center'
|
|
11
|
+
},
|
|
12
|
+
horizontal: {
|
|
13
|
+
flexDirection: 'row',
|
|
14
|
+
overflowX: 'hidden',
|
|
15
|
+
overflowY: 'visible'
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const RootView = /*#__PURE__*/forwardRef(function RootView(props, ref) {
|
|
19
|
+
const {
|
|
20
|
+
data,
|
|
21
|
+
itemHeight,
|
|
22
|
+
originalData,
|
|
23
|
+
renderItem,
|
|
24
|
+
style,
|
|
25
|
+
...otherProps
|
|
26
|
+
} = props;
|
|
27
|
+
const [maxHeightOfRenderedItems, setMaxHeightOfRenderedItems] = useState(0);
|
|
28
|
+
|
|
29
|
+
const handleItemLayout = e => {
|
|
30
|
+
const {
|
|
31
|
+
nativeEvent: {
|
|
32
|
+
layout: {
|
|
33
|
+
height
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} = e;
|
|
37
|
+
const heightInt = Math.round(height);
|
|
38
|
+
|
|
39
|
+
if (heightInt > maxHeightOfRenderedItems) {
|
|
40
|
+
setMaxHeightOfRenderedItems(heightInt);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const renderItemView = (item, index) => /*#__PURE__*/React.createElement(ItemView, {
|
|
45
|
+
key: index,
|
|
46
|
+
index: index,
|
|
47
|
+
onLayout: itemHeight === 'auto' ? handleItemLayout : undefined
|
|
48
|
+
}, interpolation => renderItem({
|
|
49
|
+
item,
|
|
50
|
+
index: index % originalData.length,
|
|
51
|
+
interpolation
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const viewStyles = [styles.root, styles.horizontal, {
|
|
55
|
+
height: itemHeight === 'auto' ? maxHeightOfRenderedItems : itemHeight
|
|
56
|
+
}, style];
|
|
57
|
+
return /*#__PURE__*/React.createElement(Animated.View, _extends({
|
|
58
|
+
ref: ref
|
|
59
|
+
}, otherProps, {
|
|
60
|
+
children: data.map(renderItemView),
|
|
61
|
+
style: viewStyles
|
|
62
|
+
}));
|
|
63
|
+
});
|
|
64
|
+
export default /*#__PURE__*/memo(RootView);
|
|
65
|
+
//# sourceMappingURL=RootView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","memo","useState","Animated","StyleSheet","ItemView","styles","create","root","width","justifyContent","horizontal","flexDirection","overflowX","overflowY","RootView","props","ref","data","itemHeight","originalData","renderItem","style","otherProps","maxHeightOfRenderedItems","setMaxHeightOfRenderedItems","handleItemLayout","e","nativeEvent","layout","height","heightInt","Math","round","renderItemView","item","index","undefined","interpolation","length","viewStyles","map"],"sources":["RootView.tsx"],"sourcesContent":["import React, { forwardRef, memo, ReactElement, useState } from 'react';\nimport type { View, ViewProps, LayoutChangeEvent } from 'react-native';\nimport { Animated } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { ItemHeight, RenderItem } from '../types';\nimport ItemView from './ItemView';\n\nconst styles = StyleSheet.create({\n root: {\n width: '100%',\n justifyContent: 'center',\n },\n horizontal: {\n flexDirection: 'row',\n overflowX: 'hidden',\n overflowY: 'visible',\n },\n});\n\nexport type RootViewProps<ItemT> = ViewProps & {\n data: ReadonlyArray<ItemT>;\n itemHeight: ItemHeight;\n originalData: ReadonlyArray<ItemT>;\n renderItem: RenderItem<ItemT>;\n};\n\nconst RootView = forwardRef<View, RootViewProps<any>>(function RootView(props, ref) {\n const {\n data,\n itemHeight,\n originalData,\n renderItem,\n style,\n ...otherProps\n } = props;\n\n const [maxHeightOfRenderedItems, setMaxHeightOfRenderedItems] = useState(0);\n\n const handleItemLayout = (e: LayoutChangeEvent) => {\n const { nativeEvent: { layout: { height } } } = e;\n\n const heightInt = Math.round(height);\n if (heightInt > maxHeightOfRenderedItems) {\n setMaxHeightOfRenderedItems(heightInt);\n }\n };\n\n const renderItemView = (item: any, index: number): ReactElement => (\n <ItemView\n key={index}\n index={index}\n onLayout={itemHeight === 'auto' ? handleItemLayout : undefined}\n >\n {(interpolation) => renderItem({\n item,\n index: index % originalData.length,\n interpolation,\n })}\n </ItemView>\n );\n\n const viewStyles = [\n styles.root,\n styles.horizontal,\n { height: itemHeight === 'auto' ? maxHeightOfRenderedItems : itemHeight },\n style,\n ];\n\n return (\n <Animated.View\n ref={ref}\n {...otherProps}\n children={data.map(renderItemView)}\n style={viewStyles}\n />\n );\n});\n\nexport default memo(RootView);\n"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,IAA5B,EAAgDC,QAAhD,QAAgE,OAAhE;AAEA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA,OAAOC,QAAP,MAAqB,YAArB;AAEA,MAAMC,MAAM,GAAGF,UAAU,CAACG,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IACFC,KAAK,EAAE,MADL;IAEFC,cAAc,EAAE;EAFd,CADuB;EAK7BC,UAAU,EAAE;IACRC,aAAa,EAAE,KADP;IAERC,SAAS,EAAE,QAFH;IAGRC,SAAS,EAAE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