Files
react-native/Libraries/Utilities/codegenNativeCommands.js
T
Kevin Gozali 4ec75b1797 Import dispatchCommand utility from the right Renderer module
Summary:
With the new architecture, this module should be using the implementation from ReactFabric instead. However, given the ReactNative module had side effects (like registering `RCTEventEmitter`), let's import from ReactFabric only in the latest "new architecture" mode.

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D36535626

fbshipit-source-id: 6758b671df9a47607d8caf4a021ac73410f4c6e9
2022-05-19 20:54:48 -07:00

39 lines
1.1 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
let dispatchCommand;
if (global.RN$Bridgeless) {
// Note: this function has the same implementation in the legacy and new renderer.
// However, evaluating the old renderer comes with some side effects.
dispatchCommand =
require('../../Libraries/Renderer/shims/ReactFabric').dispatchCommand;
} else {
dispatchCommand =
require('../../Libraries/Renderer/shims/ReactNative').dispatchCommand;
}
type Options<T = string> = $ReadOnly<{|
supportedCommands: $ReadOnlyArray<T>,
|}>;
function codegenNativeCommands<T: interface {}>(options: Options<$Keys<T>>): T {
const commandObj: {[$Keys<T>]: (...$ReadOnlyArray<mixed>) => void} = {};
options.supportedCommands.forEach(command => {
commandObj[command] = (ref, ...args) => {
dispatchCommand(ref, command, args);
};
});
return ((commandObj: any): T);
}
export default codegenNativeCommands;