Skip to content

Commit

Permalink
Revert "fix: defer change update for number input (#291)"
Browse files Browse the repository at this point in the history
This reverts commit 1f97003.
  • Loading branch information
raychanks authored and Daniel committed Feb 7, 2022
1 parent 548277b commit 69676fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
10 changes: 2 additions & 8 deletions addons/ondevice-controls/src/PropForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { memo } from 'react';
import React from 'react';
import { View } from 'react-native';
import deepEqual from 'deep-equal';

import { ArgTypes } from './ControlsPanel';
import PropField from './PropField';

Expand All @@ -27,8 +25,4 @@ const PropForm = ({ args, onFieldChange }: FormProps) => {
);
};

const deepStrictEqual = (a: any, b: any): boolean => {
return deepEqual(a, b, { strict: true });
};

export default memo(PropForm, deepStrictEqual);
export default PropForm;
33 changes: 5 additions & 28 deletions addons/ondevice-controls/src/types/Number.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from 'react';
import React from 'react';
import { StyleSheet, View } from 'react-native';
import Slider from '@react-native-community/slider';
import styled from '@emotion/native';
Expand Down Expand Up @@ -26,35 +26,18 @@ export interface NumberProps {
onChange: (value: any) => void;
}

const replaceComma = (value: number | string): string => {
return typeof value === 'string' ? value.trim().replace(/,/, '.') : value.toString();
};

const NumberType = ({ arg, onChange = (value) => value }: NumberProps) => {
const allowComma = replaceComma(arg.value);
const [numStr, setNumStr] = useState(allowComma);
const numStrRef = useRef(numStr);
const showError = Number.isNaN(Number(numStr));

const commitChange = () => {
onChange(numStr);
};
const allowComma = typeof arg.value === 'string' ? arg.value.trim().replace(/,/, '.') : arg.value;
const showError = Number.isNaN(Number(allowComma));

const renderNormal = () => {
return (
<Input
autoCapitalize="none"
underlineColorAndroid="transparent"
value={numStr}
value={arg.value.toString()}
keyboardType="numeric"
onChangeText={(text) => {
const commaReplaced = replaceComma(text);

setNumStr(commaReplaced);
numStrRef.current = commaReplaced;
}}
onSubmitEditing={commitChange}
onEndEditing={commitChange}
onChangeText={onChange}
style={showError && styles.errorBorder}
/>
);
Expand All @@ -72,12 +55,6 @@ const NumberType = ({ arg, onChange = (value) => value }: NumberProps) => {
);
};

useEffect(() => {
return () => {
onChange(numStrRef.current);
};
}, [onChange]);

return <View style={styles.spacing}>{arg.range ? renderRange() : renderNormal()}</View>;
};

Expand Down

0 comments on commit 69676fe

Please sign in to comment.