-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53695 from margelo/feat/masked-input
fix: no jumpy input in amount filter
- Loading branch information
Showing
21 changed files
with
275 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import type {ForwardedRef} from 'react'; | ||
import CONST from '@src/CONST'; | ||
import TextInput from './TextInput'; | ||
import type {BaseTextInputProps, BaseTextInputRef} from './TextInput/BaseTextInput/types'; | ||
|
||
type AmountFormProps = { | ||
/** Amount supplied by the FormProvider */ | ||
value?: string; | ||
|
||
/** Callback to update the amount in the FormProvider */ | ||
onInputChange?: (value: string) => void; | ||
|
||
/** Should we allow negative number as valid input */ | ||
shouldAllowNegative?: boolean; | ||
} & Partial<BaseTextInputProps>; | ||
|
||
function AmountWithoutCurrencyInput( | ||
{value: amount, shouldAllowNegative = false, inputID, name, defaultValue, accessibilityLabel, role, label, ...rest}: AmountFormProps, | ||
ref: ForwardedRef<BaseTextInputRef>, | ||
) { | ||
return ( | ||
<TextInput | ||
inputID={inputID} | ||
name={name} | ||
label={label} | ||
defaultValue={defaultValue} | ||
accessibilityLabel={accessibilityLabel} | ||
role={role} | ||
ref={ref} | ||
keyboardType={!shouldAllowNegative ? CONST.KEYBOARD_TYPE.DECIMAL_PAD : undefined} | ||
type="mask" | ||
mask="[09999999].[09]" | ||
allowedKeys="0123456789.," | ||
// On android autoCapitalize="words" is necessary when keyboardType="decimal-pad" or inputMode="decimal" to prevent input lag. | ||
// See https://github.com/Expensify/App/issues/51868 for more information | ||
autoCapitalize="words" | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...rest} | ||
/> | ||
); | ||
} | ||
|
||
AmountWithoutCurrencyInput.displayName = 'AmountWithoutCurrencyForm'; | ||
|
||
export default React.forwardRef(AmountWithoutCurrencyInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type {ForwardedRef} from 'react'; | ||
import React from 'react'; | ||
import type {TextInput} from 'react-native'; | ||
import type {MaskedTextInputProps} from 'react-native-advanced-input-mask'; | ||
import {MaskedTextInput} from 'react-native-advanced-input-mask'; | ||
import Animated from 'react-native-reanimated'; | ||
import useTheme from '@hooks/useTheme'; | ||
|
||
// Convert the underlying TextInput into an Animated component so that we can take an animated ref and pass it to a worklet | ||
const AnimatedTextInput = Animated.createAnimatedComponent(MaskedTextInput); | ||
|
||
type AnimatedTextInputRef = typeof AnimatedTextInput & TextInput & HTMLInputElement; | ||
|
||
function RNMaskedTextInputWithRef(props: MaskedTextInputProps, ref: ForwardedRef<AnimatedTextInputRef>) { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<AnimatedTextInput | ||
// disable autocomplete to prevent part of mask to be present on Android when value is empty | ||
autocomplete={false} | ||
allowFontScaling={false} | ||
textBreakStrategy="simple" | ||
keyboardAppearance={theme.colorScheme} | ||
ref={(refHandle) => { | ||
if (typeof ref !== 'function') { | ||
return; | ||
} | ||
ref(refHandle as AnimatedTextInputRef); | ||
}} | ||
// eslint-disable-next-line | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
RNMaskedTextInputWithRef.displayName = 'RNMaskedTextInputWithRef'; | ||
|
||
export default React.forwardRef(RNMaskedTextInputWithRef); | ||
export type {AnimatedTextInputRef}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import RNMarkdownTextInput from '@components/RNMarkdownTextInput'; | ||
import RNMaskedTextInput from '@components/RNMaskedTextInput'; | ||
import RNTextInput from '@components/RNTextInput'; | ||
import type {BaseTextInputProps, InputType} from './types'; | ||
|
||
type InputComponentType = React.ComponentType<BaseTextInputProps>; | ||
|
||
const InputComponentMap = new Map<InputType, InputComponentType>([ | ||
['default', RNTextInput], | ||
['mask', RNMaskedTextInput as InputComponentType], | ||
['markdown', RNMarkdownTextInput], | ||
]); | ||
|
||
export default InputComponentMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.