Skip to content

Commit

Permalink
Merge pull request #27749 from tienifr/fix/26505
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam authored Sep 22, 2023
2 parents 8e2edbf + 1e269a9 commit 7f6e4f4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
20 changes: 1 addition & 19 deletions src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'underscore';
import React, {useState, useRef, useEffect, useCallback} from 'react';
import {Animated, View, AppState, Keyboard, StyleSheet} from 'react-native';
import {Animated, View, StyleSheet} from 'react-native';
import Str from 'expensify-common/lib/str';
import RNTextInput from '../RNTextInput';
import TextInputLabel from './TextInputLabel';
Expand Down Expand Up @@ -38,24 +38,6 @@ function BaseTextInput(props) {
const input = useRef(null);
const isLabelActive = useRef(initialActiveLabel);

useEffect(() => {
if (!props.disableKeyboard) {
return;
}

const appStateSubscription = AppState.addEventListener('change', (nextAppState) => {
if (!nextAppState.match(/inactive|background/)) {
return;
}

Keyboard.dismiss();
});

return () => {
appStateSubscription.remove();
};
}, [props.disableKeyboard]);

// AutoFocus which only works on mount:
useEffect(() => {
// We are manually managing focus to prevent this issue: https://github.com/Expensify/App/issues/4514
Expand Down
45 changes: 33 additions & 12 deletions src/components/TextInput/index.native.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import React, {forwardRef} from 'react';
import React, {forwardRef, useEffect} from 'react';
import {AppState, Keyboard} from 'react-native';
import styles from '../../styles/styles';
import BaseTextInput from './BaseTextInput';
import * as baseTextInputPropTypes from './baseTextInputPropTypes';

const TextInput = forwardRef((props, ref) => (
<BaseTextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
// Setting autoCompleteType to new-password throws an error on Android/iOS, so fall back to password in that case
// eslint-disable-next-line react/jsx-props-no-multi-spaces
autoCompleteType={props.autoCompleteType === 'new-password' ? 'password' : props.autoCompleteType}
innerRef={ref}
inputStyle={[styles.baseTextInput, ...props.inputStyle]}
/>
));
const TextInput = forwardRef((props, ref) => {
useEffect(() => {
if (!props.disableKeyboard) {
return;
}

const appStateSubscription = AppState.addEventListener('change', (nextAppState) => {
if (!nextAppState.match(/inactive|background/)) {
return;
}

Keyboard.dismiss();
});

return () => {
appStateSubscription.remove();
};
}, [props.disableKeyboard]);

return (
<BaseTextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
// Setting autoCompleteType to new-password throws an error on Android/iOS, so fall back to password in that case
// eslint-disable-next-line react/jsx-props-no-multi-spaces
autoCompleteType={props.autoCompleteType === 'new-password' ? 'password' : props.autoCompleteType}
innerRef={ref}
inputStyle={[styles.baseTextInput, ...props.inputStyle]}
/>
);
});

TextInput.propTypes = baseTextInputPropTypes.propTypes;
TextInput.defaultProps = baseTextInputPropTypes.defaultProps;
Expand Down

0 comments on commit 7f6e4f4

Please sign in to comment.