mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 11:57:46 +08:00
Types for BackHandler
Summary: Improve types for BackHandler Reviewed By: benjaffe Differential Revision: D9838175 fbshipit-source-id: 839a5a695b468974aadb7bc0da1a23ef844fdd7f
This commit is contained in:
committed by
Facebook Github Bot
parent
6b6a27c6b0
commit
7dd2b0b5ea
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user