@xhsreds/reds-rn-next 0.10.1-beta202511211532 → 0.10.1-beta202512021041
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/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-21.json +1 -1
- package/coverage/.tmp/coverage-22.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-3.json +1 -1
- package/coverage/.tmp/coverage-31.json +1 -1
- package/coverage/.tmp/coverage-32.json +1 -1
- package/coverage/.tmp/coverage-33.json +1 -1
- package/coverage/.tmp/coverage-34.json +1 -1
- package/coverage/.tmp/coverage-35.json +1 -1
- package/coverage/.tmp/coverage-36.json +1 -1
- package/coverage/.tmp/coverage-37.json +1 -1
- package/coverage/.tmp/coverage-38.json +1 -1
- package/coverage/.tmp/coverage-39.json +1 -1
- package/coverage/.tmp/coverage-4.json +1 -1
- package/coverage/.tmp/coverage-40.json +1 -1
- package/coverage/.tmp/coverage-41.json +1 -1
- package/coverage/.tmp/coverage-42.json +1 -1
- package/coverage/.tmp/coverage-43.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/hA3qoGpS.js.map +1 -1
- package/lib/cjs/components/ActionablePopover/ActionablePopover.js +2 -2
- package/lib/cjs/components/ActionablePopover/ActionablePopover.js.map +1 -1
- package/lib/cjs/components/BottomBar/styles.js +1 -1
- package/lib/cjs/components/BottomBar/styles.js.map +1 -1
- package/lib/cjs/components/Divider/Divider.js +33 -12
- package/lib/cjs/components/Divider/Divider.js.map +1 -1
- package/lib/cjs/components/Divider/index.js +3 -3
- package/lib/cjs/components/Divider/styles.js +36 -30
- package/lib/cjs/components/Divider/styles.js.map +1 -1
- package/lib/cjs/components/List/ListItem/ListItem.js +4 -2
- package/lib/cjs/components/List/ListItem/ListItem.js.map +1 -1
- package/lib/cjs/components/PickerView/Wheel.js +57 -16
- package/lib/cjs/components/PickerView/Wheel.js.map +1 -1
- package/lib/cjs/components/Stepper/Stepper.js +1 -1
- package/lib/cjs/components/Stepper/Stepper.js.map +1 -1
- package/lib/cjs/components/Stepper/styles.js +2 -2
- package/lib/cjs/components/Stepper/styles.js.map +1 -1
- package/lib/esm/_chunks/C0MWVrjO.js.map +1 -1
- package/lib/esm/components/ActionablePopover/ActionablePopover.js +1 -1
- package/lib/esm/components/ActionablePopover/ActionablePopover.js.map +1 -1
- package/lib/esm/components/BottomBar/styles.js +1 -1
- package/lib/esm/components/BottomBar/styles.js.map +1 -1
- package/lib/esm/components/Divider/Divider.js +35 -14
- package/lib/esm/components/Divider/Divider.js.map +1 -1
- package/lib/esm/components/Divider/index.js +3 -3
- package/lib/esm/components/Divider/styles.js +36 -30
- package/lib/esm/components/Divider/styles.js.map +1 -1
- package/lib/esm/components/List/ListItem/ListItem.js +5 -3
- package/lib/esm/components/List/ListItem/ListItem.js.map +1 -1
- package/lib/esm/components/PickerView/Wheel.js +57 -16
- package/lib/esm/components/PickerView/Wheel.js.map +1 -1
- package/lib/esm/components/Stepper/Stepper.js +1 -1
- package/lib/esm/components/Stepper/Stepper.js.map +1 -1
- package/lib/esm/components/Stepper/styles.js +2 -2
- package/lib/esm/components/Stepper/styles.js.map +1 -1
- package/lib/src/components/BottomBar/styles.d.ts +1 -1
- package/lib/src/components/Divider/styles.d.ts +3 -2
- package/lib/src/components/List/ListItem/ListItem.d.ts +2 -0
- package/lib/src/components/Stepper/interface/index.d.ts +1 -0
- package/lib/src/components/Stepper/styles.d.ts +2 -2
- package/lib/types/components/BottomBar/styles.d.ts +1 -1
- package/lib/types/components/Divider/styles.d.ts +3 -2
- package/lib/types/components/List/ListItem/ListItem.d.ts +2 -0
- package/lib/types/components/Stepper/interface/index.d.ts +1 -0
- package/lib/types/components/Stepper/styles.d.ts +2 -2
- package/package.json +2 -2
- package/src/components/ActionablePopover/ActionablePopover.tsx +10 -1
- package/src/components/BottomBar/styles.ts +1 -1
- package/src/components/Divider/Divider.tsx +29 -9
- package/src/components/Divider/demo/index.tsx +12 -6
- package/src/components/Divider/styles.ts +33 -30
- package/src/components/List/ListItem/ListItem.tsx +12 -1
- package/src/components/List/demo/index.tsx +2 -0
- package/src/components/PickerView/Wheel.tsx +59 -12
- package/src/components/Stepper/Stepper.tsx +1 -1
- package/src/components/Stepper/demo/index.tsx +1 -1
- package/src/components/Stepper/doc/index.mdx +1 -0
- package/src/components/Stepper/interface/index.ts +1 -0
- package/src/components/Stepper/styles.ts +2 -2
- package/src/i18n/@types/resources.d.ts +18 -18
- package/src/i18n/index.json +31 -31
|
@@ -3,7 +3,8 @@ export declare const getStyles: (themeColor: any, typography: any) => {
|
|
|
3
3
|
display: "flex";
|
|
4
4
|
flexDirection: "row";
|
|
5
5
|
alignItems: "center";
|
|
6
|
-
justifyContent: "
|
|
6
|
+
justifyContent: "space-between";
|
|
7
|
+
width: number;
|
|
7
8
|
};
|
|
8
9
|
opacity: {
|
|
9
10
|
opacity: number;
|
|
@@ -19,7 +20,6 @@ export declare const getStyles: (themeColor: any, typography: any) => {
|
|
|
19
20
|
lineHeight: number;
|
|
20
21
|
};
|
|
21
22
|
text: {
|
|
22
|
-
paddingHorizontal: number;
|
|
23
23
|
fontWeight: any;
|
|
24
24
|
fontSize: any;
|
|
25
25
|
color: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xhsreds/reds-rn-next",
|
|
3
|
-
"version": "0.10.1-
|
|
3
|
+
"version": "0.10.1-beta202512021041",
|
|
4
4
|
"author": "贾斌(呀哈) <jiabin@xiaohongshu.com>",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"dependencies": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react-native-fs": "2.20.0",
|
|
27
27
|
"react-native-svg": "13.14.0",
|
|
28
28
|
"@xhs/react-native-harmony": "*",
|
|
29
|
-
"@xhsreds/reds-token-next": "0.10.1-
|
|
29
|
+
"@xhsreds/reds-token-next": "0.10.1-beta202512021041"
|
|
30
30
|
},
|
|
31
31
|
"peerDependenciesMeta": {
|
|
32
32
|
"ozone-schema-web": {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import React, { useState, useMemo, isValidElement, useEffect, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Text,
|
|
4
|
+
View,
|
|
5
|
+
TouchableWithoutFeedback,
|
|
6
|
+
GestureResponderEvent,
|
|
7
|
+
Animated,
|
|
8
|
+
Image,
|
|
9
|
+
Dimensions,
|
|
10
|
+
Platform,
|
|
11
|
+
} from "react-native";
|
|
3
12
|
import { RedsActionablePopover, ActionablePopoverData } from "./interface/index";
|
|
4
13
|
import { ModalWrapper } from "./component";
|
|
5
14
|
import useMounted from "../../pvCount/useUnmountedProcess";
|
|
@@ -1,28 +1,48 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState, useMemo } from "react";
|
|
2
2
|
import { View, Text } from "react-native";
|
|
3
3
|
import { RedsDivider, DividerDefaultProps } from "./interface";
|
|
4
4
|
import { getStyles } from "./styles";
|
|
5
5
|
import useMounted from "../../pvCount/useUnmountedProcess";
|
|
6
|
+
import { useThemeColor, useThemeTypography } from "../ConfigProvider";
|
|
6
7
|
|
|
7
8
|
const Divider = (props: RedsDivider) => {
|
|
9
|
+
const [textWidth, setTextWidth] = useState(0);
|
|
10
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
11
|
+
const themeColor = useThemeColor("Divider");
|
|
12
|
+
const typography = useThemeTypography("Divider");
|
|
8
13
|
useMounted("Divider");
|
|
9
14
|
const finalProps: RedsDivider = {
|
|
10
15
|
...DividerDefaultProps,
|
|
11
16
|
...props,
|
|
12
|
-
direction: props.direction as RedsDivider["direction"],
|
|
13
|
-
orientation: props.orientation as RedsDivider["orientation"],
|
|
17
|
+
direction: (props.direction || DividerDefaultProps.direction) as RedsDivider["direction"],
|
|
18
|
+
orientation: (props.orientation || DividerDefaultProps.orientation) as RedsDivider["orientation"],
|
|
14
19
|
};
|
|
15
20
|
|
|
16
|
-
const styles =
|
|
17
|
-
|
|
21
|
+
const styles = useMemo(() => {
|
|
22
|
+
return getStyles(finalProps, textWidth, containerWidth, themeColor, typography);
|
|
23
|
+
}, [textWidth, containerWidth, themeColor, typography]);
|
|
24
|
+
|
|
25
|
+
const handleLayout = (e: any) => {
|
|
26
|
+
setTextWidth(e.nativeEvent.layout.width);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handlerContainerWidth = (e: any) => {
|
|
30
|
+
setContainerWidth(e.nativeEvent.layout.width);
|
|
31
|
+
};
|
|
18
32
|
|
|
19
33
|
return (
|
|
20
|
-
<View style={[styles.divider, styles[finalProps.direction!]]}>
|
|
34
|
+
<View style={[styles.divider, styles[finalProps.direction!]]} onLayout={handlerContainerWidth}>
|
|
21
35
|
{finalProps.orientation && finalProps.direction !== "vertical" && (
|
|
22
36
|
<View style={styles.textContainer}>
|
|
23
|
-
|
|
24
|
-
{props.children
|
|
25
|
-
|
|
37
|
+
<View style={styles.before} />
|
|
38
|
+
{props.children ? (
|
|
39
|
+
<Text style={styles.text} onLayout={handleLayout}>
|
|
40
|
+
{props.children}
|
|
41
|
+
</Text>
|
|
42
|
+
) : (
|
|
43
|
+
<Text style={styles.noTextBorderStyle}></Text>
|
|
44
|
+
)}
|
|
45
|
+
<View style={styles.after} />
|
|
26
46
|
</View>
|
|
27
47
|
)}
|
|
28
48
|
</View>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
|
-
import { View, Text, StyleSheet } from "react-native";
|
|
2
|
+
import { View, Text, StyleSheet, ScrollView } from "react-native";
|
|
3
3
|
import { Divider } from "@xhs/reds-rn-next";
|
|
4
4
|
|
|
5
5
|
const styles = StyleSheet.create({
|
|
@@ -21,23 +21,29 @@ const Br = (props: { height?: number }) => <View style={{ height: props.height |
|
|
|
21
21
|
|
|
22
22
|
export default function App() {
|
|
23
23
|
return (
|
|
24
|
-
<
|
|
24
|
+
<ScrollView>
|
|
25
|
+
<Br />
|
|
26
|
+
<Br />
|
|
25
27
|
<Desc>默认用法</Desc>
|
|
26
28
|
<Divider>测试</Divider>
|
|
27
29
|
<Br />
|
|
28
|
-
<Desc>direction
|
|
30
|
+
<Desc>direction="primary"</Desc>
|
|
29
31
|
<Divider direction="primary" orientation={"center"}>
|
|
30
32
|
测试
|
|
31
33
|
</Divider>
|
|
32
34
|
<Br />
|
|
33
|
-
<
|
|
35
|
+
<Desc>direction="secondary"</Desc>
|
|
36
|
+
<Divider direction="secondary" orientation={"center"}>
|
|
37
|
+
测试
|
|
38
|
+
</Divider>
|
|
34
39
|
<Br />
|
|
35
40
|
|
|
41
|
+
<Desc>direction="vertical"</Desc>
|
|
36
42
|
<View style={styles.itemBox}>
|
|
37
43
|
<Divider direction="vertical">测试</Divider>
|
|
38
44
|
</View>
|
|
45
|
+
<Desc>direction="horizontal"</Desc>
|
|
39
46
|
<Divider direction="horizontal">测试</Divider>
|
|
40
|
-
<Divider direction="horizontal"></Divider>
|
|
41
47
|
<Br />
|
|
42
48
|
<Br />
|
|
43
49
|
|
|
@@ -67,6 +73,6 @@ export default function App() {
|
|
|
67
73
|
<Desc>margin 数组:horizontal / [上下,左右] vertical / [左右]</Desc>
|
|
68
74
|
<Divider margin={[10, 20]} stroke={2} direction="horizontal" />
|
|
69
75
|
<Divider margin={[10, 0]} stroke={2} direction="vertical" />
|
|
70
|
-
</
|
|
76
|
+
</ScrollView>
|
|
71
77
|
);
|
|
72
78
|
}
|
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
import { StyleSheet, ViewStyle, TextStyle, DimensionValue } from "react-native";
|
|
2
2
|
import { RedsDivider, DividerDefaultProps } from "./interface";
|
|
3
|
-
import { useThemeColor, useThemeTypography } from "../ConfigProvider";
|
|
4
3
|
|
|
5
4
|
const baseDivider: ViewStyle = {
|
|
6
5
|
position: "relative",
|
|
7
6
|
};
|
|
8
7
|
|
|
9
|
-
const
|
|
10
|
-
paddingVertical: 0,
|
|
11
|
-
paddingHorizontal: 16,
|
|
12
|
-
position: "absolute",
|
|
13
|
-
backgroundColor: "#fff",
|
|
14
|
-
lineHeight: 18,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const getStyles = (p: RedsDivider) => {
|
|
8
|
+
const getStyles = (p: RedsDivider, textWidth: number, containerWidth: number, themeColor: any, typography: any) => {
|
|
18
9
|
const props = { ...DividerDefaultProps, ...p };
|
|
19
|
-
const themeColor = useThemeColor("Divider");
|
|
20
|
-
const typography = useThemeTypography("Divider");
|
|
21
10
|
const isHorizontal = props.direction === "horizontal";
|
|
11
|
+
const hasTextContent = p.children;
|
|
12
|
+
|
|
13
|
+
const remainingWidth = containerWidth - textWidth;
|
|
14
|
+
|
|
22
15
|
const beforeAfterCommon: ViewStyle = {
|
|
23
16
|
borderStyle: "solid",
|
|
24
|
-
borderTopWidth: 0.5,
|
|
17
|
+
borderTopWidth: props.stroke || 0.5,
|
|
25
18
|
borderColor: props.color || themeColor.Separator2,
|
|
26
|
-
width: 8,
|
|
27
19
|
};
|
|
28
20
|
|
|
29
21
|
const dividerStyle: ViewStyle = {
|
|
30
22
|
...baseDivider,
|
|
31
|
-
borderBottomWidth: isHorizontal ? (props.stroke ? props.stroke : StyleSheet.hairlineWidth) : 0,
|
|
32
|
-
borderLeftWidth: isHorizontal ? 0 : props.stroke ? props.stroke : StyleSheet.hairlineWidth,
|
|
33
|
-
borderBottomColor: isHorizontal ? props.color || themeColor.Separator2 : undefined,
|
|
34
|
-
borderLeftColor: isHorizontal ? undefined : props.color || themeColor.Separator2,
|
|
35
|
-
borderStyle: "solid",
|
|
23
|
+
// borderBottomWidth: isHorizontal && hasTextContent ? 0 : (isHorizontal ? (props.stroke ? props.stroke : StyleSheet.hairlineWidth) : 0),
|
|
24
|
+
// borderLeftWidth: isHorizontal ? 0 : props.stroke ? props.stroke : StyleSheet.hairlineWidth,
|
|
25
|
+
// borderBottomColor: isHorizontal && !hasTextContent ? props.color || themeColor.Separator2 : undefined,
|
|
26
|
+
// borderLeftColor: isHorizontal ? undefined : props.color || themeColor.Separator2,
|
|
27
|
+
// borderStyle: "solid",
|
|
36
28
|
marginVertical: (props.margin && props.margin[0] && Number(props.margin[0])) || (isHorizontal ? 20 : 0),
|
|
37
29
|
marginHorizontal: (props.margin && props.margin[1] && Number(props.margin[1])) || (isHorizontal ? 0 : 12),
|
|
38
30
|
marginLeft:
|
|
@@ -47,17 +39,11 @@ const getStyles = (p: RedsDivider) => {
|
|
|
47
39
|
width: (isHorizontal ? props.size : "auto") as DimensionValue,
|
|
48
40
|
};
|
|
49
41
|
|
|
50
|
-
const textContainer:
|
|
51
|
-
paddingVertical: 0,
|
|
52
|
-
paddingHorizontal: 16,
|
|
53
|
-
position: "absolute",
|
|
54
|
-
lineHeight: 18,
|
|
55
|
-
left: props.orientation === "left" ? 24 : undefined,
|
|
56
|
-
right: props.orientation === "right" ? 24 : undefined,
|
|
57
|
-
alignSelf: props.orientation === "center" ? "center" : undefined,
|
|
42
|
+
const textContainer: ViewStyle = {
|
|
58
43
|
flexDirection: "row",
|
|
59
44
|
alignItems: "center",
|
|
60
|
-
|
|
45
|
+
width: "100%",
|
|
46
|
+
// 移除 position absolute,改为正常布局
|
|
61
47
|
};
|
|
62
48
|
|
|
63
49
|
const textStyle: TextStyle = {
|
|
@@ -78,13 +64,29 @@ const getStyles = (p: RedsDivider) => {
|
|
|
78
64
|
|
|
79
65
|
const beforeStyle: ViewStyle = {
|
|
80
66
|
...beforeAfterCommon,
|
|
81
|
-
marginRight: 8,
|
|
67
|
+
marginRight: props.children ? 8 : 0,
|
|
68
|
+
...(isHorizontal
|
|
69
|
+
? props.orientation === "center"
|
|
70
|
+
? { flex: 1 }
|
|
71
|
+
: { width: props.orientation === "left" ? remainingWidth * 0.15 : remainingWidth * 0.85 }
|
|
72
|
+
: { width: 8 }),
|
|
82
73
|
borderColor: props.direction === "secondary" ? "rgba(51, 51, 51, .3)" : props.color || themeColor.Separator2,
|
|
83
74
|
};
|
|
84
75
|
|
|
85
76
|
const afterStyle: ViewStyle = {
|
|
86
77
|
...beforeAfterCommon,
|
|
87
|
-
marginLeft: 8,
|
|
78
|
+
marginLeft: props.children ? 8 : 0,
|
|
79
|
+
...(isHorizontal
|
|
80
|
+
? props.orientation === "center"
|
|
81
|
+
? { flex: 1 }
|
|
82
|
+
: { width: props.orientation === "right" ? remainingWidth * 0.15 : remainingWidth * 0.85 }
|
|
83
|
+
: { width: 8 }),
|
|
84
|
+
borderColor: props.direction === "secondary" ? "rgba(51, 51, 51, .3)" : props.color || themeColor.Separator2,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const noTextBorderStyle: ViewStyle = {
|
|
88
|
+
...beforeAfterCommon,
|
|
89
|
+
width: "auto",
|
|
88
90
|
borderColor: props.direction === "secondary" ? "rgba(51, 51, 51, .3)" : props.color || themeColor.Separator2,
|
|
89
91
|
};
|
|
90
92
|
|
|
@@ -104,6 +106,7 @@ const getStyles = (p: RedsDivider) => {
|
|
|
104
106
|
text: textStyle,
|
|
105
107
|
before: beforeStyle,
|
|
106
108
|
after: afterStyle,
|
|
109
|
+
noTextBorderStyle: noTextBorderStyle,
|
|
107
110
|
});
|
|
108
111
|
};
|
|
109
112
|
|
|
@@ -21,6 +21,8 @@ export interface RedsListItem {
|
|
|
21
21
|
contentStyle?: ViewStyle;
|
|
22
22
|
badgeActionContent?: string;
|
|
23
23
|
badgeTitleContent?: string;
|
|
24
|
+
style?: any;
|
|
25
|
+
lineStyle?: any;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const ListItem: React.FC<RedsListItem> = ({
|
|
@@ -38,6 +40,8 @@ const ListItem: React.FC<RedsListItem> = ({
|
|
|
38
40
|
children,
|
|
39
41
|
badgeActionContent,
|
|
40
42
|
badgeTitleContent,
|
|
43
|
+
style,
|
|
44
|
+
lineStyle,
|
|
41
45
|
}) => {
|
|
42
46
|
useMounted("ListItem");
|
|
43
47
|
const styles = createStyles();
|
|
@@ -66,6 +70,7 @@ const ListItem: React.FC<RedsListItem> = ({
|
|
|
66
70
|
styles.listItem,
|
|
67
71
|
children ? {} : { height: listItemSizeToHeight[size] },
|
|
68
72
|
size === "expand" && styles.expand,
|
|
73
|
+
style,
|
|
69
74
|
]}
|
|
70
75
|
>
|
|
71
76
|
{children ? (
|
|
@@ -75,7 +80,13 @@ const ListItem: React.FC<RedsListItem> = ({
|
|
|
75
80
|
{prefix && (
|
|
76
81
|
<View style={[styles.prefix, { height: listItemSizeToHeight[size] }, prefixStyle]}>{prefix}</View>
|
|
77
82
|
)}
|
|
78
|
-
<View
|
|
83
|
+
<View
|
|
84
|
+
style={[
|
|
85
|
+
styles.contentBox,
|
|
86
|
+
lineItem ? { ...styles.hr, ...lineStyle } : {},
|
|
87
|
+
{ height: listItemSizeToHeight[size] },
|
|
88
|
+
]}
|
|
89
|
+
>
|
|
79
90
|
<View
|
|
80
91
|
style={[styles.contentContainer, { marginBottom: 12, marginTop: 12 }, prefix ? { height: 48 } : {}]}
|
|
81
92
|
>
|
|
@@ -15,31 +15,71 @@ const Wheel = (props: RedsWheel) => {
|
|
|
15
15
|
*/
|
|
16
16
|
const scrollerRef = useRef();
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const themeColor = useThemeColor();
|
|
18
|
+
const [scrollEnded, setScrollEnded] = useState(false);
|
|
19
|
+
|
|
20
|
+
const [scrollHeight, setScrollHeight] = useState(0);
|
|
22
21
|
|
|
23
22
|
const [lastValue, setLastValue] = useState(value);
|
|
24
23
|
|
|
24
|
+
const onScrollEndDrag = () => {
|
|
25
|
+
setScrollEnded(true);
|
|
26
|
+
};
|
|
27
|
+
|
|
25
28
|
/**
|
|
26
29
|
* 初始化滚动高度
|
|
27
30
|
*/
|
|
28
31
|
useEffect(() => {
|
|
29
32
|
if (value !== lastValue) {
|
|
30
33
|
const idx = getSelectIndex(column, value);
|
|
31
|
-
|
|
34
|
+
setIndex(idx);
|
|
32
35
|
}
|
|
33
36
|
}, [column, value]);
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
/**
|
|
39
|
+
* themeColor
|
|
40
|
+
*/
|
|
41
|
+
const themeColor = useThemeColor();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* index
|
|
45
|
+
*/
|
|
46
|
+
const [index, setIndex] = useState<any>();
|
|
47
|
+
|
|
48
|
+
const timer = useRef<any>();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 初始化滚动高度
|
|
52
|
+
*/
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
value && setIndex(getSelectIndex(column, value));
|
|
55
|
+
}, [column, value]);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const newVal = column?.[index]?.value;
|
|
59
|
+
scrollTo(index * itemHeight);
|
|
38
60
|
if (newVal) {
|
|
39
|
-
setLastValue(newVal);
|
|
40
61
|
onSelect(newVal, props.index);
|
|
62
|
+
setLastValue(newVal);
|
|
41
63
|
}
|
|
42
|
-
};
|
|
64
|
+
}, [index, props.index]);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (scrollEnded) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
if (scrollHeight != null) {
|
|
70
|
+
timer.current = setTimeout(() => {
|
|
71
|
+
const selectIndex = Math.round(scrollHeight / itemHeight);
|
|
72
|
+
if (selectIndex >= 0 && selectIndex < column.length) {
|
|
73
|
+
setIndex(selectIndex);
|
|
74
|
+
}
|
|
75
|
+
}, 0);
|
|
76
|
+
}
|
|
77
|
+
setScrollEnded(false);
|
|
78
|
+
}
|
|
79
|
+
return () => {
|
|
80
|
+
timer.current && clearTimeout(timer.current);
|
|
81
|
+
};
|
|
82
|
+
}, [scrollEnded]);
|
|
43
83
|
|
|
44
84
|
/**
|
|
45
85
|
* 滚动ScrollView
|
|
@@ -84,13 +124,17 @@ const Wheel = (props: RedsWheel) => {
|
|
|
84
124
|
e.persist?.();
|
|
85
125
|
let contentOffset = e.nativeEvent.contentOffset;
|
|
86
126
|
const selectIndex = Math.round(contentOffset.y / itemHeight);
|
|
127
|
+
setIndex(selectIndex);
|
|
87
128
|
const newVal = column?.[selectIndex]?.value;
|
|
88
129
|
setLastValue(newVal);
|
|
89
|
-
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
133
|
+
setScrollHeight(e.nativeEvent.contentOffset.y);
|
|
90
134
|
};
|
|
91
135
|
|
|
92
136
|
const handleClick = (index: number) => {
|
|
93
|
-
|
|
137
|
+
setIndex(index);
|
|
94
138
|
};
|
|
95
139
|
|
|
96
140
|
/**
|
|
@@ -127,6 +171,9 @@ const Wheel = (props: RedsWheel) => {
|
|
|
127
171
|
decelerationRate="fast"
|
|
128
172
|
snapToInterval={itemHeight}
|
|
129
173
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
174
|
+
onScrollEndDrag={onScrollEndDrag}
|
|
175
|
+
onScroll={onScroll}
|
|
176
|
+
scrollEventThrottle={16}
|
|
130
177
|
testID={`wheel${props.index}`}
|
|
131
178
|
{...accessibility}
|
|
132
179
|
>
|
|
@@ -84,7 +84,7 @@ const Stepper = (props: RedsStepper) => {
|
|
|
84
84
|
}, [colorMode]);
|
|
85
85
|
|
|
86
86
|
return (
|
|
87
|
-
<View style={styles.container}>
|
|
87
|
+
<View style={[styles.container, props.style]}>
|
|
88
88
|
<TouchableWithoutFeedback onPress={() => handleNumber("min")}>
|
|
89
89
|
<View style={[styles.icon, minus]}>
|
|
90
90
|
<Image source={{ uri: minusImage }} style={[styles.minus]} />
|
|
@@ -21,7 +21,7 @@ export default function App() {
|
|
|
21
21
|
return (
|
|
22
22
|
<View style={styles.container}>
|
|
23
23
|
<Text>基础用法</Text>
|
|
24
|
-
<Stepper value={value} onChange={handleChange} />
|
|
24
|
+
<Stepper value={value} onChange={handleChange} style={{ width: 200 }} />
|
|
25
25
|
|
|
26
26
|
<Text>基础用法(非受控)</Text>
|
|
27
27
|
<Stepper isControl={false} />
|
|
@@ -5,7 +5,8 @@ export const getStyles = (themeColor: any, typography: any) => {
|
|
|
5
5
|
display: "flex",
|
|
6
6
|
flexDirection: "row",
|
|
7
7
|
alignItems: "center",
|
|
8
|
-
justifyContent: "
|
|
8
|
+
justifyContent: "space-between",
|
|
9
|
+
width: 72,
|
|
9
10
|
},
|
|
10
11
|
opacity: {
|
|
11
12
|
opacity: 0.5,
|
|
@@ -21,7 +22,6 @@ export const getStyles = (themeColor: any, typography: any) => {
|
|
|
21
22
|
lineHeight: 20,
|
|
22
23
|
},
|
|
23
24
|
text: {
|
|
24
|
-
paddingHorizontal: 8,
|
|
25
25
|
fontWeight: typography.B1LooseFontWeight,
|
|
26
26
|
fontSize: typography.T3FontSize,
|
|
27
27
|
color: themeColor.Title,
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
interface Resources {
|
|
2
2
|
componentKey: {
|
|
3
|
-
sureKey: "
|
|
4
|
-
satisfyKey: "
|
|
5
|
-
confirmKey: "
|
|
6
|
-
uploadingKey: "
|
|
3
|
+
sureKey: "確定";
|
|
4
|
+
satisfyKey: "滿意";
|
|
5
|
+
confirmKey: "確認";
|
|
6
|
+
uploadingKey: "上傳中";
|
|
7
7
|
resetKey: "重置";
|
|
8
|
-
NoDataKey: "
|
|
8
|
+
NoDataKey: "暫無數據";
|
|
9
9
|
liveStreamingKey: "直播";
|
|
10
10
|
generallyKey: "一般";
|
|
11
|
-
uploadFailedKey: "
|
|
11
|
+
uploadFailedKey: "上傳失敗";
|
|
12
12
|
submitKey: "提交";
|
|
13
|
-
requestSuccessfulKey: "
|
|
13
|
+
requestSuccessfulKey: "請求成功";
|
|
14
14
|
cancelKey: "取消";
|
|
15
|
-
PullDownToRefreshKey: "
|
|
16
|
-
selectAllKey: "
|
|
17
|
-
requestDataKey: "
|
|
15
|
+
PullDownToRefreshKey: "下拉重繪";
|
|
16
|
+
selectAllKey: "全選";
|
|
17
|
+
requestDataKey: "請求數據中";
|
|
18
18
|
closeKey: "收起";
|
|
19
|
-
veryBadKey: "
|
|
20
|
-
searchKey: "
|
|
21
|
-
expandKey: "
|
|
22
|
-
IDCardPhotoKey: "
|
|
19
|
+
veryBadKey: "極差";
|
|
20
|
+
searchKey: "蒐索";
|
|
21
|
+
expandKey: "展開";
|
|
22
|
+
IDCardPhotoKey: "身份證人像面";
|
|
23
23
|
finishKey: "完成";
|
|
24
|
-
surpriseKey: "
|
|
25
|
-
releaseRefreshKey: "
|
|
24
|
+
surpriseKey: "驚喜";
|
|
25
|
+
releaseRefreshKey: "鬆開重繪";
|
|
26
26
|
nationalEmblemSideOfIDCardKey: "身份证国徽面";
|
|
27
|
-
buttonKey: "
|
|
28
|
-
jumpKey: "
|
|
27
|
+
buttonKey: "按鈕";
|
|
28
|
+
jumpKey: "跳轉";
|
|
29
29
|
disappointmentKey: "失望";
|
|
30
30
|
};
|
|
31
31
|
}
|
package/src/i18n/index.json
CHANGED
|
@@ -1,35 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"zh_cn": {
|
|
3
|
-
"componentKey": {
|
|
4
|
-
"sureKey": "确定",
|
|
5
|
-
"satisfyKey": "满意",
|
|
6
|
-
"confirmKey": "确认",
|
|
7
|
-
"uploadingKey": "上传中",
|
|
8
|
-
"resetKey": "重置",
|
|
9
|
-
"NoDataKey": "暂无数据",
|
|
10
|
-
"liveStreamingKey": "直播",
|
|
11
|
-
"generallyKey": "一般",
|
|
12
|
-
"uploadFailedKey": "上传失败",
|
|
13
|
-
"submitKey": "提交",
|
|
14
|
-
"requestSuccessfulKey": "请求成功",
|
|
15
|
-
"cancelKey": "取消",
|
|
16
|
-
"PullDownToRefreshKey": "下拉刷新",
|
|
17
|
-
"selectAllKey": "全选",
|
|
18
|
-
"requestDataKey": "请求数据中",
|
|
19
|
-
"closeKey": "收起",
|
|
20
|
-
"veryBadKey": "极差",
|
|
21
|
-
"searchKey": "搜索",
|
|
22
|
-
"expandKey": "展开",
|
|
23
|
-
"IDCardPhotoKey": "身份证人像面",
|
|
24
|
-
"finishKey": "完成",
|
|
25
|
-
"surpriseKey": "惊喜",
|
|
26
|
-
"releaseRefreshKey": "松开刷新",
|
|
27
|
-
"nationalEmblemSideOfIDCardKey": "身份证国徽面",
|
|
28
|
-
"buttonKey": "按钮",
|
|
29
|
-
"jumpKey": "跳转",
|
|
30
|
-
"disappointmentKey": "失望"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
2
|
"zh_tw": {
|
|
34
3
|
"componentKey": {
|
|
35
4
|
"sureKey": "確定",
|
|
@@ -91,5 +60,36 @@
|
|
|
91
60
|
"jumpKey": "Jump",
|
|
92
61
|
"disappointmentKey": "Disappointment"
|
|
93
62
|
}
|
|
63
|
+
},
|
|
64
|
+
"zh_cn": {
|
|
65
|
+
"componentKey": {
|
|
66
|
+
"sureKey": "确定",
|
|
67
|
+
"satisfyKey": "满意",
|
|
68
|
+
"confirmKey": "确认",
|
|
69
|
+
"uploadingKey": "上传中",
|
|
70
|
+
"resetKey": "重置",
|
|
71
|
+
"NoDataKey": "暂无数据",
|
|
72
|
+
"liveStreamingKey": "直播",
|
|
73
|
+
"generallyKey": "一般",
|
|
74
|
+
"uploadFailedKey": "上传失败",
|
|
75
|
+
"submitKey": "提交",
|
|
76
|
+
"requestSuccessfulKey": "请求成功",
|
|
77
|
+
"cancelKey": "取消",
|
|
78
|
+
"PullDownToRefreshKey": "下拉刷新",
|
|
79
|
+
"selectAllKey": "全选",
|
|
80
|
+
"requestDataKey": "请求数据中",
|
|
81
|
+
"closeKey": "收起",
|
|
82
|
+
"veryBadKey": "极差",
|
|
83
|
+
"searchKey": "搜索",
|
|
84
|
+
"expandKey": "展开",
|
|
85
|
+
"IDCardPhotoKey": "身份证人像面",
|
|
86
|
+
"finishKey": "完成",
|
|
87
|
+
"surpriseKey": "惊喜",
|
|
88
|
+
"releaseRefreshKey": "松开刷新",
|
|
89
|
+
"nationalEmblemSideOfIDCardKey": "身份证国徽面",
|
|
90
|
+
"buttonKey": "按钮",
|
|
91
|
+
"jumpKey": "跳转",
|
|
92
|
+
"disappointmentKey": "失望"
|
|
93
|
+
}
|
|
94
94
|
}
|
|
95
95
|
}
|