Wait 1s before clearing notifications when app is brought to the foreground (#2419)
This commit is contained in:
parent
50f6863b0e
commit
91f9ea572b
1 changed files with 18 additions and 3 deletions
|
|
@ -70,6 +70,7 @@ export default class NetworkIndicator extends PureComponent {
|
|||
const navBar = this.getNavBarHeight(props.isLandscape);
|
||||
this.top = new Animated.Value(navBar - HEIGHT);
|
||||
this.opacity = 0;
|
||||
this.clearNotificationTimeout = null;
|
||||
|
||||
this.backgroundColor = new Animated.Value(0);
|
||||
this.firstRun = true;
|
||||
|
|
@ -88,8 +89,17 @@ export default class NetworkIndicator extends PureComponent {
|
|||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const {isLandscape: prevIsLandscape, websocketStatus: previousWebsocketStatus} = prevProps;
|
||||
const {isLandscape, websocketErrorCount, websocketStatus} = this.props;
|
||||
const {
|
||||
currentChannelId: prevChannelId,
|
||||
isLandscape: prevIsLandscape,
|
||||
websocketStatus: previousWebsocketStatus,
|
||||
} = prevProps;
|
||||
const {currentChannelId, isLandscape, websocketErrorCount, websocketStatus} = this.props;
|
||||
|
||||
if (currentChannelId !== prevChannelId && this.clearNotificationTimeout) {
|
||||
clearTimeout(this.clearNotificationTimeout);
|
||||
this.clearNotificationTimeout = null;
|
||||
}
|
||||
|
||||
if (isLandscape !== prevIsLandscape) {
|
||||
const navBar = this.getNavBarHeight(isLandscape);
|
||||
|
|
@ -220,7 +230,12 @@ export default class NetworkIndicator extends PureComponent {
|
|||
this.connect(true);
|
||||
|
||||
if (currentChannelId) {
|
||||
PushNotifications.clearChannelNotifications(currentChannelId);
|
||||
// Clear the notifications for the current channel after one second
|
||||
// this is done so we can cancel it in case the app is brought to the
|
||||
// foreground by tapping a notification from another channel
|
||||
this.clearNotificationTimeout = setTimeout(() => {
|
||||
PushNotifications.clearChannelNotifications(currentChannelId);
|
||||
}, 1000);
|
||||
}
|
||||
} else {
|
||||
this.handleWebSocket(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue