UNPKG

2.14 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import {NativeEventSubscription} from '../EventEmitter/RCTNativeAppEventEmitter';
11
12/**
13 * AppState can tell you if the app is in the foreground or background,
14 * and notify you when the state changes.
15 *
16 * AppState is frequently used to determine the intent and proper behavior
17 * when handling push notifications.
18 *
19 * App State Events
20 * change - This even is received when the app state has changed.
21 * focus [Android] - Received when the app gains focus (the user is interacting with the app).
22 * blur [Android] - Received when the user is not actively interacting with the app.
23 *
24 * App States
25 * active - The app is running in the foreground
26 * background - The app is running in the background. The user is either in another app or on the home screen
27 * inactive [iOS] - This is a transition state that happens when the app launches, is asking for permissions or when a call or SMS message is received.
28 * unknown [iOS] - Initial value until the current app state is determined
29 * extension [iOS] - The app is running as an app extension
30 *
31 * For more information, see Apple's documentation: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html
32 *
33 * @see https://reactnative.dev/docs/appstate#app-states
34 */
35export type AppStateEvent = 'change' | 'memoryWarning' | 'blur' | 'focus';
36export type AppStateStatus =
37 | 'active'
38 | 'background'
39 | 'inactive'
40 | 'unknown'
41 | 'extension';
42
43export interface AppStateStatic {
44 currentState: AppStateStatus;
45 isAvailable: boolean;
46
47 /**
48 * Add a handler to AppState changes by listening to the change event
49 * type and providing the handler
50 */
51 addEventListener(
52 type: AppStateEvent,
53 listener: (state: AppStateStatus) => void,
54 ): NativeEventSubscription;
55}
56
57export const AppState: AppStateStatic;
58export type AppState = AppStateStatic;