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

[No QA] [Performance] Approximate the ideal number of reports to render on first render #4371

Merged
merged 3 commits into from
Aug 3, 2021
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
13 changes: 11 additions & 2 deletions src/components/InvertedFlatList/index.android.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import React, {forwardRef} from 'react';
import PropTypes from 'prop-types';
import BaseInvertedFlatList from './BaseInvertedFlatList';

export default forwardRef((props, ref) => (
const propTypes = {
/** The initial number of items to render */
initialNumToRender: PropTypes.number.isRequired,
};

const InvertedFlatList = forwardRef((props, ref) => (
<BaseInvertedFlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
initialNumToRender={20}
initialNumToRender={props.initialNumToRender}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can revert all these changes in this file I think?


// 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.
// eslint-disable-next-line react/jsx-props-no-multi-spaces
shouldRemoveClippedSubviews
/>
));

InvertedFlatList.propTypes = propTypes;
export default InvertedFlatList;
6 changes: 5 additions & 1 deletion src/components/InvertedFlatList/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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.
// eslint-disable-next-line react/jsx-props-no-multi-spaces
shouldRemoveClippedSubviews
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want this here. Just removing the initialNumToRender={20}. IIRC removing the clipped sub views has unexpected effects on iOS (which is why there are separate files for iOS and Android).

/>
));
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