From 2f69a8328209b6eb8649c12f6ac559f1fb93bcdc Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 11 Sep 2023 21:51:09 +0200 Subject: [PATCH] maxToRenderPerBatch=5 --- .../InvertedFlatList/BaseInvertedFlatList.js | 3 +-- src/pages/home/report/ReportActionsList.js | 7 +++++ src/pages/home/report/ReportActionsView.js | 26 ++++++------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/components/InvertedFlatList/BaseInvertedFlatList.js b/src/components/InvertedFlatList/BaseInvertedFlatList.js index 50150c0a1813..4ad3cb37e13d 100644 --- a/src/components/InvertedFlatList/BaseInvertedFlatList.js +++ b/src/components/InvertedFlatList/BaseInvertedFlatList.js @@ -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, }} diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index b3f6a8dc0d59..1336b2d42ecd 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -323,6 +323,13 @@ function ReportActionsList({ return null; }} + ListHeaderComponent={() => { + if (report.isLoadingOlderReportActions) { + return ; + } + + return null; + }} keyboardShouldPersistTaps="handled" onLayout={(event) => { setSkeletonViewHeight(event.nativeEvent.layout.height); diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index f0ded5e451b3..1d477abf4d1c 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -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