Skip to content

Commit

Permalink
Merge pull request #26180 from software-mansion-labs/ts-migration/foc…
Browse files Browse the repository at this point in the history
…us-text-input-after-animation

[No QA] [TS migration] Migrate 'focusTextInputAfterAnimation' lib to TypeScript
  • Loading branch information
tgolen authored Sep 12, 2023
2 parents 5f668c6 + 2360555 commit 2163c54
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import FocusTextInputAfterAnimation from './types';

/**
* Focus the text input with a slight delay to make sure modals are closed first.
* Since in react-native-modal `onModalHide` is called before the modal is actually hidden.
* It results in the keyboard being dismissed right away on both iOS and Android.
* See this discussion for more details: https://github.com/Expensify/App/issues/18300
*
* @param {Object} inputRef
* @param {Number} animationLength you must use your best guess as to what a good animationLength is. It can't be too short, or the animation won't be finished. It can't be too long or
* @param animationLength you must use your best guess as to what a good animationLength is. It can't be too short, or the animation won't be finished. It can't be too long or
* the user will notice that it feels sluggish
*/
const focusTextInputAfterAnimation = (inputRef, animationLength = 0) => {
const focusTextInputAfterAnimation: FocusTextInputAfterAnimation = (inputRef, animationLength = 0) => {
setTimeout(() => {
inputRef.focus();
}, animationLength);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import FocusTextInputAfterAnimation from './types';

/**
* This library is a no-op for all platforms except for Android and iOS and will immediately focus the given input without any delays.
*
* @param {Object} inputRef
*/
const focusTextInputAfterAnimation = (inputRef) => {
const focusTextInputAfterAnimation: FocusTextInputAfterAnimation = (inputRef) => {
inputRef.focus();
};

Expand Down
5 changes: 5 additions & 0 deletions src/libs/focusTextInputAfterAnimation/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {TextInput} from 'react-native';

type FocusTextInputAfterAnimation = (inputRef: TextInput | HTMLInputElement, animationLength: number) => void;

export default FocusTextInputAfterAnimation;

0 comments on commit 2163c54

Please sign in to comment.