From 8987babb0801fbc3320bf50877bebefb9702a292 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Sat, 14 May 2022 05:57:44 +0000 Subject: [PATCH] feat(application): expose `inBackground` and `suspended` (#9897) For IOSApplication to be like AndroidApplication --- packages/core/application/index.ios.ts | 9 ++++++++- packages/core/index.d.ts | 2 ++ packages/core/index.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core/application/index.ios.ts b/packages/core/application/index.ios.ts index 7f928e505..23ab08e05 100644 --- a/packages/core/application/index.ios.ts +++ b/packages/core/application/index.ios.ts @@ -20,7 +20,7 @@ import { profile } from '../profiling'; import { iOSNativeHelper } from '../utils'; import { initAccessibilityCssHelper } from '../accessibility/accessibility-css-helper'; import { initAccessibilityFontScale } from '../accessibility/font-scale'; -import { setInBackground, setSuspended } from './application-common'; +import { inBackground, setInBackground, setSuspended, suspended } from './application-common'; const IOS_PLATFORM = 'ios'; @@ -138,6 +138,13 @@ export class iOSApplication implements iOSApplicationDefinition { private _rootView: View; private _systemAppearance: 'light' | 'dark'; + get paused() { + return suspended; + } + get backgrounded() { + return inBackground; + } + constructor() { this._observers = new Array(); this.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, this.didFinishLaunchingWithOptions.bind(this)); diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts index 57604d5db..265c20fbd 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -44,6 +44,8 @@ export declare const Application: { setAutoSystemAppearanceChanged: typeof setAutoSystemAppearanceChanged; android: AndroidApplication; ios: iOSApplication; + suspended: boolean; + inBackground: boolean; }; import { setString, getString, clear, flush, getAllKeys, getBoolean, getNumber, hasKey, remove, setBoolean, setNumber } from './application-settings'; export declare const ApplicationSettings: { diff --git a/packages/core/index.ts b/packages/core/index.ts index 73428e106..5786c31bd 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -6,6 +6,8 @@ export { iOSApplication, AndroidApplication } from './application'; export type { ApplicationEventData, LaunchEventData, OrientationChangedEventData, UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData, AndroidActivityEventData, AndroidActivityBundleEventData, AndroidActivityRequestPermissionsEventData, AndroidActivityResultEventData, AndroidActivityNewIntentEventData, AndroidActivityBackPressedEventData, SystemAppearanceChangedEventData } from './application'; import { fontScaleChangedEvent, launchEvent, displayedEvent, uncaughtErrorEvent, discardedErrorEvent, suspendEvent, resumeEvent, exitEvent, lowMemoryEvent, orientationChangedEvent, systemAppearanceChanged, systemAppearanceChangedEvent, getMainEntry, getRootView, _resetRootView, getResources, setResources, setCssFileName, getCssFileName, loadAppCss, addCss, on, off, notify, hasListeners, run, orientation, getNativeApplication, hasLaunched, android as appAndroid, ios as iosApp, systemAppearance, setAutoSystemAppearanceChanged, ensureNativeApplication, setMaxRefreshRate } from './application'; +import { inBackground, suspended } from 'application/application-common'; + export const Application = { launchEvent, displayedEvent, @@ -48,6 +50,12 @@ export const Application = { ensureNativeApplication(); return iosApp; }, + get suspended() { + return suspended; + }, + get inBackground() { + return inBackground; + }, }; // Export all methods from "application-settings" as ApplicationSettings