@fountain-ui/lab 2.0.0-beta.13 → 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/ViewPager/ChildrenMemoizedPage.js +32 -35
- 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/ViewPagerNative.js +40 -16
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerWeb.js +19 -8
- package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/commonjs/ViewPager/index.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.map +1 -1
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +1 -1
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/module/ViewPager/ChildrenMemoizedPage.js +30 -33
- 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/ViewPagerNative.js +38 -16
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/module/ViewPager/ViewPagerWeb.js +16 -8
- package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/module/ViewPager/index.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.map +1 -1
- package/build/module/hooks/useUnstableCollapsibleAppBar.js +1 -1
- package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +1 -1
- package/build/typescript/ViewPager/InternalContext.d.ts +7 -0
- package/build/typescript/ViewPager/ViewPagerNative.d.ts +2 -2
- package/build/typescript/ViewPager/ViewPagerProps.d.ts +4 -22
- package/build/typescript/ViewPager/ViewPagerWeb.d.ts +2 -2
- package/build/typescript/ViewPager/index.d.ts +2 -1
- 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 +1 -1
- package/package.json +2 -2
- package/src/ViewPager/ChildrenMemoizedPage.tsx +30 -34
- package/src/ViewPager/InternalContext.ts +13 -0
- package/src/ViewPager/ViewPagerNative.tsx +52 -38
- package/src/ViewPager/ViewPagerProps.ts +4 -27
- package/src/ViewPager/ViewPagerWeb.tsx +23 -18
- package/src/ViewPager/index.ts +2 -1
- package/src/ViewPager/types.ts +24 -0
- package/src/ViewPager/usePageStore.ts +24 -0
- package/src/ViewPager/utils.tsx +1 -1
- package/src/hooks/useUnstableCollapsibleAppBar.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { memo, useMemo, 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
7
|
fill: {
|
|
8
8
|
width: '100%',
|
|
@@ -16,14 +16,17 @@ const styles = StyleSheet.create({
|
|
|
16
16
|
function Page(props) {
|
|
17
17
|
const {
|
|
18
18
|
index,
|
|
19
|
+
initialPage,
|
|
19
20
|
children,
|
|
20
21
|
loading,
|
|
21
|
-
offscreenPageRerenderLimit
|
|
22
|
-
sharedIndex
|
|
22
|
+
offscreenPageRerenderLimit
|
|
23
23
|
} = props;
|
|
24
|
+
const {
|
|
25
|
+
pageStore
|
|
26
|
+
} = useContext(InternalContext);
|
|
24
27
|
|
|
25
28
|
const assumeInitialPageState = () => {
|
|
26
|
-
const activeIndex =
|
|
29
|
+
const activeIndex = initialPage;
|
|
27
30
|
const isActive = index === activeIndex;
|
|
28
31
|
|
|
29
32
|
if (loading === 'eager') {
|
|
@@ -42,36 +45,30 @@ function Page(props) {
|
|
|
42
45
|
|
|
43
46
|
const [pageState, setPageState] = useState(assumeInitialPageState);
|
|
44
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
|
+
}
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const onBecomeNeighbor = () => {
|
|
54
|
-
setPageState(prevState => ({ ...prevState,
|
|
55
|
-
isLoaded: true
|
|
56
|
-
}));
|
|
57
|
-
};
|
|
62
|
+
if (becomeNeighbor && !prevState.isLoaded) {
|
|
63
|
+
return { ...prevState,
|
|
64
|
+
isLoaded: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const becomeNeighbor = shouldRerender && !isActive;
|
|
64
|
-
return {
|
|
65
|
-
isActive,
|
|
66
|
-
becomeNeighbor
|
|
67
|
-
};
|
|
68
|
-
}, (nextState, prevState) => {
|
|
69
|
-
if (nextState.isActive !== (prevState === null || prevState === void 0 ? void 0 : prevState.isActive)) {
|
|
70
|
-
runOnJS(onActiveStateChange)(nextState.isActive);
|
|
71
|
-
} else if (nextState.becomeNeighbor) {
|
|
72
|
-
runOnJS(onBecomeNeighbor)();
|
|
73
|
-
}
|
|
74
|
-
}, [index]);
|
|
68
|
+
return prevState;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}, [pageStore, index]);
|
|
75
72
|
const contextValue = useMemo(() => ({
|
|
76
73
|
isActive: pageState.isActive
|
|
77
74
|
}), [pageState.isActive]);
|
|
@@ -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,OAAtE;AACA,SAASC,QAAT,EAAmBC,IAAnB,QAA+B,cAA/B;AAC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,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"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React, { Children, forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from 'react';
|
|
2
2
|
import RNViewPager from 'react-native-pager-view';
|
|
3
|
-
import {
|
|
3
|
+
import { useSyncAnimatedValue } from '@fountain-ui/core';
|
|
4
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,
|
|
@@ -16,8 +18,11 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
16
18
|
style,
|
|
17
19
|
UNSTABLE_sharedPage
|
|
18
20
|
} = props;
|
|
19
|
-
const fallbackSharedPage =
|
|
21
|
+
const fallbackSharedPage = useSyncAnimatedValue({
|
|
22
|
+
initialValue: initialPage
|
|
23
|
+
});
|
|
20
24
|
const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
|
|
25
|
+
const pageRef = useRef(sharedPage.initialValue);
|
|
21
26
|
const desiredPageRef = useRef(NaN);
|
|
22
27
|
const pagerRef = useRef(null);
|
|
23
28
|
const animationFrameRef = useRef(NaN);
|
|
@@ -30,7 +35,7 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
30
35
|
var _pagerRef$current;
|
|
31
36
|
|
|
32
37
|
if (Number.isFinite(desiredPageRef.current)) {
|
|
33
|
-
if (
|
|
38
|
+
if (pageRef.current === desiredPageRef.current) {
|
|
34
39
|
// end of state machine. clear desired page.
|
|
35
40
|
desiredPageRef.current = NaN;
|
|
36
41
|
return;
|
|
@@ -52,9 +57,17 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
52
57
|
}
|
|
53
58
|
};
|
|
54
59
|
}, []);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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]);
|
|
58
71
|
const handlePageSelected = useCallback(e => {
|
|
59
72
|
if (Number.isFinite(desiredPageRef.current)) {
|
|
60
73
|
// onPageSelected is called from outer controlling mechanism
|
|
@@ -64,28 +77,37 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
64
77
|
// other than that trust the value from desiredPageRef.
|
|
65
78
|
const desiredPage = desiredPageRef.current;
|
|
66
79
|
|
|
67
|
-
if (
|
|
80
|
+
if (pageRef.current === desiredPage) {
|
|
68
81
|
// end of state machine. clear desired page.
|
|
69
82
|
desiredPageRef.current = NaN;
|
|
70
83
|
} else {
|
|
71
|
-
sharedPage.
|
|
84
|
+
sharedPage.animatedValue.setValue(desiredPage);
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
onChange === null || onChange === void 0 ? void 0 : onChange(desiredPage);
|
|
75
88
|
} else {
|
|
76
89
|
const trustfulNextPage = e.nativeEvent.position;
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
|
|
91
|
+
if (trustfulNextPage !== pageRef.current) {
|
|
92
|
+
desiredPageRef.current = trustfulNextPage;
|
|
93
|
+
sharedPage.animatedValue.setValue(trustfulNextPage);
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
onChange === null || onChange === void 0 ? void 0 : onChange(trustfulNextPage);
|
|
80
97
|
}
|
|
81
|
-
}, [onChange]);
|
|
98
|
+
}, [onChange, sharedPage]);
|
|
82
99
|
useImperativeHandle(ref, () => ({
|
|
83
100
|
setPage
|
|
84
101
|
}), [setPage]);
|
|
102
|
+
const pageStore = usePageStore(sharedPage);
|
|
85
103
|
const PageComponent = pageComponent;
|
|
86
|
-
return /*#__PURE__*/React.createElement(
|
|
104
|
+
return /*#__PURE__*/React.createElement(InternalContext.Provider, {
|
|
105
|
+
value: {
|
|
106
|
+
pageStore
|
|
107
|
+
}
|
|
108
|
+
}, /*#__PURE__*/React.createElement(RNViewPager, {
|
|
87
109
|
ref: pagerRef,
|
|
88
|
-
initialPage: sharedPage.
|
|
110
|
+
initialPage: sharedPage.initialValue,
|
|
89
111
|
keyboardDismissMode: keyboardDismissMode,
|
|
90
112
|
onPageSelected: handlePageSelected,
|
|
91
113
|
pageMargin: 8,
|
|
@@ -95,11 +117,11 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
95
117
|
key: index,
|
|
96
118
|
children: child,
|
|
97
119
|
index: index,
|
|
120
|
+
initialPage: sharedPage.initialValue,
|
|
98
121
|
loading: loading,
|
|
99
122
|
offscreenPageRerenderLimit: offscreenPageRerenderLimit,
|
|
100
|
-
rerenderKey: pageForceRerenderKey
|
|
101
|
-
|
|
102
|
-
})));
|
|
123
|
+
rerenderKey: pageForceRerenderKey
|
|
124
|
+
}))));
|
|
103
125
|
});
|
|
104
126
|
export default ViewPager;
|
|
105
127
|
//# sourceMappingURL=ViewPagerNative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","forwardRef","useCallback","useEffect","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,MAAwB,yBAAxB;AACA,SAASC,oBAAT,QAAqC,mBAArC;AAGA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,iCAA7C,EAAgFC,oBAAhF,QAA4G,SAA5G;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,MAAMC,SAAS,gBAAGb,UAAU,CAAoC,SAASa,SAAT,CAAmBC,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGV,kBAFZ;IAGFW,mBAAmB,GAAG,SAHpB;IAIFC,OAAO,GAAGX,cAJR;IAKFY,0BAA0B,GAAGX,iCAL3B;IAMFY,QANE;IAOFC,aAAa,GAAGZ,oBAPd;IAQFa,oBARE;IASFC,aAAa,GAA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AX,CA5BmC,CAAtC;EA8BA1B,mBAAmB,CACfY,GADe,EAEf,OAAO;IAAEoB;EAAF,CAAP,CAFe,EAGf,CAACA,OAAD,CAHe,CAAnB;EAMA,MAAMqB,SAAS,GAAG7C,YAAY,CAACkB,UAAD,CAA9B;EAEA,MAAM4B,aAAa,GAAGnC,aAAtB;EAEA,oBACI,oBAAC,eAAD,CAAiB,QAAjB;IAA0B,KAAK,EAAE;MAAEkC;IAAF;EAAjC,gBACI,oBAAC,WAAD;IACI,GAAG,EAAEvB,QADT;IAEI,WAAW,EAAEJ,UAAU,CAACD,YAF5B;IAGI,mBAAmB,EAAEV,mBAHzB;IAII,cAAc,EAAE+B,kBAJpB;IAKI,UAAU,EAAE,CALhB;IAMI,aAAa,EAAEzB,aANnB;IAOI,KAAK,EAAEC;EAPX,GASK1B,QAAQ,CAAC2D,GAAT,CAAa1C,QAAb,EAAuB,CAAC2C,KAAD,EAAQC,KAAR,kBACpB,oBAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,WAAW,EAAE/B,UAAU,CAACD,YAJ5B;IAKI,OAAO,EAAET,OALb;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
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
|
|
@@ -20,27 +21,34 @@ const ViewPager = /*#__PURE__*/forwardRef(function ViewPager(props, ref) {
|
|
|
20
21
|
style,
|
|
21
22
|
UNSTABLE_sharedPage
|
|
22
23
|
} = props;
|
|
23
|
-
const fallbackSharedPage =
|
|
24
|
+
const fallbackSharedPage = useSyncAnimatedValue({
|
|
25
|
+
initialValue: initialPage
|
|
26
|
+
});
|
|
24
27
|
const sharedPage = UNSTABLE_sharedPage ?? fallbackSharedPage;
|
|
25
28
|
const setPage = useCallback(newPage => {
|
|
26
|
-
sharedPage.
|
|
29
|
+
sharedPage.animatedValue.setValue(newPage);
|
|
27
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
48
|
offscreenPageRerenderLimit: 0 // All offscreen pages will not be re-rendered
|
|
40
49
|
,
|
|
41
|
-
rerenderKey: pageForceRerenderKey
|
|
42
|
-
|
|
43
|
-
})));
|
|
50
|
+
rerenderKey: pageForceRerenderKey
|
|
51
|
+
}))));
|
|
44
52
|
});
|
|
45
53
|
export default ViewPager;
|
|
46
54
|
//# sourceMappingURL=ViewPagerWeb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","forwardRef","useCallback","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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AAQ,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","useViewPagerPageState"],"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"}
|
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ChildrenMemoizedPage","defaultInitialPage","defaultLoading","defaultOffscreenPageRerenderLimit","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"}
|
|
@@ -165,7 +165,7 @@ export default function useUnstableCollapsibleAppBar() {
|
|
|
165
165
|
duration: ANIMATION_DURATION_MILLIS
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
-
}, []);
|
|
168
|
+
}, [appBarHeight]);
|
|
169
169
|
const hasCollapsible = collapsibleToolbarHeight > 0;
|
|
170
170
|
const appBarStyle = [animatedStyle, {
|
|
171
171
|
paddingTop: safeAreaInsets.top
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","Platform","useAnimatedScrollHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","useSafeAreaInsets","useAppbarStyles","useElevationStyle","useHeight","defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","safeAreaInsets","appBarHeight","onAppBarLayout","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","translateY","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","animatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","duration","savedOffsetY","scrollHandler","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,SAASA,MAAT,QAAuB,OAAvB;AACA,SAAgBC,QAAhB,QAAwF,cAAxF;AAEA,SACIC,wBADJ,EAEIC,gBAFJ,EAGIC,eAHJ,EAIIC,cAJJ,EAKIC,UALJ,QAMO,yBANP;AAOA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,SAAP,MAAsB,aAAtB;AA+BA,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gB,EAGhBH,cAAc,GAAG/C,MAAM,CAACmD,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHnC,OAFG;IAGHV,cAHG;IAIHG,0BAJG;IAKH2B,QAAQ,EAAEH,aALP;IAMHL,mBANG;IAOH4B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAG3C,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;AAAA"}
|
|
1
|
+
{"version":3,"names":["useRef","Platform","useAnimatedScrollHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","useSafeAreaInsets","useAppbarStyles","useElevationStyle","useHeight","defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","safeAreaInsets","appBarHeight","onAppBarLayout","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","translateY","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","animatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","duration","savedOffsetY","scrollHandler","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,SAASA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UAAU,CAACjB,KAAX,GAAmBX,UAAU,CAACkE,cAAD,EAAiB;QAC1ClB,QAAQ,EAAEzC;MADgC,CAAjB,CAA7B;IAGH;EApE0C,CAAD,EAqE3C,CAACe,YAAD,CArE2C,CAA9C;EAuEA,MAAM6C,cAAc,GAAG1C,wBAAwB,GAAG,CAAlD;EAEA,MAAM2C,WAAW,GAAG,CAChBjC,aADgB,EAEhB;IAAEkC,UAAU,EAAEhD,cAAc,CAACiD;EAA7B,CAFgB,EAGhBH,cAAc,GAAG/C,MAAM,CAACmD,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHnC,OAFG;IAGHV,cAHG;IAIHG,0BAJG;IAKH2B,QAAQ,EAAEH,aALP;IAMHL,mBANG;IAOH4B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAG3C,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { PageProps } from './
|
|
2
|
+
import type { PageProps } from './types';
|
|
3
3
|
declare function Page(props: PageProps): JSX.Element;
|
|
4
4
|
declare const _default: React.MemoExoticComponent<typeof Page>;
|
|
5
5
|
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { MonoStore } from '@fountain-ui/core';
|
|
3
|
+
export interface InternalContextValue {
|
|
4
|
+
pageStore: MonoStore<number>;
|
|
5
|
+
}
|
|
6
|
+
declare const InternalContext: import("react").Context<InternalContextValue>;
|
|
7
|
+
export default InternalContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type ViewPagerProps from './ViewPagerProps';
|
|
3
|
-
import type { ViewPagerInstance } from './
|
|
4
|
-
declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "scrollEnabled" | "keyboardDismissMode" | "
|
|
3
|
+
import type { ViewPagerInstance } from './types';
|
|
4
|
+
declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "scrollEnabled" | "keyboardDismissMode" | "initialPage" | "loading" | "offscreenPageRerenderLimit" | "pageComponent" | "pageForceRerenderKey" | "UNSTABLE_sharedPage"> & React.RefAttributes<ViewPagerInstance>>;
|
|
5
5
|
export default ViewPager;
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { ComponentProps } from '@fountain-ui/core';
|
|
5
|
-
export declare type KeyboardDismissMode = 'none' | 'on-drag';
|
|
6
|
-
export declare type PageProps = PropsWithChildren<ViewProps> & {
|
|
7
|
-
index: number;
|
|
8
|
-
loading: ViewPagerProps['loading'];
|
|
9
|
-
offscreenPageRerenderLimit: number;
|
|
10
|
-
sharedIndex: SharedValue<number>;
|
|
11
|
-
rerenderKey?: ViewPagerProps['pageForceRerenderKey'];
|
|
12
|
-
};
|
|
13
|
-
export declare type PageComponent = ComponentType<PageProps>;
|
|
14
|
-
export declare type Loading = 'lazy' | 'eager';
|
|
15
|
-
export interface ViewPagerInstance {
|
|
16
|
-
/**
|
|
17
|
-
* Function to scroll to a specific page in the ViewPager. Invalid index is ignored.
|
|
18
|
-
* @param index
|
|
19
|
-
*/
|
|
20
|
-
setPage: (index: number) => void;
|
|
21
|
-
}
|
|
1
|
+
import type { ReactNode, Ref } from 'react';
|
|
2
|
+
import type { ComponentProps, SyncAnimatedValue } from '@fountain-ui/core';
|
|
3
|
+
import type { KeyboardDismissMode, Loading, PageComponent, ViewPagerInstance } from './types';
|
|
22
4
|
export default interface ViewPagerProps extends ComponentProps<{
|
|
23
5
|
ref?: Ref<ViewPagerInstance>;
|
|
24
6
|
/**
|
|
@@ -67,6 +49,6 @@ export default interface ViewPagerProps extends ComponentProps<{
|
|
|
67
49
|
/**
|
|
68
50
|
* Unstable API.
|
|
69
51
|
*/
|
|
70
|
-
UNSTABLE_sharedPage?:
|
|
52
|
+
UNSTABLE_sharedPage?: SyncAnimatedValue;
|
|
71
53
|
}> {
|
|
72
54
|
}
|