mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
4231551270
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
40 lines
1.0 KiB
JavaScript
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;
|