Skip to content

Commit

Permalink
Merge pull request #27428 from software-mansion-labs/ts-migration/kow…
Browse files Browse the repository at this point in the history
…czarz/app-state-monitor

[No QA][TS migration] Migrate 'AppStateMonitor' lib to TypeScript
  • Loading branch information
robertjchen authored Sep 19, 2023
2 parents e7c887e + 05b96ec commit 778f763
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import {AppState} from 'react-native';
import {AppState, AppStateStatus} from 'react-native';
import CONST from '../../CONST';
import shouldReportActivity from './shouldReportActivity';

let appState = CONST.APP_STATE.ACTIVE;
let appState: AppStateStatus = CONST.APP_STATE.ACTIVE;

/**
* Listener that will only fire the callback when the user has become active.
*
* @param {Function} callback
* @returns {Function} to unsubscribe
* @returns callback to unsubscribe
*/
function addBecameActiveListener(callback) {
/**
* @param {String} state
*/
function appStateChangeCallback(state) {
function addBecameActiveListener(callback: () => void): () => void {
function appStateChangeCallback(state: AppStateStatus) {
if (shouldReportActivity && (appState === CONST.APP_STATE.INACTIVE || appState === CONST.APP_STATE.BACKGROUND) && state === CONST.APP_STATE.ACTIVE) {
callback();
}
Expand Down

This file was deleted.

5 changes: 5 additions & 0 deletions src/libs/AppStateMonitor/shouldReportActivity/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ShouldReportActivity from './types';

const shouldReportActivity: ShouldReportActivity = true;

export default shouldReportActivity;
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import ShouldReportActivity from './types';

// We only need to report when the app becomes active on native since web maintains most of it's network functions while
// in the "background" and the concept is not quite the same on mobile. We avoid setting this to true for web since
// the event would fire much more frequently than it does on native causing performance issues.
export default false;
const shouldReportActivity: ShouldReportActivity = false;

export default shouldReportActivity;
3 changes: 3 additions & 0 deletions src/libs/AppStateMonitor/shouldReportActivity/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type ShouldReportActivity = boolean;

export default ShouldReportActivity;

0 comments on commit 778f763

Please sign in to comment.