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

Add Unread Action Indicator #1570

Merged
merged 7 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions src/components/UnreadActionIndicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import {Animated, View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import Text from './Text';

const propTypes = {
// Animated opacity
// eslint-disable-next-line react/forbid-prop-types
animatedOpacity: PropTypes.object.isRequired,
};

const UnreadActionIndicator = props => (
<Animated.View style={[
styles.unreadIndicatorContainer,
{opacity: props.animatedOpacity},
]}
>
<View style={styles.unreadIndicatorLine} />
<Text style={styles.unreadIndicatorText}>
NEW
</Text>
</Animated.View>
);

UnreadActionIndicator.propTypes = propTypes;
UnreadActionIndicator.displayName = 'UnreadActionIndicator';

export default UnreadActionIndicator;
71 changes: 63 additions & 8 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import {View, Keyboard, AppState} from 'react-native';
import {
Animated, View, Keyboard, AppState, Easing,
} from 'react-native';
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved
import PropTypes from 'prop-types';
import _ from 'underscore';
import lodashGet from 'lodash.get';
import {withOnyx} from 'react-native-onyx';
import Text from '../../../components/Text';
import UnreadActionIndicator from '../../../components/UnreadActionIndicator';
import {fetchActions, updateLastReadActionID} from '../../../libs/actions/Report';
import ONYXKEYS from '../../../ONYXKEYS';
import ReportActionItem from './ReportActionItem';
Expand All @@ -23,6 +26,11 @@ const propTypes = {

/* Onyx Props */

// List of reports to display
reports: PropTypes.objectOf(PropTypes.shape({
reportID: PropTypes.number,
})),

// Array of report actions for this report
reportActions: PropTypes.objectOf(PropTypes.shape(ReportActionPropTypes)),

Expand All @@ -34,6 +42,7 @@ const propTypes = {
};

const defaultProps = {
reports: {},
reportActions: {},
session: {},
};
Expand All @@ -46,8 +55,15 @@ class ReportActionsView extends React.Component {
this.scrollToListBottom = this.scrollToListBottom.bind(this);
this.recordMaxAction = this.recordMaxAction.bind(this);
this.onVisibilityChange = this.onVisibilityChange.bind(this);
this.sortedReportActions = this.updateSortedReportActions();
this.setUpUnreadActionIndicator = this.setUpUnreadActionIndicator.bind(this);
this.updateSortedReportActions = this.updateSortedReportActions.bind(this);
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved

this.sortedReportActions = [];
bondydaa marked this conversation as resolved.
Show resolved Hide resolved
this.timers = [];
this.unreadActionCount = 0;
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
this.shouldShowNewActionIndicator = true;
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
this.unreadIndicatorOpacity = new Animated.Value(1);
this.unreadIndicatorTimer = null;
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved

this.state = {
refetchNeeded: true,
Expand Down Expand Up @@ -121,6 +137,7 @@ class ReportActionsView extends React.Component {
this.keyboardEvent.remove();
}

clearTimeout(this.unreadIndicatorTimer);
AppState.removeEventListener('change', this.onVisibilityChange);

_.each(this.timers, timer => clearTimeout(timer));
Expand All @@ -145,6 +162,35 @@ class ReportActionsView extends React.Component {
this.setState({refetchNeeded});
}

/**
* Checks if the unreadActionIndicator should be shown.
* If it does, starts a timeout for the fading out animation and creates
* a flag to not show it again if the report is still open
*/
setUpUnreadActionIndicator() {
if (!this.props.isActiveReport || !this.shouldShowNewActionIndicator) {
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved
return;
}

this.unreadActionCount = _.find(this.props.reports, report => (
report.reportID === this.props.reportID
)).unreadActionCount;

if (this.unreadActionCount > 0) {
this.unreadIndicatorOpacity = new Animated.Value(1);
this.unreadIndicatorTimer = setTimeout(() => {
Animated.timing(this.unreadIndicatorOpacity, {
toValue: 0,
duration: 500,
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
easing: Easing.ease,
useNativeDriver: false,
}).start();
}, 3000);
}

this.shouldShowNewActionIndicator = false;
}

/**
* Updates and sorts the report actions by sequence number
*/
Expand Down Expand Up @@ -239,12 +285,17 @@ class ReportActionsView extends React.Component {
needsLayoutCalculation,
}) {
return (
<ReportActionItem
action={item.action}
displayAsGroup={this.isConsecutiveActionMadeByPreviousActor(index)}
onLayout={onLayout}
needsLayoutCalculation={needsLayoutCalculation}
/>
<View>
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
{this.unreadActionCount > 0 && index === this.unreadActionCount - 1 && (
<UnreadActionIndicator animatedOpacity={this.unreadIndicatorOpacity} />
)}
<ReportActionItem
action={item.action}
displayAsGroup={this.isConsecutiveActionMadeByPreviousActor(index)}
onLayout={onLayout}
needsLayoutCalculation={needsLayoutCalculation}
/>
</View>
);
}

Expand All @@ -263,6 +314,7 @@ class ReportActionsView extends React.Component {
);
}

this.setUpUnreadActionIndicator();
this.updateSortedReportActions();
return (
<InvertedFlatList
Expand All @@ -281,6 +333,9 @@ ReportActionsView.propTypes = propTypes;
ReportActionsView.defaultProps = defaultProps;

export default withOnyx({
reports: {
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved
key: ONYXKEYS.COLLECTION.REPORT,
},
reportActions: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
canEvict: props => !props.isActiveReport,
Expand Down
26 changes: 26 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,32 @@ const styles = {
marginLeft: 8,
},

unreadIndicatorContainer: {
position: 'absolute',
top: -10,
left: 0,
width: '100%',
height: 20,
paddingHorizontal: 20,
flexDirection: 'row',
alignItems: 'center',
},

unreadIndicatorLine: {
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved
height: 1,
backgroundColor: themeColors.unreadIndicator,
flexGrow: 1,
marginRight: 8,
opacity: 0.5,
},

unreadIndicatorText: {
color: themeColors.unreadIndicator,
lucas-neuhaus-dev marked this conversation as resolved.
Show resolved Hide resolved
fontFamily: fontFamily.GTA_BOLD,
fontSize: variables.fontSizeSmall,
fontWeight: fontWeightBold,
},

flipUpsideDown: {
transform: [{rotate: '180deg'}],
},
Expand Down
1 change: 1 addition & 0 deletions src/styles/themes/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export default {
pillBG: colors.gray2,
buttonDisabledBG: colors.gray2,
buttonHoveredBG: colors.gray1,
unreadIndicator: colors.green,
};