Skip to content

Commit

Permalink
Merge pull request #4371 from rdjuric/calculateIdealNumOfMessages
Browse files Browse the repository at this point in the history
[Performance] Approximate the ideal number of reports to render on first render
  • Loading branch information
marcaaron authored Aug 3, 2021
2 parents 22e7f0a + 9905d36 commit 553e9b8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/components/InvertedFlatList/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
initialNumToRender={20}

// Remove clipped subviews helps prevent avatars and attachments from eating up excess memory on Android. When
// we run out of memory images stop appearing without any warning.
Expand Down
1 change: 0 additions & 1 deletion src/components/InvertedFlatList/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
initialNumToRender={20}
/>
));
1 change: 0 additions & 1 deletion src/components/InvertedFlatList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class InvertedFlatList extends React.Component {
{...this.props}
ref={el => this.list = el}
shouldMeasureItems
initialNumToRender={25}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Text = React.forwardRef(({
};

if (componentStyle.fontSize === variables.fontSizeNormal) {
componentStyle.lineHeight = 20;
componentStyle.lineHeight = variables.fontSizeNormalHeight;
}

return (
Expand Down
16 changes: 16 additions & 0 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager';
import {contextMenuRef} from './ContextMenu/ReportActionContextMenu';
import PopoverReportActionContextMenu from './ContextMenu/PopoverReportActionContextMenu';
import variables from '../../../styles/variables';

const propTypes = {
/** The ID of the report actions will be created for */
Expand Down Expand Up @@ -258,6 +259,20 @@ class ReportActionsView extends React.Component {
});
}

/**
* Calculates the ideal number of report actions to render in the first render, based on the screen height and on
* the height of the smallest report action possible.
* @return {Number}
*/
calculateInitialNumToRender() {
const minimumReportActionHeight = styles.chatItem.paddingTop + styles.chatItem.paddingBottom
+ variables.fontSizeNormalHeight;
const availableHeight = this.props.windowHeight
- (styles.chatItemCompose.minHeight + variables.contentHeaderHeight);
return Math.ceil(availableHeight / minimumReportActionHeight);
}


/**
* Updates and sorts the report actions by sequence number
*
Expand Down Expand Up @@ -420,6 +435,7 @@ class ReportActionsView extends React.Component {
contentContainerStyle={styles.chatContentScrollView}
keyExtractor={this.keyExtractor}
initialRowHeight={32}
initialNumToRender={this.calculateInitialNumToRender()}
onEndReached={this.loadMoreChats}
onEndReachedThreshold={0.75}
ListFooterComponent={this.state.isLoadingMoreChats
Expand Down

0 comments on commit 553e9b8

Please sign in to comment.