@xhsreds/reds-rn-next 0.1.2 → 0.1.3
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/benchmarks/out.json +900 -820
- package/coverage/.tmp/coverage-0.json +1 -1
- package/coverage/.tmp/coverage-1.json +1 -1
- package/coverage/.tmp/coverage-10.json +1 -1
- package/coverage/.tmp/coverage-11.json +1 -1
- package/coverage/.tmp/coverage-12.json +1 -1
- package/coverage/.tmp/coverage-13.json +1 -1
- package/coverage/.tmp/coverage-14.json +1 -1
- package/coverage/.tmp/coverage-15.json +1 -1
- package/coverage/.tmp/coverage-16.json +1 -1
- package/coverage/.tmp/coverage-17.json +1 -1
- package/coverage/.tmp/coverage-18.json +1 -1
- package/coverage/.tmp/coverage-19.json +1 -1
- package/coverage/.tmp/coverage-2.json +1 -1
- package/coverage/.tmp/coverage-20.json +1 -1
- package/coverage/.tmp/coverage-21.json +1 -1
- package/coverage/.tmp/coverage-22.json +1 -1
- package/coverage/.tmp/coverage-23.json +1 -1
- package/coverage/.tmp/coverage-24.json +1 -1
- package/coverage/.tmp/coverage-25.json +1 -1
- package/coverage/.tmp/coverage-26.json +1 -1
- package/coverage/.tmp/coverage-27.json +1 -1
- package/coverage/.tmp/coverage-28.json +1 -1
- package/coverage/.tmp/coverage-29.json +1 -0
- package/coverage/.tmp/coverage-3.json +1 -1
- package/coverage/.tmp/coverage-30.json +1 -0
- package/coverage/.tmp/coverage-31.json +1 -0
- package/coverage/.tmp/coverage-4.json +1 -1
- package/coverage/.tmp/coverage-5.json +1 -1
- package/coverage/.tmp/coverage-6.json +1 -1
- package/coverage/.tmp/coverage-7.json +1 -1
- package/coverage/.tmp/coverage-8.json +1 -1
- package/coverage/.tmp/coverage-9.json +1 -1
- package/lib/cjs/_chunks/CkkZzOy_.js +23 -0
- package/lib/cjs/_chunks/CkkZzOy_.js.map +1 -0
- package/lib/cjs/_chunks/RPaDcSae.js +20 -0
- package/lib/cjs/_chunks/RPaDcSae.js.map +1 -0
- package/lib/cjs/_chunks/bwo-gq0b.js +66 -0
- package/lib/cjs/_chunks/bwo-gq0b.js.map +1 -0
- package/lib/cjs/components/ActionSheets/ActionSheets.js +99 -0
- package/lib/cjs/components/ActionSheets/ActionSheets.js.map +1 -0
- package/lib/cjs/components/ActionSheets/index.js +37 -0
- package/lib/cjs/components/ActionSheets/index.js.map +1 -0
- package/lib/cjs/components/ActionSheets/interface/index.js +9 -0
- package/lib/cjs/components/ActionSheets/interface/index.js.map +1 -0
- package/lib/cjs/components/ActionSheets/styles.js +59 -0
- package/lib/cjs/components/ActionSheets/styles.js.map +1 -0
- package/lib/cjs/components/AvatarGroup/AvatarGroup.js +10 -4
- package/lib/cjs/components/AvatarGroup/AvatarGroup.js.map +1 -1
- package/lib/cjs/components/AvatarGroup/index.js +17 -11
- package/lib/cjs/components/AvatarGroup/index.js.map +1 -1
- package/lib/cjs/components/ImagePreview/ImagePreview.js +11 -5
- package/lib/cjs/components/ImagePreview/ImagePreview.js.map +1 -1
- package/lib/cjs/components/ImagePreview/index.js +18 -12
- package/lib/cjs/components/ImagePreview/index.js.map +1 -1
- package/lib/cjs/components/List/ListItem/ListItem.js +11 -5
- package/lib/cjs/components/List/ListItem/ListItem.js.map +1 -1
- package/lib/cjs/components/List/index.js +16 -10
- package/lib/cjs/components/List/index.js.map +1 -1
- package/lib/cjs/components/Picker/Picker.js +6 -1
- package/lib/cjs/components/Picker/Picker.js.map +1 -1
- package/lib/cjs/components/Picker/index.js +6 -1
- package/lib/cjs/components/Picker/index.js.map +1 -1
- package/lib/cjs/components/Sheets/Sheets.js +168 -16
- package/lib/cjs/components/Sheets/Sheets.js.map +1 -1
- package/lib/cjs/components/Sheets/index.js +9 -3
- package/lib/cjs/components/Sheets/index.js.map +1 -1
- package/lib/cjs/components/Sheets/interface/index.js +6 -1
- package/lib/cjs/components/Sheets/interface/index.js.map +1 -1
- package/lib/cjs/components/Sheets/styles.js +39 -11
- package/lib/cjs/components/Sheets/styles.js.map +1 -1
- package/lib/cjs/components/Silder/Silder.js +71 -0
- package/lib/cjs/components/Silder/Silder.js.map +1 -0
- package/lib/cjs/components/Silder/index.js +18 -0
- package/lib/cjs/components/Silder/index.js.map +1 -0
- package/lib/cjs/components/Silder/interface/index.js +9 -0
- package/lib/cjs/components/Silder/interface/index.js.map +1 -0
- package/lib/cjs/components/Silder/styles.js +29 -0
- package/lib/cjs/components/Silder/styles.js.map +1 -0
- package/lib/cjs/components/TabBar/TabBar.js +10 -10
- package/lib/cjs/components/TabBar/TabBar.js.map +1 -1
- package/lib/cjs/index.js +12 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/_chunks/BJ2Kj1Vd.js +58 -0
- package/lib/esm/_chunks/BJ2Kj1Vd.js.map +1 -0
- package/lib/esm/_chunks/DHJk9lIr.js +19 -0
- package/lib/esm/_chunks/DHJk9lIr.js.map +1 -0
- package/lib/esm/_chunks/RRfNwNcs.js +17 -0
- package/lib/esm/_chunks/RRfNwNcs.js.map +1 -0
- package/lib/esm/components/ActionSheets/ActionSheets.js +95 -0
- package/lib/esm/components/ActionSheets/ActionSheets.js.map +1 -0
- package/lib/esm/components/ActionSheets/index.js +31 -0
- package/lib/esm/components/ActionSheets/index.js.map +1 -0
- package/lib/esm/components/ActionSheets/interface/index.js +2 -0
- package/lib/esm/components/ActionSheets/interface/index.js.map +1 -0
- package/lib/esm/components/ActionSheets/styles.js +55 -0
- package/lib/esm/components/ActionSheets/styles.js.map +1 -0
- package/lib/esm/components/AvatarGroup/AvatarGroup.js +10 -4
- package/lib/esm/components/AvatarGroup/AvatarGroup.js.map +1 -1
- package/lib/esm/components/AvatarGroup/index.js +17 -11
- package/lib/esm/components/AvatarGroup/index.js.map +1 -1
- package/lib/esm/components/ImagePreview/ImagePreview.js +11 -5
- package/lib/esm/components/ImagePreview/ImagePreview.js.map +1 -1
- package/lib/esm/components/ImagePreview/index.js +18 -12
- package/lib/esm/components/ImagePreview/index.js.map +1 -1
- package/lib/esm/components/List/ListItem/ListItem.js +11 -5
- package/lib/esm/components/List/ListItem/ListItem.js.map +1 -1
- package/lib/esm/components/List/index.js +16 -10
- package/lib/esm/components/List/index.js.map +1 -1
- package/lib/esm/components/Picker/Picker.js +6 -1
- package/lib/esm/components/Picker/Picker.js.map +1 -1
- package/lib/esm/components/Picker/index.js +6 -1
- package/lib/esm/components/Picker/index.js.map +1 -1
- package/lib/esm/components/Sheets/Sheets.js +170 -18
- package/lib/esm/components/Sheets/Sheets.js.map +1 -1
- package/lib/esm/components/Sheets/index.js +9 -3
- package/lib/esm/components/Sheets/index.js.map +1 -1
- package/lib/esm/components/Sheets/interface/index.js +1 -1
- package/lib/esm/components/Sheets/styles.js +39 -11
- package/lib/esm/components/Sheets/styles.js.map +1 -1
- package/lib/esm/components/Silder/Silder.js +67 -0
- package/lib/esm/components/Silder/Silder.js.map +1 -0
- package/lib/esm/components/Silder/index.js +12 -0
- package/lib/esm/components/Silder/index.js.map +1 -0
- package/lib/esm/components/Silder/interface/index.js +3 -0
- package/lib/esm/components/Silder/interface/index.js.map +1 -0
- package/lib/esm/components/Silder/styles.js +25 -0
- package/lib/esm/components/Silder/styles.js.map +1 -0
- package/lib/esm/components/TabBar/TabBar.js +10 -10
- package/lib/esm/components/TabBar/TabBar.js.map +1 -1
- package/lib/esm/index.js +8 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/types/components/ActionSheets/ActionSheets.d.ts +10 -0
- package/lib/types/components/ActionSheets/demo/index.d.ts +2 -0
- package/lib/types/components/ActionSheets/index.d.ts +4 -0
- package/lib/types/components/ActionSheets/interface/index.d.ts +23 -0
- package/lib/types/components/ActionSheets/styles.d.ts +51 -0
- package/lib/types/components/ActionSheets/test/index.bench.d.ts +1 -0
- package/lib/types/components/ActionSheets/test/index.test.d.ts +1 -0
- package/lib/types/components/ActionSheets/test/paper.bench.d.ts +1 -0
- package/lib/types/components/FAB/test/paper.bench.d.ts +1 -0
- package/lib/types/components/Sheets/Sheets.d.ts +17 -1
- package/lib/types/components/Sheets/interface/index.d.ts +45 -0
- package/lib/types/components/Sheets/styles.d.ts +38 -9
- package/lib/types/components/Sheets/test/index.test.d.ts +1 -1
- package/lib/types/components/Silder/Silder.d.ts +13 -0
- package/lib/types/components/Silder/demo/index.d.ts +2 -0
- package/lib/types/components/Silder/index.d.ts +4 -0
- package/lib/types/components/Silder/interface/index.d.ts +19 -0
- package/lib/types/components/Silder/styles.d.ts +20 -0
- package/lib/types/components/Silder/test/index.bench.d.ts +1 -0
- package/lib/types/components/Silder/test/index.test.d.ts +1 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +2 -3
- package/src/components/ActionSheets/ActionSheets.tsx +66 -0
- package/src/components/ActionSheets/demo/index.tsx +65 -0
- package/src/components/ActionSheets/doc/index.mdx +24 -0
- package/src/components/ActionSheets/index.ts +5 -0
- package/src/components/ActionSheets/interface/index.ts +27 -0
- package/src/components/ActionSheets/styles.ts +54 -0
- package/src/components/ActionSheets/test/index.bench.tsx +13 -0
- package/src/components/ActionSheets/test/index.test.tsx +81 -0
- package/src/components/ActionSheets/test/paper.bench.tsx +17 -0
- package/src/components/Avatar/test/__snapshots__/index.test.tsx.snap +32 -0
- package/src/components/Avatar/test/paper.bench.tsx +1 -1
- package/src/components/Button/test/__snapshots__/index.test.tsx.snap +0 -10
- package/src/components/Divider/test/__snapshots__/index.test.tsx.snap +420 -6
- package/src/components/Divider/test/index.test.tsx +43 -35
- package/src/components/FAB/test/__snapshots__/index.test.tsx.snap +0 -2
- package/src/components/FAB/test/paper.bench.tsx +12 -0
- package/src/components/Picker/test/index.test.tsx +17 -25
- package/src/components/Progress/test/__snapshots__/index.test.tsx.snap +332 -3
- package/src/components/Progress/test/index.test.tsx +29 -19
- package/src/components/PullRefresh/test/index.bench.tsx +1 -1
- package/src/components/Sheets/Sheets.tsx +293 -20
- package/src/components/Sheets/demo/index.tsx +191 -14
- package/src/components/Sheets/doc/index.mdx +16 -5
- package/src/components/Sheets/interface/index.ts +50 -0
- package/src/components/Sheets/styles.ts +38 -10
- package/src/components/Sheets/test/index.test.tsx +71 -48
- package/src/components/Sheets/test/paper.bench.tsx +1 -1
- package/src/components/Silder/Silder.tsx +49 -0
- package/src/components/Silder/demo/index.tsx +53 -0
- package/src/components/Silder/doc/index.mdx +26 -0
- package/src/components/Silder/index.ts +5 -0
- package/src/components/Silder/interface/index.ts +20 -0
- package/src/components/Silder/styles.ts +24 -0
- package/src/components/Silder/test/index.bench.tsx +13 -0
- package/src/components/Silder/test/index.test.tsx +18 -0
- package/src/components/TabBar/TabBar.tsx +17 -17
- package/src/components/Toast/test/paper.bench.tsx +9 -5
- package/src/index.ts +2 -0
- package/lib/cjs/_chunks/DIhBCUjt.js +0 -17
- package/lib/cjs/_chunks/DIhBCUjt.js.map +0 -1
- package/lib/esm/_chunks/B3_9dzWY.js +0 -14
- package/lib/esm/_chunks/B3_9dzWY.js.map +0 -1
|
@@ -1,45 +1,318 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import React, { useState, useRef, useMemo, useEffect } from "react";
|
|
2
|
+
import { alwaysColor } from "@xhs/reds-token-next";
|
|
3
|
+
import {
|
|
4
|
+
View,
|
|
5
|
+
TouchableWithoutFeedback,
|
|
6
|
+
Text,
|
|
7
|
+
Animated,
|
|
8
|
+
LayoutChangeEvent,
|
|
9
|
+
PanResponder,
|
|
10
|
+
Dimensions,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import {
|
|
13
|
+
RedsSheets,
|
|
14
|
+
SheetsDefaultProps,
|
|
15
|
+
SheetsMaskMode,
|
|
16
|
+
SheetsType,
|
|
17
|
+
SheetsIconType,
|
|
18
|
+
SheetsActionType,
|
|
19
|
+
SheetsSize,
|
|
20
|
+
} from "./interface/index";
|
|
4
21
|
import { Portal } from "../Portal";
|
|
5
22
|
import { useThemeColor } from "../ConfigProvider";
|
|
6
23
|
import styles from "./styles";
|
|
24
|
+
import { Button } from "../Button";
|
|
25
|
+
import { Icon } from "../Icon";
|
|
26
|
+
import { Close, ArrowLeft } from "@xhs/reder-icon-svg";
|
|
7
27
|
|
|
8
28
|
const Sheets = (props: RedsSheets) => {
|
|
9
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
visible,
|
|
31
|
+
onCancel,
|
|
32
|
+
onConfirm,
|
|
33
|
+
children,
|
|
34
|
+
label,
|
|
35
|
+
mask,
|
|
36
|
+
maskMode,
|
|
37
|
+
cancelType,
|
|
38
|
+
closeType,
|
|
39
|
+
cancelText,
|
|
40
|
+
closeText,
|
|
41
|
+
sheetsType,
|
|
42
|
+
cancel,
|
|
43
|
+
close,
|
|
44
|
+
iconType,
|
|
45
|
+
size,
|
|
46
|
+
} = props;
|
|
47
|
+
|
|
48
|
+
console.log("visible", visible);
|
|
10
49
|
|
|
11
50
|
const themeColor = useThemeColor();
|
|
12
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Sheets容器高度动画
|
|
54
|
+
*/
|
|
55
|
+
const [sheetsHeight] = useState(new Animated.Value(0));
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sheets容器child内容高度
|
|
59
|
+
*/
|
|
60
|
+
const childHeightRef = useRef(0);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 底部操作区高度
|
|
64
|
+
*/
|
|
65
|
+
const [actionHeight, setActionHeight] = useState(0);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 标题区域高度
|
|
69
|
+
*/
|
|
70
|
+
const [labelHeight, setLabelHeight] = useState(0);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* child高度
|
|
74
|
+
*/
|
|
75
|
+
const [childHeight, setChildHeight] = useState(0);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 是否展示标题
|
|
79
|
+
*/
|
|
80
|
+
const showLabel = useMemo(() => {
|
|
81
|
+
return sheetsType === SheetsType.normal && (cancel || close || label);
|
|
82
|
+
}, [sheetsType, cancel, close, label]);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 是否展示底部操作栏
|
|
86
|
+
*/
|
|
87
|
+
const showAction = useMemo(() => {
|
|
88
|
+
return sheetsType === SheetsType.action && (cancel || close);
|
|
89
|
+
}, [sheetsType, cancel, close]);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 关闭Sheets
|
|
93
|
+
*/
|
|
13
94
|
const handleMask = () => {
|
|
95
|
+
handleClose();
|
|
14
96
|
onCancel?.();
|
|
15
97
|
};
|
|
16
98
|
|
|
99
|
+
/**
|
|
100
|
+
* 确定 or 完成
|
|
101
|
+
*/
|
|
17
102
|
const handleConfirm = () => {
|
|
103
|
+
handleClose();
|
|
18
104
|
onConfirm?.();
|
|
19
105
|
};
|
|
20
106
|
|
|
107
|
+
/**
|
|
108
|
+
* 返回 or 取消
|
|
109
|
+
*/
|
|
21
110
|
const handleCancel = () => {
|
|
111
|
+
handleClose();
|
|
22
112
|
onCancel?.();
|
|
23
113
|
};
|
|
24
114
|
|
|
115
|
+
/**
|
|
116
|
+
* 计算子容器高度
|
|
117
|
+
* @param evt LayoutChangeEvent
|
|
118
|
+
*/
|
|
119
|
+
const handleLayout = (evt: LayoutChangeEvent) => {
|
|
120
|
+
const { height } = evt.nativeEvent.layout;
|
|
121
|
+
setChildHeight(height);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 计算底部操作区高度
|
|
126
|
+
* @param evt
|
|
127
|
+
*/
|
|
128
|
+
const handleActionLayout = (evt: LayoutChangeEvent) => {
|
|
129
|
+
const { height } = evt.nativeEvent.layout;
|
|
130
|
+
setActionHeight(height);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 计算标题高度
|
|
135
|
+
* @param evt
|
|
136
|
+
*/
|
|
137
|
+
const handleLabelLayout = (evt: LayoutChangeEvent) => {
|
|
138
|
+
const { height } = evt.nativeEvent.layout;
|
|
139
|
+
setLabelHeight(height);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 外层容器高度变化
|
|
144
|
+
*/
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
const factHeight = actionHeight + labelHeight + childHeight + 34;
|
|
147
|
+
const fullScreenHeight = Dimensions.get("screen").height - 34;
|
|
148
|
+
const halfScreenHeight = Math.floor(fullScreenHeight / 2) - 34;
|
|
149
|
+
const threeQuaterScreenHeight = Math.floor(fullScreenHeight * 0.75) - 34;
|
|
150
|
+
const calculateHeight =
|
|
151
|
+
sheetsType !== SheetsType.dragable
|
|
152
|
+
? size === SheetsSize.auto
|
|
153
|
+
? factHeight
|
|
154
|
+
: size === SheetsSize.half
|
|
155
|
+
? halfScreenHeight
|
|
156
|
+
: size === SheetsSize.threeQuater
|
|
157
|
+
? threeQuaterScreenHeight
|
|
158
|
+
: fullScreenHeight
|
|
159
|
+
: factHeight;
|
|
160
|
+
childHeightRef.current = calculateHeight;
|
|
161
|
+
Animated.timing(sheetsHeight, {
|
|
162
|
+
toValue: calculateHeight,
|
|
163
|
+
duration: 100, // 动画持续时间 (毫秒)
|
|
164
|
+
useNativeDriver: false, // `height` 不支持 useNativeDriver
|
|
165
|
+
}).start();
|
|
166
|
+
}, [actionHeight, labelHeight, childHeight]);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 关闭容器取消动画
|
|
170
|
+
* @param evt LayoutChangeEvent
|
|
171
|
+
*/
|
|
172
|
+
const handleClose = () => {
|
|
173
|
+
Animated.timing(sheetsHeight, { toValue: 0, useNativeDriver: false }).start();
|
|
174
|
+
sheetsHeight.setValue(0);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 手势监听
|
|
179
|
+
*/
|
|
180
|
+
const panResponder = useRef(
|
|
181
|
+
PanResponder.create({
|
|
182
|
+
onMoveShouldSetPanResponder: () => true,
|
|
183
|
+
onPanResponderMove: (event, gestureState) => {
|
|
184
|
+
console.log("childHeightRef.current", childHeightRef.current);
|
|
185
|
+
const fullScreenHeight = Dimensions.get("screen").height - 34;
|
|
186
|
+
const halfScreenHeight = Math.floor(fullScreenHeight / 2) - 34;
|
|
187
|
+
const threeQuaterScreenHeight = Math.floor(fullScreenHeight * 0.75) - 34;
|
|
188
|
+
const maxHeight =
|
|
189
|
+
size === SheetsSize.auto
|
|
190
|
+
? fullScreenHeight
|
|
191
|
+
: size === SheetsSize.half
|
|
192
|
+
? halfScreenHeight
|
|
193
|
+
: size === SheetsSize.threeQuater
|
|
194
|
+
? threeQuaterScreenHeight
|
|
195
|
+
: fullScreenHeight;
|
|
196
|
+
const newHeight = Math.min(
|
|
197
|
+
maxHeight,
|
|
198
|
+
Math.max(childHeightRef.current, childHeightRef.current - gestureState.dy),
|
|
199
|
+
);
|
|
200
|
+
sheetsHeight.setValue(newHeight);
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
).current;
|
|
204
|
+
|
|
205
|
+
/** icon wrapper */
|
|
206
|
+
const iconWrapper = (type: string) => {
|
|
207
|
+
return iconType === SheetsIconType.bg ? (
|
|
208
|
+
<TouchableWithoutFeedback onPress={handleCancel}>
|
|
209
|
+
<View style={[styles.iconBg, { backgroundColor: themeColor.Fill1 }]}>
|
|
210
|
+
{type === "confirm" ? (
|
|
211
|
+
<Icon icon={Close} fill={themeColor.Bg} size={20} onClick={handleCancel} />
|
|
212
|
+
) : (
|
|
213
|
+
<Icon icon={ArrowLeft} fill={themeColor.Bg} size={20} onClick={handleCancel} />
|
|
214
|
+
)}
|
|
215
|
+
</View>
|
|
216
|
+
</TouchableWithoutFeedback>
|
|
217
|
+
) : type === "confirm" ? (
|
|
218
|
+
<Icon icon={Close} fill={themeColor.Title} size={20} onClick={handleCancel} />
|
|
219
|
+
) : (
|
|
220
|
+
<Icon icon={ArrowLeft} fill={themeColor.Title} size={20} onClick={handleCancel} />
|
|
221
|
+
);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** block占位 */
|
|
225
|
+
const Block = () => {
|
|
226
|
+
return <View style={styles.block} />;
|
|
227
|
+
};
|
|
228
|
+
|
|
25
229
|
return visible ? (
|
|
26
230
|
<Portal>
|
|
27
|
-
<View style={styles.
|
|
28
|
-
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
|
|
231
|
+
<View style={styles.wrapper}>
|
|
232
|
+
{mask ? (
|
|
233
|
+
<TouchableWithoutFeedback onPress={handleMask}>
|
|
234
|
+
<View
|
|
235
|
+
style={[
|
|
236
|
+
styles.mask,
|
|
237
|
+
{ backgroundColor: maskMode === SheetsMaskMode.light ? alwaysColor.MaskBg : "rgba(0,0,0,0.8)" },
|
|
238
|
+
]}
|
|
239
|
+
></View>
|
|
240
|
+
</TouchableWithoutFeedback>
|
|
241
|
+
) : (
|
|
242
|
+
<></>
|
|
243
|
+
)}
|
|
244
|
+
<Animated.View
|
|
245
|
+
style={[styles.picker, { backgroundColor: themeColor.Bg2 }, { height: sheetsHeight }]}
|
|
246
|
+
{...panResponder.panHandlers}
|
|
247
|
+
>
|
|
248
|
+
{/** normal */}
|
|
249
|
+
{showLabel ? (
|
|
250
|
+
<View style={[styles.labelContainer, { backgroundColor: themeColor.Bg2 }]} onLayout={handleLabelLayout}>
|
|
251
|
+
{cancel ? (
|
|
252
|
+
<TouchableWithoutFeedback onPress={handleCancel}>
|
|
253
|
+
{cancelType === SheetsActionType.text ? (
|
|
254
|
+
<Text style={[styles.cancel, { color: themeColor.Description }]}>{cancelText}</Text>
|
|
255
|
+
) : (
|
|
256
|
+
iconWrapper("cancel")
|
|
257
|
+
)}
|
|
258
|
+
</TouchableWithoutFeedback>
|
|
259
|
+
) : (
|
|
260
|
+
<Block />
|
|
261
|
+
)}
|
|
262
|
+
{label ? <Text style={[styles.label, { color: themeColor.Title }]}>{label}</Text> : <></>}
|
|
263
|
+
{close ? (
|
|
264
|
+
<TouchableWithoutFeedback onPress={handleConfirm}>
|
|
265
|
+
{closeType === SheetsActionType.text ? (
|
|
266
|
+
<Text style={[styles.confirm, { color: themeColor.Primary }]}>{closeText}</Text>
|
|
267
|
+
) : (
|
|
268
|
+
iconWrapper("confirm")
|
|
269
|
+
)}
|
|
270
|
+
</TouchableWithoutFeedback>
|
|
271
|
+
) : (
|
|
272
|
+
<Block />
|
|
273
|
+
)}
|
|
274
|
+
</View>
|
|
275
|
+
) : (
|
|
276
|
+
<></>
|
|
277
|
+
)}
|
|
278
|
+
|
|
279
|
+
{/** 拖拽按钮 */}
|
|
280
|
+
{sheetsType === SheetsType.dragable ? (
|
|
281
|
+
<Animated.View style={[styles.dragableContainer]} {...panResponder.panHandlers}>
|
|
282
|
+
<View style={[styles.dragable, { backgroundColor: themeColor.Fill3 }]} />
|
|
283
|
+
</Animated.View>
|
|
284
|
+
) : (
|
|
285
|
+
<></>
|
|
286
|
+
)}
|
|
287
|
+
|
|
288
|
+
<View onLayout={handleLayout}>{children}</View>
|
|
289
|
+
|
|
290
|
+
{/** action */}
|
|
291
|
+
{showAction ? (
|
|
292
|
+
<View style={[styles.actionContainer]} onLayout={handleActionLayout}>
|
|
293
|
+
{cancel ? (
|
|
294
|
+
<View style={styles.action}>
|
|
295
|
+
<Button block onClick={handleCancel}>
|
|
296
|
+
{cancelText}
|
|
297
|
+
</Button>
|
|
298
|
+
</View>
|
|
299
|
+
) : (
|
|
300
|
+
<></>
|
|
301
|
+
)}
|
|
302
|
+
{close ? (
|
|
303
|
+
<View style={styles.action}>
|
|
304
|
+
<Button block onClick={handleConfirm} type="primary">
|
|
305
|
+
{closeText}
|
|
306
|
+
</Button>
|
|
307
|
+
</View>
|
|
308
|
+
) : (
|
|
309
|
+
<></>
|
|
310
|
+
)}
|
|
311
|
+
</View>
|
|
312
|
+
) : (
|
|
313
|
+
<></>
|
|
314
|
+
)}
|
|
315
|
+
</Animated.View>
|
|
43
316
|
</View>
|
|
44
317
|
</Portal>
|
|
45
318
|
) : (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useRef, useEffect, useState } from "react";
|
|
2
2
|
import { View, Text, StyleSheet, FlatList, ScrollView } from "react-native";
|
|
3
|
-
import { Sheets, Button } from "@xhs/reds-rn-next";
|
|
3
|
+
import { Sheets, Button, SheetsType } from "@xhs/reds-rn-next";
|
|
4
4
|
|
|
5
5
|
const styles = StyleSheet.create({
|
|
6
6
|
container: {
|
|
@@ -8,6 +8,7 @@ const styles = StyleSheet.create({
|
|
|
8
8
|
justifyContent: "center",
|
|
9
9
|
paddingTop: 100,
|
|
10
10
|
paddingBottom: 100,
|
|
11
|
+
backgroundColor: "#eee",
|
|
11
12
|
},
|
|
12
13
|
scrollView: {
|
|
13
14
|
backgroundColor: "pink",
|
|
@@ -18,25 +19,201 @@ const styles = StyleSheet.create({
|
|
|
18
19
|
},
|
|
19
20
|
});
|
|
20
21
|
|
|
22
|
+
const Children = () => {
|
|
23
|
+
return (
|
|
24
|
+
<View
|
|
25
|
+
style={{
|
|
26
|
+
height: 200,
|
|
27
|
+
backgroundColor: "pink",
|
|
28
|
+
width: "100%",
|
|
29
|
+
display: "flex",
|
|
30
|
+
justifyContent: "center",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<Text>这是一个默认sheet</Text>
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
21
38
|
export default function App() {
|
|
22
|
-
const [
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
const [visible1, setVisible1] = useState(false);
|
|
40
|
+
const [visible2, setVisible2] = useState(false);
|
|
41
|
+
const [visible3, setVisible3] = useState(false);
|
|
42
|
+
const [visible4, setVisible4] = useState(false);
|
|
43
|
+
const [visible5, setVisible5] = useState(false);
|
|
44
|
+
const [visible6, setVisible6] = useState(false);
|
|
45
|
+
const [visible7, setVisible7] = useState(false);
|
|
46
|
+
const [visible8, setVisible8] = useState(false);
|
|
47
|
+
const [visible9, setVisible9] = useState(false);
|
|
48
|
+
const [visible10, setVisible10] = useState(false);
|
|
49
|
+
const [visible11, setVisible11] = useState(false);
|
|
27
50
|
|
|
28
51
|
return (
|
|
29
52
|
<View style={styles.container}>
|
|
30
|
-
<Button onClick={
|
|
53
|
+
<Button onClick={() => setVisible1(true)}>显示标题与关闭按钮</Button>
|
|
54
|
+
<Sheets
|
|
55
|
+
visible={visible1}
|
|
56
|
+
label={"标题"}
|
|
57
|
+
onCancel={() => setVisible1(false)}
|
|
58
|
+
onConfirm={() => setVisible1(false)}
|
|
59
|
+
cancel={false}
|
|
60
|
+
close={true}
|
|
61
|
+
closeType={SheetsType.SheetsActionType.icon}
|
|
62
|
+
mask={true}
|
|
63
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
64
|
+
>
|
|
65
|
+
<Children />
|
|
66
|
+
</Sheets>
|
|
67
|
+
|
|
68
|
+
<Button onClick={() => setVisible2(true)}>显示返回按钮</Button>
|
|
69
|
+
<Sheets
|
|
70
|
+
visible={visible2}
|
|
71
|
+
label={"标题"}
|
|
72
|
+
onCancel={() => setVisible2(false)}
|
|
73
|
+
onConfirm={() => setVisible2(false)}
|
|
74
|
+
mask={true}
|
|
75
|
+
cancel={true}
|
|
76
|
+
close={true}
|
|
77
|
+
closeType={SheetsType.SheetsActionType.icon}
|
|
78
|
+
cancelType={SheetsType.SheetsActionType.icon}
|
|
79
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
80
|
+
>
|
|
81
|
+
<Children />
|
|
82
|
+
</Sheets>
|
|
83
|
+
|
|
84
|
+
<Button onClick={() => setVisible3(true)}>显示圆形关闭按钮</Button>
|
|
85
|
+
<Sheets
|
|
86
|
+
visible={visible3}
|
|
87
|
+
onCancel={() => setVisible3(false)}
|
|
88
|
+
onConfirm={() => setVisible3(false)}
|
|
89
|
+
mask={true}
|
|
90
|
+
cancel={false}
|
|
91
|
+
close={true}
|
|
92
|
+
closeType={SheetsType.SheetsActionType.icon}
|
|
93
|
+
iconType={SheetsType.SheetsIconType.bg}
|
|
94
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
95
|
+
>
|
|
96
|
+
<Children />
|
|
97
|
+
</Sheets>
|
|
98
|
+
|
|
99
|
+
<Button onClick={() => setVisible4(true)}>显示文字按钮</Button>
|
|
100
|
+
<Sheets
|
|
101
|
+
visible={visible4}
|
|
102
|
+
label={"标题"}
|
|
103
|
+
onCancel={() => setVisible4(false)}
|
|
104
|
+
onConfirm={() => setVisible4(false)}
|
|
105
|
+
mask={true}
|
|
106
|
+
cancel={true}
|
|
107
|
+
close={true}
|
|
108
|
+
closeType={SheetsType.SheetsActionType.text}
|
|
109
|
+
cancelType={SheetsType.SheetsActionType.text}
|
|
110
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
111
|
+
>
|
|
112
|
+
<Children />
|
|
113
|
+
</Sheets>
|
|
114
|
+
|
|
115
|
+
<Button onClick={() => setVisible5(true)}>显示底部必选操作、无关闭按钮</Button>
|
|
116
|
+
<Sheets
|
|
117
|
+
visible={visible5}
|
|
118
|
+
label={"标题"}
|
|
119
|
+
onCancel={() => setVisible5(false)}
|
|
120
|
+
onConfirm={() => setVisible5(false)}
|
|
121
|
+
mask={false}
|
|
122
|
+
cancel={true}
|
|
123
|
+
close={true}
|
|
124
|
+
sheetsType={SheetsType.SheetsType.action}
|
|
125
|
+
cancelText={"暂不开启"}
|
|
126
|
+
closeText={"按钮"}
|
|
127
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
128
|
+
>
|
|
129
|
+
<Children />
|
|
130
|
+
</Sheets>
|
|
131
|
+
|
|
132
|
+
<Button onClick={() => setVisible7(true)}>显示底部一个操作按钮</Button>
|
|
133
|
+
<Sheets
|
|
134
|
+
visible={visible7}
|
|
135
|
+
label={"标题"}
|
|
136
|
+
onCancel={() => setVisible7(false)}
|
|
137
|
+
onConfirm={() => setVisible7(false)}
|
|
138
|
+
mask={false}
|
|
139
|
+
cancel={false}
|
|
140
|
+
close={true}
|
|
141
|
+
sheetsType={SheetsType.SheetsType.action}
|
|
142
|
+
closeText={"按钮"}
|
|
143
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
144
|
+
>
|
|
145
|
+
<Children />
|
|
146
|
+
</Sheets>
|
|
147
|
+
|
|
148
|
+
<Button onClick={() => setVisible6(true)}>可拖拽(不限制最大高度)</Button>
|
|
149
|
+
<Sheets
|
|
150
|
+
visible={visible6}
|
|
151
|
+
label={"标题"}
|
|
152
|
+
onCancel={() => setVisible6(false)}
|
|
153
|
+
onConfirm={() => setVisible6(false)}
|
|
154
|
+
mask={true}
|
|
155
|
+
sheetsType={SheetsType.SheetsType.dragable}
|
|
156
|
+
maskMode={SheetsType.SheetsMaskMode.light}
|
|
157
|
+
>
|
|
158
|
+
<Children />
|
|
159
|
+
</Sheets>
|
|
160
|
+
|
|
161
|
+
<Button onClick={() => setVisible8(true)}>可拖拽(限制最大高度是整个屏幕高度的50%)</Button>
|
|
162
|
+
<Sheets
|
|
163
|
+
visible={visible8}
|
|
164
|
+
label={"标题"}
|
|
165
|
+
onCancel={() => setVisible8(false)}
|
|
166
|
+
onConfirm={() => setVisible8(false)}
|
|
167
|
+
mask={true}
|
|
168
|
+
size={SheetsType.SheetsSize.half}
|
|
169
|
+
sheetsType={SheetsType.SheetsType.dragable}
|
|
170
|
+
maskMode={SheetsType.SheetsMaskMode.light}
|
|
171
|
+
>
|
|
172
|
+
<Children />
|
|
173
|
+
</Sheets>
|
|
174
|
+
|
|
175
|
+
<Button onClick={() => setVisible9(true)}>可拖拽(限制最大高度是整个屏幕高度的75%)</Button>
|
|
176
|
+
<Sheets
|
|
177
|
+
visible={visible9}
|
|
178
|
+
label={"标题"}
|
|
179
|
+
onCancel={() => setVisible9(false)}
|
|
180
|
+
onConfirm={() => setVisible9(false)}
|
|
181
|
+
mask={true}
|
|
182
|
+
size={SheetsType.SheetsSize.threeQuater}
|
|
183
|
+
sheetsType={SheetsType.SheetsType.dragable}
|
|
184
|
+
maskMode={SheetsType.SheetsMaskMode.light}
|
|
185
|
+
>
|
|
186
|
+
<Children />
|
|
187
|
+
</Sheets>
|
|
188
|
+
|
|
189
|
+
<Button onClick={() => setVisible10(true)}>可拖拽(限制最大高度是整个屏幕高度的100%)</Button>
|
|
190
|
+
<Sheets
|
|
191
|
+
visible={visible10}
|
|
192
|
+
label={"标题"}
|
|
193
|
+
onCancel={() => setVisible10(false)}
|
|
194
|
+
onConfirm={() => setVisible10(false)}
|
|
195
|
+
mask={true}
|
|
196
|
+
size={SheetsType.SheetsSize.full}
|
|
197
|
+
sheetsType={SheetsType.SheetsType.dragable}
|
|
198
|
+
maskMode={SheetsType.SheetsMaskMode.light}
|
|
199
|
+
>
|
|
200
|
+
<Children />
|
|
201
|
+
</Sheets>
|
|
202
|
+
|
|
203
|
+
<Button onClick={() => setVisible11(true)}>高度整个屏幕高度的50%</Button>
|
|
31
204
|
<Sheets
|
|
32
|
-
visible={
|
|
33
|
-
label={"
|
|
34
|
-
onCancel={() =>
|
|
35
|
-
onConfirm={() =>
|
|
205
|
+
visible={visible11}
|
|
206
|
+
label={"标题"}
|
|
207
|
+
onCancel={() => setVisible11(false)}
|
|
208
|
+
onConfirm={() => setVisible11(false)}
|
|
209
|
+
cancel={false}
|
|
210
|
+
close={true}
|
|
211
|
+
size={SheetsType.SheetsSize.half}
|
|
212
|
+
closeType={SheetsType.SheetsActionType.icon}
|
|
213
|
+
mask={true}
|
|
214
|
+
maskMode={SheetsType.SheetsMaskMode.dark}
|
|
36
215
|
>
|
|
37
|
-
<
|
|
38
|
-
<Text>这是一个默认sheet</Text>
|
|
39
|
-
</View>
|
|
216
|
+
<Children />
|
|
40
217
|
</Sheets>
|
|
41
218
|
</View>
|
|
42
219
|
);
|
|
@@ -10,11 +10,22 @@ import BaseDemo from "!!raw-loader!../demo/index.tsx";
|
|
|
10
10
|
|
|
11
11
|
### Props
|
|
12
12
|
|
|
13
|
-
| 属性
|
|
14
|
-
|
|
|
15
|
-
| label
|
|
16
|
-
|
|
|
17
|
-
|
|
|
13
|
+
| 属性 | 描述 | 类型 | 默认值 |
|
|
14
|
+
| ---------- | -------------- | ---------------- | --------------------- |
|
|
15
|
+
| label | 标题 | string | |
|
|
16
|
+
| mask | 是否展示遮罩层 | boolean | true |
|
|
17
|
+
| maskMode | 背景颜色类型 | SheetsMaskMode | SheetsMaskMode.light |
|
|
18
|
+
| sheetsType | sheets类型 | SheetsType | SheetsType.normal |
|
|
19
|
+
| cancel | 返回按钮 | boolean | true |
|
|
20
|
+
| close | 关闭按钮 | boolean | true |
|
|
21
|
+
| cancelType | 返回按钮类型 | SheetsActionType | SheetsActionType.icon |
|
|
22
|
+
| closeType | 确定按钮类型 | SheetsActionType | SheetsActionType.icon |
|
|
23
|
+
| cancelText | 取消操作文案 | string | 取消 |
|
|
24
|
+
| closeText | 确定操作文案 | string | 确定 |
|
|
25
|
+
| iconType | icon 类型 | SheetsIconType | SheetsIconType.normal |
|
|
26
|
+
| size | size | SheetsSize | SheetsSize.auto |
|
|
27
|
+
| visible | 是否展示sheets | boolean | false |
|
|
28
|
+
| children | sheets内容 | ReactNode | |
|
|
18
29
|
|
|
19
30
|
### Events
|
|
20
31
|
|
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
export const enum SheetsMaskMode {
|
|
4
|
+
light = "light",
|
|
5
|
+
dark = "dark",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const enum SheetsType {
|
|
9
|
+
normal = "narmal",
|
|
10
|
+
dragable = "dragable",
|
|
11
|
+
action = "action",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const enum SheetsActionType {
|
|
15
|
+
text = "text",
|
|
16
|
+
icon = "icon",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const enum SheetsIconType {
|
|
20
|
+
bg = "bg",
|
|
21
|
+
normal = "normal",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const enum SheetsSize {
|
|
25
|
+
auto = "auto",
|
|
26
|
+
half = "half",
|
|
27
|
+
full = "full",
|
|
28
|
+
threeQuater = "threeQuater",
|
|
29
|
+
}
|
|
2
30
|
export interface RedsSheets {
|
|
3
31
|
label?: string;
|
|
32
|
+
mask?: boolean;
|
|
33
|
+
maskMode?: SheetsMaskMode;
|
|
34
|
+
sheetsType?: SheetsType;
|
|
35
|
+
cancel?: boolean;
|
|
36
|
+
close?: boolean;
|
|
37
|
+
cancelType?: SheetsActionType;
|
|
38
|
+
closeType?: SheetsActionType;
|
|
39
|
+
cancelText?: string;
|
|
40
|
+
closeText?: string;
|
|
41
|
+
iconType?: SheetsIconType;
|
|
42
|
+
size?: SheetsSize;
|
|
4
43
|
onCancel: () => any;
|
|
5
44
|
onConfirm: () => any;
|
|
6
45
|
visible: boolean;
|
|
@@ -10,6 +49,17 @@ export interface RedsSheets {
|
|
|
10
49
|
export interface RedsSheetsEvent {}
|
|
11
50
|
export const SheetsDefaultProps = {
|
|
12
51
|
label: "",
|
|
52
|
+
mask: true,
|
|
53
|
+
maskMode: SheetsMaskMode.light,
|
|
54
|
+
sheetsType: SheetsType.normal,
|
|
55
|
+
cancel: true,
|
|
56
|
+
close: true,
|
|
57
|
+
cancelType: SheetsActionType.icon,
|
|
58
|
+
closeType: SheetsActionType.icon,
|
|
59
|
+
cancelText: "取消",
|
|
60
|
+
closeText: "确定",
|
|
61
|
+
iconType: SheetsIconType.normal,
|
|
62
|
+
size: SheetsSize.auto,
|
|
13
63
|
onCancel: () => {},
|
|
14
64
|
onConfirm: () => {},
|
|
15
65
|
visible: false,
|