diff --git a/src/libs/Visibility/index.desktop.js b/src/libs/Visibility/index.desktop.js index 04e5bb4ff9ca..e3a7eab5bf56 100644 --- a/src/libs/Visibility/index.desktop.js +++ b/src/libs/Visibility/index.desktop.js @@ -11,6 +11,13 @@ function isVisible() { return window.electron.sendSync(ELECTRON_EVENTS.REQUEST_VISIBILITY); } +/** + * @returns {Boolean} + */ +function hasFocus() { + return true; +} + /** * Adds event listener for changes in visibility state * @@ -32,4 +39,5 @@ function onVisibilityChange(callback) { export default { isVisible, onVisibilityChange, + hasFocus, }; diff --git a/src/libs/Visibility/index.js b/src/libs/Visibility/index.js index 2d6c7d2f0906..91a003168ccd 100644 --- a/src/libs/Visibility/index.js +++ b/src/libs/Visibility/index.js @@ -9,6 +9,15 @@ function isVisible() { return document.visibilityState === 'visible'; } +/** + * Whether the app is focused. + * + * @returns {Boolean} + */ +function hasFocus() { + return document.hasFocus(); +} + /** * Adds event listener for changes in visibility state * @@ -25,5 +34,6 @@ function onVisibilityChange(callback) { export default { isVisible, + hasFocus, onVisibilityChange, }; diff --git a/src/libs/Visibility/index.native.js b/src/libs/Visibility/index.native.js index c8b4f93048c1..b888cf1a2b9f 100644 --- a/src/libs/Visibility/index.native.js +++ b/src/libs/Visibility/index.native.js @@ -8,6 +8,13 @@ import {AppState} from 'react-native'; */ const isVisible = () => AppState.currentState === 'active'; +/** + * @returns {Boolean} + */ +function hasFocus() { + return true; +} + /** * Adds event listener for changes in visibility state * @@ -24,5 +31,6 @@ function onVisibilityChange(callback) { export default { isVisible, + hasFocus, onVisibilityChange, }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 0890b6e5720e..6991ae7f316d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1218,7 +1218,7 @@ function shouldShowReportActionNotification(reportID, action = null, isRemote = } // If we are currently viewing this report do not show a notification. - if (reportID === Navigation.getReportIDFromRoute() && Visibility.isVisible()) { + if (reportID === Navigation.getReportIDFromRoute() && Visibility.isVisible() && Visibility.hasFocus()) { Log.info(`${tag} No notification because it was a comment for the current report`); return false; }