Skip to content

Commit

Permalink
Merge pull request #36031 from margelo/e2e/fix-open-search-tests
Browse files Browse the repository at this point in the history
[NoQA] fix broken e2e open search test
  • Loading branch information
mountiny authored Feb 9, 2024
2 parents ed6f8e3 + c0987db commit 4f9d415
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ const CONST = {
REPORT_INITIAL_RENDER: 'report_initial_render',
SWITCH_REPORT: 'switch_report',
SIDEBAR_LOADED: 'sidebar_loaded',
OPEN_SEARCH: 'open_search',
LOAD_SEARCH_OPTIONS: 'load_search_options',
COLD: 'cold',
WARM: 'warm',
Expand Down
12 changes: 0 additions & 12 deletions src/components/OptionsList/BaseOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import SectionList from '@components/SectionList';
import Text from '@components/Text';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import Timing from '@libs/actions/Timing';
import Performance from '@libs/Performance';
import type {OptionData} from '@libs/ReportUtils';
import StringUtils from '@libs/StringUtils';
import variables from '@styles/variables';
Expand Down Expand Up @@ -110,16 +108,6 @@ function BaseOptionsList(
flattenedData.current = buildFlatSectionArray();
});

useEffect(() => {
if (isLoading) {
return;
}

// Mark the end of the search page load time. This data is collected only for Search page.
Timing.end(CONST.TIMING.OPEN_SEARCH);
Performance.markEnd(CONST.TIMING.OPEN_SEARCH);
}, [isLoading]);

const onViewableItemsChanged = () => {
if (didLayout.current || !onLayout) {
return;
Expand Down
11 changes: 10 additions & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
shouldUseDynamicMaxToRenderPerBatch = false,
rightHandSideComponent,
isLoadingNewOptions = false,
onLayout,
}: BaseSelectionListProps<TItem>,
inputRef: ForwardedRef<RNTextInput>,
) {
Expand Down Expand Up @@ -320,6 +321,14 @@ function BaseSelectionList<TItem extends User | RadioItem>(
[focusedIndex, isInitialSectionListRender, scrollToIndex, shouldUseDynamicMaxToRenderPerBatch],
);

const onSectionListLayout = useCallback(
(nativeEvent: LayoutChangeEvent) => {
onLayout?.(nativeEvent);
scrollToFocusedIndexOnFirstRender(nativeEvent);
},
[onLayout, scrollToFocusedIndexOnFirstRender],
);

const updateAndScrollToFocusedIndex = useCallback(
(newFocusedIndex: number) => {
setFocusedIndex(newFocusedIndex);
Expand Down Expand Up @@ -468,7 +477,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
windowSize={5}
viewabilityConfig={{viewAreaCoveragePercentThreshold: 95}}
testID="selection-list"
onLayout={scrollToFocusedIndexOnFirstRender}
onLayout={onSectionListLayout}
style={(!maxToRenderPerBatch || isInitialSectionListRender) && styles.opacity0}
/>
{children}
Expand Down
5 changes: 4 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ReactElement, ReactNode} from 'react';
import type {GestureResponderEvent, InputModeOptions, SectionListData, StyleProp, TextStyle, ViewStyle} from 'react-native';
import type {GestureResponderEvent, InputModeOptions, LayoutChangeEvent, SectionListData, StyleProp, TextStyle, ViewStyle} from 'react-native';
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type ChildrenProps from '@src/types/utils/ChildrenProps';

Expand Down Expand Up @@ -233,6 +233,9 @@ type BaseSelectionListProps<TItem extends User | RadioItem> = Partial<ChildrenPr

/** Whether to show the loading indicator for new options */
isLoadingNewOptions?: boolean;

/** Fired when the list is displayed with the items */
onLayout?: (event: LayoutChangeEvent) => void;
};

type ItemLayout = {
Expand Down

0 comments on commit 4f9d415

Please sign in to comment.