Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced LHNOptionsList FlashList -> RN FlatList #40380

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {useRoute} from '@react-navigation/native';
import type {FlashListProps} from '@shopify/flash-list';
import {FlashList} from '@shopify/flash-list';
import type {ReactElement} from 'react';
import React, {memo, useCallback, useContext, useEffect, useMemo, useRef} from 'react';
import {StyleSheet, View} from 'react-native';
import type {FlatListProps} from 'react-native';
import {FlatList, StyleSheet, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
Expand Down Expand Up @@ -45,7 +44,7 @@ function LHNOptionsList({
onFirstItemRendered = () => {},
}: LHNOptionsListProps) {
const {saveScrollOffset, getScrollOffset} = useContext(ScrollOffsetContext);
const flashListRef = useRef<FlashList<string>>(null);
const flatListRef = useRef<FlatList>(null);
const route = useRoute();

const theme = useTheme();
Expand Down Expand Up @@ -172,19 +171,19 @@ function LHNOptionsList({
const previousOptionMode = usePrevious(optionMode);

useEffect(() => {
if (previousOptionMode === null || previousOptionMode === optionMode || !flashListRef.current) {
if (previousOptionMode === null || previousOptionMode === optionMode || !flatListRef.current) {
return;
}

if (!flashListRef.current) {
if (!flatListRef.current) {
return;
}

// If the option mode changes want to scroll to the top of the list because rendered items will have different height.
flashListRef.current.scrollToOffset({offset: 0});
flatListRef.current.scrollToOffset({offset: 0});
}, [previousOptionMode, optionMode]);

const onScroll = useCallback<NonNullable<FlashListProps<string>['onScroll']>>(
const onScroll = useCallback<NonNullable<FlatListProps<string>['onScroll']>>(
(e) => {
// If the layout measurement is 0, it means the flashlist is not displayed but the onScroll may be triggered with offset value 0.
// We should ignore this case.
Expand All @@ -199,18 +198,18 @@ function LHNOptionsList({
const onLayout = useCallback(() => {
const offset = getScrollOffset(route);

if (!(offset && flashListRef.current)) {
if (!(offset && flatListRef.current)) {
return;
}

// We need to use requestAnimationFrame to make sure it will scroll properly on iOS.
requestAnimationFrame(() => {
if (!(offset && flashListRef.current)) {
if (!(offset && flatListRef.current)) {
return;
}
flashListRef.current.scrollToOffset({offset});
flatListRef.current.scrollToOffset({offset});
});
}, [route, flashListRef, getScrollOffset]);
}, [route, flatListRef, getScrollOffset]);

return (
<View style={[style ?? styles.flex1, shouldShowEmptyLHN ? styles.emptyLHNWrapper : undefined]}>
Expand All @@ -224,16 +223,15 @@ function LHNOptionsList({
CustomSubtitle={emptyLHNSubtitle}
/>
) : (
<FlashList
ref={flashListRef}
<FlatList
ref={flatListRef}
indicatorStyle="white"
keyboardShouldPersistTaps="always"
contentContainerStyle={StyleSheet.flatten(contentContainerStyles)}
data={data}
testID="lhn-options-list"
keyExtractor={keyExtractor}
renderItem={renderItem}
estimatedItemSize={optionMode === CONST.OPTION_MODE.COMPACT ? variables.optionRowHeightCompact : variables.optionRowHeight}
extraData={extraData}
showsVerticalScrollIndicator={false}
onLayout={onLayout}
Expand Down
Loading