Skip to content

Commit 1f133a0

Browse files
committed
Revert "Merge pull request Expensify#81869 from software-mansion-labs/@zfurtak/migrate-NewChatPage"
This reverts commit a8d6dc5, reversing changes made to aa28e1f.
1 parent b75bbe3 commit 1f133a0

8 files changed

Lines changed: 94 additions & 119 deletions

File tree

src/components/SelectionList/SelectionListWithSections/BaseSelectionListWithSections.tsx

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useIsFocused} from '@react-navigation/native';
22
import {FlashList} from '@shopify/flash-list';
33
import type {FlashListRef, ListRenderItemInfo} from '@shopify/flash-list';
4-
import React, {useCallback, useImperativeHandle, useRef} from 'react';
4+
import React, {useImperativeHandle, useRef} from 'react';
55
import type {TextInputKeyPressEvent} from 'react-native';
66
import {View} from 'react-native';
77
import type {ValueOf} from 'type-fest';
@@ -97,26 +97,23 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
9797
hasKeyBeenPressed.current = true;
9898
};
9999

100-
const scrollToIndex = useCallback(
101-
(index: number) => {
102-
if (index < 0 || index >= flattenedData.length || !listRef.current) {
103-
return;
104-
}
105-
const item = flattenedData.at(index);
106-
if (!item) {
107-
return;
108-
}
109-
try {
110-
listRef.current.scrollToIndex({index});
111-
} catch (error) {
112-
// FlashList may throw if layout for this index doesn't exist yet
113-
// This can happen when data changes rapidly (e.g., during search filtering)
114-
// The layout will be computed on next render, so we can safely ignore this
115-
Log.warn('SelectionListWithSections: error scrolling to index', {error});
116-
}
117-
},
118-
[flattenedData],
119-
);
100+
const scrollToIndex = (index: number) => {
101+
if (index < 0 || index >= flattenedData.length || !listRef.current) {
102+
return;
103+
}
104+
const item = flattenedData.at(index);
105+
if (!item) {
106+
return;
107+
}
108+
try {
109+
listRef.current.scrollToIndex({index});
110+
} catch (error) {
111+
// FlashList may throw if layout for this index doesn't exist yet
112+
// This can happen when data changes rapidly (e.g., during search filtering)
113+
// The layout will be computed on next render, so we can safely ignore this
114+
Log.warn('SelectionListWithSections: error scrolling to index', {error});
115+
}
116+
};
120117

121118
const debouncedScrollToIndex = useDebounce(scrollToIndex, CONST.TIMING.LIST_SCROLLING_DEBOUNCE_TIME, {leading: true, trailing: true});
122119

@@ -182,10 +179,6 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
182179
innerTextInputRef.current?.focus();
183180
};
184181

185-
const clearInputAfterSelect = () => {
186-
textInputOptions?.onChangeText?.('');
187-
};
188-
189182
const updateAndScrollToFocusedIndex = (index: number, shouldScroll = true) => {
190183
setFocusedIndex(index);
191184
if (shouldScroll) {
@@ -202,8 +195,6 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
202195

203196
useImperativeHandle(ref, () => ({
204197
focusTextInput,
205-
scrollToIndex,
206-
clearInputAfterSelect,
207198
updateAndScrollToFocusedIndex,
208199
updateExternalTextInputFocus,
209200
getFocusedOption: getFocusedItem,

src/components/SelectionList/SelectionListWithSections/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ type SelectionListWithSectionsProps<TItem extends ListItem> = BaseSelectionListP
5353

5454
type SelectionListWithSectionsHandle<TItem extends ListItem = ListItem> = {
5555
focusTextInput: () => void;
56-
scrollToIndex: (index: number) => void;
57-
clearInputAfterSelect: () => void;
5856
updateAndScrollToFocusedIndex: (index: number, shouldScroll?: boolean) => void;
5957
updateExternalTextInputFocus: (isTextInputFocused: boolean) => void;
6058
getFocusedOption: () => TItem | undefined;

src/components/SelectionList/components/TextInput.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,7 @@ function TextInput({
6565
}: TextInputProps) {
6666
const styles = useThemeStyles();
6767
const {translate} = useLocalize();
68-
const {
69-
label,
70-
value,
71-
onChangeText,
72-
errorText,
73-
headerMessage,
74-
hint,
75-
disableAutoFocus,
76-
placeholder,
77-
maxLength,
78-
inputMode,
79-
ref: optionsRef,
80-
style,
81-
disableAutoCorrect,
82-
shouldInterceptSwipe,
83-
} = options ?? {};
68+
const {label, value, onChangeText, errorText, headerMessage, hint, disableAutoFocus, placeholder, maxLength, inputMode, ref: optionsRef, style, disableAutoCorrect} = options ?? {};
8469
const resultsFound = headerMessage !== translate('common.noResultsFound');
8570
const noData = dataLength === 0 && !showLoadingPlaceholder;
8671
const shouldShowHeaderMessage = !!headerMessage && (!isLoadingNewOptions || resultsFound || noData);
@@ -149,8 +134,8 @@ function TextInput({
149134
isLoading={isLoading}
150135
testID="selection-list-text-input"
151136
errorText={errorText}
137+
shouldInterceptSwipe={false}
152138
autoCorrect={!disableAutoCorrect}
153-
shouldInterceptSwipe={shouldInterceptSwipe ?? false}
154139
/>
155140
</View>
156141
{shouldShowHeaderMessage && (

src/components/SelectionList/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ type TextInputOptions = {
250250
/** Whether the text input auto correct should be disabled */
251251
disableAutoCorrect?: boolean;
252252

253-
/** Whether the text input should intercept swipes */
254-
shouldInterceptSwipe?: boolean;
255-
256253
/** Styles for the text input */
257254
style?: {
258255
/** Styles for the text input container */

src/hooks/useFilteredOptions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO
103103
if (!options || isLoadingMore) {
104104
return;
105105
}
106-
setIsLoadingMore(true);
107-
setReportsLimit((prev) => prev + batchSize);
106+
107+
const hasMoreToLoad = options.reports.length < totalReports;
108+
if (hasMoreToLoad) {
109+
setIsLoadingMore(true);
110+
setReportsLimit((prev) => prev + batchSize);
111+
}
108112
};
109113

110-
const hasMore = options ? reportsLimit < totalReports : false;
114+
const hasMore = options ? options.reports.length < totalReports : false;
111115

112116
return {
113117
options,

src/libs/OptionsListUtils/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,19 @@ function formatSectionsFromSearchTerm(
29692969
};
29702970
}
29712971

2972+
/**
2973+
* Helper method to get the `keyForList` for the first option in the OptionsList
2974+
*/
2975+
function getFirstKeyForList(data?: Option[] | null) {
2976+
if (!data?.length) {
2977+
return '';
2978+
}
2979+
2980+
const firstNonEmptyDataObj = data.at(0);
2981+
2982+
return firstNonEmptyDataObj?.keyForList ? firstNonEmptyDataObj?.keyForList : '';
2983+
}
2984+
29722985
function getPersonalDetailSearchTerms(item: Partial<SearchOptionData>, currentUserAccountID: number) {
29732986
if (item.accountID === currentUserAccountID) {
29742987
return getCurrentUserSearchTerms(item);
@@ -3366,6 +3379,7 @@ export {
33663379
getFilteredRecentAttendees,
33673380
getCurrentUserSearchTerms,
33683381
getEmptyOptions,
3382+
getFirstKeyForList,
33693383
getHeaderMessage,
33703384
getHeaderMessageForNonUserList,
33713385
getIOUConfirmationOptionsFromPayeePersonalDetail,

0 commit comments

Comments
 (0)