Skip to content

Commit

Permalink
Merge pull request #28790 from jeet-dhandha/fix-27153
Browse files Browse the repository at this point in the history
fix: auto focus and scroll to bottom on large-text in composer
  • Loading branch information
nkuoch authored Oct 17, 2023
2 parents 5570eba + ce44e6e commit 7fcb4c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/libs/UpdateMultilineInputRange/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* See https://github.com/Expensify/App/issues/20836 for more details.
*
* @param {Object} input the input element
* @param {boolean} shouldAutoFocus
*/
export default function updateMultilineInputRange(input) {
export default function updateMultilineInputRange(input, shouldAutoFocus = true) {
if (!input) {
return;
}
Expand All @@ -19,5 +20,7 @@ export default function updateMultilineInputRange(input) {
* Issue: does not scroll multiline input when text exceeds the maximum number of lines
* For more details: https://github.com/Expensify/App/pull/27702#issuecomment-1728651132
*/
input.focus();
if (shouldAutoFocus) {
input.focus();
}
}
4 changes: 3 additions & 1 deletion src/libs/UpdateMultilineInputRange/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
* See https://github.com/Expensify/App/issues/20836 for more details.
*
* @param {Object} input the input element
* @param {boolean} shouldAutoFocus
*/
export default function updateMultilineInputRange(input) {
// eslint-disable-next-line no-unused-vars
export default function updateMultilineInputRange(input, shouldAutoFocus = true) {
if (!input) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import withKeyboardState from '../../../../components/withKeyboardState';
import {propTypes, defaultProps} from './composerWithSuggestionsProps';
import focusWithDelay from '../../../../libs/focusWithDelay';
import useDebounce from '../../../../hooks/useDebounce';
import updateMultilineInputRange from '../../../../libs/UpdateMultilineInputRange';
import * as InputFocus from '../../../../libs/actions/InputFocus';

const {RNTextInputReset} = NativeModules;
Expand Down Expand Up @@ -496,9 +497,13 @@ function ComposerWithSuggestions({
focus();
}, [focus, prevIsFocused, editFocused, prevIsModalVisible, isFocused, modal.isVisible, isNextModalWillOpenRef]);
useEffect(() => {
// Scrolls the composer to the bottom and sets the selection to the end, so that longer drafts are easier to edit
updateMultilineInputRange(textInputRef.current, shouldAutoFocus);

if (value.length === 0) {
return;
}

Report.setReportWithDraft(reportID, true);

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit 7fcb4c1

Please sign in to comment.