@fountain-ui/lab 2.0.0-beta.42 → 2.0.0-beta.44
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/BottomSheet/BottomSheetNative.js +24 -3
- package/build/commonjs/BottomSheet/BottomSheetNative.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetProps.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetWeb.js +24 -25
- package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
- package/build/commonjs/BottomSheet/useDynamicSnapPoints.js +37 -21
- package/build/commonjs/BottomSheet/useDynamicSnapPoints.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetNative.js +25 -5
- package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetWeb.js +24 -26
- package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
- package/build/module/BottomSheet/useDynamicSnapPoints.js +33 -22
- package/build/module/BottomSheet/useDynamicSnapPoints.js.map +1 -1
- package/build/typescript/BottomSheet/BottomSheetProps.d.ts +13 -1
- package/build/typescript/BottomSheet/useDynamicSnapPoints.d.ts +7 -6
- package/build/typescript/Carousel/Carousel.d.ts +1 -1
- package/build/typescript/ViewPager/ViewPager.d.ts +1 -1
- package/build/typescript/ViewPager/ViewPager.native.d.ts +1 -1
- package/package.json +4 -4
- package/src/BottomSheet/BottomSheetNative.tsx +28 -3
- package/src/BottomSheet/BottomSheetProps.ts +15 -1
- package/src/BottomSheet/BottomSheetWeb.tsx +31 -25
- package/src/BottomSheet/useDynamicSnapPoints.ts +49 -28
- package/build/commonjs/BottomSheet/BottomSheet.js +0 -177
- package/build/commonjs/BottomSheet/BottomSheet.js.map +0 -1
- package/build/module/BottomSheet/BottomSheet.js +0 -161
- package/build/module/BottomSheet/BottomSheet.js.map +0 -1
- package/build/typescript/BottomSheet/BottomSheet.d.ts +0 -2
- package/src/BottomSheet/BottomSheet.tsx +0 -184
|
@@ -1,41 +1,52 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
3
|
import { useWindowDimensions } from 'react-native';
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
if (typeof
|
|
6
|
-
return
|
|
5
|
+
const convertSnapPoint = (snapPoint, windowHeight, maxDynamicContentSize) => {
|
|
6
|
+
if (typeof snapPoint === 'number') {
|
|
7
|
+
return Math.min(maxDynamicContentSize, snapPoint);
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
const percentageRegex = new RegExp(/^[0-9]+%$/);
|
|
10
11
|
|
|
11
|
-
if (percentageRegex.test(
|
|
12
|
-
const percentage = parseFloat(
|
|
13
|
-
return isNaN(percentage) ? 0 : Math.round(windowHeight * percentage);
|
|
12
|
+
if (percentageRegex.test(snapPoint)) {
|
|
13
|
+
const percentage = parseFloat(snapPoint) / 100;
|
|
14
|
+
return isNaN(percentage) ? 0 : Math.min(maxDynamicContentSize, Math.round(windowHeight * percentage));
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
return 0;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export default function useDynamicSnapPoints(
|
|
20
|
+
export default function useDynamicSnapPoints(params) {
|
|
20
21
|
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
enableDynamicSizing,
|
|
23
|
+
maxHeightNormalizedRatio,
|
|
24
|
+
snapPoints
|
|
25
|
+
} = params;
|
|
24
26
|
const {
|
|
25
|
-
height:
|
|
27
|
+
height: windowHeight
|
|
26
28
|
} = useWindowDimensions();
|
|
27
|
-
const [
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const [contentHeight, setContentHeight] = useState(0);
|
|
30
|
+
const convertedSnapPoints = useMemo(() => {
|
|
31
|
+
const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio);
|
|
32
|
+
const convertedSnapPoints = snapPoints.map(snapPoint => {
|
|
33
|
+
return convertSnapPoint(snapPoint, windowHeight, maxDynamicContentSize);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (enableDynamicSizing && contentHeight !== 0) {
|
|
37
|
+
convertedSnapPoints.push(convertSnapPoint(contentHeight, windowHeight, maxDynamicContentSize));
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
|
|
40
|
+
return Array.from(new Set(convertedSnapPoints)).sort((a, b) => a - b);
|
|
41
|
+
}, [contentHeight, snapPoints, windowHeight]);
|
|
42
|
+
const highestSnapPoint = R.last(convertedSnapPoints) ?? 0;
|
|
43
|
+
const handleContentSizeChange = useCallback((_, height) => {
|
|
44
|
+
setContentHeight(height);
|
|
45
|
+
}, []);
|
|
36
46
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
convertedSnapPoints,
|
|
48
|
+
handleContentSizeChange,
|
|
49
|
+
highestSnapPoint
|
|
39
50
|
};
|
|
40
51
|
}
|
|
41
52
|
//# sourceMappingURL=useDynamicSnapPoints.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useState","useWindowDimensions","
|
|
1
|
+
{"version":3,"names":["R","useCallback","useMemo","useState","useWindowDimensions","convertSnapPoint","snapPoint","windowHeight","maxDynamicContentSize","Math","min","percentageRegex","RegExp","test","percentage","parseFloat","isNaN","round","useDynamicSnapPoints","params","enableDynamicSizing","maxHeightNormalizedRatio","snapPoints","height","contentHeight","setContentHeight","convertedSnapPoints","map","push","Array","from","Set","sort","a","b","highestSnapPoint","last","handleContentSizeChange","_"],"sources":["useDynamicSnapPoints.ts"],"sourcesContent":["import * as R from 'ramda';\nimport { useCallback, useMemo, useState } from 'react';\nimport { useWindowDimensions } from 'react-native';\n\ninterface UseDynamicSnapPointsParams {\n enableDynamicSizing: boolean;\n maxHeightNormalizedRatio: number;\n snapPoints: (number | string)[];\n}\n\ninterface UseDynamicSnapPointsReturns {\n convertedSnapPoints: number[];\n handleContentSizeChange: (w: number, h: number) => void;\n highestSnapPoint: number;\n}\n\nconst convertSnapPoint = (snapPoint: number | string, windowHeight: number, maxDynamicContentSize: number): number => {\n if (typeof snapPoint === 'number') {\n return Math.min(maxDynamicContentSize, snapPoint);\n }\n\n const percentageRegex = new RegExp(/^[0-9]+%$/);\n if (percentageRegex.test(snapPoint)) {\n const percentage = parseFloat(snapPoint) / 100;\n return isNaN(percentage) ? 0 : Math.min(maxDynamicContentSize, Math.round(windowHeight * percentage));\n }\n\n return 0;\n};\n\nexport default function useDynamicSnapPoints(params: UseDynamicSnapPointsParams): UseDynamicSnapPointsReturns {\n const {\n enableDynamicSizing,\n maxHeightNormalizedRatio,\n snapPoints,\n } = params;\n\n const { height: windowHeight } = useWindowDimensions();\n\n const [contentHeight, setContentHeight] = useState<number>(0);\n\n const convertedSnapPoints = useMemo(() => {\n const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio);\n\n const convertedSnapPoints = snapPoints.map((snapPoint) => {\n return convertSnapPoint(snapPoint, windowHeight, maxDynamicContentSize);\n });\n\n if (enableDynamicSizing && contentHeight !== 0) {\n convertedSnapPoints.push(\n convertSnapPoint(contentHeight, windowHeight, maxDynamicContentSize),\n );\n }\n\n return Array.from(new Set(convertedSnapPoints)).sort((a, b) => a - b);\n }, [\n contentHeight,\n snapPoints,\n windowHeight,\n ]);\n\n const highestSnapPoint = R.last(convertedSnapPoints) ?? 0;\n\n const handleContentSizeChange = useCallback((_: number, height: number) => {\n setContentHeight(height);\n }, []);\n\n return {\n convertedSnapPoints,\n handleContentSizeChange,\n highestSnapPoint,\n };\n}\n"],"mappings":"AAAA,OAAO,KAAKA,CAAZ,MAAmB,OAAnB;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,OAA/C;AACA,SAASC,mBAAT,QAAoC,cAApC;;AAcA,MAAMC,gBAAgB,GAAG,CAACC,SAAD,EAA6BC,YAA7B,EAAmDC,qBAAnD,KAA6F;EAClH,IAAI,OAAOF,SAAP,KAAqB,QAAzB,EAAmC;IAC/B,OAAOG,IAAI,CAACC,GAAL,CAASF,qBAAT,EAAgCF,SAAhC,CAAP;EACH;;EAED,MAAMK,eAAe,GAAG,IAAIC,MAAJ,CAAW,WAAX,CAAxB;;EACA,IAAID,eAAe,CAACE,IAAhB,CAAqBP,SAArB,CAAJ,EAAqC;IACjC,MAAMQ,UAAU,GAAGC,UAAU,CAACT,SAAD,CAAV,GAAwB,GAA3C;IACA,OAAOU,KAAK,CAACF,UAAD,CAAL,GAAoB,CAApB,GAAwBL,IAAI,CAACC,GAAL,CAASF,qBAAT,EAAgCC,IAAI,CAACQ,KAAL,CAAWV,YAAY,GAAGO,UAA1B,CAAhC,CAA/B;EACH;;EAED,OAAO,CAAP;AACH,CAZD;;AAcA,eAAe,SAASI,oBAAT,CAA8BC,MAA9B,EAA+F;EAC1G,MAAM;IACFC,mBADE;IAEFC,wBAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,MAAM;IAAEI,MAAM,EAAEhB;EAAV,IAA2BH,mBAAmB,EAApD;EAEA,MAAM,CAACoB,aAAD,EAAgBC,gBAAhB,IAAoCtB,QAAQ,CAAS,CAAT,CAAlD;EAEA,MAAMuB,mBAAmB,GAAGxB,OAAO,CAAC,MAAM;IACtC,MAAMM,qBAAqB,GAAGC,IAAI,CAACQ,KAAL,CAAWV,YAAY,GAAGc,wBAA1B,CAA9B;IAEA,MAAMK,mBAAmB,GAAGJ,UAAU,CAACK,GAAX,CAAgBrB,SAAD,IAAe;MACtD,OAAOD,gBAAgB,CAACC,SAAD,EAAYC,YAAZ,EAA0BC,qBAA1B,CAAvB;IACH,CAF2B,CAA5B;;IAIA,IAAIY,mBAAmB,IAAII,aAAa,KAAK,CAA7C,EAAgD;MAC5CE,mBAAmB,CAACE,IAApB,CACIvB,gBAAgB,CAACmB,aAAD,EAAgBjB,YAAhB,EAA8BC,qBAA9B,CADpB;IAGH;;IAED,OAAOqB,KAAK,CAACC,IAAN,CAAW,IAAIC,GAAJ,CAAQL,mBAAR,CAAX,EAAyCM,IAAzC,CAA8C,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,GAAGC,CAA5D,CAAP;EACH,CAdkC,EAchC,CACCV,aADD,EAECF,UAFD,EAGCf,YAHD,CAdgC,CAAnC;EAoBA,MAAM4B,gBAAgB,GAAGnC,CAAC,CAACoC,IAAF,CAAOV,mBAAP,KAA+B,CAAxD;EAEA,MAAMW,uBAAuB,GAAGpC,WAAW,CAAC,CAACqC,CAAD,EAAYf,MAAZ,KAA+B;IACvEE,gBAAgB,CAACF,MAAD,CAAhB;EACH,CAF0C,EAExC,EAFwC,CAA3C;EAIA,OAAO;IACHG,mBADG;IAEHW,uBAFG;IAGHF;EAHG,CAAP;AAKH"}
|
|
@@ -10,6 +10,11 @@ export default interface BottomSheetProps extends ComponentProps<{
|
|
|
10
10
|
* BottomSheet children, usually the included sub-components.
|
|
11
11
|
*/
|
|
12
12
|
children?: React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Enable dynamic sizing for content size.
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
enableDynamicSizing?: boolean;
|
|
13
18
|
/**
|
|
14
19
|
* Area to be fixed on the top of the bottom sheet.
|
|
15
20
|
*/
|
|
@@ -18,6 +23,12 @@ export default interface BottomSheetProps extends ComponentProps<{
|
|
|
18
23
|
* Snap index. You could also provide -1 to bottom sheet in closed state.
|
|
19
24
|
*/
|
|
20
25
|
index: number;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum height(normalized value) of dialog
|
|
28
|
+
* ex. 30% => 0.3 / 90% => 0.9
|
|
29
|
+
* @default 0.9
|
|
30
|
+
*/
|
|
31
|
+
maxHeightNormalizedRatio?: number;
|
|
21
32
|
/**
|
|
22
33
|
* Callback fired when the index is changed.
|
|
23
34
|
* Important! Use memoized value.
|
|
@@ -27,7 +38,8 @@ export default interface BottomSheetProps extends ComponentProps<{
|
|
|
27
38
|
* Points for the bottom sheet to snap to, points should be sorted from bottom to top.
|
|
28
39
|
* Important! Use memoized value.
|
|
29
40
|
* Only number type or string type(~% format) can be used.
|
|
41
|
+
* @default []
|
|
30
42
|
*/
|
|
31
|
-
snapPoints
|
|
43
|
+
snapPoints?: Array<number | string>;
|
|
32
44
|
}> {
|
|
33
45
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { LayoutChangeEvent } from 'react-native';
|
|
2
1
|
interface UseDynamicSnapPointsParams {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
enableDynamicSizing: boolean;
|
|
3
|
+
maxHeightNormalizedRatio: number;
|
|
4
|
+
snapPoints: (number | string)[];
|
|
5
5
|
}
|
|
6
6
|
interface UseDynamicSnapPointsReturns {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
convertedSnapPoints: number[];
|
|
8
|
+
handleContentSizeChange: (w: number, h: number) => void;
|
|
9
|
+
highestSnapPoint: number;
|
|
9
10
|
}
|
|
10
|
-
export default function useDynamicSnapPoints(
|
|
11
|
+
export default function useDynamicSnapPoints(params: UseDynamicSnapPointsParams): UseDynamicSnapPointsReturns;
|
|
11
12
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type CarouselProps from './CarouselProps';
|
|
3
3
|
import type { CarouselInstance } from './types';
|
|
4
|
-
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<CarouselProps<any>, "style" | "data" | "autoplay" | "autoplayInterval" | "createItemStyle" | "createScrollAnimation" | "disableSmartAutoplay" | "initialIndex" | "itemHeight" | "itemWidth" | "loop" | "onIndexChange" | "renderItem" | "
|
|
4
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<CarouselProps<any>, "style" | "data" | "scrollEnabled" | "autoplay" | "autoplayInterval" | "createItemStyle" | "createScrollAnimation" | "disableSmartAutoplay" | "initialIndex" | "itemHeight" | "itemWidth" | "loop" | "onIndexChange" | "renderItem" | "windowSize"> & React.RefAttributes<CarouselInstance>>>;
|
|
5
5
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type ViewPagerProps from './ViewPagerProps';
|
|
3
3
|
import type { ViewPagerInstance } from './types';
|
|
4
|
-
declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "
|
|
4
|
+
declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "keyboardDismissMode" | "scrollEnabled" | "initialPage" | "loading" | "offscreenPageRerenderLimit" | "pageForceRerenderKey" | "UNSTABLE_sharedPage"> & React.RefAttributes<ViewPagerInstance>>;
|
|
5
5
|
export default ViewPager;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type ViewPagerProps from './ViewPagerProps';
|
|
3
3
|
import type { ViewPagerInstance } from './types';
|
|
4
|
-
declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "
|
|
4
|
+
declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "keyboardDismissMode" | "scrollEnabled" | "initialPage" | "loading" | "offscreenPageRerenderLimit" | "pageForceRerenderKey" | "UNSTABLE_sharedPage"> & React.RefAttributes<ViewPagerInstance>>;
|
|
5
5
|
export default ViewPager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fountain-ui/lab",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.44",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Fountain-UI Team",
|
|
6
6
|
"description": "Incubator for Fountain-UI React components.",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@fountain-ui/core": "^2.0.0-beta.3",
|
|
26
|
-
"@gorhom/bottom-sheet": "^4.
|
|
26
|
+
"@gorhom/bottom-sheet": "^4.5.0",
|
|
27
27
|
"date-fns": "^2.0.0",
|
|
28
28
|
"react": "^16.8.0 || ^17.0.0",
|
|
29
29
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@gorhom/bottom-sheet": "4.
|
|
46
|
+
"@gorhom/bottom-sheet": "^4.5.0",
|
|
47
47
|
"date-fns": "^2.23.0",
|
|
48
48
|
"react-native-pager-view": "^4.2.4",
|
|
49
49
|
"react-native-safe-area-context": "^4.0.0"
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "d6c9346f8fd3675ac5096ee5caaad3f372f9def6"
|
|
74
74
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Platform } from 'react-native';
|
|
2
|
+
import { Platform, useWindowDimensions, View } from 'react-native';
|
|
3
3
|
import { useTheme } from '@fountain-ui/styles';
|
|
4
4
|
import {
|
|
5
5
|
BottomSheetBackdrop,
|
|
6
6
|
BottomSheetBackdropProps,
|
|
7
7
|
BottomSheetModal,
|
|
8
8
|
BottomSheetModalProvider,
|
|
9
|
+
BottomSheetScrollView,
|
|
9
10
|
} from '@gorhom/bottom-sheet';
|
|
10
11
|
import type BottomSheetProps from './BottomSheetProps';
|
|
11
12
|
import TransparentBackdrop from './TransparentBackdrop';
|
|
@@ -16,14 +17,20 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
16
17
|
const {
|
|
17
18
|
backdropOpacity = 0.5,
|
|
18
19
|
children,
|
|
20
|
+
enableDynamicSizing = true,
|
|
21
|
+
header,
|
|
19
22
|
index,
|
|
23
|
+
maxHeightNormalizedRatio = 0.9,
|
|
20
24
|
onChange,
|
|
21
|
-
snapPoints,
|
|
25
|
+
snapPoints = [],
|
|
22
26
|
} = props;
|
|
23
27
|
|
|
24
28
|
const indexRef = React.useRef<number>(-1);
|
|
25
29
|
const bottomSheetRef = React.useRef<BottomSheetModal | null>(null);
|
|
26
30
|
|
|
31
|
+
const { height: windowHeight } = useWindowDimensions();
|
|
32
|
+
const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio);
|
|
33
|
+
|
|
27
34
|
const handleChange = React.useCallback((newIndex: number) => {
|
|
28
35
|
indexRef.current = newIndex;
|
|
29
36
|
|
|
@@ -64,6 +71,12 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
64
71
|
const backgroundStyle = {
|
|
65
72
|
backgroundColor: theme.palette.paper.default,
|
|
66
73
|
};
|
|
74
|
+
const contentWrapperStyle = {
|
|
75
|
+
flex: 1,
|
|
76
|
+
borderTopLeftRadius: 15,
|
|
77
|
+
borderTopRightRadius: 15,
|
|
78
|
+
overflow: 'hidden',
|
|
79
|
+
};
|
|
67
80
|
|
|
68
81
|
const isBackdropTransparent = backdropOpacity <= 0;
|
|
69
82
|
|
|
@@ -91,8 +104,20 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
91
104
|
snapPoints={snapPoints}
|
|
92
105
|
style={modalStyle}
|
|
93
106
|
enablePanDownToClose={Boolean(onChange)}
|
|
107
|
+
enableDynamicSizing={enableDynamicSizing}
|
|
108
|
+
maxDynamicContentSize={maxDynamicContentSize}
|
|
94
109
|
>
|
|
95
|
-
{
|
|
110
|
+
{/* @ts-ignore */}
|
|
111
|
+
<View style={contentWrapperStyle}>
|
|
112
|
+
<BottomSheetScrollView
|
|
113
|
+
bounces={false}
|
|
114
|
+
stickyHeaderIndices={header ? [0] : undefined}
|
|
115
|
+
>
|
|
116
|
+
{header}
|
|
117
|
+
|
|
118
|
+
{children}
|
|
119
|
+
</BottomSheetScrollView>
|
|
120
|
+
</View>
|
|
96
121
|
</BottomSheetModal>
|
|
97
122
|
</BottomSheetModalProvider>
|
|
98
123
|
);
|
|
@@ -13,6 +13,12 @@ export default interface BottomSheetProps extends ComponentProps<{
|
|
|
13
13
|
*/
|
|
14
14
|
children?: React.ReactNode;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Enable dynamic sizing for content size.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
enableDynamicSizing?: boolean;
|
|
21
|
+
|
|
16
22
|
/**
|
|
17
23
|
* Area to be fixed on the top of the bottom sheet.
|
|
18
24
|
*/
|
|
@@ -23,6 +29,13 @@ export default interface BottomSheetProps extends ComponentProps<{
|
|
|
23
29
|
*/
|
|
24
30
|
index: number;
|
|
25
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Maximum height(normalized value) of dialog
|
|
34
|
+
* ex. 30% => 0.3 / 90% => 0.9
|
|
35
|
+
* @default 0.9
|
|
36
|
+
*/
|
|
37
|
+
maxHeightNormalizedRatio?: number;
|
|
38
|
+
|
|
26
39
|
/**
|
|
27
40
|
* Callback fired when the index is changed.
|
|
28
41
|
* Important! Use memoized value.
|
|
@@ -33,6 +46,7 @@ export default interface BottomSheetProps extends ComponentProps<{
|
|
|
33
46
|
* Points for the bottom sheet to snap to, points should be sorted from bottom to top.
|
|
34
47
|
* Important! Use memoized value.
|
|
35
48
|
* Only number type or string type(~% format) can be used.
|
|
49
|
+
* @default []
|
|
36
50
|
*/
|
|
37
|
-
snapPoints
|
|
51
|
+
snapPoints?: Array<number | string>;
|
|
38
52
|
}> {}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ScrollView } from 'react-native';
|
|
3
3
|
import { Modal, Paper, StyleSheet, css, useTheme } from '@fountain-ui/core';
|
|
4
4
|
import { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
|
|
5
5
|
import AnimatedY from '../AnimatedY';
|
|
6
6
|
import type BottomSheetProps from './BottomSheetProps';
|
|
7
|
+
import useDynamicSnapPoints from './useDynamicSnapPoints';
|
|
7
8
|
|
|
8
9
|
type BottomSheetStyles = NamedStylesStringUnion<'root' | 'animated' | 'paper'>;
|
|
9
10
|
|
|
@@ -29,41 +30,42 @@ const useStyles: UseStyles<BottomSheetStyles> = function (): BottomSheetStyles {
|
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
const convertHeightAsPixel = (windowHeight: number, value: number | string): number => {
|
|
33
|
-
if (typeof value === 'number') {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const percentageRegex = new RegExp(/^[0-9]+%$/);
|
|
38
|
-
if (percentageRegex.test(value)) {
|
|
39
|
-
const percentage = parseFloat(value) / 100;
|
|
40
|
-
return isNaN(percentage) ? 0 : Math.round(windowHeight * percentage);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return 0;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
33
|
export default function BottomSheet(props: BottomSheetProps) {
|
|
47
34
|
const {
|
|
48
35
|
backdropOpacity,
|
|
49
36
|
children,
|
|
37
|
+
enableDynamicSizing = true,
|
|
38
|
+
header,
|
|
50
39
|
index,
|
|
40
|
+
maxHeightNormalizedRatio = 0.9,
|
|
51
41
|
onChange,
|
|
52
|
-
snapPoints,
|
|
42
|
+
snapPoints = [],
|
|
53
43
|
} = props;
|
|
54
44
|
|
|
55
45
|
const styles = useStyles();
|
|
56
46
|
|
|
57
|
-
const { height: windowHeight } = useWindowDimensions();
|
|
58
|
-
|
|
59
47
|
const handleClose = () => {
|
|
60
48
|
if (onChange) {
|
|
61
49
|
onChange(-1);
|
|
62
50
|
}
|
|
63
51
|
};
|
|
64
52
|
|
|
65
|
-
const
|
|
66
|
-
|
|
53
|
+
const {
|
|
54
|
+
convertedSnapPoints,
|
|
55
|
+
handleContentSizeChange,
|
|
56
|
+
highestSnapPoint,
|
|
57
|
+
} = useDynamicSnapPoints({
|
|
58
|
+
enableDynamicSizing,
|
|
59
|
+
maxHeightNormalizedRatio,
|
|
60
|
+
snapPoints,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const translateY = highestSnapPoint - (convertedSnapPoints[index] ?? 0);
|
|
64
|
+
|
|
65
|
+
const paperStyles = [
|
|
66
|
+
styles.paper,
|
|
67
|
+
{ height: highestSnapPoint },
|
|
68
|
+
];
|
|
67
69
|
|
|
68
70
|
return (
|
|
69
71
|
<Modal
|
|
@@ -78,12 +80,16 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
78
80
|
>
|
|
79
81
|
<Paper
|
|
80
82
|
elevation={12}
|
|
81
|
-
style={
|
|
82
|
-
styles.paper,
|
|
83
|
-
{ height },
|
|
84
|
-
]}
|
|
83
|
+
style={paperStyles}
|
|
85
84
|
>
|
|
86
|
-
|
|
85
|
+
<ScrollView
|
|
86
|
+
onContentSizeChange={handleContentSizeChange}
|
|
87
|
+
stickyHeaderIndices={header ? [0] : undefined}
|
|
88
|
+
>
|
|
89
|
+
{header}
|
|
90
|
+
|
|
91
|
+
{children}
|
|
92
|
+
</ScrollView>
|
|
87
93
|
</Paper>
|
|
88
94
|
</AnimatedY>
|
|
89
95
|
</Modal>
|
|
@@ -1,52 +1,73 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { useWindowDimensions } from 'react-native';
|
|
3
4
|
|
|
4
5
|
interface UseDynamicSnapPointsParams {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
enableDynamicSizing: boolean;
|
|
7
|
+
maxHeightNormalizedRatio: number;
|
|
8
|
+
snapPoints: (number | string)[];
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
interface UseDynamicSnapPointsReturns {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
convertedSnapPoints: number[];
|
|
13
|
+
handleContentSizeChange: (w: number, h: number) => void;
|
|
14
|
+
highestSnapPoint: number;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
const
|
|
15
|
-
if (typeof
|
|
16
|
-
return
|
|
17
|
+
const convertSnapPoint = (snapPoint: number | string, windowHeight: number, maxDynamicContentSize: number): number => {
|
|
18
|
+
if (typeof snapPoint === 'number') {
|
|
19
|
+
return Math.min(maxDynamicContentSize, snapPoint);
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
const percentageRegex = new RegExp(/^[0-9]+%$/);
|
|
20
|
-
if (percentageRegex.test(
|
|
21
|
-
const percentage = parseFloat(
|
|
22
|
-
return isNaN(percentage) ? 0 : Math.round(windowHeight * percentage);
|
|
23
|
+
if (percentageRegex.test(snapPoint)) {
|
|
24
|
+
const percentage = parseFloat(snapPoint) / 100;
|
|
25
|
+
return isNaN(percentage) ? 0 : Math.min(maxDynamicContentSize, Math.round(windowHeight * percentage));
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
return 0;
|
|
26
29
|
};
|
|
27
30
|
|
|
28
|
-
export default function useDynamicSnapPoints(
|
|
31
|
+
export default function useDynamicSnapPoints(params: UseDynamicSnapPointsParams): UseDynamicSnapPointsReturns {
|
|
29
32
|
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
enableDynamicSizing,
|
|
34
|
+
maxHeightNormalizedRatio,
|
|
35
|
+
snapPoints,
|
|
36
|
+
} = params;
|
|
37
|
+
|
|
38
|
+
const { height: windowHeight } = useWindowDimensions();
|
|
33
39
|
|
|
34
|
-
const
|
|
40
|
+
const [contentHeight, setContentHeight] = useState<number>(0);
|
|
35
41
|
|
|
36
|
-
const
|
|
42
|
+
const convertedSnapPoints = useMemo(() => {
|
|
43
|
+
const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio);
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const convertedSnapPoints = snapPoints.map((snapPoint) => {
|
|
46
|
+
return convertSnapPoint(snapPoint, windowHeight, maxDynamicContentSize);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (enableDynamicSizing && contentHeight !== 0) {
|
|
50
|
+
convertedSnapPoints.push(
|
|
51
|
+
convertSnapPoint(contentHeight, windowHeight, maxDynamicContentSize),
|
|
52
|
+
);
|
|
45
53
|
}
|
|
46
|
-
}, [currentIndex, initialSnapPoints]);
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
return Array.from(new Set(convertedSnapPoints)).sort((a, b) => a - b);
|
|
56
|
+
}, [
|
|
57
|
+
contentHeight,
|
|
50
58
|
snapPoints,
|
|
59
|
+
windowHeight,
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const highestSnapPoint = R.last(convertedSnapPoints) ?? 0;
|
|
63
|
+
|
|
64
|
+
const handleContentSizeChange = useCallback((_: number, height: number) => {
|
|
65
|
+
setContentHeight(height);
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
convertedSnapPoints,
|
|
70
|
+
handleContentSizeChange,
|
|
71
|
+
highestSnapPoint,
|
|
51
72
|
};
|
|
52
73
|
}
|