Skip to content
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
8 changes: 8 additions & 0 deletions src/libs/Visibility/index.desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -32,4 +39,5 @@ function onVisibilityChange(callback) {
export default {
isVisible,
onVisibilityChange,
hasFocus,
};
10 changes: 10 additions & 0 deletions src/libs/Visibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ function isVisible() {
return document.visibilityState === 'visible';
}

/**
* Whether the app is focused.
*
* @returns {Boolean}
*/
function hasFocus() {
return document.hasFocus();
}
Comment thread
luacmartins marked this conversation as resolved.

/**
* Adds event listener for changes in visibility state
*
Expand All @@ -25,5 +34,6 @@ function onVisibilityChange(callback) {

export default {
isVisible,
hasFocus,
onVisibilityChange,
};
8 changes: 8 additions & 0 deletions src/libs/Visibility/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {AppState} from 'react-native';
*/
const isVisible = () => AppState.currentState === 'active';

/**
* @returns {Boolean}
*/
function hasFocus() {
return true;
}
Comment on lines +14 to +16

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Assuming it has focus is weird?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

bump @tienifr

cc: @luacmartins thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's fine since checking isVisible should be enough on the native case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see your point @Santhosh-Sellavel. In the future, we might want this function to behave as onResume-onPause lifecycle on Android. I mean, for instance, sometimes the App might be foregrounded and partially visible but not focused because there is a system alert on top of it. But I also do agree with @luacmartins that this might be out of scope for now.


/**
* Adds event listener for changes in visibility state
*
Expand All @@ -24,5 +31,6 @@ function onVisibilityChange(callback) {

export default {
isVisible,
hasFocus,
onVisibilityChange,
};
2 changes: 1 addition & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Comment thread
luacmartins marked this conversation as resolved.
Log.info(`${tag} No notification because it was a comment for the current report`);
return false;
}
Expand Down