Skip to content

Commit

Permalink
Merge pull request #129 from ZeroGachis/task/get-value-when-leave-inp…
Browse files Browse the repository at this point in the history
…ut-text

SmartOrder - get the value when user leave the inputText
  • Loading branch information
ulricden authored Nov 28, 2023
2 parents 0b8e879 + 02889ed commit caeb5f5
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/components/numberSelector/NumberSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { IconName } from '../icons/IconProps';
export interface Props {
value: number;
onValueChange: (value: number) => void;
onEndEditing?: ((value: string | undefined) => void) | undefined
minValue: number;
maxValue: number;
style?: ViewStyle;
Expand All @@ -22,6 +23,7 @@ export interface Props {
export const NumberSelector = ({
value,
onValueChange,
onEndEditing = undefined,
minValue = 0,
maxValue,
style,
Expand All @@ -45,25 +47,26 @@ export const NumberSelector = ({
const onAdd = () => {
Keyboard.dismiss();
if (!addDisabled) {
onChangeText(
(
Math.round(
(value + 1 < maxValue ? value + 1 : maxValue) * 10
) / 10
).toString()
);
const newValue = (
Math.round(
(value + 1 < maxValue ? value + 1 : maxValue) * 10
) / 10
).toString();
onChangeText(newValue);
onEndEditing && onEndEditing(newValue);
}
};
const onMinus = () => {
Keyboard.dismiss();
if (!minusDisabled)
onChangeText(
(
Math.round(
(value - 1 > minValue ? value - 1 : minValue) * 10
) / 10
).toString()
);
if (!minusDisabled){
const newValue = (
Math.round(
(value - 1 > minValue ? value - 1 : minValue) * 10
) / 10
).toString();
onChangeText(newValue);
onEndEditing && onEndEditing(newValue);
}
};
const onChangeText = (text: string) => {
if (tempValue !== '' && tempValue != '-') refInput?.current?.focus();
Expand Down Expand Up @@ -118,6 +121,7 @@ export const NumberSelector = ({
minValue={minValue}
maxValue={maxValue}
onChangeText={onChangeText}
onEndEditing={(e) => onEndEditing && onEndEditing(e.nativeEvent.text)}
selectTextOnFocus={showSoftInputOnFocus}
decimal={decimal}
size={size}
Expand Down

0 comments on commit caeb5f5

Please sign in to comment.