@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.
- package/build/commonjs/BottomSheet/BottomSheetNative.js +30 -91
- package/build/commonjs/BottomSheet/BottomSheetNative.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetProps.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetWeb.js +31 -82
- package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
- package/build/commonjs/BottomSheet/useDynamicSnapPoints.js +23 -9
- package/build/commonjs/BottomSheet/useDynamicSnapPoints.js.map +1 -1
- package/build/commonjs/DateTimePicker/DateTimePicker.js +2 -2
- package/build/commonjs/DateTimePicker/DateTimePicker.js.map +1 -1
- package/build/commonjs/DateTimePicker/YearPicker.js +2 -2
- package/build/commonjs/DateTimePicker/YearPicker.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetNative.js +30 -84
- package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetWeb.js +34 -85
- package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
- package/build/module/BottomSheet/useDynamicSnapPoints.js +22 -9
- package/build/module/BottomSheet/useDynamicSnapPoints.js.map +1 -1
- package/build/module/DateTimePicker/DateTimePicker.js +2 -2
- package/build/module/DateTimePicker/DateTimePicker.js.map +1 -1
- package/build/module/DateTimePicker/YearPicker.js +2 -2
- package/build/module/DateTimePicker/YearPicker.js.map +1 -1
- package/build/typescript/BottomSheet/BottomSheetProps.d.ts +1 -14
- package/build/typescript/BottomSheet/useDynamicSnapPoints.d.ts +3 -2
- 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 +5 -5
- package/src/BottomSheet/BottomSheetNative.tsx +26 -95
- package/src/BottomSheet/BottomSheetProps.ts +1 -17
- package/src/BottomSheet/BottomSheetWeb.tsx +34 -110
- package/src/BottomSheet/useDynamicSnapPoints.ts +24 -10
- package/src/DateTimePicker/DateTimePicker.tsx +2 -2
- package/src/DateTimePicker/YearPicker.tsx +2 -2
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { LayoutChangeEvent,
|
|
3
|
-
import { Column, css, Modal,
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { LayoutChangeEvent, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { Column, css, Modal, StyleSheet, 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
7
|
import useDynamicSnapPoints from './useDynamicSnapPoints';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
return (event: LayoutChangeEvent) => {
|
|
11
|
-
const { height } = event.nativeEvent.layout;
|
|
12
|
-
setHeight(height);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type BottomSheetStyles = NamedStylesStringUnion<'root' | 'animated' | 'paper' | 'topElementLocation' | 'headerContainer' | 'headerBorder' | 'stickyBottomElement' | 'stickyBottomElementShadow'>;
|
|
9
|
+
type BottomSheetStyles = NamedStylesStringUnion<'root' | 'animated' | 'paper' | 'topElementLocation'>;
|
|
17
10
|
|
|
18
11
|
const useStyles: UseStyles<BottomSheetStyles> = function (): BottomSheetStyles {
|
|
19
12
|
const theme = useTheme();
|
|
20
|
-
const stickyBottomElementShadow = useElevationStyle(8);
|
|
21
13
|
|
|
22
14
|
return {
|
|
23
15
|
root: {
|
|
@@ -30,33 +22,20 @@ const useStyles: UseStyles<BottomSheetStyles> = function (): BottomSheetStyles {
|
|
|
30
22
|
width: '100%',
|
|
31
23
|
},
|
|
32
24
|
paper: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
borderBottomRightRadius: 0,
|
|
25
|
+
backgroundColor: theme.palette.surface.base,
|
|
26
|
+
borderTopLeftRadius: theme.shape.radius.xxl,
|
|
27
|
+
borderTopRightRadius: theme.shape.radius.xxl,
|
|
37
28
|
flexGrow: 1,
|
|
29
|
+
minHeight: 300,
|
|
38
30
|
overflow: 'hidden',
|
|
31
|
+
paddingBottom: theme.spacing(6),
|
|
32
|
+
paddingTop: theme.spacing(5.5),
|
|
39
33
|
},
|
|
40
34
|
topElementLocation: {
|
|
41
35
|
position: 'absolute',
|
|
42
36
|
bottom: 0,
|
|
43
37
|
width: '100%',
|
|
44
38
|
},
|
|
45
|
-
headerContainer: {
|
|
46
|
-
backgroundColor: theme.palette.paper.default,
|
|
47
|
-
},
|
|
48
|
-
headerBorder: {
|
|
49
|
-
borderBottomWidth: 0.5,
|
|
50
|
-
borderBottomColor: theme.palette.divider,
|
|
51
|
-
},
|
|
52
|
-
stickyBottomElement: {
|
|
53
|
-
position: 'absolute',
|
|
54
|
-
bottom: 0,
|
|
55
|
-
left: 0,
|
|
56
|
-
right: 0,
|
|
57
|
-
backgroundColor: theme.palette.paper.default,
|
|
58
|
-
},
|
|
59
|
-
stickyBottomElementShadow,
|
|
60
39
|
};
|
|
61
40
|
};
|
|
62
41
|
|
|
@@ -66,14 +45,11 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
66
45
|
borderRadius,
|
|
67
46
|
children,
|
|
68
47
|
enableDynamicSizing = true,
|
|
69
|
-
header,
|
|
70
|
-
stickyBottomElement,
|
|
71
48
|
topElement,
|
|
72
49
|
index,
|
|
73
|
-
maxHeightNormalizedRatio = 0.
|
|
50
|
+
maxHeightNormalizedRatio = 0.8,
|
|
74
51
|
onChange,
|
|
75
52
|
snapPoints = [],
|
|
76
|
-
enableScrollableHeaderBorder = false,
|
|
77
53
|
} = props;
|
|
78
54
|
|
|
79
55
|
const styles = useStyles();
|
|
@@ -81,14 +57,13 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
81
57
|
const { height: windowHeight } = useWindowDimensions();
|
|
82
58
|
|
|
83
59
|
const [topElementHeight, setTopElementHeight] = useState(0);
|
|
84
|
-
const [stickyBottomElementHeight, setStickyBottomElementHeight] = useState(0);
|
|
85
|
-
const [contentHeight, setContentHeight] = useState(0);
|
|
86
|
-
const [isScrollable, setIsScrollable] = useState(false);
|
|
87
60
|
|
|
88
61
|
const maxDynamicContentSize = Math.round(windowHeight * maxHeightNormalizedRatio) - topElementHeight;
|
|
89
62
|
|
|
90
|
-
const handleTopElementLayout =
|
|
91
|
-
|
|
63
|
+
const handleTopElementLayout = (event: LayoutChangeEvent) => {
|
|
64
|
+
const { height } = event.nativeEvent.layout;
|
|
65
|
+
setTopElementHeight(height);
|
|
66
|
+
};
|
|
92
67
|
|
|
93
68
|
const handleClose = () => {
|
|
94
69
|
if (onChange) {
|
|
@@ -98,46 +73,24 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
98
73
|
|
|
99
74
|
const {
|
|
100
75
|
convertedSnapPoints,
|
|
101
|
-
|
|
76
|
+
handleLayout,
|
|
102
77
|
highestSnapPoint,
|
|
103
78
|
} = useDynamicSnapPoints({
|
|
104
79
|
enableDynamicSizing,
|
|
105
|
-
|
|
80
|
+
maxDynamicContentSize,
|
|
106
81
|
snapPoints,
|
|
107
82
|
});
|
|
108
83
|
|
|
109
84
|
const translateY = highestSnapPoint - (convertedSnapPoints[index] ?? 0);
|
|
110
85
|
|
|
111
|
-
const
|
|
112
|
-
const adjustedHighestSnapPoint = highestSnapPoint + stickyBottomElementHeight;
|
|
113
|
-
|
|
114
|
-
return Math.min(maxDynamicContentSize, adjustedHighestSnapPoint);
|
|
115
|
-
}, [highestSnapPoint, stickyBottomElementHeight]);
|
|
116
|
-
|
|
117
|
-
const contentStyles = [
|
|
86
|
+
const contentStyles = css([
|
|
118
87
|
styles.paper,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
isScrollable && enableScrollableHeaderBorder ? styles.headerBorder : {},
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
const stickyBottomElementStyles = [
|
|
129
|
-
styles.stickyBottomElement,
|
|
130
|
-
isScrollable ? styles.stickyBottomElementShadow : {},
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
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]);
|
|
88
|
+
{
|
|
89
|
+
...(borderRadius ? { borderTopLeftRadius: borderRadius, borderTopRightRadius: borderRadius } : {}),
|
|
90
|
+
...(highestSnapPoint !== maxDynamicContentSize ? { height: highestSnapPoint } : {}),
|
|
91
|
+
maxHeight: maxDynamicContentSize,
|
|
92
|
+
},
|
|
93
|
+
]);
|
|
141
94
|
|
|
142
95
|
return (
|
|
143
96
|
<Modal
|
|
@@ -146,51 +99,22 @@ export default function BottomSheet(props: BottomSheetProps) {
|
|
|
146
99
|
visible={index >= 0}
|
|
147
100
|
style={css([StyleSheet.absoluteFill, styles.root])}
|
|
148
101
|
>
|
|
149
|
-
<AnimatedY
|
|
150
|
-
style={styles.animated}
|
|
151
|
-
translateY={translateY}
|
|
152
|
-
>
|
|
102
|
+
<AnimatedY translateY={translateY}>
|
|
153
103
|
{topElement ? (
|
|
154
|
-
<Column
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
{topElement}
|
|
160
|
-
</Column>
|
|
104
|
+
<Column
|
|
105
|
+
onLayout={handleTopElementLayout}
|
|
106
|
+
style={styles.topElementLocation}
|
|
107
|
+
>
|
|
108
|
+
{topElement}
|
|
161
109
|
</Column>
|
|
162
110
|
) : null}
|
|
163
111
|
|
|
164
|
-
<
|
|
165
|
-
|
|
112
|
+
<View
|
|
113
|
+
onLayout={handleLayout}
|
|
166
114
|
style={contentStyles}
|
|
167
115
|
>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
setContentHeight(contentHeight);
|
|
171
|
-
handleContentSizeChange(contentWidth, contentHeight);
|
|
172
|
-
}}
|
|
173
|
-
stickyHeaderIndices={header ? [0] : undefined}
|
|
174
|
-
style={{ paddingBottom: stickyBottomElementHeight }}
|
|
175
|
-
>
|
|
176
|
-
{header ? (
|
|
177
|
-
<View style={headerStyles}>
|
|
178
|
-
{header}
|
|
179
|
-
</View>
|
|
180
|
-
): null}
|
|
181
|
-
|
|
182
|
-
{children}
|
|
183
|
-
</ScrollView>
|
|
184
|
-
|
|
185
|
-
{stickyBottomElement ? (
|
|
186
|
-
<Column
|
|
187
|
-
style={stickyBottomElementStyles}
|
|
188
|
-
onLayout={handleStickyBottomElementLayout}
|
|
189
|
-
>
|
|
190
|
-
{stickyBottomElement}
|
|
191
|
-
</Column>
|
|
192
|
-
): null}
|
|
193
|
-
</Paper>
|
|
116
|
+
{children}
|
|
117
|
+
</View>
|
|
194
118
|
</AnimatedY>
|
|
195
119
|
</Modal>
|
|
196
120
|
);
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { LayoutChangeEvent, useWindowDimensions } from 'react-native';
|
|
1
3
|
import * as R from 'ramda';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
const INITIAL_CONTAINER_HEIGHT = -999;
|
|
4
6
|
|
|
5
7
|
interface UseDynamicSnapPointsParams {
|
|
6
8
|
enableDynamicSizing: boolean;
|
|
7
|
-
|
|
9
|
+
maxDynamicContentSize: number;
|
|
8
10
|
snapPoints: (number | string)[];
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
interface UseDynamicSnapPointsReturns {
|
|
12
14
|
convertedSnapPoints: number[];
|
|
13
|
-
|
|
15
|
+
handleLayout: (e: LayoutChangeEvent) => void;
|
|
14
16
|
highestSnapPoint: number;
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -31,16 +33,20 @@ const convertSnapPoint = (snapPoint: number | string, windowHeight: number, maxD
|
|
|
31
33
|
export default function useDynamicSnapPoints(params: UseDynamicSnapPointsParams): UseDynamicSnapPointsReturns {
|
|
32
34
|
const {
|
|
33
35
|
enableDynamicSizing,
|
|
34
|
-
|
|
36
|
+
maxDynamicContentSize,
|
|
35
37
|
snapPoints,
|
|
36
38
|
} = params;
|
|
37
39
|
|
|
38
40
|
const { height: windowHeight } = useWindowDimensions();
|
|
39
41
|
|
|
40
|
-
const [contentHeight, setContentHeight] = useState<number>(
|
|
42
|
+
const [contentHeight, setContentHeight] = useState<number>(INITIAL_CONTAINER_HEIGHT);
|
|
43
|
+
|
|
44
|
+
const hasMeasureRef = useRef<boolean>(false);
|
|
41
45
|
|
|
42
46
|
const convertedSnapPoints = useMemo(() => {
|
|
43
|
-
|
|
47
|
+
if (contentHeight === INITIAL_CONTAINER_HEIGHT) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
44
50
|
|
|
45
51
|
const convertedSnapPoints = snapPoints.map((snapPoint) => {
|
|
46
52
|
return convertSnapPoint(snapPoint, windowHeight, maxDynamicContentSize);
|
|
@@ -55,19 +61,27 @@ export default function useDynamicSnapPoints(params: UseDynamicSnapPointsParams)
|
|
|
55
61
|
return Array.from(new Set(convertedSnapPoints)).sort((a, b) => a - b);
|
|
56
62
|
}, [
|
|
57
63
|
contentHeight,
|
|
64
|
+
enableDynamicSizing,
|
|
65
|
+
maxDynamicContentSize,
|
|
58
66
|
snapPoints,
|
|
59
67
|
windowHeight,
|
|
60
68
|
]);
|
|
61
69
|
|
|
62
|
-
const highestSnapPoint = R.last(convertedSnapPoints) ??
|
|
70
|
+
const highestSnapPoint = R.last(convertedSnapPoints) ?? maxDynamicContentSize;
|
|
71
|
+
|
|
72
|
+
const handleLayout = useCallback((event: LayoutChangeEvent) => {
|
|
73
|
+
if (hasMeasureRef.current) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
hasMeasureRef.current = true;
|
|
78
|
+
const { height } = event.nativeEvent.layout;
|
|
65
79
|
setContentHeight(height);
|
|
66
80
|
}, []);
|
|
67
81
|
|
|
68
82
|
return {
|
|
69
83
|
convertedSnapPoints,
|
|
70
|
-
|
|
84
|
+
handleLayout,
|
|
71
85
|
highestSnapPoint,
|
|
72
86
|
};
|
|
73
87
|
}
|
|
@@ -32,8 +32,8 @@ export default function DateTimePicker(props: DateTimePickerProps) {
|
|
|
32
32
|
const { locales } = useDateTimePicker();
|
|
33
33
|
|
|
34
34
|
//TODO: Need to update arrow components
|
|
35
|
-
const LeftArrow = <Typography children={'<'} color={'
|
|
36
|
-
const RightArrow = <Typography children={'>'} color={'
|
|
35
|
+
const LeftArrow = <Typography children={'<'} color={'strong'}/>;
|
|
36
|
+
const RightArrow = <Typography children={'>'} color={'strong'}/>;
|
|
37
37
|
|
|
38
38
|
const onYearPress = (date: Date) => {
|
|
39
39
|
setYearPickerVisible(false);
|