@fountain-ui/lab 2.0.0-beta.87 → 3.0.0-alpha.1

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.
Files changed (34) hide show
  1. package/build/commonjs/BottomSheet/BottomSheetNative.js +30 -91
  2. package/build/commonjs/BottomSheet/BottomSheetNative.js.map +1 -1
  3. package/build/commonjs/BottomSheet/BottomSheetProps.js.map +1 -1
  4. package/build/commonjs/BottomSheet/BottomSheetWeb.js +31 -82
  5. package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
  6. package/build/commonjs/BottomSheet/useDynamicSnapPoints.js +23 -9
  7. package/build/commonjs/BottomSheet/useDynamicSnapPoints.js.map +1 -1
  8. package/build/commonjs/DateTimePicker/DateTimePicker.js +2 -2
  9. package/build/commonjs/DateTimePicker/DateTimePicker.js.map +1 -1
  10. package/build/commonjs/DateTimePicker/YearPicker.js +2 -2
  11. package/build/commonjs/DateTimePicker/YearPicker.js.map +1 -1
  12. package/build/module/BottomSheet/BottomSheetNative.js +30 -84
  13. package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
  14. package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
  15. package/build/module/BottomSheet/BottomSheetWeb.js +34 -85
  16. package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
  17. package/build/module/BottomSheet/useDynamicSnapPoints.js +22 -9
  18. package/build/module/BottomSheet/useDynamicSnapPoints.js.map +1 -1
  19. package/build/module/DateTimePicker/DateTimePicker.js +2 -2
  20. package/build/module/DateTimePicker/DateTimePicker.js.map +1 -1
  21. package/build/module/DateTimePicker/YearPicker.js +2 -2
  22. package/build/module/DateTimePicker/YearPicker.js.map +1 -1
  23. package/build/typescript/BottomSheet/BottomSheetProps.d.ts +1 -14
  24. package/build/typescript/BottomSheet/useDynamicSnapPoints.d.ts +3 -2
  25. package/build/typescript/Carousel/Carousel.d.ts +1 -1
  26. package/build/typescript/ViewPager/ViewPager.d.ts +1 -1
  27. package/build/typescript/ViewPager/ViewPager.native.d.ts +1 -1
  28. package/package.json +5 -5
  29. package/src/BottomSheet/BottomSheetNative.tsx +26 -95
  30. package/src/BottomSheet/BottomSheetProps.ts +1 -17
  31. package/src/BottomSheet/BottomSheetWeb.tsx +34 -110
  32. package/src/BottomSheet/useDynamicSnapPoints.ts +24 -10
  33. package/src/DateTimePicker/DateTimePicker.tsx +2 -2
  34. package/src/DateTimePicker/YearPicker.tsx +2 -2
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = BottomSheet;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactNative = require("react-native");
11
11
 
@@ -19,66 +19,52 @@ var _TransparentBackdrop = _interopRequireDefault(require("./TransparentBackdrop
19
19
 
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
22
26
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
27
 
24
28
  const NoHandle = () => null;
25
29
 
26
- const createHeightLayoutHandler = setHeight => {
27
- return event => {
28
- const {
29
- height
30
- } = event.nativeEvent.layout;
31
- setHeight(height);
32
- };
33
- };
34
-
35
30
  function BottomSheet(props) {
36
31
  const {
37
32
  backdropOpacity = 0.5,
38
33
  borderRadius: borderRadiusProp,
39
34
  children,
40
35
  enableDynamicSizing = true,
41
- header,
42
- stickyBottomElement,
43
36
  topElement,
44
37
  index,
45
- maxHeightNormalizedRatio = 0.9,
38
+ maxHeightNormalizedRatio = 0.8,
46
39
  onChange,
47
- snapPoints = [],
48
- enableScrollableHeaderBorder = false
40
+ snapPoints = []
49
41
  } = props;
50
-
51
- const indexRef = _react.default.useRef(-1);
52
-
53
- const bottomSheetRef = _react.default.useRef(null);
54
-
42
+ const indexRef = (0, _react.useRef)(-1);
43
+ const bottomSheetRef = (0, _react.useRef)(null);
55
44
  const {
56
45
  height: windowHeight
57
46
  } = (0, _reactNative.useWindowDimensions)();
58
-
59
- const [isScrollable, setIsScrollable] = _react.default.useState(false);
60
-
61
- const [topElementHeight, setTopElementHeight] = _react.default.useState(0);
62
-
63
- const [stickyBottomElementHeight, setStickyBottomElementHeight] = _react.default.useState(0);
64
-
47
+ const [topElementHeight, setTopElementHeight] = (0, _react.useState)(0);
65
48
  const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;
66
- const handleTopElementLayout = createHeightLayoutHandler(setTopElementHeight);
67
- const handleStickyBottomElementLayout = createHeightLayoutHandler(setStickyBottomElementHeight);
68
49
 
69
- const handleChange = _react.default.useCallback(newIndex => {
50
+ const handleTopElementLayout = event => {
51
+ const {
52
+ height
53
+ } = event.nativeEvent.layout;
54
+ setTopElementHeight(height);
55
+ };
56
+
57
+ const handleChange = (0, _react.useCallback)(newIndex => {
70
58
  indexRef.current = newIndex;
71
59
 
72
60
  if (onChange) {
73
61
  onChange(newIndex);
74
62
  }
75
63
  }, [onChange]);
76
-
77
- const handleDismiss = _react.default.useCallback(() => {
64
+ const handleDismiss = (0, _react.useCallback)(() => {
78
65
  handleChange(-1);
79
66
  }, [handleChange]);
80
-
81
- _react.default.useEffect(() => {
67
+ (0, _react.useEffect)(() => {
82
68
  if (index === indexRef.current) {
83
69
  return;
84
70
  }
@@ -98,31 +84,20 @@ function BottomSheet(props) {
98
84
  (_bottomSheetRef$curre3 = bottomSheetRef.current) === null || _bottomSheetRef$curre3 === void 0 ? void 0 : _bottomSheetRef$curre3.snapToIndex(index);
99
85
  }
100
86
  }, [index]);
101
-
102
87
  const theme = (0, _styles.useTheme)();
103
- const shadow = theme.shadow[12];
104
- const borderRadius = borderRadiusProp ?? theme.shape.roundnessExtra;
105
- const modalStyle = {
106
- backgroundColor: '#ffffff00',
107
- borderTopLeftRadius: borderRadius,
108
- borderTopRightRadius: borderRadius,
109
- ..._reactNative.Platform.select({
110
- android: shadow === null || shadow === void 0 ? void 0 : shadow.elevation,
111
- ios: shadow === null || shadow === void 0 ? void 0 : shadow.shadow,
112
- web: shadow === null || shadow === void 0 ? void 0 : shadow.boxShadow
113
- })
114
- };
115
- const backgroundColor = theme.palette.paper.default;
88
+ const borderRadius = borderRadiusProp ?? theme.shape.radius.xxl;
116
89
  const backgroundStyle = {
117
- backgroundColor,
90
+ backgroundColor: theme.palette.surface.base,
118
91
  borderTopLeftRadius: borderRadius,
119
92
  borderTopRightRadius: borderRadius
120
93
  };
121
94
  const contentWrapperStyle = {
122
95
  flex: 1,
123
- borderTopLeftRadius: borderRadius,
124
- borderTopRightRadius: borderRadius,
125
- overflow: 'hidden'
96
+ maxHeight: maxDynamicContentSize,
97
+ minHeight: 300,
98
+ overflow: 'hidden',
99
+ paddingBottom: theme.spacing(6),
100
+ paddingTop: theme.spacing(5.5)
126
101
  };
127
102
  const isBackdropTransparent = backdropOpacity <= 0;
128
103
 
@@ -153,32 +128,6 @@ function BottomSheet(props) {
153
128
  }).start();
154
129
  };
155
130
 
156
- const handleContentSizeChange = (_, contentHeight) => {
157
- setIsScrollable(contentHeight > maxDynamicContentSize);
158
- };
159
-
160
- const headerStyle = {
161
- backgroundColor,
162
- ...(isScrollable && enableScrollableHeaderBorder ? {
163
- borderBottomWidth: 0.5,
164
- borderBottomColor: theme.palette.divider
165
- } : {})
166
- };
167
- const childrenStyle = {
168
- backgroundColor,
169
- paddingBottom: stickyBottomElementHeight
170
- };
171
- const stickyBottomElementShadow = (0, _core.useElevationStyle)(8);
172
- const stickyBottomElementStyle = {
173
- backgroundColor: theme.palette.paper.default,
174
- ...(isScrollable ? stickyBottomElementShadow : {})
175
- };
176
-
177
- const renderFooter = props => /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetFooter, props, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
178
- onLayout: handleStickyBottomElementLayout,
179
- style: stickyBottomElementStyle
180
- }, stickyBottomElement));
181
-
182
131
  return /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetModalProvider, null, /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetModal, {
183
132
  backdropComponent: isBackdropTransparent ? _TransparentBackdrop.default : OpacityAwareBackdrop // @ts-ignore
184
133
  ,
@@ -189,29 +138,19 @@ function BottomSheet(props) {
189
138
  onDismiss: handleDismiss,
190
139
  ref: bottomSheetRef,
191
140
  snapPoints: snapPoints,
192
- style: modalStyle,
193
141
  enablePanDownToClose: Boolean(onChange),
194
142
  enableDynamicSizing: enableDynamicSizing,
195
143
  maxDynamicContentSize: maxDynamicContentSize,
196
144
  detached: Boolean(topElement),
197
- onAnimate: topElement ? onAnimate : undefined,
198
- footerComponent: stickyBottomElement ? renderFooter : undefined
145
+ onAnimate: topElement ? onAnimate : undefined
199
146
  }, topElement ? /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
200
147
  style: topElementAnimationStyle
201
148
  }, /*#__PURE__*/_react.default.createElement(_core.Column, {
202
149
  onLayout: handleTopElementLayout,
203
150
  style: topElementLocationStyle
204
- }, topElement)) : null, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
151
+ }, topElement)) : null, /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetView, {
205
152
  style: contentWrapperStyle
206
- }, /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetScrollView, {
207
- bounces: false,
208
- stickyHeaderIndices: header ? [0] : undefined,
209
- onContentSizeChange: handleContentSizeChange
210
- }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
211
- style: headerStyle
212
- }, header), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
213
- style: childrenStyle
214
- }, children)))));
153
+ }, children)));
215
154
  }
216
155
 
217
156
  ;
@@ -1 +1 @@
1
- {"version":3,"names":["NoHandle","createHeightLayoutHandler","setHeight","event","height","nativeEvent","layout","BottomSheet","props","backdropOpacity","borderRadius","borderRadiusProp","children","enableDynamicSizing","header","stickyBottomElement","topElement","index","maxHeightNormalizedRatio","onChange","snapPoints","enableScrollableHeaderBorder","indexRef","React","useRef","bottomSheetRef","windowHeight","useWindowDimensions","isScrollable","setIsScrollable","useState","topElementHeight","setTopElementHeight","stickyBottomElementHeight","setStickyBottomElementHeight","maxDynamicContentSize","Math","round","handleTopElementLayout","handleStickyBottomElementLayout","handleChange","useCallback","newIndex","current","handleDismiss","useEffect","present","dismiss","snapToIndex","theme","useTheme","shadow","shape","roundnessExtra","modalStyle","backgroundColor","borderTopLeftRadius","borderTopRightRadius","Platform","select","android","elevation","ios","web","boxShadow","palette","paper","default","backgroundStyle","contentWrapperStyle","flex","overflow","isBackdropTransparent","OpacityAwareBackdrop","topElementOpacity","useAnimatedValue","topElementAnimationStyle","opacity","topElementLocationStyle","position","width","bottom","onAnimate","fromIndex","toIndex","isVisible","Animated","timing","toValue","duration","useNativeDriver","isNotAndroid12","start","handleContentSizeChange","_","contentHeight","headerStyle","borderBottomWidth","borderBottomColor","divider","childrenStyle","paddingBottom","stickyBottomElementShadow","useElevationStyle","stickyBottomElementStyle","renderFooter","TransparentBackdrop","Boolean","undefined"],"sources":["BottomSheetNative.tsx"],"sourcesContent":["import React from 'react';\nimport { Animated, LayoutChangeEvent, Platform, useWindowDimensions, View, ViewStyle } from 'react-native';\nimport {\n BottomSheetBackdrop,\n BottomSheetBackdropProps,\n BottomSheetFooter,\n BottomSheetFooterProps,\n BottomSheetModal,\n BottomSheetModalProvider,\n BottomSheetScrollView,\n} from '@gorhom/bottom-sheet';\nimport { Column, ExtendedStyle, isNotAndroid12, useAnimatedValue, useElevationStyle } from '@fountain-ui/core';\nimport { useTheme } from '@fountain-ui/styles';\nimport type BottomSheetProps from './BottomSheetProps';\nimport TransparentBackdrop from './TransparentBackdrop';\n\nconst NoHandle = () => null;\n\nconst createHeightLayoutHandler = (setHeight: React.Dispatch<React.SetStateAction<number>>) => {\n return (event: LayoutChangeEvent) => {\n const { height } = event.nativeEvent.layout;\n setHeight(height);\n };\n}\n\nexport default function BottomSheet(props: BottomSheetProps) {\n const {\n backdropOpacity = 0.5,\n borderRadius: borderRadiusProp,\n children,\n enableDynamicSizing = true,\n header,\n stickyBottomElement,\n topElement,\n index,\n maxHeightNormalizedRatio = 0.9,\n onChange,\n snapPoints = [],\n enableScrollableHeaderBorder = false,\n } = props;\n\n const indexRef = React.useRef<number>(-1);\n const bottomSheetRef = React.useRef<BottomSheetModal | null>(null);\n\n const { height: windowHeight } = useWindowDimensions();\n const [isScrollable, setIsScrollable] = React.useState(false);\n const [topElementHeight, setTopElementHeight] = React.useState(0);\n const [stickyBottomElementHeight, setStickyBottomElementHeight] = React.useState(0);\n\n const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;\n\n const handleTopElementLayout = createHeightLayoutHandler(setTopElementHeight);\n const handleStickyBottomElementLayout = createHeightLayoutHandler(setStickyBottomElementHeight);\n\n const handleChange = React.useCallback((newIndex: number) => {\n indexRef.current = newIndex;\n\n if (onChange) {\n onChange(newIndex);\n }\n }, [onChange]);\n\n const handleDismiss = React.useCallback(() => {\n handleChange(-1);\n }, [handleChange]);\n\n React.useEffect(() => {\n if (index === indexRef.current) {\n return;\n }\n\n if (indexRef.current < 0 && index >= 0) {\n bottomSheetRef.current?.present();\n } else if (indexRef.current >= 0 && index < 0) {\n bottomSheetRef.current?.dismiss();\n } else {\n // @ts-ignore\n bottomSheetRef.current?.snapToIndex(index);\n }\n }, [index]);\n\n const theme = useTheme();\n const shadow = theme.shadow[12];\n const borderRadius = borderRadiusProp ?? theme.shape.roundnessExtra;\n const modalStyle = {\n backgroundColor: '#ffffff00',\n borderTopLeftRadius: borderRadius,\n borderTopRightRadius: borderRadius,\n ...Platform.select<object>({\n android: shadow?.elevation,\n ios: shadow?.shadow,\n web: shadow?.boxShadow,\n }),\n };\n const backgroundColor = theme.palette.paper.default;\n const backgroundStyle = {\n backgroundColor,\n borderTopLeftRadius: borderRadius,\n borderTopRightRadius: borderRadius,\n };\n const contentWrapperStyle: ViewStyle = {\n flex: 1,\n borderTopLeftRadius: borderRadius,\n borderTopRightRadius: borderRadius,\n overflow: 'hidden',\n };\n\n const isBackdropTransparent = backdropOpacity <= 0;\n\n const OpacityAwareBackdrop = (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n appearsOnIndex={0}\n disappearsOnIndex={-1}\n opacity={backdropOpacity}\n pressBehavior={onChange ? 'close' : 'none'}\n />\n );\n\n const topElementOpacity = useAnimatedValue(0);\n const topElementAnimationStyle: Animated.WithAnimatedValue<ExtendedStyle> = { opacity: topElementOpacity };\n const topElementLocationStyle: ExtendedStyle = {\n position: 'absolute',\n width: '100%',\n bottom: 0,\n };\n const onAnimate = (fromIndex: number, toIndex: number) => {\n const isVisible = toIndex > -1;\n\n Animated.timing(topElementOpacity, {\n toValue: isVisible ? 1 : 0,\n duration: 0,\n useNativeDriver: isNotAndroid12,\n }).start();\n };\n\n const handleContentSizeChange = (_: number, contentHeight: number) => {\n setIsScrollable(contentHeight > maxDynamicContentSize);\n };\n\n const headerStyle = {\n backgroundColor,\n ...(isScrollable && enableScrollableHeaderBorder ? {\n borderBottomWidth: 0.5,\n borderBottomColor: theme.palette.divider,\n }: {})\n }\n\n const childrenStyle = {\n backgroundColor,\n paddingBottom: stickyBottomElementHeight,\n }\n\n const stickyBottomElementShadow = useElevationStyle(8);\n\n const stickyBottomElementStyle = {\n backgroundColor: theme.palette.paper.default,\n ...(isScrollable ? stickyBottomElementShadow : {}),\n }\n\n const renderFooter = (props: BottomSheetFooterProps) => (\n <BottomSheetFooter {...props}>\n <View\n onLayout={handleStickyBottomElementLayout}\n style={stickyBottomElementStyle}\n >\n {stickyBottomElement}\n </View>\n </BottomSheetFooter>\n );\n\n return (\n <BottomSheetModalProvider>\n <BottomSheetModal\n backdropComponent={isBackdropTransparent ? TransparentBackdrop : OpacityAwareBackdrop}\n // @ts-ignore\n backgroundStyle={backgroundStyle}\n index={index}\n handleComponent={NoHandle}\n onChange={handleChange}\n onDismiss={handleDismiss}\n ref={bottomSheetRef}\n snapPoints={snapPoints}\n style={modalStyle}\n enablePanDownToClose={Boolean(onChange)}\n enableDynamicSizing={enableDynamicSizing}\n maxDynamicContentSize={maxDynamicContentSize}\n detached={Boolean(topElement)}\n onAnimate={topElement ? onAnimate : undefined}\n footerComponent={stickyBottomElement ? renderFooter : undefined}\n >\n {topElement ? (\n <Animated.View style={topElementAnimationStyle}>\n <Column\n onLayout={handleTopElementLayout}\n style={topElementLocationStyle}\n >\n {topElement}\n </Column>\n </Animated.View>\n ) : null}\n\n <View style={contentWrapperStyle}>\n <BottomSheetScrollView\n bounces={false}\n stickyHeaderIndices={header ? [0] : undefined}\n onContentSizeChange={handleContentSizeChange}\n >\n <View style={headerStyle}>\n {header}\n </View>\n\n <View style={childrenStyle}>\n {children}\n </View>\n </BottomSheetScrollView>\n </View>\n </BottomSheetModal>\n </Bottom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B,QALrB;IAMI,QAAQ,EAAEwC,YANd;IAOI,SAAS,EAAEI,aAPf;IAQI,GAAG,EAAEnB,cART;IASI,UAAU,EAAEL,UAThB;IAUI,KAAK,EAAEkC,UAVX;IAWI,oBAAoB,EAAEqD,OAAO,CAACxF,QAAD,CAXjC;IAYI,mBAAmB,EAAEN,mBAZzB;IAaI,qBAAqB,EAAEsB,qBAb3B;IAcI,QAAQ,EAAEwE,OAAO,CAAC3F,UAAD,CAdrB;IAeI,SAAS,EAAEA,UAAU,GAAGkE,SAAH,GAAe0B,SAfxC;IAgBI,eAAe,EAAE7F,mBAAmB,GAAG0F,YAAH,GAAkBG;EAhB1D,GAkBK5F,UAAU,gBACP,6BAAC,qBAAD,CAAU,IAAV;IAAe,KAAK,EAAE4D;EAAtB,gBACI,6BAAC,YAAD;IACI,QAAQ,EAAEtC,sBADd;IAEI,KAAK,EAAEwC;EAFX,GAIK9D,UAJL,CADJ,CADO,GASP,IA3BR,eA6BI,6BAAC,iBAAD;IAAM,KAAK,EAAEqD;EAAb,gBACI,6BAAC,kCAAD;IACI,OAAO,EAAE,KADb;IAEI,mBAAmB,EAAEvD,MAAM,GAAG,CAAC,CAAD,CAAH,GAAS8F,SAFxC;IAGI,mBAAmB,EAAEf;EAHzB,gBAKI,6BAAC,iBAAD;IAAM,KAAK,EAAEG;EAAb,GACKlF,MADL,CALJ,eASI,6BAAC,iBAAD;IAAM,KAAK,EAAEsF;EAAb,GACKxF,QADL,CATJ,CADJ,CA7BJ,CADJ,CADJ;AAiDH;;AAAA"}
1
+ {"version":3,"names":["NoHandle","BottomSheet","props","backdropOpacity","borderRadius","borderRadiusProp","children","enableDynamicSizing","topElement","index","maxHeightNormalizedRatio","onChange","snapPoints","indexRef","useRef","bottomSheetRef","height","windowHeight","useWindowDimensions","topElementHeight","setTopElementHeight","useState","maxDynamicContentSize","Math","round","handleTopElementLayout","event","nativeEvent","layout","handleChange","useCallback","newIndex","current","handleDismiss","useEffect","present","dismiss","snapToIndex","theme","useTheme","shape","radius","xxl","backgroundStyle","backgroundColor","palette","surface","base","borderTopLeftRadius","borderTopRightRadius","contentWrapperStyle","flex","maxHeight","minHeight","overflow","paddingBottom","spacing","paddingTop","isBackdropTransparent","OpacityAwareBackdrop","topElementOpacity","useAnimatedValue","topElementAnimationStyle","opacity","topElementLocationStyle","position","width","bottom","onAnimate","fromIndex","toIndex","isVisible","Animated","timing","toValue","duration","useNativeDriver","isNotAndroid12","start","TransparentBackdrop","Boolean","undefined"],"sources":["BottomSheetNative.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { Animated, LayoutChangeEvent, useWindowDimensions, ViewStyle } from 'react-native';\nimport {\n BottomSheetBackdrop,\n BottomSheetBackdropProps,\n BottomSheetModal,\n BottomSheetModalProvider,\n BottomSheetView,\n} from '@gorhom/bottom-sheet';\nimport { Column, ExtendedStyle, isNotAndroid12, useAnimatedValue } from '@fountain-ui/core';\nimport { useTheme } from '@fountain-ui/styles';\nimport type BottomSheetProps from './BottomSheetProps';\nimport TransparentBackdrop from './TransparentBackdrop';\n\nconst NoHandle = () => null;\n\nexport default function BottomSheet(props: BottomSheetProps) {\n const {\n backdropOpacity = 0.5,\n borderRadius: borderRadiusProp,\n children,\n enableDynamicSizing = true,\n topElement,\n index,\n maxHeightNormalizedRatio = 0.8,\n onChange,\n snapPoints = [],\n } = props;\n\n const indexRef = useRef<number>(-1);\n const bottomSheetRef = useRef<BottomSheetModal | null>(null);\n\n const { height: windowHeight } = useWindowDimensions();\n const [topElementHeight, setTopElementHeight] = useState(0);\n\n const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;\n\n const handleTopElementLayout = (event: LayoutChangeEvent) => {\n const { height } = event.nativeEvent.layout;\n setTopElementHeight(height);\n };\n\n const handleChange = useCallback((newIndex: number) => {\n indexRef.current = newIndex;\n\n if (onChange) {\n onChange(newIndex);\n }\n }, [onChange]);\n\n const handleDismiss = useCallback(() => {\n handleChange(-1);\n }, [handleChange]);\n\n useEffect(() => {\n if (index === indexRef.current) {\n return;\n }\n\n if (indexRef.current < 0 && index >= 0) {\n bottomSheetRef.current?.present();\n } else if (indexRef.current >= 0 && index < 0) {\n bottomSheetRef.current?.dismiss();\n } else {\n // @ts-ignore\n bottomSheetRef.current?.snapToIndex(index);\n }\n }, [index]);\n\n const theme = useTheme();\n\n const borderRadius = borderRadiusProp ?? theme.shape.radius.xxl;\n const backgroundStyle = {\n backgroundColor: theme.palette.surface.base,\n borderTopLeftRadius: borderRadius,\n borderTopRightRadius: borderRadius,\n };\n\n const contentWrapperStyle: ViewStyle = {\n flex: 1,\n maxHeight: maxDynamicContentSize,\n minHeight: 300,\n overflow: 'hidden',\n paddingBottom: theme.spacing(6),\n paddingTop: theme.spacing(5.5),\n };\n\n const isBackdropTransparent = backdropOpacity <= 0;\n\n const OpacityAwareBackdrop = (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n appearsOnIndex={0}\n disappearsOnIndex={-1}\n opacity={backdropOpacity}\n pressBehavior={onChange ? 'close' : 'none'}\n />\n );\n\n const topElementOpacity = useAnimatedValue(0);\n const topElementAnimationStyle: Animated.WithAnimatedValue<ExtendedStyle> = { opacity: topElementOpacity };\n const topElementLocationStyle: ExtendedStyle = {\n position: 'absolute',\n width: '100%',\n bottom: 0,\n };\n const onAnimate = (fromIndex: number, toIndex: number) => {\n const isVisible = toIndex > -1;\n\n Animated.timing(topElementOpacity, {\n toValue: isVisible ? 1 : 0,\n duration: 0,\n useNativeDriver: isNotAndroid12,\n }).start();\n };\n\n return (\n <BottomSheetModalProvider>\n <BottomSheetModal\n backdropComponent={isBackdropTransparent ? TransparentBackdrop : OpacityAwareBackdrop}\n // @ts-ignore\n backgroundStyle={backgroundStyle}\n index={index}\n handleComponent={NoHandle}\n onChange={handleChange}\n onDismiss={handleDismiss}\n ref={bottomSheetRef}\n snapPoints={snapPoints}\n enablePanDownToClose={Boolean(onChange)}\n enableDynamicSizing={enableDynamicSizing}\n maxDynamicContentSize={maxDynamicContentSize}\n detached={Boolean(topElement)}\n onAnimate={topElement ? onAnimate : undefined}\n >\n {topElement ? (\n <Animated.View style={topElementAnimationStyle}>\n <Column\n onLayout={handleTopElementLayout}\n style={topElementLocationStyle}\n >\n {topElement}\n </Column>\n </Animated.View>\n ) : null}\n\n <BottomSheetView style={contentWrapperStyle}>\n {children}\n </BottomSheetView>\n </BottomSheetModal>\n </BottomSheetModalProvider>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAOA;;AACA;;AAEA;;;;;;;;;;AAEA,MAAMA,QAAQ,GAAG,MAAM,IAAvB;;AAEe,SAASC,WAAT,CAAqBC,KAArB,EAA8C;EACzD,MAAM;IACFC,eAAe,GAAG,GADhB;IAEFC,YAAY,EAAEC,gBAFZ;IAGFC,QAHE;IAIFC,mBAAmB,GAAG,IAJpB;IAKFC,UALE;IAMFC,KANE;IAOFC,wBAAwB,GAAG,GAPzB;IAQFC,QARE;IASFC,UAAU,GAAG;EATX,IAUFV,KAVJ;EAYA,MAAMW,QAAQ,GAAG,IAAAC,aAAA,EAAe,CAAC,CAAhB,CAAjB;EACA,MAAMC,cAAc,GAAG,IAAAD,aAAA,EAAgC,IAAhC,CAAvB;EAEA,MAAM;IAAEE,MAAM,EAAEC;EAAV,IAA2B,IAAAC,gCAAA,GAAjC;EACA,MAAM,CAACC,gBAAD,EAAmBC,mBAAnB,IAA0C,IAAAC,eAAA,EAAS,CAAT,CAAhD;EAEA,MAAMC,qBAAqB,GAAGC,IAAI,CAACC,KAAL,CAAWP,YAAY,GAAGP,wBAA1B,IAAsDS,gBAApF;;EAEA,MAAMM,sBAAsB,GAAIC,KAAD,IAA8B;IACzD,MAAM;MAAEV;IAAF,IAAaU,KAAK,CAACC,WAAN,CAAkBC,MAArC;IACAR,mBAAmB,CAACJ,MAAD,CAAnB;EACH,CAHD;;EAKA,MAAMa,YAAY,GAAG,IAAAC,kBAAA,EAAaC,QAAD,IAA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EAAElB,cART;IASI,UAAU,EAAEH,UAThB;IAUI,oBAAoB,EAAEoE,OAAO,CAACrE,QAAD,CAVjC;IAWI,mBAAmB,EAAEJ,mBAXzB;IAYI,qBAAqB,EAAEe,qBAZ3B;IAaI,QAAQ,EAAE0D,OAAO,CAACxE,UAAD,CAbrB;IAcI,SAAS,EAAEA,UAAU,GAAG4D,SAAH,GAAea;EAdxC,GAgBKzE,UAAU,gBACP,6BAAC,qBAAD,CAAU,IAAV;IAAe,KAAK,EAAEsD;EAAtB,gBACI,6BAAC,YAAD;IACI,QAAQ,EAAErC,sBADd;IAEI,KAAK,EAAEuC;EAFX,GAIKxD,UAJL,CADJ,CADO,GASP,IAzBR,eA2BI,6BAAC,4BAAD;IAAiB,KAAK,EAAE0C;EAAxB,GACK5C,QADL,CA3BJ,CADJ,CADJ;AAmCH;;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["BottomSheetProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ComponentProps } from '@fountain-ui/core';\n\nexport default interface BottomSheetProps extends ComponentProps<{\n /**\n * Opacity for BackdropComponent\n * @default 0.5\n */\n backdropOpacity?: number;\n\n /**\n * Border radius for bottom sheet\n */\n borderRadius?: number;\n\n /**\n * BottomSheet children, usually the included sub-components.\n */\n children?: React.ReactNode;\n\n /**\n * Enable dynamic sizing for content size.\n * @default true\n */\n enableDynamicSizing?: boolean;\n\n /**\n * Area to be fixed on the top of the bottom sheet.\n */\n header?: React.ReactNode;\n\n /**\n * If set to true, a border will be applied to the header area when the bottom sheet content is scrollable.\n * This visually separates the header from the scrollable content.\n */\n enableScrollableHeaderBorder?: boolean;\n\n /**\n * Area to be fixed on the bottom of the bottom sheet.\n */\n stickyBottomElement?: React.ReactNode;\n\n /**\n * Top element for displaying additional information on the bottom sheet.\n */\n topElement?: React.ReactNode;\n\n /**\n * Snap index. You could also provide -1 to bottom sheet in closed state.\n */\n index: number;\n\n /**\n * Maximum height(normalized value) of dialog\n * ex. 30% => 0.3 / 90% => 0.9\n * @default 0.9\n */\n maxHeightNormalizedRatio?: number;\n\n /**\n * Callback fired when the index is changed.\n * Important! Use memoized value.\n */\n onChange?: (newIndex: number) => void;\n\n /**\n * Points for the bottom sheet to snap to, points should be sorted from bottom to top.\n * Important! Use memoized value.\n * Only number type or string type(~% format) can be used.\n * @default []\n */\n snapPoints?: Array<number | string>;\n}> {}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["BottomSheetProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ComponentProps } from '@fountain-ui/core';\n\nexport default interface BottomSheetProps extends ComponentProps<{\n /**\n * Opacity for BackdropComponent\n * @default 0.5\n */\n backdropOpacity?: number;\n\n /**\n * Border radius for bottom sheet\n */\n borderRadius?: number;\n\n /**\n * BottomSheet children, usually the included sub-components.\n */\n children?: React.ReactNode;\n\n /**\n * Enable dynamic sizing for content size.\n * @default true\n */\n enableDynamicSizing?: boolean;\n\n /**\n * Top element for displaying additional information on the bottom sheet.\n */\n topElement?: React.ReactNode;\n\n /**\n * Snap index. You could also provide -1 to bottom sheet in closed state.\n */\n index: number;\n\n /**\n * Maximum height(normalized value) of dialog\n * ex. 30% => 0.3 / 90% => 0.9\n * @default 0.8\n */\n maxHeightNormalizedRatio?: number;\n\n /**\n * Callback fired when the index is changed.\n * Important! Use memoized value.\n */\n onChange?: (newIndex: number) => void;\n\n /**\n * Points for the bottom sheet to snap to, points should be sorted from bottom to top.\n * Important! Use memoized value.\n * Only number type or string type(~% format) can be used.\n * @default []\n */\n snapPoints?: Array<number | string>;\n}> {}\n"],"mappings":""}
@@ -21,18 +21,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
21
21
 
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
23
 
24
- const createHeightLayoutHandler = setHeight => {
25
- return event => {
26
- const {
27
- height
28
- } = event.nativeEvent.layout;
29
- setHeight(height);
30
- };
31
- };
32
-
33
24
  const useStyles = function () {
34
25
  const theme = (0, _core.useTheme)();
35
- const stickyBottomElementShadow = (0, _core.useElevationStyle)(8);
36
26
  return {
37
27
  root: {
38
28
  justifyContent: 'flex-end',
@@ -44,33 +34,20 @@ const useStyles = function () {
44
34
  width: '100%'
45
35
  },
46
36
  paper: {
47
- borderTopLeftRadius: theme.shape.roundnessExtra,
48
- borderTopRightRadius: theme.shape.roundnessExtra,
49
- borderBottomLeftRadius: 0,
50
- borderBottomRightRadius: 0,
37
+ backgroundColor: theme.palette.surface.base,
38
+ borderTopLeftRadius: theme.shape.radius.xxl,
39
+ borderTopRightRadius: theme.shape.radius.xxl,
51
40
  flexGrow: 1,
52
- overflow: 'hidden'
41
+ minHeight: 300,
42
+ overflow: 'hidden',
43
+ paddingBottom: theme.spacing(6),
44
+ paddingTop: theme.spacing(5.5)
53
45
  },
54
46
  topElementLocation: {
55
47
  position: 'absolute',
56
48
  bottom: 0,
57
49
  width: '100%'
58
- },
59
- headerContainer: {
60
- backgroundColor: theme.palette.paper.default
61
- },
62
- headerBorder: {
63
- borderBottomWidth: 0.5,
64
- borderBottomColor: theme.palette.divider
65
- },
66
- stickyBottomElement: {
67
- position: 'absolute',
68
- bottom: 0,
69
- left: 0,
70
- right: 0,
71
- backgroundColor: theme.palette.paper.default
72
- },
73
- stickyBottomElementShadow
50
+ }
74
51
  };
75
52
  };
76
53
 
@@ -80,26 +57,25 @@ function BottomSheet(props) {
80
57
  borderRadius,
81
58
  children,
82
59
  enableDynamicSizing = true,
83
- header,
84
- stickyBottomElement,
85
60
  topElement,
86
61
  index,
87
- maxHeightNormalizedRatio = 0.9,
62
+ maxHeightNormalizedRatio = 0.8,
88
63
  onChange,
89
- snapPoints = [],
90
- enableScrollableHeaderBorder = false
64
+ snapPoints = []
91
65
  } = props;
92
66
  const styles = useStyles();
93
67
  const {
94
68
  height: windowHeight
95
69
  } = (0, _reactNative.useWindowDimensions)();
96
70
  const [topElementHeight, setTopElementHeight] = (0, _react.useState)(0);
97
- const [stickyBottomElementHeight, setStickyBottomElementHeight] = (0, _react.useState)(0);
98
- const [contentHeight, setContentHeight] = (0, _react.useState)(0);
99
- const [isScrollable, setIsScrollable] = (0, _react.useState)(false);
100
71
  const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;
101
- const handleTopElementLayout = createHeightLayoutHandler(setTopElementHeight);
102
- const handleStickyBottomElementLayout = createHeightLayoutHandler(setStickyBottomElementHeight);
72
+
73
+ const handleTopElementLayout = event => {
74
+ const {
75
+ height
76
+ } = event.nativeEvent.layout;
77
+ setTopElementHeight(height);
78
+ };
103
79
 
104
80
  const handleClose = () => {
105
81
  if (onChange) {
@@ -109,64 +85,37 @@ function BottomSheet(props) {
109
85
 
110
86
  const {
111
87
  convertedSnapPoints,
112
- handleContentSizeChange,
88
+ handleLayout,
113
89
  highestSnapPoint
114
90
  } = (0, _useDynamicSnapPoints.default)({
115
91
  enableDynamicSizing,
116
- maxHeightNormalizedRatio,
92
+ maxDynamicContentSize,
117
93
  snapPoints
118
94
  });
119
95
  const translateY = highestSnapPoint - (convertedSnapPoints[index] ?? 0);
120
- const adjustedContentHeight = (0, _react.useMemo)(() => {
121
- const adjustedHighestSnapPoint = highestSnapPoint + stickyBottomElementHeight;
122
- return Math.min(maxDynamicContentSize, adjustedHighestSnapPoint);
123
- }, [highestSnapPoint, stickyBottomElementHeight]);
124
- const contentStyles = [styles.paper, borderRadius ? {
125
- borderTopLeftRadius: borderRadius,
126
- borderTopRightRadius: borderRadius
127
- } : {}, {
128
- height: adjustedContentHeight,
96
+ const contentStyles = (0, _core.css)([styles.paper, { ...(borderRadius ? {
97
+ borderTopLeftRadius: borderRadius,
98
+ borderTopRightRadius: borderRadius
99
+ } : {}),
100
+ ...(highestSnapPoint !== maxDynamicContentSize ? {
101
+ height: highestSnapPoint
102
+ } : {}),
129
103
  maxHeight: maxDynamicContentSize
130
- }];
131
- const headerStyles = [styles.headerContainer, isScrollable && enableScrollableHeaderBorder ? styles.headerBorder : {}];
132
- const stickyBottomElementStyles = [styles.stickyBottomElement, isScrollable ? styles.stickyBottomElementShadow : {}];
133
- (0, _react.useLayoutEffect)(() => {
134
- if (contentHeight === 0 || highestSnapPoint === 0) {
135
- return;
136
- }
137
-
138
- const adjustedHighestSnapPoint = highestSnapPoint + stickyBottomElementHeight;
139
- setIsScrollable(adjustedHighestSnapPoint > maxDynamicContentSize);
140
- }, [contentHeight, highestSnapPoint, stickyBottomElementHeight, maxDynamicContentSize]);
104
+ }]);
141
105
  return /*#__PURE__*/_react.default.createElement(_core.Modal, {
142
106
  backdropOpacity: backdropOpacity,
143
107
  onClose: handleClose,
144
108
  visible: index >= 0,
145
109
  style: (0, _core.css)([_core.StyleSheet.absoluteFill, styles.root])
146
110
  }, /*#__PURE__*/_react.default.createElement(_AnimatedY.default, {
147
- style: styles.animated,
148
111
  translateY: translateY
149
- }, topElement ? /*#__PURE__*/_react.default.createElement(_core.Column, null, /*#__PURE__*/_react.default.createElement(_core.Column, {
112
+ }, topElement ? /*#__PURE__*/_react.default.createElement(_core.Column, {
150
113
  onLayout: handleTopElementLayout,
151
114
  style: styles.topElementLocation
152
- }, topElement)) : null, /*#__PURE__*/_react.default.createElement(_core.Paper, {
153
- elevation: 12,
115
+ }, topElement) : null, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
116
+ onLayout: handleLayout,
154
117
  style: contentStyles
155
- }, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
156
- onContentSizeChange: (contentWidth, contentHeight) => {
157
- setContentHeight(contentHeight);
158
- handleContentSizeChange(contentWidth, contentHeight);
159
- },
160
- stickyHeaderIndices: header ? [0] : undefined,
161
- style: {
162
- paddingBottom: stickyBottomElementHeight
163
- }
164
- }, header ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
165
- style: headerStyles
166
- }, header) : null, children), stickyBottomElement ? /*#__PURE__*/_react.default.createElement(_core.Column, {
167
- style: stickyBottomElementStyles,
168
- onLayout: handleStickyBottomElementLayout
169
- }, stickyBottomElement) : null)));
118
+ }, children)));
170
119
  }
171
120
 
172
121
  ;
@@ -1 +1 @@
1
- {"version":3,"names":["createHeightLayoutHandler","setHeight","event","height","nativeEvent","layout","useStyles","theme","useTheme","stickyBottomElementShadow","useElevationStyle","root","justifyContent","zIndex","dialog","animated","alignSelf","maxWidth","width","paper","borderTopLeftRadius","shape","roundnessExtra","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","flexGrow","overflow","topElementLocation","position","bottom","headerContainer","backgroundColor","palette","default","headerBorder","borderBottomWidth","borderBottomColor","divider","stickyBottomElement","left","right","BottomSheet","props","backdropOpacity","borderRadius","children","enableDynamicSizing","header","topElement","index","maxHeightNormalizedRatio","onChange","snapPoints","enableScrollableHeaderBorder","styles","windowHeight","useWindowDimensions","topElementHeight","setTopElementHeight","useState","stickyBottomElementHeight","setStickyBottomElementHeight","contentHeight","setContentHeight","isScrollable","setIsScrollable","maxDynamicContentSize","Math","round","handleTopElementLayout","handleStickyBottomElementLayout","handleClose","convertedSnapPoints","handleContentSizeChange","highestSnapPoint","useDynamicSnapPoints","translateY","adjustedContentHeight","useMemo","adjustedHighestSnapPoint","min","contentStyles","maxHeight","headerStyles","stickyBottomElementStyles","useLayoutEffect","css","StyleSheet","absoluteFill","contentWidth","undefined","paddingBottom"],"sources":["BottomSheetWeb.tsx"],"sourcesContent":["import React, { useLayoutEffect, useMemo, useState } from 'react';\nimport { LayoutChangeEvent, ScrollView, useWindowDimensions, View } from 'react-native';\nimport { Column, css, Modal, Paper, StyleSheet, useElevationStyle, useTheme } from '@fountain-ui/core';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport AnimatedY from '../AnimatedY';\nimport type BottomSheetProps from './BottomSheetProps';\nimport useDynamicSnapPoints from './useDynamicSnapPoints';\n\nconst createHeightLayoutHandler = (setHeight: React.Dispatch<React.SetStateAction<number>>) => {\n return (event: LayoutChangeEvent) => {\n const { height } = event.nativeEvent.layout;\n setHeight(height);\n };\n}\n\ntype BottomSheetStyles = NamedStylesStringUnion<'root' | 'animated' | 'paper' | 'topElementLocation' | 'headerContainer' | 'headerBorder' | 'stickyBottomElement' | 'stickyBottomElementShadow'>;\n\nconst useStyles: UseStyles<BottomSheetStyles> = function (): BottomSheetStyles {\n const theme = useTheme();\n const stickyBottomElementShadow = useElevationStyle(8);\n\n return {\n root: {\n justifyContent: 'flex-end',\n zIndex: theme.zIndex.dialog,\n },\n animated: {\n alignSelf: 'center',\n maxWidth: 720,\n width: '100%',\n },\n paper: {\n borderTopLeftRadius: theme.shape.roundnessExtra,\n borderTopRightRadius: theme.shape.roundnessExtra,\n borderBottomLeftRadius: 0,\n borderBottomRightRadius: 0,\n flexGrow: 1,\n overflow: 'hidden',\n },\n topElementLocation: {\n position: 'absolute',\n bottom: 0,\n width: '100%',\n },\n headerContainer: {\n backgroundColor: theme.palette.paper.default,\n },\n headerBorder: {\n borderBottomWidth: 0.5,\n borderBottomColor: theme.palette.divider,\n },\n stickyBottomElement: {\n position: 'absolute',\n bottom: 0,\n left: 0,\n right: 0,\n backgroundColor: theme.palette.paper.default,\n },\n stickyBottomElementShadow,\n };\n};\n\nexport default function BottomSheet(props: BottomSheetProps) {\n const {\n backdropOpacity,\n borderRadius,\n children,\n enableDynamicSizing = true,\n header,\n stickyBottomElement,\n topElement,\n index,\n maxHeightNormalizedRatio = 0.9,\n onChange,\n snapPoints = [],\n enableScrollableHeaderBorder = false,\n } = props;\n\n const styles = useStyles();\n\n const { height: windowHeight } = useWindowDimensions();\n\n const [topElementHeight, setTopElementHeight] = useState(0);\n const [stickyBottomElementHeight, setStickyBottomElementHeight] = useState(0);\n const [contentHeight, setContentHeight] = useState(0);\n const [isScrollable, setIsScrollable] = useState(false);\n\n const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;\n\n const handleTopElementLayout = createHeightLayoutHandler(setTopElementHeight);\n const handleStickyBottomElementLayout = createHeightLayoutHandler(setStickyBottomElementHeight);\n\n const handleClose = () => {\n if (onChange) {\n onChange(-1);\n }\n };\n\n const {\n convertedSnapPoints,\n handleContentSizeChange,\n highestSnapPoint,\n } = useDynamicSnapPoints({\n enableDynamicSizing,\n maxHeightNormalizedRatio,\n snapPoints,\n });\n\n const translateY = highestSnapPoint - (convertedSnapPoints[index] ?? 0);\n\n const adjustedContentHeight = useMemo(() => {\n const adjustedHighestSnapPoint = highestSnapPoint + stickyBottomElementHeight;\n\n return Math.min(maxDynamicContentSize, adjustedHighestSnapPoint);\n }, [highestSnapPoint, stickyBottomElementHeight]);\n\n const contentStyles = [\n styles.paper,\n borderRadius ? { borderTopLeftRadius: borderRadius, borderTopRightRadius: borderRadius } : {},\n { height: adjustedContentHeight, maxHeight: maxDynamicContentSize },\n ];\n\n const headerStyles = [\n styles.headerContainer,\n isScrollable && enableScrollableHeaderBorder ? styles.headerBorder : {},\n ];\n\n const stickyBottomElementStyles = [\n styles.stickyBottomElement,\n isScrollable ? styles.stickyBottomElementShadow : {},\n ];\n\n useLayoutEffect(() => {\n if (contentHeight === 0 || highestSnapPoint === 0) {\n return;\n }\n\n const adjustedHighestSnapPoint = highestSnapPoint + stickyBottomElementHeight;\n setIsScrollable(adjustedHighestSnapPoint > maxDynamicContentSize);\n }, [contentHeight, highestSnapPoint, stickyBottomElementHeight, maxDynamicContentSize]);\n\n return (\n <Modal\n backdropOpacity={backdropOpacity}\n onClose={handleClose}\n visible={index >= 0}\n style={css([StyleSheet.absoluteFill, styles.root])}\n >\n <AnimatedY\n style={styles.animated}\n translateY={translateY}\n >\n {topElement ? (\n <Column>\n <Column\n onLayout={handleTopElementLayout}\n style={styles.topElementLocation}\n >\n {topElement}\n </Column>\n </Column>\n ) : null}\n\n <Paper\n elevation={12}\n style={contentStyles}\n >\n <ScrollView\n onContentSizeChange={(contentWidth: number, contentHeight: number) => {\n setContentHeight(contentHeight);\n handleContentSizeChange(contentWidth, contentHeight);\n }}\n stickyHeaderIndices={header ? [0] : undefined}\n style={{ paddingBottom: stickyBottomElementHeight }}\n >\n {header ? (\n <View style={headerStyles}>\n {header}\n </View>\n ): null}\n\n {children}\n </ScrollView>\n\n {stickyBottomElement ? (\n <Column\n style={stickyBottomElementStyles}\n onLayout={handleStickyBottomElementLayout}\n >\n {stickyBottomElement}\n </Column>\n ): null}\n </Paper>\n </AnimatedY>\n </Modal>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEA;;;;;;;;AAEA,MAAMA,yBAAyB,GAAIC,SAAD,IAA6D;EAC3F,OAAQC,KAAD,IAA8B;IACjC,MAAM;MAAEC;IAAF,IAAaD,KAAK,CAACE,WAAN,CAAkBC,MAArC;IACAJ,SAAS,CAACE,MAAD,CAAT;EACH,CAHD;AAIH,CALD;;AASA,MAAMG,SAAuC,GAAG,YAA+B;EAC3E,MAAMC,KAAK,GAAG,IAAAC,cAAA,GAAd;EACA,MAAMC,yBAAyB,GAAG,IAAAC,uBAAA,EAAkB,CAAlB,CAAlC;EAEA,OAAO;IACHC,IAAI,EAAE;MACFC,cAAc,EAAE,UADd;MAEFC,MAAM,EAAEN,KAAK,CAACM,MAAN,CAAaC;IAFnB,CADH;IAKHC,QAAQ,EAAE;MACNC,SAAS,EAAE,QADL;MAENC,QAAQ,EAAE,GAFJ;MAGNC,KAAK,EAAE;IAHD,CALP;IAUHC,KAAK,EAAE;MACHC,mBAAm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aAAvB,KAAiD;MAClEC,gBAAgB,CAACD,aAAD,CAAhB;MACAW,uBAAuB,CAACgB,YAAD,EAAe3B,aAAf,CAAvB;IACH,CAJL;IAKI,mBAAmB,EAAEf,MAAM,GAAG,CAAC,CAAD,CAAH,GAAS2C,SALxC;IAMI,KAAK,EAAE;MAAEC,aAAa,EAAE/B;IAAjB;EANX,GAQKb,MAAM,gBACH,6BAAC,iBAAD;IAAM,KAAK,EAAEoC;EAAb,GACKpC,MADL,CADG,GAIJ,IAZP,EAcKF,QAdL,CAJJ,EAqBKP,mBAAmB,gBAChB,6BAAC,YAAD;IACI,KAAK,EAAE8C,yBADX;IAEI,QAAQ,EAAEd;EAFd,GAIKhC,mBAJL,CADgB,GAOjB,IA5BP,CAfJ,CANJ,CADJ;AAuDH;;AAAA"}
1
+ {"version":3,"names":["useStyles","theme","useTheme","root","justifyContent","zIndex","dialog","animated","alignSelf","maxWidth","width","paper","backgroundColor","palette","surface","base","borderTopLeftRadius","shape","radius","xxl","borderTopRightRadius","flexGrow","minHeight","overflow","paddingBottom","spacing","paddingTop","topElementLocation","position","bottom","BottomSheet","props","backdropOpacity","borderRadius","children","enableDynamicSizing","topElement","index","maxHeightNormalizedRatio","onChange","snapPoints","styles","height","windowHeight","useWindowDimensions","topElementHeight","setTopElementHeight","useState","maxDynamicContentSize","Math","round","handleTopElementLayout","event","nativeEvent","layout","handleClose","convertedSnapPoints","handleLayout","highestSnapPoint","useDynamicSnapPoints","translateY","contentStyles","css","maxHeight","StyleSheet","absoluteFill"],"sources":["BottomSheetWeb.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { LayoutChangeEvent, useWindowDimensions, View } from 'react-native';\nimport { Column, css, Modal, StyleSheet, useTheme } from '@fountain-ui/core';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport AnimatedY from '../AnimatedY';\nimport type BottomSheetProps from './BottomSheetProps';\nimport useDynamicSnapPoints from './useDynamicSnapPoints';\n\ntype BottomSheetStyles = NamedStylesStringUnion<'root' | 'animated' | 'paper' | 'topElementLocation'>;\n\nconst useStyles: UseStyles<BottomSheetStyles> = function (): BottomSheetStyles {\n const theme = useTheme();\n\n return {\n root: {\n justifyContent: 'flex-end',\n zIndex: theme.zIndex.dialog,\n },\n animated: {\n alignSelf: 'center',\n maxWidth: 720,\n width: '100%',\n },\n paper: {\n backgroundColor: theme.palette.surface.base,\n borderTopLeftRadius: theme.shape.radius.xxl,\n borderTopRightRadius: theme.shape.radius.xxl,\n flexGrow: 1,\n minHeight: 300,\n overflow: 'hidden',\n paddingBottom: theme.spacing(6),\n paddingTop: theme.spacing(5.5),\n },\n topElementLocation: {\n position: 'absolute',\n bottom: 0,\n width: '100%',\n },\n };\n};\n\nexport default function BottomSheet(props: BottomSheetProps) {\n const {\n backdropOpacity,\n borderRadius,\n children,\n enableDynamicSizing = true,\n topElement,\n index,\n maxHeightNormalizedRatio = 0.8,\n onChange,\n snapPoints = [],\n } = props;\n\n const styles = useStyles();\n\n const { height: windowHeight } = useWindowDimensions();\n\n const [topElementHeight, setTopElementHeight] = useState(0);\n\n const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;\n\n const handleTopElementLayout = (event: LayoutChangeEvent) => {\n const { height } = event.nativeEvent.layout;\n setTopElementHeight(height);\n };\n\n const handleClose = () => {\n if (onChange) {\n onChange(-1);\n }\n };\n\n const {\n convertedSnapPoints,\n handleLayout,\n highestSnapPoint,\n } = useDynamicSnapPoints({\n enableDynamicSizing,\n maxDynamicContentSize,\n snapPoints,\n });\n\n const translateY = highestSnapPoint - (convertedSnapPoints[index] ?? 0);\n\n const contentStyles = css([\n styles.paper,\n {\n ...(borderRadius ? { borderTopLeftRadius: borderRadius, borderTopRightRadius: borderRadius } : {}),\n ...(highestSnapPoint !== maxDynamicContentSize ? { height: highestSnapPoint } : {}),\n maxHeight: maxDynamicContentSize,\n },\n ]);\n\n return (\n <Modal\n backdropOpacity={backdropOpacity}\n onClose={handleClose}\n visible={index >= 0}\n style={css([StyleSheet.absoluteFill, styles.root])}\n >\n <AnimatedY translateY={translateY}>\n {topElement ? (\n <Column\n onLayout={handleTopElementLayout}\n style={styles.topElementLocation}\n >\n {topElement}\n </Column>\n ) : null}\n\n <View\n onLayout={handleLayout}\n style={contentStyles}\n >\n {children}\n </View>\n </AnimatedY>\n </Modal>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEA;;;;;;;;AAIA,MAAMA,SAAuC,GAAG,YAA+B;EAC3E,MAAMC,KAAK,GAAG,IAAAC,cAAA,GAAd;EAEA,OAAO;IACHC,IAAI,EAAE;MACFC,cAAc,EAAE,UADd;MAEFC,MAAM,EAAEJ,KAAK,CAACI,MAAN,CAAaC;IAFnB,CADH;IAKHC,QAAQ,EAAE;MACNC,SAAS,EAAE,QADL;MAENC,QAAQ,EAAE,GAFJ;MAGNC,KAAK,EAAE;IAHD,CALP;IAUHC,KAAK,EAAE;MACHC,eAAe,EAAEX,KAAK,CAACY,OAAN,CAAcC,OAAd,CAAsBC,IADpC;MAEHC,mBAAmB,EAAEf,KAAK,CAACgB,KAAN,CAAYC,MAAZ,CAAmBC,GAFrC;MAGHC,oBAAoB,EAAEnB,KAAK,CAACgB,KAAN,CAAYC,MAAZ,CAAmBC,GAHtC;MAIHE,QAAQ,EAAE,CAJP;MAKHC,SAAS,EAAE,GALR;MAMHC,QAAQ,EAAE,QANP;MAOHC,aAAa,EAAEvB,KAAK,CAACwB,OAAN,CAAc,CAAd,CAPZ;MAQHC,UAAU,EAAEzB,KAAK,CAACwB,OAAN,CAAc,GAAd;IART,CAVJ;IAoBHE,kBAAkB,EAAE;MAChBC,QAAQ,EAAE,UADM;MAEhBC,MAAM,EAAE,CAFQ;MAGhBnB,KAAK,EAAE;IAHS;EApBjB,CAAP;AA0BH,CA7BD;;AA+Be,SAASoB,WAAT,CAAqBC,KAArB,EAA8C;EACzD,MAAM;IACFC,eADE;IAEFC,YAFE;IAGFC,QAH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AEf;EAHf,CAFsB,CAAJ,CAAtB;EASA,oBACI,6BAAC,WAAD;IACI,eAAe,EAAEhB,eADrB;IAEI,OAAO,EAAEuB,WAFb;IAGI,OAAO,EAAElB,KAAK,IAAI,CAHtB;IAII,KAAK,EAAE,IAAAyB,SAAA,EAAI,CAACE,gBAAA,CAAWC,YAAZ,EAA0BxB,MAAM,CAACtC,IAAjC,CAAJ;EAJX,gBAMI,6BAAC,kBAAD;IAAW,UAAU,EAAEyD;EAAvB,GACKxB,UAAU,gBACP,6BAAC,YAAD;IACI,QAAQ,EAAEe,sBADd;IAEI,KAAK,EAAEV,MAAM,CAACd;EAFlB,GAIKS,UAJL,CADO,GAOP,IARR,eAUI,6BAAC,iBAAD;IACI,QAAQ,EAAEqB,YADd;IAEI,KAAK,EAAEI;EAFX,GAIK3B,QAJL,CAVJ,CANJ,CADJ;AA0BH;;AAAA"}
@@ -5,16 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useDynamicSnapPoints;
7
7
 
8
- var R = _interopRequireWildcard(require("ramda"));
9
-
10
8
  var _react = require("react");
11
9
 
12
10
  var _reactNative = require("react-native");
13
11
 
12
+ var R = _interopRequireWildcard(require("ramda"));
13
+
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
 
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
 
18
+ const INITIAL_CONTAINER_HEIGHT = -999;
19
+
18
20
  const convertSnapPoint = (snapPoint, windowHeight, maxDynamicContentSize) => {
19
21
  if (typeof snapPoint === 'number') {
20
22
  return Math.min(maxDynamicContentSize, snapPoint);
@@ -33,15 +35,19 @@ const convertSnapPoint = (snapPoint, windowHeight, maxDynamicContentSize) => {
33
35
  function useDynamicSnapPoints(params) {
34
36
  const {
35
37
  enableDynamicSizing,
36
- maxHeightNormalizedRatio,
38
+ maxDynamicContentSize,
37
39
  snapPoints
38
40
  } = params;
39
41
  const {
40
42
  height: windowHeight
41
43
  } = (0, _reactNative.useWindowDimensions)();
42
- const [contentHeight, setContentHeight] = (0, _react.useState)(0);
44
+ const [contentHeight, setContentHeight] = (0, _react.useState)(INITIAL_CONTAINER_HEIGHT);
45
+ const hasMeasureRef = (0, _react.useRef)(false);
43
46
  const convertedSnapPoints = (0, _react.useMemo)(() => {
44
- const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio);
47
+ if (contentHeight === INITIAL_CONTAINER_HEIGHT) {
48
+ return [];
49
+ }
50
+
45
51
  const convertedSnapPoints = snapPoints.map(snapPoint => {
46
52
  return convertSnapPoint(snapPoint, windowHeight, maxDynamicContentSize);
47
53
  });
@@ -51,14 +57,22 @@ function useDynamicSnapPoints(params) {
51
57
  }
52
58
 
53
59
  return Array.from(new Set(convertedSnapPoints)).sort((a, b) => a - b);
54
- }, [contentHeight, snapPoints, windowHeight]);
55
- const highestSnapPoint = R.last(convertedSnapPoints) ?? 0;
56
- const handleContentSizeChange = (0, _react.useCallback)((_, height) => {
60
+ }, [contentHeight, enableDynamicSizing, maxDynamicContentSize, snapPoints, windowHeight]);
61
+ const highestSnapPoint = R.last(convertedSnapPoints) ?? maxDynamicContentSize;
62
+ const handleLayout = (0, _react.useCallback)(event => {
63
+ if (hasMeasureRef.current) {
64
+ return;
65
+ }
66
+
67
+ hasMeasureRef.current = true;
68
+ const {
69
+ height
70
+ } = event.nativeEvent.layout;
57
71
  setContentHeight(height);
58
72
  }, []);
59
73
  return {
60
74
  convertedSnapPoints,
61
- handleContentSizeChange,
75
+ handleLayout,
62
76
  highestSnapPoint
63
77
  };
64
78
  }
@@ -1 +1 @@
1
- {"version":3,"names":["convertSnapPoint","snapPoint","windowHeight","maxDynamicContentSize","Math","min","percentageRegex","RegExp","test","percentage","parseFloat","isNaN","round","useDynamicSnapPoints","params","enableDynamicSizing","maxHeightNormalizedRatio","snapPoints","height","useWindowDimensions","contentHeight","setContentHeight","useState","convertedSnapPoints","useMemo","map","push","Array","from","Set","sort","a","b","highestSnapPoint","R","last","handleContentSizeChange","useCallback","_"],"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;;AACA;;AACA;;;;;;AAcA,MAAMA,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;;AAce,SAASI,oBAAT,CAA8BC,MAA9B,EAA+F;EAC1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HEIGHT","convertSnapPoint","snapPoint","windowHeight","maxDynamicContentSize","Math","min","percentageRegex","RegExp","test","percentage","parseFloat","isNaN","round","useDynamicSnapPoints","params","enableDynamicSizing","snapPoints","height","useWindowDimensions","contentHeight","setContentHeight","useState","hasMeasureRef","useRef","convertedSnapPoints","useMemo","map","push","Array","from","Set","sort","a","b","highestSnapPoint","R","last","handleLayout","useCallback","event","current","nativeEvent","layout"],"sources":["useDynamicSnapPoints.ts"],"sourcesContent":["import { useCallback, useMemo, useRef, useState } from 'react';\nimport { LayoutChangeEvent, useWindowDimensions } from 'react-native';\nimport * as R from 'ramda';\n\nconst INITIAL_CONTAINER_HEIGHT = -999;\n\ninterface UseDynamicSnapPointsParams {\n enableDynamicSizing: boolean;\n maxDynamicContentSize: number;\n snapPoints: (number | string)[];\n}\n\ninterface UseDynamicSnapPointsReturns {\n convertedSnapPoints: number[];\n handleLayout: (e: LayoutChangeEvent) => 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 maxDynamicContentSize,\n snapPoints,\n } = params;\n\n const { height: windowHeight } = useWindowDimensions();\n\n const [contentHeight, setContentHeight] = useState<number>(INITIAL_CONTAINER_HEIGHT);\n\n const hasMeasureRef = useRef<boolean>(false);\n\n const convertedSnapPoints = useMemo(() => {\n if (contentHeight === INITIAL_CONTAINER_HEIGHT) {\n return [];\n }\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 enableDynamicSizing,\n maxDynamicContentSize,\n snapPoints,\n windowHeight,\n ]);\n\n const highestSnapPoint = R.last(convertedSnapPoints) ?? maxDynamicContentSize;\n\n const handleLayout = useCallback((event: LayoutChangeEvent) => {\n if (hasMeasureRef.current) {\n return;\n }\n\n hasMeasureRef.current = true;\n const { height } = event.nativeEvent.layout;\n setContentHeight(height);\n }, []);\n\n return {\n convertedSnapPoints,\n handleLayout,\n highestSnapPoint,\n };\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,MAAMA,wBAAwB,GAAG,CAAC,GAAlC;;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;;AAce,SAASI,oBAAT,CAA8BC,MAA9B,EAA+F;EAC1G,MAAM;IACFC,mBADE;IAEFZ,qBAFE;IAGFa;EA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C,MAArC;IACAtB,gBAAgB,CAACH,MAAD,CAAhB;EACH,CARoB,EAQlB,EARkB,CAArB;EAUA,OAAO;IACHO,mBADG;IAEHa,YAFG;IAGHH;EAHG,CAAP;AAKH"}
@@ -51,12 +51,12 @@ function DateTimePicker(props) {
51
51
 
52
52
  const LeftArrow = /*#__PURE__*/_react.default.createElement(_core.Typography, {
53
53
  children: '<',
54
- color: 'textPrimary'
54
+ color: 'strong'
55
55
  });
56
56
 
57
57
  const RightArrow = /*#__PURE__*/_react.default.createElement(_core.Typography, {
58
58
  children: '>',
59
- color: 'textPrimary'
59
+ color: 'strong'
60
60
  });
61
61
 
62
62
  const onYearPress = date => {