Skip to content

Commit

Permalink
Merge pull request #42170 from charles-liang/charles
Browse files Browse the repository at this point in the history
fix: [Search v1] Search page scroll is not smooth
  • Loading branch information
puneetlath authored May 27, 2024
2 parents 95d328f + 6034aee commit a1cb473
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 120 deletions.
11 changes: 11 additions & 0 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ function Search({query, policyIDs}: SearchProps) {
return (
<SelectionList
customListHeader={<SearchTableHeader data={searchResults?.data} />}
// To enhance the smoothness of scrolling and minimize the risk of encountering blank spaces during scrolling,
// we have configured a larger windowSize and a longer delay between batch renders.
// The windowSize determines the number of items rendered before and after the currently visible items.
// A larger windowSize helps pre-render more items, reducing the likelihood of blank spaces appearing.
// The updateCellsBatchingPeriod sets the delay (in milliseconds) between rendering batches of cells.
// A longer delay allows the UI to handle rendering in smaller increments, which can improve performance and smoothness.
// For more information, refer to the React Native documentation:
// https://reactnative.dev/docs/0.73/optimizing-flatlist-configuration#windowsize
// https://reactnative.dev/docs/0.73/optimizing-flatlist-configuration#updatecellsbatchingperiod
windowSize={111}
updateCellsBatchingPeriod={200}
ListItem={ListItem}
sections={[{data, isDisabled: false}]}
onSelectRow={(item) => {
Expand Down
8 changes: 6 additions & 2 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function BaseSelectionList<TItem extends ListItem>(
listHeaderContent,
onEndReached = () => {},
onEndReachedThreshold,
windowSize = 5,
updateCellsBatchingPeriod = 50,
}: BaseSelectionListProps<TItem>,
ref: ForwardedRef<SelectionListHandle>,
) {
Expand Down Expand Up @@ -410,7 +412,8 @@ function BaseSelectionList<TItem extends ListItem>(
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
// We're already handling the Enter key press in the useKeyboardShortcut hook, so we don't want the list item to submit the form
shouldPreventEnterKeySubmit
rightHandSideComponent={rightHandSideComponent}
// Change this because of lint
rightHandSideComponent={rightHandSideComponent && (typeof rightHandSideComponent === 'function' ? rightHandSideComponent({} as TItem) : rightHandSideComponent)}
keyForList={item.keyForList ?? ''}
isMultilineSupported={isRowMultilineSupported}
onFocus={() => {
Expand Down Expand Up @@ -649,7 +652,8 @@ function BaseSelectionList<TItem extends ListItem>(
showsVerticalScrollIndicator={showScrollIndicator}
initialNumToRender={12}
maxToRenderPerBatch={maxToRenderPerBatch}
windowSize={5}
windowSize={windowSize}
updateCellsBatchingPeriod={updateCellsBatchingPeriod}
viewabilityConfig={{viewAreaCoveragePercentThreshold: 95}}
testID="selection-list"
onLayout={onSectionListLayout}
Expand Down
Loading

0 comments on commit a1cb473

Please sign in to comment.