Files
react-native/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js
T
Peter Argany 4231551270 Lazily create NativeTVNavigationEventEmitter
Summary:
Every single RN iOS application is initializing this native module on first bundle load, regardless if it is used or not. This wrapperModule makes it lazy.

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D23175668

fbshipit-source-id: 0424a62d6c0b4fe7d5ce95f6c96e641a03b5fb2c
2020-08-17 17:01:40 -07:00

40 lines
1.0 KiB
JavaScript

/**
* 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 strict
* @format
*/
'use strict';
import type {TurboModule} from '../../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';
export interface Spec extends TurboModule {
+addListener: (eventName: string) => void;
+removeListeners: (count: number) => void;
}
let NativeModule: ?Spec = null;
const wrapperModule = {
addListener(eventName: string) {
if (NativeModule == null) {
NativeModule = TurboModuleRegistry.get<Spec>('TVNavigationEventEmitter');
}
NativeModule && NativeModule.addListener(eventName);
},
removeListeners(count: number) {
if (NativeModule == null) {
NativeModule = TurboModuleRegistry.get<Spec>('TVNavigationEventEmitter');
}
NativeModule && NativeModule.removeListeners(count);
},
};
export default wrapperModule;