Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Libraries/NativeModules/specs/NativeDeviceEventManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

'use strict';

import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';

import Platform from '../../Utilities/Platform';

export interface Spec extends TurboModule {
+invokeDefaultBackPressHandler: () => void;
}

export default (Platform.OS === 'android'
? TurboModuleRegistry.getEnforcing<Spec>('DeviceEventManager')
: undefined);
11 changes: 7 additions & 4 deletions Libraries/Utilities/BackHandler.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

'use strict';

const DeviceEventManager = require('../BatchedBridge/NativeModules')
.DeviceEventManager;
const RCTDeviceEventEmitter = require('../EventEmitter/RCTDeviceEventEmitter');
import NativeDeviceEventManager from '../../Libraries/NativeModules/specs/NativeDeviceEventManager';
import RCTDeviceEventEmitter from '../EventEmitter/RCTDeviceEventEmitter';

const DEVICE_BACK_EVENT = 'hardwareBackPress';

Expand Down Expand Up @@ -73,7 +72,11 @@ type TBackHandler = {|
|};
const BackHandler: TBackHandler = {
exitApp: function(): void {
DeviceEventManager.invokeDefaultBackPressHandler();
if (!NativeDeviceEventManager) {
return;
}

NativeDeviceEventManager.invokeDefaultBackPressHandler();
},

/**
Expand Down