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

replace FlatList with .map solution #53655

Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 7 additions & 8 deletions src/pages/Debug/Report/DebugReportActions.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import type {ListRenderItemInfo} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import FlatList from '@components/FlatList';
import {PressableWithFeedback} from '@components/Pressable';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
Expand All @@ -28,17 +26,20 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {
canEvict: false,
selector: (allReportActions) => ReportActionsUtils.getSortedReportActionsForDisplay(allReportActions, canUserPerformWriteAction, true),
});
const renderItem = ({item}: ListRenderItemInfo<ReportAction>) => (

const renderItem = (item: ReportAction, index: number) => (
<PressableWithFeedback
accessibilityLabel={translate('common.details')}
onPress={() => Navigation.navigate(ROUTES.DEBUG_REPORT_ACTION.getRoute(reportID, item.reportActionID))}
style={({pressed}) => [styles.flexRow, styles.justifyContentBetween, pressed && styles.hoveredComponentBG, styles.p4]}
hoverStyle={styles.hoveredComponentBG}
key={index}
>
<Text>{item.reportActionID}</Text>
<Text style={styles.textLabelSupporting}>{datetimeToCalendarTime(item.created, false, false)}</Text>
</PressableWithFeedback>
);

return (
<ScrollView style={styles.mv5}>
<Button
Expand All @@ -48,11 +49,9 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {
onPress={() => Navigation.navigate(ROUTES.DEBUG_REPORT_ACTION_CREATE.getRoute(reportID))}
style={[styles.pb5, styles.ph3]}
/>
<FlatList
data={sortedAllReportActions}
renderItem={renderItem}
scrollEnabled={false}
/>
{/* This list was previously rendered as a FlatList, but it turned out that it caused the component to flash in some cases,
so it was replaced by this solution. */}
{sortedAllReportActions?.map((item, index) => renderItem(item, index))}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to .map() isn't ideal since FlatList provides built-in virtualization and better performance for large lists.

The flashing issue you mentioned might be due to the missing keyExtractor prop in the FlatList.

I suggest re-adding FlatList with a keyExtractor like this to see if it resolves the issue:

<FlatList
    data={sortedAllReportActions}
    renderItem={renderItem}
    keyExtractor={(item) => item.reportActionID.toString()}
    scrollEnabled={false}
/>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it before (forgot to mention it in the proposal) and unfortunately this doesn't fix it.

Here is a demo:

keyextractor-compressed.mov

</ScrollView>
);
}
Expand Down
13 changes: 5 additions & 8 deletions src/pages/Debug/Transaction/DebugTransactionViolations.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import type {ListRenderItemInfo} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import FlatList from '@components/FlatList';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
Expand All @@ -23,12 +21,13 @@ function DebugTransactionViolations({transactionID}: DebugTransactionViolationsP
const styles = useThemeStyles();
const {translate} = useLocalize();

const renderItem = ({item, index}: ListRenderItemInfo<TransactionViolation>) => (
const renderItem = (item: TransactionViolation, index: number) => (
<PressableWithFeedback
accessibilityLabel={translate('common.details')}
onPress={() => Navigation.navigate(ROUTES.DEBUG_TRANSACTION_VIOLATION.getRoute(transactionID, String(index)))}
style={({pressed}) => [styles.flexRow, styles.justifyContentBetween, pressed && styles.hoveredComponentBG, styles.p4]}
hoverStyle={styles.hoveredComponentBG}
key={index}
>
<Text>{item.type}</Text>
<Text>{item.name}</Text>
Expand All @@ -44,11 +43,9 @@ function DebugTransactionViolations({transactionID}: DebugTransactionViolationsP
onPress={() => Navigation.navigate(ROUTES.DEBUG_TRANSACTION_VIOLATION_CREATE.getRoute(transactionID))}
style={[styles.pb5, styles.ph3]}
/>
<FlatList
data={transactionViolations}
renderItem={renderItem}
scrollEnabled={false}
/>
{/* This list was previously rendered as a FlatList, but it turned out that it caused the component to flash in some cases,
so it was replaced by this solution. */}
{transactionViolations?.map((item, index) => renderItem(item, index))}
</ScrollView>
);
}
Expand Down
Loading