From cc4be96ab22fe8b7fa8a23b8890efeeaa12bcfb9 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 9 Jan 2025 16:21:26 +0700 Subject: [PATCH 1/2] fix: scroll list to the top when adding user --- src/components/SelectionList/BaseSelectionList.tsx | 13 +++++-------- src/components/SelectionList/types.ts | 1 + src/pages/NewChatPage.tsx | 2 ++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index 4738bf6a92d8..94813f0d0dbb 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -754,14 +754,11 @@ function BaseSelectionList( isTextInputFocusedRef.current = isTextInputFocused; }, []); - useImperativeHandle(ref, () => ({scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex, getFocusedOption}), [ - scrollAndHighlightItem, - clearInputAfterSelect, - updateAndScrollToFocusedIndex, - updateExternalTextInputFocus, - scrollToIndex, - getFocusedOption, - ]); + useImperativeHandle( + ref, + () => ({scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex, getFocusedOption, focusTextInput}), + [scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex, getFocusedOption, focusTextInput], + ); /** Selects row when pressing Enter */ useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, selectFocusedOption, { diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 19c47414b089..5aa18013d894 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -642,6 +642,7 @@ type SelectionListHandle = { updateAndScrollToFocusedIndex: (newFocusedIndex: number) => void; updateExternalTextInputFocus: (isTextInputFocused: boolean) => void; getFocusedOption: () => ListItem | undefined; + focusTextInput: () => void; }; type ItemLayout = { diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 65aa253ff09d..3afca28084c8 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -235,6 +235,8 @@ function NewChatPage() { selectionListRef?.current?.clearInputAfterSelect?.(); + selectionListRef.current?.focusTextInput(); + selectionListRef?.current?.scrollToIndex(Math.max(newSelectedOptions.length - 1, 0), true); setSelectedOptions(newSelectedOptions); } From b7d1056cc003847d45a7fb5b4e560b87dfb36509 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 10 Jan 2025 11:22:37 +0700 Subject: [PATCH 2/2] fix lint --- src/pages/NewChatPage.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 3afca28084c8..30151d3eacb2 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -230,7 +230,7 @@ function NewChatPage() { if (isOptionInList) { newSelectedOptions = reject(selectedOptions, (selectedOption) => selectedOption.login === option.login); } else { - newSelectedOptions = [...selectedOptions, {...option, isSelected: true, selected: true, reportID: option.reportID ?? '-1'}]; + newSelectedOptions = [...selectedOptions, {...option, isSelected: true, selected: true, reportID: option.reportID ?? ''}]; } selectionListRef?.current?.clearInputAfterSelect?.(); @@ -274,7 +274,10 @@ function NewChatPage() { if (!personalData || !personalData.login || !personalData.accountID) { return; } - const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({login: option.login ?? '', accountID: option.accountID ?? -1})); + const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({ + login: option.login ?? '', + accountID: option.accountID ?? CONST.DEFAULT_NUMBER_ID, + })); const logins = [...selectedParticipants, {login: personalData.login, accountID: personalData.accountID}]; Report.setGroupDraft({participants: logins}); Navigation.navigate(ROUTES.NEW_CHAT_CONFIRM);