Skip to content

Commit 6bb32b6

Browse files
authored
Merge pull request #857 from thundersdata-frontend/rn-issue
feat: 数字输入组件支持输入负数
2 parents 84987bd + a4597ec commit 6bb32b6

File tree

7 files changed

+79
-34
lines changed

7 files changed

+79
-34
lines changed

.changeset/tame-dolphins-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@td-design/react-native': patch
3+
---
4+
5+
feat: 数字输入组件支持输入负数

packages/lego/src/three-dimensional-pie/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ export default forwardRef<ReactEcharts, ThreeDimensionalPieProps>(
9696
const endRatio = option.series[hoveredIndex]?.pieData?.endRatio;
9797
const k = option.series[hoveredIndex]?.pieStatus?.k;
9898

99+
const value =
100+
option.series[hoveredIndex] && option.series[hoveredIndex].pieData
101+
? option.series[hoveredIndex].pieData.value
102+
: 30;
99103
// 对当前点击的扇形,执行取消高亮操作(对 option 更新)
100104
option.series[hoveredIndex].parametricEquation = getParametricEquation(
101105
startRatio,
102106
endRatio,
103107
isSelected,
104108
isHovered,
105109
k * kCondition,
106-
generate3DHeight(isFlat, option.series[hoveredIndex].pieData?.value, upCondition * coefficient)
110+
generate3DHeight(isFlat, value, upCondition * coefficient)
107111
);
108112

109113
if (option?.series[hoveredIndex]?.pieStatus) {

packages/react-native/src/number-keyboard/NumberKeyboardInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const NumberKeyboardInput = forwardRef<NumberKeyboardRef, NumberKeyboardInputPro
3838
brief,
3939
activeOpacity = 0.6,
4040
itemHeight,
41+
allowNegative = false,
4142
...restProps
4243
},
4344
ref
@@ -61,6 +62,7 @@ const NumberKeyboardInput = forwardRef<NumberKeyboardRef, NumberKeyboardInputPro
6162
value: currentText === placeholder ? '' : currentText,
6263
onSubmit: handleSubmit,
6364
activeOpacity,
65+
allowNegative,
6466
});
6567
};
6668

packages/react-native/src/number-keyboard/NumberKeyboardItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const NumberKeyboardItem = forwardRef<NumberKeyboardRef, NumberKeyboardItemProps
3030
digit = 0,
3131
activeOpacity = 0.6,
3232
inForm,
33+
allowNegative = false,
3334
...restProps
3435
},
3536
ref
@@ -53,6 +54,7 @@ const NumberKeyboardItem = forwardRef<NumberKeyboardRef, NumberKeyboardItemProps
5354
value: currentText === placeholder ? '' : currentText,
5455
onSubmit: handleSubmit,
5556
activeOpacity,
57+
allowNegative,
5658
});
5759
};
5860

packages/react-native/src/number-keyboard/NumberKeyboardModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const NumberKeyboardModal: FC<
2121
NumberKeyboardModalProps & {
2222
onAnimationEnd?: (visible: boolean) => void;
2323
}
24-
> = ({ type, value = '', onPress, onDelete, onSubmit, prefixLabel = '当前值', onAnimationEnd }) => {
24+
> = ({ type, allowNegative, value = '', onPress, onDelete, onSubmit, prefixLabel = '当前值', onAnimationEnd }) => {
2525
const theme = useTheme<Theme>();
2626
const { text, visible, setFalse, handleChange, handleSubmit, handleDelete } = useNumberKeyboardModal({
2727
value,
@@ -59,7 +59,7 @@ const NumberKeyboardModal: FC<
5959
<SvgIcon name="down" size={px(20)} color={theme.colors.gray500} />
6060
</Pressable>
6161
</Flex>
62-
<NumberKeyboardView type={type} onPress={handleChange} onDelete={handleDelete} onSubmit={handleSubmit} />
62+
<NumberKeyboardView type={type} allowNegative={allowNegative} onPress={handleChange} onDelete={handleDelete} onSubmit={handleSubmit} />
6363
</Modal>
6464
);
6565
};

packages/react-native/src/number-keyboard/NumberKeyboardView.tsx

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC } from 'react';
1+
import React, { FC, useMemo } from 'react';
22
import { StyleSheet } from 'react-native';
33
import { SvgXml } from 'react-native-svg';
44

@@ -17,42 +17,14 @@ const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
1717

1818
const PER_WIDTH = deviceWidth / 4;
1919

20-
const keyTypes = {
21-
number: [
22-
{
23-
key: '0',
24-
flex: 2,
25-
},
26-
{
27-
key: '.',
28-
flex: 1,
29-
},
30-
],
31-
idcard: [
32-
{
33-
key: '0',
34-
flex: 2,
35-
},
36-
{
37-
key: 'X',
38-
flex: 1,
39-
},
40-
],
41-
integer: [
42-
{
43-
key: '0',
44-
flex: 1,
45-
},
46-
],
47-
};
48-
4920
const NumberKeyboardView: FC<NumberKeyboardViewProps> = ({
5021
type = 'number',
5122
onPress,
5223
onDelete,
5324
onSubmit,
5425
submitText = '确定',
5526
activeOpacity = 0.6,
27+
allowNegative,
5628
}) => {
5729
const theme = useTheme<Theme>();
5830

@@ -76,6 +48,64 @@ const NumberKeyboardView: FC<NumberKeyboardViewProps> = ({
7648
},
7749
});
7850

51+
const keyTypes = useMemo(() => {
52+
const numberType = allowNegative ? [
53+
{
54+
key: '0',
55+
flex: 1,
56+
},
57+
{
58+
key: '.',
59+
flex: 1,
60+
},
61+
{
62+
key: '-',
63+
flex: 1,
64+
},
65+
] : [
66+
{
67+
key: '0',
68+
flex: 2,
69+
},
70+
{
71+
key: '.',
72+
flex: 1,
73+
},
74+
];
75+
const integerType = allowNegative ? [
76+
{
77+
key: '0',
78+
flex: 2,
79+
},
80+
{
81+
key: '-',
82+
flex: 1,
83+
},
84+
] : [
85+
{
86+
key: '0',
87+
flex: 1,
88+
},
89+
];
90+
91+
const types = {
92+
number: numberType,
93+
idcard: [
94+
{
95+
key: '0',
96+
flex: 2,
97+
},
98+
{
99+
key: 'X',
100+
flex: 1,
101+
},
102+
],
103+
integer: integerType,
104+
};
105+
106+
return types;
107+
}, [allowNegative]);
108+
79109
return (
80110
<Flex backgroundColor="transparent">
81111
<Box width={PER_WIDTH * 3}>

packages/react-native/src/number-keyboard/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ export interface NumberKeyboardViewProps {
1616
submitText?: string;
1717
/** 按下时的不透明度 */
1818
activeOpacity?: number;
19+
/** 是否允许负数 */
20+
allowNegative?: boolean;
1921
}
2022

21-
export interface NumberKeyboardItemProps extends Pick<NumberKeyboardViewProps, 'type' | 'activeOpacity'> {
23+
export interface NumberKeyboardItemProps extends Pick<NumberKeyboardViewProps, 'type' | 'activeOpacity' | 'allowNegative'> {
2224
value?: string;
2325
onChange?: (value: string) => void;
2426
onCheck?: (value: string) => Promise<any>;

0 commit comments

Comments
 (0)