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 android keyboard doesn't show up and ios text input content doesn't scroll to bottom when edit message #31041

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import FocusTextInputAfterAnimation from './types';

/**
* Focus the text input with a slight delay to make sure modals are closed first.
* Initially this file is intended for native ios but use index.native.js filename and affects android.
*
* Initial comment for this file is:
* "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
* See this discussion for more details: https://github.com/Expensify/App/issues/18300"
*
* But the bug already fixed, without using setTimeout for IOS the focus seems to work properly.
* Instead there is new IOS bug of text input content doesn't scroll to bottom if using setTimeout,
* also there is an android keyboard doesn't show up bug when text input is focused and
* the use of setTimeout will make the keyboard show up properly.
*
* @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
Expand Down
12 changes: 3 additions & 9 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,6 @@ function ReportActionItemMessageEdit(props) {
[props.action.reportActionID],
);

// Scroll content of textInputRef to bottom
useEffect(() => {
if (!textInputRef.current) {
return;
}
textInputRef.current.focus();
textInputRef.current.scrollTop = textInputRef.current.scrollHeight;
}, []);

useEffect(() => {
// For mobile Safari, updating the selection prop on an unfocused input will cause it to automatically gain focus
// and subsequent programmatic focus shifts (e.g., modal focus trap) to show the blue frame (:focus-visible style),
Expand All @@ -190,6 +181,9 @@ function ReportActionItemMessageEdit(props) {
});
return prevDraft;
});

// Scroll content of textInputRef to bottom
textInputRef.current.scrollTop = textInputRef.current.scrollHeight;
}

return () => {
Expand Down
Loading