Skip to content

Commit

Permalink
move isAnimatedTextInputRef function to common file
Browse files Browse the repository at this point in the history
  • Loading branch information
bgawkuc committed May 28, 2024
1 parent 03e4302 commit 6cd6194
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/components/AmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
import CONST from '@src/CONST';
import BigNumberPad from './BigNumberPad';
import FormHelpMessage from './FormHelpMessage';
import type {AnimatedTextInputRef} from './RNTextInput';
import isAnimatedTextInputRef from './TextInput/BaseTextInput/isAnimatedTextInoutRef';
import type {BaseTextInputProps, BaseTextInputRef} from './TextInput/BaseTextInput/types';
import TextInputWithCurrencySymbol from './TextInputWithCurrencySymbol';
import type TextInputWithCurrencySymbolProps from './TextInputWithCurrencySymbol/types';
Expand Down Expand Up @@ -52,9 +52,6 @@ const getNewSelection = (oldSelection: {start: number; end: number}, prevLength:
return {start: cursorPosition, end: cursorPosition};
};

const isAnimatedTextInputRef = (textInput: React.MutableRefObject<BaseTextInputRef | null>) =>
textInput.current && 'isFocused' in textInput.current && (textInput.current as AnimatedTextInputRef).isFocused();

const AMOUNT_VIEW_ID = 'amountView';
const NUM_PAD_CONTAINER_VIEW_ID = 'numPadContainerView';
const NUM_PAD_VIEW_ID = 'numPadView';
Expand Down
5 changes: 1 addition & 4 deletions src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import {scrollTo} from 'react-native-reanimated';
import EmojiPickerMenuItem from '@components/EmojiPicker/EmojiPickerMenuItem';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import isAnimatedTextInputRef from '@components/TextInput/BaseTextInput/isAnimatedTextInoutRef';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -28,9 +28,6 @@ import useEmojiPickerMenu from './useEmojiPickerMenu';

const throttleTime = Browser.isMobile() ? 200 : 50;

const isAnimatedTextInputRef = (textInput: React.MutableRefObject<BaseTextInputRef | null>) =>
textInput.current && 'isFocused' in textInput.current && (textInput.current as AnimatedTextInputRef).isFocused();

function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, ref: ForwardedRef<BaseTextInputRef>) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down
5 changes: 1 addition & 4 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as CurrencyUtils from '@libs/CurrencyUtils';
import getOperatingSystem from '@libs/getOperatingSystem';
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
import CONST from '@src/CONST';
import type {AnimatedTextInputRef} from './RNTextInput';
import isAnimatedTextInputRef from './TextInput/BaseTextInput/isAnimatedTextInoutRef';
import type {BaseTextInputRef} from './TextInput/BaseTextInput/types';
import TextInputWithCurrencySymbol from './TextInputWithCurrencySymbol';

Expand Down Expand Up @@ -90,9 +90,6 @@ const getNewSelection = (oldSelection: Selection, prevLength: number, newLength:
return {start: cursorPosition, end: cursorPosition};
};

const isAnimatedTextInputRef = (textInput: React.MutableRefObject<BaseTextInputRef | null>) =>
textInput.current && 'isFocused' in textInput.current && (textInput.current as AnimatedTextInputRef).isFocused();

function MoneyRequestAmountInput(
{
amount = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import type {BaseTextInputRef} from './types';

export default function isAnimatedTextInputRef(textInput: React.MutableRefObject<BaseTextInputRef | null>): boolean | null {
return textInput.current && 'isFocused' in textInput.current && (textInput.current as AnimatedTextInputRef).isFocused();
}
5 changes: 1 addition & 4 deletions src/pages/iou/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Button from '@components/Button';
import FormHelpMessage from '@components/FormHelpMessage';
import MoneyRequestAmountInput from '@components/MoneyRequestAmountInput';
import type {MoneyRequestAmountInputRef} from '@components/MoneyRequestAmountInput';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import ScrollView from '@components/ScrollView';
import SettlementButton from '@components/SettlementButton';
import isAnimatedTextInputRef from '@components/TextInput/BaseTextInput/isAnimatedTextInoutRef';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -67,9 +67,6 @@ type MoneyRequestAmountFormProps = {
selectedTab?: SelectedTabRequest;
};

const isAnimatedTextInputRef = (textInput: React.MutableRefObject<BaseTextInputRef | null>) =>
textInput.current && 'isFocused' in textInput.current && (textInput.current as AnimatedTextInputRef).isFocused();

const isAmountInvalid = (amount: string) => !amount.length || parseFloat(amount) < 0.01;
const isTaxAmountInvalid = (currentAmount: string, taxAmount: number, isTaxAmountForm: boolean) =>
isTaxAmountForm && Number.parseFloat(currentAmount) > CurrencyUtils.convertToFrontendAmount(Math.abs(taxAmount));
Expand Down
7 changes: 2 additions & 5 deletions src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import AppleSignIn from '@components/SignInButtons/AppleSignIn';
import GoogleSignIn from '@components/SignInButtons/GoogleSignIn';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import isAnimatedTextInputRef from '@components/TextInput/BaseTextInput/isAnimatedTextInoutRef';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
import withToggleVisibilityView from '@components/withToggleVisibilityView';
import type {WithToggleVisibilityViewProps} from '@components/withToggleVisibilityView';
Expand Down Expand Up @@ -54,9 +54,6 @@ type BaseLoginFormProps = WithToggleVisibilityViewProps & BaseLoginFormOnyxProps

const willBlurTextInputOnTapOutside = willBlurTextInputOnTapOutsideFunc();

const isAnimatedTextInputRef = (textInput: React.MutableRefObject<BaseTextInputRef | null>) =>
textInput.current && 'isFocused' in textInput.current && (textInput.current as AnimatedTextInputRef).isFocused();

function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
const styles = useThemeStyles();
const {isOffline} = useNetwork();
Expand Down Expand Up @@ -204,7 +201,7 @@ function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false
if (!input.current) {
return false;
}
return (isAnimatedTextInputRef(input) ?? input.current.focus()) as boolean;
return !!isAnimatedTextInputRef(input);
},
clearDataAndFocus(clearLogin = true) {
if (!input.current) {
Expand Down

0 comments on commit 6cd6194

Please sign in to comment.