Skip to content

Commit

Permalink
Merge pull request #50143 from software-mansion-labs/@szymczak/fix-se…
Browse files Browse the repository at this point in the history
…arch-router-performance

Fix performance of SearchRouter
  • Loading branch information
luacmartins authored Oct 3, 2024
2 parents cb58008 + ea856bd commit 0c2900c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 43 deletions.
69 changes: 28 additions & 41 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import debounce from 'lodash/debounce';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import {useOptionsList} from '@components/OptionListContextProvider';
import type {SearchQueryJSON} from '@components/Search/types';
import type {SelectionListHandle} from '@components/SelectionList/types';
Expand Down Expand Up @@ -160,48 +158,37 @@ function SearchRouter() {
clearUserQuery();
});

const modalType = isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.POPOVER;
const modalWidth = isSmallScreenWidth ? styles.w100 : {width: variables.popoverWidth};

return (
<Modal
type={modalType}
fullscreen
isVisible={isSearchRouterDisplayed}
popoverAnchorPosition={{right: 20, top: 20}}
onClose={closeSearchRouter}
>
<FocusTrapForModal active={isSearchRouterDisplayed}>
<View style={[styles.flex1, modalWidth, styles.h100, !isSmallScreenWidth && styles.mh85vh]}>
{isSmallScreenWidth && (
<HeaderWithBackButton
title={translate('common.search')}
onBackButtonPress={() => closeSearchRouter()}
/>
)}
<SearchRouterInput
value={textInputValue}
setValue={setTextInputValue}
isFullWidth={isSmallScreenWidth}
updateSearch={onSearchChange}
routerListRef={listRef}
wrapperStyle={[isSmallScreenWidth ? styles.mv3 : styles.mv2, isSmallScreenWidth ? styles.mh5 : styles.mh2, styles.border]}
wrapperFocusedStyle={[styles.borderColorFocus]}
isSearchingForReports={isSearchingForReports}
/>
<SearchRouterList
currentQuery={userSearchQuery}
reportForContextualSearch={contextualReportData}
recentSearches={sortedRecentSearches?.slice(0, 5)}
recentReports={recentReports}
onSearchSubmit={onSearchSubmit}
updateUserSearchQuery={updateUserSearchQuery}
closeAndClearRouter={closeAndClearRouter}
ref={listRef}
/>
</View>
</FocusTrapForModal>
</Modal>
<View style={[styles.flex1, modalWidth, styles.h100, !isSmallScreenWidth && styles.mh85vh]}>
{isSmallScreenWidth && (
<HeaderWithBackButton
title={translate('common.search')}
onBackButtonPress={() => closeSearchRouter()}
/>
)}
<SearchRouterInput
value={textInputValue}
setValue={setTextInputValue}
isFullWidth={isSmallScreenWidth}
updateSearch={onSearchChange}
routerListRef={listRef}
wrapperStyle={[isSmallScreenWidth ? styles.mv3 : styles.mv2, isSmallScreenWidth ? styles.mh5 : styles.mh2, styles.border]}
wrapperFocusedStyle={[styles.borderColorFocus]}
isSearchingForReports={isSearchingForReports}
/>
<SearchRouterList
currentQuery={userSearchQuery}
reportForContextualSearch={contextualReportData}
recentSearches={sortedRecentSearches?.slice(0, 5)}
recentReports={recentReports}
onSearchSubmit={onSearchSubmit}
updateUserSearchQuery={updateUserSearchQuery}
closeAndClearRouter={closeAndClearRouter}
ref={listRef}
/>
</View>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/components/Search/SearchRouter/SearchRouterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function SearchRouterList(
containerStyle={[styles.mh100]}
sectionListStyle={[isSmallScreenWidth ? styles.ph5 : styles.ph2, styles.pb2]}
ref={ref}
showScrollIndicator={!isSmallScreenWidth}
/>
);
}
Expand Down
30 changes: 30 additions & 0 deletions src/components/Search/SearchRouter/SearchRouterModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
import Modal from '@components/Modal';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import CONST from '@src/CONST';
import SearchRouter from './SearchRouter';
import {useSearchRouterContext} from './SearchRouterContext';

function SearchRouterModal() {
const {isSmallScreenWidth} = useResponsiveLayout();
const {isSearchRouterDisplayed, closeSearchRouter} = useSearchRouterContext();

const modalType = isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.POPOVER;

return (
<Modal
type={modalType}
fullscreen
isVisible={isSearchRouterDisplayed}
popoverAnchorPosition={{right: 20, top: 20}}
onClose={closeSearchRouter}
>
<FocusTrapForModal active={isSearchRouterDisplayed}>{isSearchRouterDisplayed && <SearchRouter />}</FocusTrapForModal>
</Modal>
);
}

SearchRouterModal.displayName = 'SearchRouterModal';

export default SearchRouterModal;
4 changes: 2 additions & 2 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ActiveGuidesEventListener from '@components/ActiveGuidesEventListener';
import ComposeProviders from '@components/ComposeProviders';
import OptionsListContextProvider from '@components/OptionListContextProvider';
import {SearchContextProvider} from '@components/Search/SearchContext';
import SearchRouter from '@components/Search/SearchRouter/SearchRouter';
import SearchRouterModal from '@components/Search/SearchRouter/SearchRouterModal';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useOnboardingFlowRouter from '@hooks/useOnboardingFlow';
import usePermissions from '@hooks/usePermissions';
Expand Down Expand Up @@ -578,7 +578,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
);
})}
</RootStack.Navigator>
<SearchRouter />
<SearchRouterModal />
</View>
{didPusherInit && <ActiveGuidesEventListener />}
</ComposeProviders>
Expand Down

0 comments on commit 0c2900c

Please sign in to comment.