UNPKG

1.2 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
12export type BackPressEventName = 'hardwareBackPress';
13
14/**
15 * Detect hardware back button presses, and programmatically invoke the
16 * default back button functionality to exit the app if there are no
17 * listeners or if none of the listeners return true.
18 * The event subscriptions are called in reverse order
19 * (i.e. last registered subscription first), and if one subscription
20 * returns true then subscriptions registered earlier
21 * will not be called.
22 *
23 * @see https://reactnative.dev/docs/backhandler
24 */
25export interface BackHandlerStatic {
26 exitApp(): void;
27 addEventListener(
28 eventName: BackPressEventName,
29 handler: () => boolean | null | undefined,
30 ): NativeEventSubscription;
31 removeEventListener(
32 eventName: BackPressEventName,
33 handler: () => boolean | null | undefined,
34 ): void;
35}
36
37export const BackHandler: BackHandlerStatic;
38export type BackHandler = BackHandlerStatic;