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

Show a skeleton view above optimistic report actions when we're still loading the rest of the report #13590

Merged
merged 5 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 38 additions & 9 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import PropTypes from 'prop-types';
import React from 'react';
import {Animated} from 'react-native';
import _ from 'underscore';
import InvertedFlatList from '../../../components/InvertedFlatList';
import withDrawerState, {withDrawerPropTypes} from '../../../components/withDrawerState';
import compose from '../../../libs/compose';
import * as ReportScrollManager from '../../../libs/ReportScrollManager';
import styles from '../../../styles/styles';
import * as ReportUtils from '../../../libs/ReportUtils';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import {withPersonalDetails} from '../../../components/OnyxProvider';
import {withNetwork, withPersonalDetails} from '../../../components/OnyxProvider';
import ReportActionItem from './ReportActionItem';
import ReportActionsSkeletonView from '../../../components/ReportActionsSkeletonView';
import variables from '../../../styles/variables';
Expand All @@ -18,6 +19,7 @@ import reportActionPropTypes from './reportActionPropTypes';
import CONST from '../../../CONST';
import * as StyleUtils from '../../../styles/StyleUtils';
import reportPropTypes from '../../reportPropTypes';
import networkPropTypes from '../../../components/networkPropTypes';

const propTypes = {
/** Position of the "New" line marker */
Expand Down Expand Up @@ -47,6 +49,9 @@ const propTypes = {
/** Function to load more chats */
loadMoreChats: PropTypes.func.isRequired,

/** Information about the network */
network: networkPropTypes.isRequired,

...withDrawerPropTypes,
...windowDimensionsPropTypes,
};
Expand All @@ -65,6 +70,7 @@ class ReportActionsList extends React.Component {

this.state = {
fadeInAnimation: new Animated.Value(0),
skeletonViewHeight: 0,
};
}

Expand Down Expand Up @@ -159,15 +165,37 @@ class ReportActionsList extends React.Component {
initialNumToRender={this.calculateInitialNumToRender()}
onEndReached={this.props.loadMoreChats}
onEndReachedThreshold={0.75}
ListFooterComponent={this.props.isLoadingMoreReportActions
? (
<ReportActionsSkeletonView
containerHeight={CONST.CHAT_SKELETON_VIEW.AVERAGE_ROW_HEIGHT * 3}
/>
)
: null}
ListFooterComponent={() => {
if (this.props.report.isLoadingMoreReportActions) {
return (
<ReportActionsSkeletonView
containerHeight={CONST.CHAT_SKELETON_VIEW.AVERAGE_ROW_HEIGHT * 3}
/>
);
}

// Make sure the oldest report action loaded is not the first. This is so we do not show the
// skeleton view above the created action in a newly generated optimistic chat or one with not
// that many comments.
const lastReportAction = _.last(this.props.sortedReportActions);
if (this.props.report.isLoadingReportActions && lastReportAction.sequenceNumber > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment will be helpful regarding why you are doing lastReportAction.sequenceNumber > 0.

return (
<ReportActionsSkeletonView
containerHeight={this.state.skeletonViewHeight}
animate={!this.props.network.isOffline}
/>
);
}

return null;
}}
keyboardShouldPersistTaps="handled"
onLayout={this.props.onLayout}
onLayout={(event) => {
this.setState({
skeletonViewHeight: event.nativeEvent.layout.height,
});
this.props.onLayout(event);
}}
onScroll={this.props.onScroll}
extraData={extraData}
/>
Expand All @@ -183,4 +211,5 @@ export default compose(
withDrawerState,
withWindowDimensions,
withPersonalDetails(),
withNetwork(),
)(ReportActionsList);
4 changes: 4 additions & 0 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class ReportActionsView extends React.Component {
return true;
}

if (nextProps.report.isLoadingReportActions !== this.props.report.isLoadingReportActions) {
return true;
}

if (nextProps.report.lastReadSequenceNumber !== this.props.report.lastReadSequenceNumber) {
return true;
}
Expand Down