@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 @@
|
|
|
1
|
+
{"version":3,"names":["directions"],"sources":["types.ts"],"sourcesContent":["import type { ReactElement } from 'react';\nimport type { Animated, ViewProps } from 'react-native';\n\nconst directions = ['next', 'prev', 'stay'] as const;\n\nexport type PagingDirection = (typeof directions)[number];\n\nexport type ItemHeight = number | 'auto';\n\nexport interface RenderItem<T> {\n (info: { item: T, index: number, interpolation: Animated.AnimatedInterpolation }): ReactElement | null;\n}\n\nexport interface CreateScrollAnimation {\n (aValue: Animated.AnimatedValue, toValue: number): Animated.CompositeAnimation;\n}\n\nexport interface CreateItemStyle {\n (itemInterpolation: Animated.AnimatedInterpolation, itemWidth: number): Animated.AnimatedProps<ViewProps['style']>;\n}\n\nexport interface GetCurrentIndex {\n (): number;\n}\n\nexport interface IndexController {\n currentIndex: number;\n getCurrentIndex: GetCurrentIndex;\n lastIndex: number;\n monitorElement: ReactElement;\n}\n\nexport type PagingAnimationType = 'directional' | 'index';\n\nexport interface BasePagingAnimationConfig {\n animated?: boolean;\n}\n\nexport interface DirectionalPagingAnimationConfig extends BasePagingAnimationConfig {\n direction: PagingDirection;\n isOriginatedFromGesture?: boolean;\n}\n\nexport interface IndexPagingAnimationConfig extends BasePagingAnimationConfig {\n index: number;\n}\n\nexport type PagingAnimationConfig = DirectionalPagingAnimationConfig | IndexPagingAnimationConfig;\n\nexport interface StartPagingAnimation {\n (type: PagingAnimationType, config: PagingAnimationConfig): void;\n}\n\nexport type VisibleIndexRanges = Array<[number, number]>;\n\nexport interface StoreSubscription {\n (): void;\n}\n\nexport interface ItemVisibilityStore {\n dispatch: (ranges: VisibleIndexRanges) => void;\n subscribe: (listener: (ranges: VisibleIndexRanges) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n\nexport interface AutoplayController {\n pause: () => void;\n resume: () => void;\n}\n\nexport interface ScrollToOption {\n index: number;\n animated?: boolean;\n}\n\nexport interface CarouselInstance {\n /**\n * Get current visible item index.\n */\n getCurrentIndex: GetCurrentIndex;\n\n /**\n * Scroll to next visible item.\n */\n next: () => void;\n\n /**\n * Scroll to previous visible item.\n */\n prev: () => void;\n\n /**\n * Scroll to desired indexed item.\n * Invalid index is ignored.\n */\n scrollTo: (option: ScrollToOption) => void;\n}\n"],"mappings":"AAGA,MAAMA,UAAU,GAAG,CAAC,MAAD,EAAS,MAAT,EAAiB,MAAjB,CAAnB"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import React, { memo, useState } from 'react';
|
|
1
|
+
import React, { memo, useContext, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { Platform, View } from 'react-native';
|
|
3
|
-
import { runOnJS, useAnimatedReaction } from 'react-native-reanimated';
|
|
4
3
|
import { StyleSheet } from '@fountain-ui/core';
|
|
5
|
-
|
|
4
|
+
import PageStateContext from './PageStateContext';
|
|
5
|
+
import InternalContext from './InternalContext';
|
|
6
6
|
const styles = StyleSheet.create({
|
|
7
|
+
fill: {
|
|
8
|
+
width: '100%',
|
|
9
|
+
height: '100%'
|
|
10
|
+
},
|
|
7
11
|
none: {
|
|
8
12
|
display: 'none'
|
|
9
13
|
}
|
|
@@ -12,81 +16,69 @@ const styles = StyleSheet.create({
|
|
|
12
16
|
function Page(props) {
|
|
13
17
|
const {
|
|
14
18
|
index,
|
|
19
|
+
initialPage,
|
|
15
20
|
children,
|
|
16
21
|
loading,
|
|
17
|
-
|
|
22
|
+
offscreenPageRerenderLimit
|
|
18
23
|
} = props;
|
|
24
|
+
const {
|
|
25
|
+
pageStore
|
|
26
|
+
} = useContext(InternalContext);
|
|
19
27
|
|
|
20
28
|
const assumeInitialPageState = () => {
|
|
21
|
-
const activeIndex =
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
if (Platform.OS === 'web') {
|
|
25
|
-
return {
|
|
26
|
-
active,
|
|
27
|
-
visited: active
|
|
28
|
-
};
|
|
29
|
-
}
|
|
29
|
+
const activeIndex = initialPage;
|
|
30
|
+
const isActive = index === activeIndex;
|
|
30
31
|
|
|
31
32
|
if (loading === 'eager') {
|
|
32
33
|
return {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
isActive,
|
|
35
|
+
isLoaded: true
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
const
|
|
39
|
+
const isLoaded = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
|
|
39
40
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
isActive,
|
|
42
|
+
isLoaded
|
|
42
43
|
};
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
const [pageState, setPageState] = useState(assumeInitialPageState);
|
|
46
|
-
const content = pageState.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
const content = pageState.isLoaded ? children : null;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return pageStore.subscribe(newPage => {
|
|
50
|
+
const activeIndex = newPage;
|
|
51
|
+
const isActive = index === activeIndex;
|
|
52
|
+
const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
|
|
53
|
+
const becomeNeighbor = shouldRerender && !isActive;
|
|
54
|
+
setPageState(prevState => {
|
|
55
|
+
if (prevState.isActive !== isActive) {
|
|
56
|
+
return { ...prevState,
|
|
57
|
+
isActive,
|
|
58
|
+
isLoaded: isActive || prevState.isLoaded
|
|
59
|
+
};
|
|
60
|
+
}
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
if (becomeNeighbor && !prevState.isLoaded) {
|
|
63
|
+
return { ...prevState,
|
|
64
|
+
isLoaded: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
return prevState;
|
|
69
|
+
});
|
|
64
70
|
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const willActive = index === activeIndex;
|
|
71
|
-
const willNeighbor = Platform.OS === 'web' ? false : willVisible && !willActive;
|
|
72
|
-
return {
|
|
73
|
-
willActive,
|
|
74
|
-
willNeighbor
|
|
75
|
-
};
|
|
76
|
-
}, (nextState, prevState) => {
|
|
77
|
-
const activeStateChanged = nextState.willActive !== (prevState === null || prevState === void 0 ? void 0 : prevState.willActive);
|
|
78
|
-
const willNewNeighbor = nextState.willNeighbor && !(prevState !== null && prevState !== void 0 && prevState.willNeighbor);
|
|
79
|
-
|
|
80
|
-
if (activeStateChanged || willNewNeighbor) {
|
|
81
|
-
runOnJS(updatePageState)(nextState.willActive, nextState.willNeighbor);
|
|
82
|
-
}
|
|
83
|
-
}, [index]);
|
|
84
|
-
const style = Platform.OS === 'web' ? pageState.active ? StyleSheet.absoluteFill : styles.none : undefined;
|
|
71
|
+
}, [pageStore, index]);
|
|
72
|
+
const contextValue = useMemo(() => ({
|
|
73
|
+
isActive: pageState.isActive
|
|
74
|
+
}), [pageState.isActive]);
|
|
75
|
+
const style = Platform.OS === 'web' ? pageState.isActive ? StyleSheet.absoluteFill : styles.none : styles.fill;
|
|
85
76
|
return /*#__PURE__*/React.createElement(View, {
|
|
86
|
-
children: content,
|
|
87
77
|
collapsable: false,
|
|
88
78
|
style: style
|
|
89
|
-
}
|
|
79
|
+
}, /*#__PURE__*/React.createElement(PageStateContext.Provider, {
|
|
80
|
+
value: contextValue
|
|
81
|
+
}, content));
|
|
90
82
|
}
|
|
91
83
|
|
|
92
84
|
export default /*#__PURE__*/memo(Page, (prevProps, nextProps) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","memo","
|
|
1
|
+
{"version":3,"names":["React","memo","useContext","useEffect","useMemo","useState","Platform","View","StyleSheet","PageStateContext","InternalContext","styles","create","fill","width","height","none","display","Page","props","index","initialPage","children","loading","offscreenPageRerenderLimit","pageStore","assumeInitialPageState","activeIndex","isActive","isLoaded","pageState","setPageState","content","subscribe","newPage","shouldRerender","becomeNeighbor","prevState","contextValue","style","OS","absoluteFill","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useContext, useEffect, useMemo, useState } from 'react';\nimport { Platform, View } from 'react-native';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { PageProps } from './types';\nimport PageStateContext from './PageStateContext';\nimport InternalContext from './InternalContext';\n\nconst styles = StyleSheet.create({\n fill: { width: '100%', height: '100%' },\n none: { display: 'none' },\n});\n\ninterface InternalPageState {\n isActive: boolean;\n isLoaded: boolean;\n}\n\nfunction Page(props: PageProps) {\n const {\n index,\n initialPage,\n children,\n loading,\n offscreenPageRerenderLimit,\n } = props;\n\n const { pageStore } = useContext(InternalContext);\n\n const assumeInitialPageState = (): InternalPageState => {\n const activeIndex = initialPage;\n\n const isActive = index === activeIndex;\n\n if (loading === 'eager') {\n return { isActive, isLoaded: true };\n }\n\n const isLoaded = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n return { isActive, isLoaded };\n };\n\n const [pageState, setPageState] = useState<InternalPageState>(assumeInitialPageState);\n\n const content = pageState.isLoaded ? children : null;\n\n useEffect(() => {\n return pageStore.subscribe(newPage => {\n const activeIndex = newPage;\n\n const isActive = index === activeIndex;\n\n const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n const becomeNeighbor = shouldRerender && !isActive;\n\n setPageState(prevState => {\n if (prevState.isActive !== isActive) {\n return {\n ...prevState,\n isActive,\n isLoaded: isActive || prevState.isLoaded,\n };\n }\n\n if (becomeNeighbor && !prevState.isLoaded) {\n return {\n ...prevState,\n isLoaded: true,\n };\n }\n\n return prevState;\n });\n });\n }, [pageStore, index]);\n\n const contextValue = useMemo(() => ({\n isActive: pageState.isActive,\n }), [pageState.isActive]);\n\n const style = Platform.OS === 'web'\n ? (pageState.isActive ? StyleSheet.absoluteFill : styles.none)\n : styles.fill;\n\n return (\n <View\n collapsable={false}\n style={style}\n >\n <PageStateContext.Provider value={contextValue}>\n {content}\n </PageStateContext.Provider>\n </View>\n );\n}\n\nexport default memo(Page, (prevProps, nextProps) => {\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.index !== nextProps.index;\n});\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,IAAhB,EAAsBC,UAAtB,EAAkCC,SAAlC,EAA6CC,OAA7C,EAAsDC,QAAtD,QAAsE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qD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOF,SAAS,CAACtB,KAAV,KAAoBuB,SAAS,CAACvB,KAArC;AACH,CANkB,CAAnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","MockStore","InternalContext","pageStore"],"sources":["InternalContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport type { MonoStore } from '@fountain-ui/core';\nimport { MockStore } from '@fountain-ui/core';\n\nexport interface InternalContextValue {\n pageStore: MonoStore<number>;\n}\n\nconst InternalContext = createContext<InternalContextValue>({\n pageStore: new MockStore(),\n});\n\nexport default InternalContext;\n"],"mappings":"AAAA,SAASA,aAAT,QAA8B,OAA9B;AAEA,SAASC,SAAT,QAA0B,mBAA1B;AAMA,MAAMC,eAAe,gBAAGF,aAAa,CAAuB;EACxDG,SAAS,EAAE,IAAIF,SAAJ;AAD6C,CAAvB,CAArC;AAIA,eAAeC,eAAf"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
const initialPageState = {
|
|
3
|
+
isActive: false
|
|
4
|
+
};
|
|
5
|
+
const PageStateContext = /*#__PURE__*/createContext(initialPageState);
|
|
6
|
+
export const useViewPagerPageState = () => {
|
|
7
|
+
return useContext(PageStateContext);
|
|
8
|
+
};
|
|
9
|
+
export default PageStateContext;
|
|
10
|
+
//# sourceMappingURL=PageStateContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","useContext","initialPageState","isActive","PageStateContext","useViewPagerPageState"],"sources":["PageStateContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\ninterface PageState {\n isActive: boolean;\n}\n\nconst initialPageState: Readonly<PageState> = { isActive: false };\n\nconst PageStateContext = createContext<PageState>(initialPageState);\n\nexport const useViewPagerPageState = () => {\n return useContext(PageStateContext);\n};\n\nexport default PageStateContext;\n"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAMA,MAAMC,gBAAqC,GAAG;EAAEC,QAAQ,EAAE;AAAZ,CAA9C;AAEA,MAAMC,gBAAgB,gBAAGJ,aAAa,CAAYE,gBAAZ,CAAtC;AAEA,OAAO,MAAMG,qBAAqB,GAAG,MAAM;EACvC,OAAOJ,UAAU,CAACG,gBAAD,CAAjB;AACH,CAFM;AAIP,eAAeA,gBAAf"}
|
|
@@ -1,51 +1,113 @@
|
|
|
1
|
-
import React, { Children, forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
|
|
1
|
+
import React, { Children, forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from 'react';
|
|
2
2
|
import RNViewPager from 'react-native-pager-view';
|
|
3
|
-
import {
|
|
4
|
-
import { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';
|
|
3
|
+
import { useSyncAnimatedValue } from '@fountain-ui/core';
|
|
4
|
+
import { defaultInitialPage, defaultLoading, defaultOffscreenPageRerenderLimit, defaultPageComponent } from './utils';
|
|
5
|
+
import usePageStore from './usePageStore';
|
|
6
|
+
import InternalContext from './InternalContext';
|
|
5
7
|
const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
6
8
|
const {
|
|
7
9
|
children,
|
|
8
10
|
initialPage = defaultInitialPage,
|
|
9
11
|
keyboardDismissMode = 'on-drag',
|
|
10
12
|
loading = defaultLoading,
|
|
13
|
+
offscreenPageRerenderLimit = defaultOffscreenPageRerenderLimit,
|
|
11
14
|
onChange,
|
|
12
15
|
pageComponent = defaultPageComponent,
|
|
13
16
|
pageForceRerenderKey,
|
|
14
17
|
scrollEnabled = true,
|
|
15
|
-
style
|
|
18
|
+
style,
|
|
19
|
+
UNSTABLE_sharedPage
|
|
16
20
|
} = props;
|
|
17
|
-
const
|
|
21
|
+
const fallbackSharedPage = useSyncAnimatedValue({
|
|
22
|
+
initialValue: initialPage
|
|
23
|
+
});
|
|
24
|
+
const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
|
|
25
|
+
const pageRef = useRef(sharedPage.initialValue);
|
|
26
|
+
const desiredPageRef = useRef(NaN);
|
|
18
27
|
const pagerRef = useRef(null);
|
|
28
|
+
const animationFrameRef = useRef(NaN);
|
|
29
|
+
const setPage = useCallback(newPage => {
|
|
30
|
+
if (!Number.isInteger(newPage)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
19
33
|
|
|
20
|
-
|
|
21
|
-
requestAnimationFrame(() => {
|
|
34
|
+
animationFrameRef.current = requestAnimationFrame(() => {
|
|
22
35
|
var _pagerRef$current;
|
|
23
36
|
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
if (Number.isFinite(desiredPageRef.current)) {
|
|
38
|
+
if (pageRef.current === desiredPageRef.current) {
|
|
39
|
+
// end of state machine. clear desired page.
|
|
40
|
+
desiredPageRef.current = NaN;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
if (newPage === desiredPageRef.current) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
desiredPageRef.current = newPage;
|
|
50
|
+
(_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newPage);
|
|
51
|
+
});
|
|
52
|
+
}, []);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
return () => {
|
|
55
|
+
if (animationFrameRef.current) {
|
|
56
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const animatedValue = sharedPage.animatedValue;
|
|
62
|
+
const id = animatedValue.addListener(newValue => {
|
|
63
|
+
const newPage = newValue.value;
|
|
64
|
+
pageRef.current = newPage;
|
|
65
|
+
setPage(newPage);
|
|
66
|
+
});
|
|
67
|
+
return () => {
|
|
68
|
+
animatedValue.removeListener(id);
|
|
69
|
+
};
|
|
70
|
+
}, [sharedPage]);
|
|
31
71
|
const handlePageSelected = useCallback(e => {
|
|
32
|
-
|
|
33
|
-
|
|
72
|
+
if (Number.isFinite(desiredPageRef.current)) {
|
|
73
|
+
// onPageSelected is called from outer controlling mechanism
|
|
74
|
+
// e.g. sharedPage.value is changed, setPage() is called
|
|
75
|
+
// Due to the onPageSelected bug,
|
|
76
|
+
// we don't trust the value from event, (e.nativeEvent.position)
|
|
77
|
+
// other than that trust the value from desiredPageRef.
|
|
78
|
+
const desiredPage = desiredPageRef.current;
|
|
34
79
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
80
|
+
if (pageRef.current === desiredPage) {
|
|
81
|
+
// end of state machine. clear desired page.
|
|
82
|
+
desiredPageRef.current = NaN;
|
|
83
|
+
} else {
|
|
84
|
+
sharedPage.animatedValue.setValue(desiredPage);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(desiredPage);
|
|
88
|
+
} else {
|
|
89
|
+
const trustfulNextPage = e.nativeEvent.position;
|
|
38
90
|
|
|
39
|
-
|
|
91
|
+
if (trustfulNextPage !== pageRef.current) {
|
|
92
|
+
desiredPageRef.current = trustfulNextPage;
|
|
93
|
+
sharedPage.animatedValue.setValue(trustfulNextPage);
|
|
94
|
+
}
|
|
40
95
|
|
|
41
|
-
|
|
42
|
-
onChange(nextIndex);
|
|
96
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(trustfulNextPage);
|
|
43
97
|
}
|
|
44
|
-
}, [onChange]);
|
|
98
|
+
}, [onChange, sharedPage]);
|
|
99
|
+
useImperativeHandle(ref, () => ({
|
|
100
|
+
setPage
|
|
101
|
+
}), [setPage]);
|
|
102
|
+
const pageStore = usePageStore(sharedPage);
|
|
45
103
|
const PageComponent = pageComponent;
|
|
46
|
-
return /*#__PURE__*/React.createElement(
|
|
104
|
+
return /*#__PURE__*/React.createElement(InternalContext.Provider, {
|
|
105
|
+
value: {
|
|
106
|
+
pageStore
|
|
107
|
+
}
|
|
108
|
+
}, /*#__PURE__*/React.createElement(RNViewPager, {
|
|
47
109
|
ref: pagerRef,
|
|
48
|
-
initialPage:
|
|
110
|
+
initialPage: sharedPage.initialValue,
|
|
49
111
|
keyboardDismissMode: keyboardDismissMode,
|
|
50
112
|
onPageSelected: handlePageSelected,
|
|
51
113
|
pageMargin: 8,
|
|
@@ -55,10 +117,11 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
55
117
|
key: index,
|
|
56
118
|
children: child,
|
|
57
119
|
index: index,
|
|
120
|
+
initialPage: sharedPage.initialValue,
|
|
58
121
|
loading: loading,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})));
|
|
122
|
+
offscreenPageRerenderLimit: offscreenPageRerenderLimit,
|
|
123
|
+
rerenderKey: pageForceRerenderKey
|
|
124
|
+
}))));
|
|
62
125
|
});
|
|
63
126
|
export default ViewPager;
|
|
64
127
|
//# sourceMappingURL=ViewPagerNative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","forwardRef","useCallback","useImperativeHandle","useRef","RNViewPager","
|
|
1
|
+
{"version":3,"names":["React","Children","forwardRef","useCallback","useEffect","useImperativeHandle","useRef","RNViewPager","useSyncAnimatedValue","defaultInitialPage","defaultLoading","defaultOffscreenPageRerenderLimit","defaultPageComponent","usePageStore","InternalContext","ViewPager","props","ref","children","initialPage","keyboardDismissMode","loading","offscreenPageRerenderLimit","onChange","pageComponent","pageForceRerenderKey","scrollEnabled","style","UNSTABLE_sharedPage","fallbackSharedPage","initialValue","sharedPage","pageRef","desiredPageRef","NaN","pagerRef","animationFrameRef","setPage","newPage","Number","isInteger","current","requestAnimationFrame","isFinite","cancelAnimationFrame","animatedValue","id","addListener","newValue","value","removeListener","handlePageSelected","e","desiredPage","setValue","trustfulNextPage","nativeEvent","position","pageStore","PageComponent","map","child","index"],"sources":["ViewPagerNative.tsx"],"sourcesContent":["import React, { Children, forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from 'react';\nimport type { ViewPagerOnPageSelectedEvent } from 'react-native-pager-view';\nimport RNViewPager from 'react-native-pager-view';\nimport { useSyncAnimatedValue } from '@fountain-ui/core';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './types';\nimport { defaultInitialPage, defaultLoading, defaultOffscreenPageRerenderLimit, defaultPageComponent } from './utils';\nimport usePageStore from './usePageStore';\nimport InternalContext from './InternalContext';\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n keyboardDismissMode = 'on-drag',\n loading = defaultLoading,\n offscreenPageRerenderLimit = defaultOffscreenPageRerenderLimit,\n onChange,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n scrollEnabled = true,\n style,\n UNSTABLE_sharedPage,\n } = props;\n\n const fallbackSharedPage = useSyncAnimatedValue({ initialValue: initialPage });\n\n const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;\n\n const pageRef = useRef<number>(sharedPage.initialValue);\n\n const desiredPageRef = useRef<number>(NaN);\n\n const pagerRef = useRef<RNViewPager | null>(null);\n\n const animationFrameRef = useRef<number>(NaN);\n\n const setPage = useCallback((newPage: number) => {\n if (!Number.isInteger(newPage)) {\n return;\n }\n\n animationFrameRef.current = requestAnimationFrame(() => {\n if (Number.isFinite(desiredPageRef.current)) {\n if (pageRef.current === desiredPageRef.current) {\n // end of state machine. clear desired page.\n desiredPageRef.current = NaN;\n return;\n }\n\n if (newPage === desiredPageRef.current) {\n return;\n }\n }\n\n desiredPageRef.current = newPage;\n pagerRef.current?.setPage(newPage);\n });\n }, []);\n\n useEffect(() => {\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current);\n }\n };\n }, []);\n\n useEffect(() => {\n const animatedValue = sharedPage.animatedValue;\n const id = animatedValue.addListener(newValue => {\n const newPage = newValue.value;\n pageRef.current = newPage;\n setPage(newPage);\n });\n\n return () => {\n animatedValue.removeListener(id);\n };\n }, [sharedPage]);\n\n const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {\n if (Number.isFinite(desiredPageRef.current)) {\n // onPageSelected is called from outer controlling mechanism\n // e.g. sharedPage.value is changed, setPage() is called\n // Due to the onPageSelected bug,\n // we don't trust the value from event, (e.nativeEvent.position)\n // other than that trust the value from desiredPageRef.\n\n const desiredPage = desiredPageRef.current;\n\n if (pageRef.current === desiredPage) {\n // end of state machine. clear desired page.\n desiredPageRef.current = NaN;\n } else {\n sharedPage.animatedValue.setValue(desiredPage);\n }\n\n onChange?.(desiredPage);\n } else {\n const trustfulNextPage = e.nativeEvent.position;\n\n if (trustfulNextPage !== pageRef.current) {\n desiredPageRef.current = trustfulNextPage;\n sharedPage.animatedValue.setValue(trustfulNextPage);\n }\n\n onChange?.(trustfulNextPage);\n }\n }, [onChange, sharedPage]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const pageStore = usePageStore(sharedPage);\n\n const PageComponent = pageComponent;\n\n return (\n <InternalContext.Provider value={{ pageStore }}>\n <RNViewPager\n ref={pagerRef}\n initialPage={sharedPage.initialValue}\n keyboardDismissMode={keyboardDismissMode}\n onPageSelected={handlePageSelected}\n pageMargin={8}\n scrollEnabled={scrollEnabled}\n style={style}\n >\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n initialPage={sharedPage.initialValue}\n loading={loading}\n offscreenPageRerenderLimit={offscreenPageRerenderLimit}\n rerenderKey={pageForceRerenderKey}\n />\n ))}\n </RNViewPager>\n </InternalContext.Provider>\n );\n});\n\nexport default ViewPager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,WAAtC,EAAmDC,SAAnD,EAA8DC,mBAA9D,EAAmFC,MAAnF,QAAiG,OAAjG;AAEA,OAAOC,WAAP,MAAw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ALb;IAMI,0BAA0B,EAAEC,0BANhC;IAOI,WAAW,EAAEG;EAPjB,EADH,CATL,CADJ,CADJ;AAyBH,CAxI2B,CAA5B;AA0IA,eAAeV,SAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ViewPagerProps.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"names":[],"sources":["ViewPagerProps.ts"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport type { ComponentProps, SyncAnimatedValue } from '@fountain-ui/core';\nimport type { KeyboardDismissMode, Loading, PageComponent, ViewPagerInstance } from './types';\n\nexport default interface ViewPagerProps extends ComponentProps<{\n ref?: Ref<ViewPagerInstance>;\n\n /**\n * Collection of ViewPager components.\n */\n children?: ReactNode;\n\n /**\n * Index of initial page that should be selected.\n * @default 0\n */\n initialPage?: number;\n\n /**\n * Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * Mobile only. The number of pages that should be re-rendered to either side of the current page.\n * Changing this value after the component mount has no effect.\n * @default 0\n */\n offscreenPageRerenderLimit?: number;\n\n /**\n * Callback fired when an index is changed.\n */\n onChange?: (newIndex: number) => void,\n\n /**\n * The component used to render the wrapper of the page.\n * @default 'ChildrenMemoizedPage'\n */\n pageComponent?: PageComponent,\n\n /**\n * When this value is changed, page will be rerender.\n */\n pageForceRerenderKey?: any;\n\n /**\n * Mobile only. Should pager view scroll, when scroll enabled.\n * @default true\n */\n scrollEnabled?: boolean;\n\n /**\n * Mobile only. Determines whether the keyboard gets dismissed in response to a drag.\n * @default 'on-drag'\n */\n keyboardDismissMode?: KeyboardDismissMode;\n\n /**\n * Unstable API.\n */\n UNSTABLE_sharedPage?: SyncAnimatedValue;\n}> {}\n"],"mappings":""}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { Children, forwardRef, useImperativeHandle } from 'react';
|
|
1
|
+
import React, { Children, forwardRef, useCallback, useImperativeHandle } from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
import { StyleSheet } from '@fountain-ui/core';
|
|
3
|
+
import { StyleSheet, useSyncAnimatedValue } from '@fountain-ui/core';
|
|
5
4
|
import { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';
|
|
5
|
+
import usePageStore from './usePageStore';
|
|
6
|
+
import InternalContext from './InternalContext';
|
|
6
7
|
const styles = StyleSheet.create({
|
|
7
8
|
root: {
|
|
8
9
|
// @ts-ignore
|
|
@@ -17,28 +18,37 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
17
18
|
loading = defaultLoading,
|
|
18
19
|
pageComponent = defaultPageComponent,
|
|
19
20
|
pageForceRerenderKey,
|
|
20
|
-
style
|
|
21
|
+
style,
|
|
22
|
+
UNSTABLE_sharedPage
|
|
21
23
|
} = props;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const fallbackSharedPage = useSyncAnimatedValue({
|
|
25
|
+
initialValue: initialPage
|
|
26
|
+
});
|
|
27
|
+
const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
|
|
28
|
+
const setPage = useCallback(newPage => {
|
|
29
|
+
sharedPage.animatedValue.setValue(newPage);
|
|
30
|
+
}, [sharedPage]);
|
|
28
31
|
useImperativeHandle(ref, () => ({
|
|
29
32
|
setPage
|
|
30
|
-
}), []);
|
|
33
|
+
}), [setPage]);
|
|
34
|
+
const pageStore = usePageStore(sharedPage);
|
|
31
35
|
const PageComponent = pageComponent;
|
|
32
|
-
return /*#__PURE__*/React.createElement(
|
|
36
|
+
return /*#__PURE__*/React.createElement(InternalContext.Provider, {
|
|
37
|
+
value: {
|
|
38
|
+
pageStore
|
|
39
|
+
}
|
|
40
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
33
41
|
style: [styles.root, style]
|
|
34
42
|
}, Children.map(children, (child, index) => /*#__PURE__*/React.createElement(PageComponent, {
|
|
35
43
|
key: index,
|
|
36
44
|
children: child,
|
|
37
45
|
index: index,
|
|
46
|
+
initialPage: sharedPage.initialValue,
|
|
38
47
|
loading: loading,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
offscreenPageRerenderLimit: 0 // All offscreen pages will not be re-rendered
|
|
49
|
+
,
|
|
50
|
+
rerenderKey: pageForceRerenderKey
|
|
51
|
+
}))));
|
|
42
52
|
});
|
|
43
53
|
export default ViewPager;
|
|
44
54
|
//# sourceMappingURL=ViewPagerWeb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","forwardRef","useImperativeHandle","View","
|
|
1
|
+
{"version":3,"names":["React","Children","forwardRef","useCallback","useImperativeHandle","View","StyleSheet","useSyncAnimatedValue","defaultInitialPage","defaultLoading","defaultPageComponent","usePageStore","InternalContext","styles","create","root","overflow","position","ViewPager","props","ref","children","initialPage","loading","pageComponent","pageForceRerenderKey","style","UNSTABLE_sharedPage","fallbackSharedPage","initialValue","sharedPage","setPage","newPage","animatedValue","setValue","pageStore","PageComponent","map","child","index"],"sources":["ViewPagerWeb.tsx"],"sourcesContent":["import React, { Children, forwardRef, useCallback, useImperativeHandle } from 'react';\nimport { View } from 'react-native';\nimport { StyleSheet, useSyncAnimatedValue } from '@fountain-ui/core';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './types';\nimport { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';\nimport usePageStore from './usePageStore';\nimport InternalContext from './InternalContext';\n\nconst styles = StyleSheet.create({\n root: {\n // @ts-ignore\n overflow: 'auto',\n position: 'relative',\n },\n});\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n loading = defaultLoading,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n style,\n UNSTABLE_sharedPage,\n } = props;\n\n const fallbackSharedPage = useSyncAnimatedValue({ initialValue: initialPage });\n\n const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;\n\n const setPage = useCallback((newPage: number) => {\n sharedPage.animatedValue.setValue(newPage);\n }, [sharedPage]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const pageStore = usePageStore(sharedPage);\n\n const PageComponent = pageComponent;\n\n return (\n <InternalContext.Provider value={{ pageStore }}>\n <View style={[styles.root, style]}>\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n initialPage={sharedPage.initialValue}\n loading={loading}\n offscreenPageRerenderLimit={0} // All offscreen pages will not be re-rendered\n rerenderKey={pageForceRerenderKey}\n />\n ))}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default ViewPager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,WAAtC,EAAmDC,mBAAnD,QAA8E,OAA9E;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,SAASC,UAAT,EAAqBC,oBAArB,QAAiD,mBAAjD;AAGA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,oBAA7C,QAAyE,SAAzE;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,MAAMC,MAAM,GAAGP,UAAU,CAACQ,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IACF;IACAC,QAAQ,EAAE,MAFR;IAGFC,QAAQ,EAAE;EAHR;AADuB,CAAlB,CAAf;AAQA,MAAMC,SAAS,gBAAGhB,UAAU,CAAoC,SAASgB,SAAT,CAAmBC,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGd,kBAFZ;IAGFe,OAAO,GAAGd,cAHR;IAIFe,aAAa,GAAGd,oBAJd;IAKFe,oBALE;IAMFC,KANE;IAOFC;EAPE,IAQFR,KARJ;EAUA,MAAMS,kBAAkB,GAAGrB,oBAAoB,CAAC;IAAEsB,YAAY,EAAEP;EAAhB,CAAD,CAA/C;EAEA,MAAMQ,UAAU,GAAGH,mBAAmB,IAAIC,kBAA1C;EAEA,MAAMG,OAAO,GAAG5B,WAAW,CAAE6B,OAAD,IAAqB;IAC7CF,UAAU,CAACG,aAAX,CAAyBC,QAAzB,CAAkCF,OAAlC;EACH,CAF0B,EAExB,CAACF,UAAD,CAFwB,CAA3B;EAIA1B,mBAAmB,CACfgB,GADe,EAEf,OAAO;IAAEW;EAAF,CAAP,CAFe,EAGf,CAACA,OAAD,CAHe,CAAnB;EAMA,MAAMI,SAAS,GAAGxB,YAAY,CAACmB,UAAD,CAA9B;EAEA,MAAMM,aAAa,GAAGZ,aAAtB;EAEA,oBACI,oBAAC,eAAD,CAAiB,QAAjB;IAA0B,KAAK,EAAE;MAAEW;IAAF;EAAjC,gBACI,oBAAC,IAAD;IAAM,KAAK,EAAE,CAACtB,MAAM,CAACE,IAAR,EAAcW,KAAd;EAAb,GACKzB,QAAQ,CAACoC,GAAT,CAAahB,QAAb,EAAuB,CAACiB,KAAD,EAAQC,KAAR,kBACpB,oBAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,WAAW,EAAET,UAAU,CAACD,YAJ5B;IAKI,OAAO,EAAEN,OALb;IAMI,0BAA0B,EAAE,CANhC,CAMmC;IANnC;IAOI,WAAW,EAAEE;EAPjB,EADH,CADL,CADJ,CADJ;AAiBH,CA9C2B,CAA5B;AAgDA,eAAeP,SAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './ViewPagerWeb';\nexport type { default as ViewPagerProps
|
|
1
|
+
{"version":3,"names":["default","useViewPagerPageState"],"sources":["index.ts"],"sourcesContent":["export { default } from './ViewPagerWeb';\nexport type { default as ViewPagerProps } from './ViewPagerProps';\nexport type { ViewPagerInstance } from './types';\nexport { useViewPagerPageState } from './PageStateContext';\n"],"mappings":"AAAA,SAASA,OAAT,QAAwB,gBAAxB;AAGA,SAASC,qBAAT,QAAsC,oBAAtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default"],"sources":["index.native.ts"],"sourcesContent":["export { default } from './ViewPagerNative';\n"],"mappings":"AAAA,SAASA,OAAT,QAAwB,mBAAxB"}
|
|
1
|
+
{"version":3,"names":["default","useViewPagerPageState"],"sources":["index.native.ts"],"sourcesContent":["export { default } from './ViewPagerNative';\nexport { useViewPagerPageState } from './PageStateContext';\n"],"mappings":"AAAA,SAASA,OAAT,QAAwB,mBAAxB;AACA,SAASC,qBAAT,QAAsC,oBAAtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ComponentType, PropsWithChildren } from 'react';\nimport type { ViewProps } from 'react-native';\n\nexport type PageProps = PropsWithChildren<ViewProps> & {\n index: number;\n initialPage: number;\n loading: Loading;\n offscreenPageRerenderLimit: number;\n rerenderKey?: any;\n};\n\nexport type KeyboardDismissMode = 'none' | 'on-drag';\n\nexport type PageComponent = ComponentType<PageProps>;\n\nexport type Loading = 'lazy' | 'eager';\n\nexport interface ViewPagerInstance {\n /**\n * Function to scroll to a specific page in the ViewPager. Invalid index is ignored.\n * @param index\n */\n setPage: (index: number) => void;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { SimpleStore } from '@fountain-ui/core';
|
|
3
|
+
export default function usePageStore(value) {
|
|
4
|
+
const {
|
|
5
|
+
animatedValue,
|
|
6
|
+
initialValue
|
|
7
|
+
} = value;
|
|
8
|
+
const store = useRef(new SimpleStore(initialValue)).current;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const id = animatedValue.addListener(newPage => {
|
|
11
|
+
store.dispatch(newPage.value);
|
|
12
|
+
});
|
|
13
|
+
return () => {
|
|
14
|
+
animatedValue.removeListener(id);
|
|
15
|
+
};
|
|
16
|
+
}, [animatedValue]);
|
|
17
|
+
return store;
|
|
18
|
+
}
|
|
19
|
+
;
|
|
20
|
+
//# sourceMappingURL=usePageStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","SimpleStore","usePageStore","value","animatedValue","initialValue","store","current","id","addListener","newPage","dispatch","removeListener"],"sources":["usePageStore.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { MonoStore, SyncAnimatedValue } from '@fountain-ui/core';\nimport { SimpleStore } from '@fountain-ui/core';\n\nexport default function usePageStore(value: SyncAnimatedValue): MonoStore<number> {\n const {\n animatedValue,\n initialValue,\n } = value;\n\n const store = useRef(new SimpleStore(initialValue)).current;\n\n useEffect(() => {\n const id = animatedValue.addListener((newPage) => {\n store.dispatch(newPage.value);\n });\n\n return () => {\n animatedValue.removeListener(id);\n };\n }, [animatedValue]);\n\n return store;\n};\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AAEA,SAASC,WAAT,QAA4B,mBAA5B;AAEA,eAAe,SAASC,YAAT,CAAsBC,KAAtB,EAAmE;EAC9E,MAAM;IACFC,aADE;IAEFC;EAFE,IAGFF,KAHJ;EAKA,MAAMG,KAAK,GAAGN,MAAM,CAAC,IAAIC,WAAJ,CAAgBI,YAAhB,CAAD,CAAN,CAAsCE,OAApD;EAEAR,SAAS,CAAC,MAAM;IACZ,MAAMS,EAAE,GAAGJ,aAAa,CAACK,WAAd,CAA2BC,OAAD,IAAa;MAC9CJ,KAAK,CAACK,QAAN,CAAeD,OAAO,CAACP,KAAvB;IACH,CAFU,CAAX;IAIA,OAAO,MAAM;MACTC,aAAa,CAACQ,cAAd,CAA6BJ,EAA7B;IACH,CAFD;EAGH,CARQ,EAQN,CAACJ,aAAD,CARM,CAAT;EAUA,OAAOE,KAAP;AACH;AAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ChildrenMemoizedPage from './ChildrenMemoizedPage';
|
|
2
2
|
export const defaultInitialPage = 0;
|
|
3
3
|
export const defaultLoading = 'lazy';
|
|
4
|
+
export const defaultOffscreenPageRerenderLimit = 0;
|
|
4
5
|
export const defaultPageComponent = ChildrenMemoizedPage;
|
|
5
6
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ChildrenMemoizedPage","defaultInitialPage","defaultLoading","defaultPageComponent"],"sources":["utils.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"names":["ChildrenMemoizedPage","defaultInitialPage","defaultLoading","defaultOffscreenPageRerenderLimit","defaultPageComponent"],"sources":["utils.tsx"],"sourcesContent":["import ChildrenMemoizedPage from './ChildrenMemoizedPage';\nimport type { Loading, PageComponent } from './types';\n\nexport const defaultInitialPage: number = 0;\n\nexport const defaultLoading: Loading = 'lazy';\n\nexport const defaultOffscreenPageRerenderLimit: number = 0;\n\nexport const defaultPageComponent: PageComponent = ChildrenMemoizedPage;\n"],"mappings":"AAAA,OAAOA,oBAAP,MAAiC,wBAAjC;AAGA,OAAO,MAAMC,kBAA0B,GAAG,CAAnC;AAEP,OAAO,MAAMC,cAAuB,GAAG,MAAhC;AAEP,OAAO,MAAMC,iCAAyC,GAAG,CAAlD;AAEP,OAAO,MAAMC,oBAAmC,GAAGJ,oBAA5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["Viewability.ts"],"sourcesContent":["export default interface Viewability {\n visible: boolean;\n}\n"],"mappings":""}
|