diff --git a/Libraries/TurboModule/TurboModuleRegistry.js b/Libraries/TurboModule/TurboModuleRegistry.js index 1f06b8271a6..9719d833497 100644 --- a/Libraries/TurboModule/TurboModuleRegistry.js +++ b/Libraries/TurboModule/TurboModuleRegistry.js @@ -16,7 +16,7 @@ import invariant from 'invariant'; const turboModuleProxy = global.__turboModuleProxy; -export function get(name: string): ?T { +function requireModule(name: string, schema?: ?$FlowFixMe): ?T { // Bridgeless mode requires TurboModules if (!global.RN$Bridgeless) { // Backward compatibility layer during migration. @@ -27,15 +27,35 @@ export function get(name: string): ?T { } if (turboModuleProxy != null) { - const module: ?T = turboModuleProxy(name); + const module: ?T = turboModuleProxy(name, schema); return module; } return null; } +export function get(name: string): ?T { + /** + * What is Schema? + * + * @react-native/babel-plugin-codegen will parse the NativeModule + * spec, and pass in the generated schema as the second argument + * to this function + */ + const schema = arguments.length === 2 ? arguments[1] : undefined; + return requireModule(name, schema); +} + export function getEnforcing(name: string): T { - const module = get(name); + /** + * What is Schema? + * + * @react-native/babel-plugin-codegen will parse the NativeModule + * spec, and pass in the generated schema as the second argument + * to this function + */ + const schema = arguments.length === 2 ? arguments[1] : undefined; + const module = requireModule(name, schema); invariant( module != null, `TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. ` + diff --git a/packages/react-native-codegen/src/parsers/flow/modules/schema.js b/packages/react-native-codegen/src/parsers/flow/modules/schema.js index 68b1d61c98b..c1e4c80cfd5 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/schema.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/schema.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict';