mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Codegen: Add JNI C++ generator for TurboModule subclasses
Summary: This adds the C++ classes for Android, just like checked in here: https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni The whitespace/formatting is slightly different but the functionality should be preserved. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D23489368 fbshipit-source-id: 60c112a48b6de2d2eb19f7d1bcc894048334610f
This commit is contained in:
1 parent
fc2b1cac82
commit
02fed06340
8 files changed
+1137
-2
No files matched your search
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 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 {SchemaType} from '../../CodegenSchema';
|
||||
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
const moduleTemplate = `/**
|
||||
* JNI C++ class for module '::_MODULE_NAME_::'
|
||||
*/
|
||||
class JSI_EXPORT Native::_MODULE_NAME_::SpecJSI : public JavaTurboModule {
|
||||
public:
|
||||
Native::_MODULE_NAME_::SpecJSI(const JavaTurboModule::InitParams ¶ms);
|
||||
};
|
||||
`;
|
||||
|
||||
const template = `
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* ${'@'}generated by codegen project: GenerateModuleJniH.js
|
||||
*/
|
||||
|
||||
#import <ReactCommon/JavaTurboModule.h>
|
||||
#import <ReactCommon/TurboModule.h>
|
||||
#import <fb/fbjni.h>
|
||||
#import <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
::_MODULES_::
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
generate(
|
||||
libraryName: string,
|
||||
schema: SchemaType,
|
||||
moduleSpecName: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = Object.keys(schema.modules)
|
||||
.sort()
|
||||
.map(moduleName => {
|
||||
const modules = schema.modules[moduleName].nativeModules;
|
||||
if (modules == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return modules;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.reduce((acc, components) => Object.assign(acc, components), {});
|
||||
|
||||
const modules = Object.keys(nativeModules)
|
||||
.map(name => moduleTemplate.replace(/::_MODULE_NAME_::/g, name))
|
||||
.join('\n');
|
||||
|
||||
const fileName = `${moduleSpecName}.h`;
|
||||
const replacedTemplate = template.replace(/::_MODULES_::/g, modules);
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user