Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chrome android input bug #55210

15 changes: 9 additions & 6 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {AnimatedTextInputRef} from '@components/RNTextInput';
import RNTextInput from '@components/RNTextInput';
import SwipeInterceptPanResponder from '@components/SwipeInterceptPanResponder';
import Text from '@components/Text';
import * as styleConst from '@components/TextInput/styleConst';
import {ACTIVE_LABEL_SCALE, ACTIVE_LABEL_TRANSLATE_Y, INACTIVE_LABEL_SCALE, INACTIVE_LABEL_TRANSLATE_Y} from '@components/TextInput/styleConst';
import TextInputClearButton from '@components/TextInput/TextInputClearButton';
import TextInputLabel from '@components/TextInput/TextInputLabel';
import useHtmlPaste from '@hooks/useHtmlPaste';
Expand Down Expand Up @@ -102,8 +102,8 @@ function BaseTextInput(
const [textInputHeight, setTextInputHeight] = useState(0);
const [width, setWidth] = useState<number | null>(null);

const labelScale = useSharedValue<number>(initialActiveLabel ? styleConst.ACTIVE_LABEL_SCALE : styleConst.INACTIVE_LABEL_SCALE);
const labelTranslateY = useSharedValue<number>(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y);
const labelScale = useSharedValue<number>(initialActiveLabel ? ACTIVE_LABEL_SCALE : INACTIVE_LABEL_SCALE);
const labelTranslateY = useSharedValue<number>(initialActiveLabel ? ACTIVE_LABEL_TRANSLATE_Y : INACTIVE_LABEL_TRANSLATE_Y);

const input = useRef<HTMLInputElement | null>(null);
const isLabelActive = useRef(initialActiveLabel);
Expand Down Expand Up @@ -142,7 +142,7 @@ function BaseTextInput(
return;
}

animateLabel(styleConst.ACTIVE_LABEL_TRANSLATE_Y, styleConst.ACTIVE_LABEL_SCALE);
animateLabel(ACTIVE_LABEL_TRANSLATE_Y, ACTIVE_LABEL_SCALE);
isLabelActive.current = true;
}, [animateLabel, value]);

Expand All @@ -153,7 +153,7 @@ function BaseTextInput(
return;
}

animateLabel(styleConst.INACTIVE_LABEL_TRANSLATE_Y, styleConst.INACTIVE_LABEL_SCALE);
animateLabel(INACTIVE_LABEL_TRANSLATE_Y, INACTIVE_LABEL_SCALE);
isLabelActive.current = false;
}, [animateLabel, forceActiveLabel, prefixCharacter, suffixCharacter, value]);

Expand Down Expand Up @@ -265,6 +265,9 @@ function BaseTextInput(

const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);
// This is workaround for https://github.com/Expensify/App/issues/47939: in case when user is using Chrome on Android we set inputMode to 'search' to disable autocomplete bar above the keyboard.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this comment it helps a lot debugging in the future ❤️

// If we need some other inputMode (eg. 'decimal'), then the autocomplete bar will show, but we can do nothing about it as it's a known Chrome bug.
const inputMode = inputProps.inputMode ?? (isMobileChrome() ? 'search' : undefined);

return (
<>
Expand Down Expand Up @@ -383,7 +386,7 @@ function BaseTextInput(
secureTextEntry={passwordHidden}
onPressOut={inputProps.onPress}
showSoftInputOnFocus={!disableKeyboard}
inputMode={inputProps.inputMode}
inputMode={inputMode}
value={uncontrolled ? undefined : value}
selection={inputProps.selection}
readOnly={isReadOnly}
Expand Down