From 781c68cb43a5e4bb2a3a7e5053b673de6484a9d3 Mon Sep 17 00:00:00 2001 From: Jean Regisser Date: Wed, 22 May 2019 03:18:24 -0700 Subject: [PATCH] Add spec for TVNavigationEventEmitter (#24898) Summary: Part of #24875 ## Changelog [General] [Added] - Add TurboModule spec for TVNavigationEventEmitter Pull Request resolved: https://github.com/facebook/react-native/pull/24898 Reviewed By: fkgozali Differential Revision: D15391716 Pulled By: rickhanlonii fbshipit-source-id: 015120c755894a5c8f75a99c2670a6ac5545b454 --- .../AppleTV/NativeTVNavigationEventEmitter.js | 21 +++++++++++++++++++ .../Components/AppleTV/TVEventHandler.js | 8 +++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js diff --git a/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js b/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js new file mode 100644 index 0000000000..4870931e0d --- /dev/null +++ b/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js @@ -0,0 +1,21 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +'use strict'; + +import type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +addListener: (eventName: string) => void; + +removeListeners: (count: number) => void; +} + +export default TurboModuleRegistry.get('TVNavigationEventEmitter'); diff --git a/Libraries/Components/AppleTV/TVEventHandler.js b/Libraries/Components/AppleTV/TVEventHandler.js index debaa0f341..852038ba12 100644 --- a/Libraries/Components/AppleTV/TVEventHandler.js +++ b/Libraries/Components/AppleTV/TVEventHandler.js @@ -11,10 +11,10 @@ 'use strict'; const Platform = require('../../Utilities/Platform'); -const TVNavigationEventEmitter = require('../../BatchedBridge/NativeModules') - .TVNavigationEventEmitter; const NativeEventEmitter = require('../../EventEmitter/NativeEventEmitter'); +import NativeTVNavigationEventEmitter from './NativeTVNavigationEventEmitter'; + function TVEventHandler() { this.__nativeTVNavigationEventListener = null; this.__nativeTVNavigationEventEmitter = null; @@ -24,12 +24,12 @@ TVEventHandler.prototype.enable = function( component: ?any, callback: Function, ) { - if (Platform.OS === 'ios' && !TVNavigationEventEmitter) { + if (Platform.OS === 'ios' && !NativeTVNavigationEventEmitter) { return; } this.__nativeTVNavigationEventEmitter = new NativeEventEmitter( - TVNavigationEventEmitter, + NativeTVNavigationEventEmitter, ); this.__nativeTVNavigationEventListener = this.__nativeTVNavigationEventEmitter.addListener( 'onHWKeyEvent',