Skip to content

Commit b6ea9a1

Browse files
authored
Merge pull request Expensify#67297 from Krishna2323/krishna2323/issue/65855
fix: Android - Search - Keyboard is not automatically opened despite input being focused.
2 parents b863e23 + 0e63056 commit b6ea9a1

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/components/Search/SearchAutocompleteInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ function SearchAutocompleteInput(
239239
multiline={false}
240240
parser={parser}
241241
selection={selection}
242+
shouldDelayFocus
242243
/>
243244
</View>
244245
{!!value && (

src/components/TextInput/BaseTextInput/implementation/index.native.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {useFocusEffect} from '@react-navigation/native';
12
import {Str} from 'expensify-common';
23
import type {ForwardedRef} from 'react';
34
import React, {forwardRef, useCallback, useEffect, useRef, useState} from 'react';
@@ -78,6 +79,7 @@ function BaseTextInput(
7879
placeholderTextColor,
7980
onClearInput,
8081
iconContainerStyle,
82+
shouldDelayFocus = false,
8183
shouldUseDefaultLineHeightForPrefix = true,
8284
...props
8385
}: BaseTextInputProps,
@@ -93,6 +95,7 @@ function BaseTextInput(
9395
const markdownStyle = useMarkdownStyle(false, excludedMarkdownStyles);
9496
const StyleUtils = useStyleUtils();
9597
const {translate} = useLocalize();
98+
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
9699

97100
const {hasError = false} = inputProps;
98101
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
@@ -283,6 +286,24 @@ function BaseTextInput(
283286
// Height fix is needed only for Text single line inputs
284287
const shouldApplyHeight = !shouldUseFullInputHeight && !isMultiline && !isMarkdownEnabled;
285288

289+
/** We added a delay to focus on text input to allow navigation/modal animations to get completed, see issue https://github.com/Expensify/App/issues/65855 for more details */
290+
useFocusEffect(
291+
useCallback(() => {
292+
if (!shouldDelayFocus || !inputProps.autoFocus) {
293+
return;
294+
}
295+
296+
focusTimeoutRef.current = setTimeout(() => {
297+
if (!input.current) {
298+
return;
299+
}
300+
input.current.focus();
301+
}, CONST.ANIMATED_TRANSITION);
302+
303+
return () => focusTimeoutRef.current && clearTimeout(focusTimeoutRef.current);
304+
}, [shouldDelayFocus, inputProps.autoFocus]),
305+
);
306+
286307
return (
287308
<>
288309
<View style={[containerStyles]}>
@@ -420,6 +441,7 @@ function BaseTextInput(
420441
readOnly={isReadOnly}
421442
defaultValue={defaultValue}
422443
markdownStyle={markdownStyle}
444+
autoFocus={shouldDelayFocus ? false : inputProps.autoFocus}
423445
/>
424446
{!!suffixCharacter && (
425447
<View style={[styles.textInputSuffixWrapper, suffixContainerStyle]}>

src/components/TextInput/BaseTextInput/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ type CustomBaseTextInputProps = {
187187
/** Whether the input should be enforced to take full height of container. Default is `false` */
188188
shouldUseFullInputHeight?: boolean;
189189

190+
/** Whether focus event should be delayed */
191+
shouldDelayFocus?: boolean;
192+
190193
/** Whether the input prefix should use the default `Text` line height fallback. Disable this if you intentionally want the prefix to have `lineHeight: undefined` */
191194
shouldUseDefaultLineHeightForPrefix?: boolean;
192195
};

0 commit comments

Comments
 (0)