Skip to content

Commit

Permalink
Merge pull request #857 from thundersdata-frontend/rn-issue
Browse files Browse the repository at this point in the history
feat: 数字输入组件支持输入负数
  • Loading branch information
chj-damon authored Apr 28, 2024
2 parents 84987bd + a4597ec commit 6bb32b6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-dolphins-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@td-design/react-native': patch
---

feat: 数字输入组件支持输入负数
6 changes: 5 additions & 1 deletion packages/lego/src/three-dimensional-pie/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ export default forwardRef<ReactEcharts, ThreeDimensionalPieProps>(
const endRatio = option.series[hoveredIndex]?.pieData?.endRatio;
const k = option.series[hoveredIndex]?.pieStatus?.k;

const value =
option.series[hoveredIndex] && option.series[hoveredIndex].pieData
? option.series[hoveredIndex].pieData.value
: 30;
// 对当前点击的扇形,执行取消高亮操作(对 option 更新)
option.series[hoveredIndex].parametricEquation = getParametricEquation(
startRatio,
endRatio,
isSelected,
isHovered,
k * kCondition,
generate3DHeight(isFlat, option.series[hoveredIndex].pieData?.value, upCondition * coefficient)
generate3DHeight(isFlat, value, upCondition * coefficient)
);

if (option?.series[hoveredIndex]?.pieStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const NumberKeyboardInput = forwardRef<NumberKeyboardRef, NumberKeyboardInputPro
brief,
activeOpacity = 0.6,
itemHeight,
allowNegative = false,
...restProps
},
ref
Expand All @@ -61,6 +62,7 @@ const NumberKeyboardInput = forwardRef<NumberKeyboardRef, NumberKeyboardInputPro
value: currentText === placeholder ? '' : currentText,
onSubmit: handleSubmit,
activeOpacity,
allowNegative,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const NumberKeyboardItem = forwardRef<NumberKeyboardRef, NumberKeyboardItemProps
digit = 0,
activeOpacity = 0.6,
inForm,
allowNegative = false,
...restProps
},
ref
Expand All @@ -53,6 +54,7 @@ const NumberKeyboardItem = forwardRef<NumberKeyboardRef, NumberKeyboardItemProps
value: currentText === placeholder ? '' : currentText,
onSubmit: handleSubmit,
activeOpacity,
allowNegative,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const NumberKeyboardModal: FC<
NumberKeyboardModalProps & {
onAnimationEnd?: (visible: boolean) => void;
}
> = ({ type, value = '', onPress, onDelete, onSubmit, prefixLabel = '当前值', onAnimationEnd }) => {
> = ({ type, allowNegative, value = '', onPress, onDelete, onSubmit, prefixLabel = '当前值', onAnimationEnd }) => {
const theme = useTheme<Theme>();
const { text, visible, setFalse, handleChange, handleSubmit, handleDelete } = useNumberKeyboardModal({
value,
Expand Down Expand Up @@ -59,7 +59,7 @@ const NumberKeyboardModal: FC<
<SvgIcon name="down" size={px(20)} color={theme.colors.gray500} />
</Pressable>
</Flex>
<NumberKeyboardView type={type} onPress={handleChange} onDelete={handleDelete} onSubmit={handleSubmit} />
<NumberKeyboardView type={type} allowNegative={allowNegative} onPress={handleChange} onDelete={handleDelete} onSubmit={handleSubmit} />
</Modal>
);
};
Expand Down
90 changes: 60 additions & 30 deletions packages/react-native/src/number-keyboard/NumberKeyboardView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React, { FC, useMemo } from 'react';
import { StyleSheet } from 'react-native';
import { SvgXml } from 'react-native-svg';

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

const PER_WIDTH = deviceWidth / 4;

const keyTypes = {
number: [
{
key: '0',
flex: 2,
},
{
key: '.',
flex: 1,
},
],
idcard: [
{
key: '0',
flex: 2,
},
{
key: 'X',
flex: 1,
},
],
integer: [
{
key: '0',
flex: 1,
},
],
};

const NumberKeyboardView: FC<NumberKeyboardViewProps> = ({
type = 'number',
onPress,
onDelete,
onSubmit,
submitText = '确定',
activeOpacity = 0.6,
allowNegative,
}) => {
const theme = useTheme<Theme>();

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

const keyTypes = useMemo(() => {
const numberType = allowNegative ? [
{
key: '0',
flex: 1,
},
{
key: '.',
flex: 1,
},
{
key: '-',
flex: 1,
},
] : [
{
key: '0',
flex: 2,
},
{
key: '.',
flex: 1,
},
];
const integerType = allowNegative ? [
{
key: '0',
flex: 2,
},
{
key: '-',
flex: 1,
},
] : [
{
key: '0',
flex: 1,
},
];

const types = {
number: numberType,
idcard: [
{
key: '0',
flex: 2,
},
{
key: 'X',
flex: 1,
},
],
integer: integerType,
};

return types;
}, [allowNegative]);

return (
<Flex backgroundColor="transparent">
<Box width={PER_WIDTH * 3}>
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/src/number-keyboard/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export interface NumberKeyboardViewProps {
submitText?: string;
/** 按下时的不透明度 */
activeOpacity?: number;
/** 是否允许负数 */
allowNegative?: boolean;
}

export interface NumberKeyboardItemProps extends Pick<NumberKeyboardViewProps, 'type' | 'activeOpacity'> {
export interface NumberKeyboardItemProps extends Pick<NumberKeyboardViewProps, 'type' | 'activeOpacity' | 'allowNegative'> {
value?: string;
onChange?: (value: string) => void;
onCheck?: (value: string) => Promise<any>;
Expand Down

0 comments on commit 6bb32b6

Please sign in to comment.