Skip to content
Snippets Groups Projects
Unverified Commit 2df774d9 authored by ilar's avatar ilar Committed by GitHub
Browse files

Mobile auto decimal (#2536)

* Format the input field when entering transaction value, automatically populate decimal position.

* Add note.

* Fix linting issues.

* Turn off autoDecimal if we're hiding decimals anyway.

* Shorten changelog.
parent c96c957a
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import {
getNumberFormat,
} from 'loot-core/src/shared/util';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useMergedRefs } from '../../../hooks/useMergedRefs';
import { theme } from '../../../style';
import { Button } from '../../common/Button';
......@@ -22,6 +23,7 @@ const AmountInput = memo(function AmountInput({
const [text, setText] = useState('');
const [value, setValue] = useState(0);
const inputRef = useRef();
const [hideFraction = false] = useLocalPref('hideFraction');
const mergedInputRef = useMergedRefs(props.inputRef, inputRef);
const initialValue = Math.abs(props.value);
......@@ -69,6 +71,16 @@ const AmountInput = memo(function AmountInput({
};
const onChangeText = text => {
if (text.slice(-1) === '.') {
text = text.slice(0, -1);
}
if (!hideFraction) {
text = text.replaceAll(/[,.]/g, '');
text = text.replace(/^0+(?!$)/, '');
text = text.padStart(3, '0');
text = text.slice(0, -2) + '.' + text.slice(-2);
}
setEditing(true);
setText(text);
props.onChange?.(text);
......@@ -108,7 +120,7 @@ const AmountInput = memo(function AmountInput({
data-testid="amount-fake-input"
pointerEvents="none"
>
{editing ? text : amountToCurrency(value)}
{editing ? amountToCurrency(text) : amountToCurrency(value)}
</Text>
</View>
);
......
---
category: Enhancements
authors: [ilar]
---
When adding a mobile view transaction, format the edit field according to the currency and add an automatic/fixed position decimal when applicable.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment