Types for BackHandler

Summary: Improve types for BackHandler

Reviewed By: benjaffe

Differential Revision: D9838175

fbshipit-source-id: 839a5a695b468974aadb7bc0da1a23ef844fdd7f
This commit is contained in:
Naman Goel
2018-11-06 12:35:17 -08:00
committed by Facebook Github Bot
parent 6b6a27c6b0
commit 7dd2b0b5ea
2 changed files with 29 additions and 12 deletions

View File

@@ -4,8 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @format
*/
'use strict';
@@ -15,10 +15,7 @@ const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
const DEVICE_BACK_EVENT = 'hardwareBackPress';
type BackPressEventName = $Enum<{
backPress: string,
hardwareBackPress: string,
}>;
type BackPressEventName = 'backPress' | 'hardwareBackPress';
const _backPressSubscriptions = [];
@@ -62,7 +59,18 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
* });
* ```
*/
const BackHandler = {
type TBackHandler = {|
+exitApp: () => void,
+addEventListener: (
eventName: BackPressEventName,
handler: Function,
) => {remove: () => void},
+removeEventListener: (
eventName: BackPressEventName,
handler: Function,
) => void,
|};
const BackHandler: TBackHandler = {
exitApp: function(): void {
DeviceEventManager.invokeDefaultBackPressHandler();
},