Skip to content

Commit

Permalink
maxToRenderPerBatch=5
Browse files Browse the repository at this point in the history
  • Loading branch information
perunt committed Sep 11, 2023
1 parent a480524 commit 2f69a83
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/components/InvertedFlatList/BaseInvertedFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ class BaseInvertedFlatList extends Component {
// Web requires that items be measured or else crazy things happen when scrolling.
getItemLayout={this.props.shouldMeasureItems ? this.getItemLayout : undefined}
// We keep this property very low so that chat switching remains fast
maxToRenderPerBatch={1}
maxToRenderPerBatch={5}
windowSize={15}

// Commenting the line below as it breaks the unread indicator test
// we will look at fixing/reusing this after RN v0.72
// maintainVisibleContentPosition={{minIndexForVisible: 0, autoscrollToTopThreshold: 0}}
maintainVisibleContentPosition={{
minIndexForVisible: 0,
}}
Expand Down
7 changes: 7 additions & 0 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ function ReportActionsList({

return null;
}}
ListHeaderComponent={() => {
if (report.isLoadingOlderReportActions) {
return <ReportActionsSkeletonView containerHeight={CONST.CHAT_SKELETON_VIEW.AVERAGE_ROW_HEIGHT * 3} />;
}

return null;
}}
keyboardShouldPersistTaps="handled"
onLayout={(event) => {
setSkeletonViewHeight(event.nativeEvent.layout.height);
Expand Down
26 changes: 8 additions & 18 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,51 +133,41 @@ function ReportActionsView(props) {
}
}, [props.report, didSubscribeToReportTypingEvents, reportID]);

const {oldestReportAction, newestReportAction} = useMemo(() => {
const lengthOfReportActions = props.reportActions.length;
if (lengthOfReportActions === 0) {
return {
oldestReportAction: null,
newestReportAction: null,
};
}
return {
oldestReportAction: props.reportActions[0],
newestReportAction: props.reportActions[lengthOfReportActions - 1],
};
}, [props.reportActions]);

/**
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
*/
const loadOlderChats = useCallback(() => {
const loadOlderChats = () => {
// Only fetch more if we are not already fetching so that we don't initiate duplicate requests.
if (props.report.isLoadingOlderReportActions) {
return;
}

const oldestReportAction = _.last(props.reportActions);

// Don't load more chats if we're already at the beginning of the chat history
if (oldestReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) {
return;
}
// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments
Report.getOlderAction(reportID, oldestReportAction.reportActionID);
}, [props.report.isLoadingOlderReportActions, oldestReportAction]);
};

/**
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
*/
const loadNewerChats = useCallback(() => {
const loadNewerChats = () => {
// Only fetch more if we are not already fetching so that we don't initiate duplicate requests.
if (props.report.isLoadingNewerReportActions || isFirstRender.current || props.report.isLoadingReportActions || props.report.isLoadingOlderReportActions) {
isFirstRender.current = false;
return;
}

const newestReportAction = _.first(props.reportActions);

Report.getNewerAction(reportID, newestReportAction.reportActionID);
}, [props.report.isLoadingNewerReportActions, props.report.isLoadingReportActions, props.report.isLoadingOlderReportActions, props.reportActions, newestReportAction]);
};

/**
* Runs when the FlatList finishes laying out
Expand Down

0 comments on commit 2f69a83

Please sign in to comment.