@fountain-ui/lab 2.0.0-beta.41 → 2.0.0-beta.43

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 (39) hide show
  1. package/build/commonjs/BottomSheet/BottomSheetNative.js +15 -3
  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 +24 -25
  5. package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
  6. package/build/commonjs/BottomSheet/useDynamicSnapPoints.js +37 -21
  7. package/build/commonjs/BottomSheet/useDynamicSnapPoints.js.map +1 -1
  8. package/build/commonjs/ComicViewer/ComicViewer.js +2 -1
  9. package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
  10. package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
  11. package/build/module/BottomSheet/BottomSheetNative.js +16 -5
  12. package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
  13. package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
  14. package/build/module/BottomSheet/BottomSheetWeb.js +24 -26
  15. package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
  16. package/build/module/BottomSheet/useDynamicSnapPoints.js +33 -22
  17. package/build/module/BottomSheet/useDynamicSnapPoints.js.map +1 -1
  18. package/build/module/ComicViewer/ComicViewer.js +2 -1
  19. package/build/module/ComicViewer/ComicViewer.js.map +1 -1
  20. package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
  21. package/build/typescript/BottomSheet/BottomSheetProps.d.ts +13 -1
  22. package/build/typescript/BottomSheet/useDynamicSnapPoints.d.ts +7 -6
  23. package/build/typescript/Carousel/Carousel.d.ts +1 -1
  24. package/build/typescript/ComicViewer/ComicViewerProps.d.ts +5 -0
  25. package/build/typescript/ViewPager/ViewPager.d.ts +1 -1
  26. package/build/typescript/ViewPager/ViewPager.native.d.ts +1 -1
  27. package/package.json +4 -4
  28. package/src/BottomSheet/BottomSheetNative.tsx +16 -3
  29. package/src/BottomSheet/BottomSheetProps.ts +15 -1
  30. package/src/BottomSheet/BottomSheetWeb.tsx +31 -25
  31. package/src/BottomSheet/useDynamicSnapPoints.ts +49 -28
  32. package/src/ComicViewer/ComicViewer.tsx +2 -1
  33. package/src/ComicViewer/ComicViewerProps.ts +6 -0
  34. package/build/commonjs/BottomSheet/BottomSheet.js +0 -177
  35. package/build/commonjs/BottomSheet/BottomSheet.js.map +0 -1
  36. package/build/module/BottomSheet/BottomSheet.js +0 -161
  37. package/build/module/BottomSheet/BottomSheet.js.map +0 -1
  38. package/build/typescript/BottomSheet/BottomSheet.d.ts +0 -2
  39. package/src/BottomSheet/BottomSheet.tsx +0 -184
@@ -1,184 +0,0 @@
1
- import React, { useEffect, useMemo, useRef } from 'react';
2
- import {
3
- Animated,
4
- LayoutChangeEvent,
5
- LayoutRectangle,
6
- NativeScrollEvent,
7
- NativeSyntheticEvent,
8
- PanResponder,
9
- ScrollView,
10
- View,
11
- } from 'react-native';
12
- import { css, Modal, Paper, StyleSheet, useAnimatedValue, useTheme } from '@fountain-ui/core';
13
- import { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
14
- import BottomSheetProps from './BottomSheetProps';
15
- import useDynamicSnapPoints from './useDynamicSnapPoints';
16
-
17
- type BottomSheetStyles = NamedStylesStringUnion<'root' | 'animated' | 'paper' | 'scrollView'>;
18
-
19
- const useStyles: UseStyles<BottomSheetStyles> = function (): BottomSheetStyles {
20
- const theme = useTheme();
21
-
22
- return {
23
- root: {
24
- justifyContent: 'flex-end',
25
- zIndex: theme.zIndex.dialog,
26
- },
27
- animated: {
28
- alignSelf: 'center',
29
- maxWidth: 720,
30
- width: '100%',
31
- },
32
- paper: {
33
- borderBottomLeftRadius: 0,
34
- borderBottomRightRadius: 0,
35
- flexGrow: 1,
36
- overflow: 'hidden',
37
- },
38
- scrollView: {
39
- flexGrow: 1,
40
- },
41
- };
42
- };
43
-
44
- export default function BottomSheet(props: BottomSheetProps) {
45
- const {
46
- backdropOpacity,
47
- children,
48
- header,
49
- index,
50
- onChange,
51
- snapPoints: initialSnapPoints,
52
- } = props;
53
-
54
- const styles = useStyles();
55
-
56
- const contentLayout = useRef<LayoutRectangle>({ x: 0, y: 0, width: 0, height: 0 });
57
- const currentScrollY = useRef<number>(0);
58
-
59
- const {
60
- snapPoints,
61
- handleContentLayout,
62
- } = useDynamicSnapPoints({
63
- index,
64
- initialSnapPoints,
65
- });
66
-
67
- const height = snapPoints[snapPoints.length - 1] ?? 0;
68
- const translateY = height - (snapPoints[index] ?? 0);
69
-
70
- const animatedY = useAnimatedValue(translateY);
71
-
72
- const isInsideScrollView = (locationX: number, locationY: number): boolean => {
73
- const {
74
- current: { x, y, width, height },
75
- } = contentLayout;
76
-
77
- return locationX >= x && locationX <= x + width && locationY >= y && locationY <= y + height;
78
- };
79
-
80
- const panResponder = useMemo(() => (
81
- PanResponder.create({
82
- onMoveShouldSetPanResponder: (event, gestureState) => {
83
- const {
84
- nativeEvent: { locationX, locationY },
85
- } = event;
86
-
87
- if (isInsideScrollView(locationX, locationY)) {
88
- return gestureState.dy > 0 && currentScrollY.current === 0;
89
- }
90
-
91
- return true;
92
- },
93
- onPanResponderMove: (_, gestureState) => {
94
- if (gestureState.dy > 0) {
95
- animatedY.setValue(translateY + gestureState.dy);
96
- }
97
- },
98
- onPanResponderRelease: (_, gestureState) => {
99
- if (gestureState.dy > 0 && gestureState.vy > 0.5) {
100
- handleClose();
101
- } else {
102
- Animated.timing(animatedY, {
103
- toValue: translateY,
104
- useNativeDriver: false,
105
- duration: 300,
106
- }).start();
107
- }
108
- },
109
- })
110
- ), [translateY]);
111
-
112
- useEffect(() => {
113
- if (translateY >= 0) {
114
- Animated.timing(animatedY, {
115
- toValue: translateY,
116
- useNativeDriver: false,
117
- duration: 300,
118
- }).start();
119
- }
120
- }, [translateY]);
121
-
122
- const handleClose = () => {
123
- if (onChange) {
124
- onChange(-1);
125
- }
126
- };
127
-
128
- const handleScrollViewLayout = (event: LayoutChangeEvent) => {
129
- contentLayout.current = event.nativeEvent.layout;
130
- };
131
-
132
- const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
133
- currentScrollY.current = event.nativeEvent.contentOffset.y;
134
- };
135
-
136
- const animatedStyles = [
137
- styles.animated,
138
- { transform: [{ translateY: animatedY }] },
139
- ];
140
-
141
- const paperStyles = [
142
- styles.paper,
143
- { ...(height !== 0 ? { height } : {}) },
144
- ];
145
-
146
- const contentStyle = {
147
- ...(snapPoints[index] !== 0 ? { height: snapPoints[index] } : {}),
148
- };
149
-
150
- return (
151
- <Modal
152
- backdropOpacity={backdropOpacity}
153
- onClose={handleClose}
154
- visible={index >= 0}
155
- style={css([StyleSheet.absoluteFill, styles.root])}
156
- >
157
- <Animated.View
158
- style={animatedStyles}
159
- {...panResponder.panHandlers}
160
- >
161
- <Paper
162
- elevation={12}
163
- style={paperStyles}
164
- >
165
- <View
166
- style={contentStyle}
167
- onLayout={handleContentLayout}
168
- >
169
- {header}
170
-
171
- <ScrollView
172
- onLayout={handleScrollViewLayout}
173
- onScroll={handleScroll}
174
- scrollEventThrottle={300}
175
- style={styles.scrollView}
176
- >
177
- {children}
178
- </ScrollView>
179
- </View>
180
- </Paper>
181
- </Animated.View>
182
- </Modal>
183
- );
184
- }