nitrogen 0.2.23 → 0.29.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -109
- package/lib/Logger.d.ts +10 -0
- package/lib/Logger.js +56 -0
- package/lib/autolinking/Autolinking.d.ts +8 -0
- package/lib/autolinking/Autolinking.js +1 -0
- package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
- package/lib/autolinking/android/createCMakeExtension.js +106 -0
- package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
- package/lib/autolinking/android/createGradleExtension.js +36 -0
- package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
- package/lib/autolinking/android/createHybridObjectInitializer.js +159 -0
- package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
- package/lib/autolinking/createAndroidAutolinking.js +13 -0
- package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
- package/lib/autolinking/createIOSAutolinking.js +19 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.js +97 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.js +69 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.js +117 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.js +74 -0
- package/lib/config/NitroConfig.d.ts +52 -0
- package/lib/config/NitroConfig.js +112 -0
- package/lib/config/NitroUserConfig.d.ts +22 -0
- package/lib/config/NitroUserConfig.js +88 -0
- package/lib/config/getConfig.d.ts +2 -0
- package/lib/config/getConfig.js +84 -0
- package/lib/createGitAttributes.d.ts +1 -0
- package/lib/createGitAttributes.js +11 -0
- package/lib/createPlatformSpec.d.ts +4 -0
- package/lib/createPlatformSpec.js +127 -0
- package/lib/getFiles.d.ts +1 -0
- package/lib/getFiles.js +28 -0
- package/lib/getPlatformSpecs.d.ts +17 -0
- package/lib/getPlatformSpecs.js +153 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +113 -10
- package/lib/init.d.ts +1 -0
- package/lib/init.js +123 -0
- package/lib/nitrogen.d.ts +11 -0
- package/lib/nitrogen.js +165 -0
- package/lib/prettifyDirectory.d.ts +1 -0
- package/lib/prettifyDirectory.js +27 -0
- package/lib/syntax/BridgedType.d.ts +41 -0
- package/lib/syntax/BridgedType.js +1 -0
- package/lib/syntax/CodeNode.d.ts +23 -0
- package/lib/syntax/CodeNode.js +1 -0
- package/lib/syntax/HybridObjectSpec.d.ts +13 -0
- package/lib/syntax/HybridObjectSpec.js +1 -0
- package/lib/syntax/Method.d.ts +41 -0
- package/lib/syntax/Method.js +108 -0
- package/lib/syntax/Parameter.d.ts +15 -0
- package/lib/syntax/Parameter.js +65 -0
- package/lib/syntax/Property.d.ts +50 -0
- package/lib/syntax/Property.js +147 -0
- package/lib/syntax/SourceFile.d.ts +70 -0
- package/lib/syntax/SourceFile.js +7 -0
- package/lib/syntax/c++/CppEnum.d.ts +6 -0
- package/lib/syntax/c++/CppEnum.js +110 -0
- package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
- package/lib/syntax/c++/CppHybridObject.js +146 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.js +18 -0
- package/lib/syntax/c++/CppStruct.d.ts +3 -0
- package/lib/syntax/c++/CppStruct.js +108 -0
- package/lib/syntax/c++/CppUnion.d.ts +6 -0
- package/lib/syntax/c++/CppUnion.js +88 -0
- package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
- package/lib/syntax/c++/getForwardDeclaration.js +14 -0
- package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
- package/lib/syntax/c++/includeNitroHeader.js +34 -0
- package/lib/syntax/createType.d.ts +15 -0
- package/lib/syntax/createType.js +303 -0
- package/lib/syntax/getAllTypes.d.ts +3 -0
- package/lib/syntax/getAllTypes.js +11 -0
- package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
- package/lib/syntax/getCustomTypeConfig.js +53 -0
- package/lib/syntax/getHybridObjectName.d.ts +36 -0
- package/lib/syntax/getHybridObjectName.js +10 -0
- package/lib/syntax/getInterfaceProperties.d.ts +4 -0
- package/lib/syntax/getInterfaceProperties.js +9 -0
- package/lib/syntax/getReferencedTypes.d.ts +2 -0
- package/lib/syntax/getReferencedTypes.js +47 -0
- package/lib/syntax/helpers.d.ts +13 -0
- package/lib/syntax/helpers.js +53 -0
- package/lib/syntax/isCoreType.d.ts +9 -0
- package/lib/syntax/isCoreType.js +47 -0
- package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/FbjniHybridObject.js +261 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.js +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +17 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.js +893 -0
- package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinEnum.js +113 -0
- package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinFunction.js +256 -0
- package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObject.js +177 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.js +26 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +172 -0
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinVariant.js +191 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +819 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +17 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +613 -0
- package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
- package/lib/syntax/swift/SwiftEnum.js +52 -0
- package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
- package/lib/syntax/swift/SwiftFunction.js +83 -0
- package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObject.js +103 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.js +451 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.js +42 -0
- package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
- package/lib/syntax/swift/SwiftStruct.js +75 -0
- package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
- package/lib/syntax/swift/SwiftVariant.js +58 -0
- package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
- package/lib/syntax/types/ArrayBufferType.js +37 -0
- package/lib/syntax/types/ArrayType.d.ts +12 -0
- package/lib/syntax/types/ArrayType.js +52 -0
- package/lib/syntax/types/BigIntType.d.ts +10 -0
- package/lib/syntax/types/BigIntType.js +27 -0
- package/lib/syntax/types/BooleanType.d.ts +10 -0
- package/lib/syntax/types/BooleanType.js +27 -0
- package/lib/syntax/types/CustomType.d.ts +14 -0
- package/lib/syntax/types/CustomType.js +36 -0
- package/lib/syntax/types/DateType.d.ts +10 -0
- package/lib/syntax/types/DateType.js +35 -0
- package/lib/syntax/types/EnumType.d.ts +23 -0
- package/lib/syntax/types/EnumType.js +101 -0
- package/lib/syntax/types/ErrorType.d.ts +11 -0
- package/lib/syntax/types/ErrorType.js +37 -0
- package/lib/syntax/types/FunctionType.d.ts +29 -0
- package/lib/syntax/types/FunctionType.js +147 -0
- package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
- package/lib/syntax/types/HybridObjectBaseType.js +38 -0
- package/lib/syntax/types/HybridObjectType.d.ts +23 -0
- package/lib/syntax/types/HybridObjectType.js +131 -0
- package/lib/syntax/types/MapType.d.ts +10 -0
- package/lib/syntax/types/MapType.js +37 -0
- package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
- package/lib/syntax/types/NamedWrappingType.js +27 -0
- package/lib/syntax/types/NullType.d.ts +10 -0
- package/lib/syntax/types/NullType.js +23 -0
- package/lib/syntax/types/NumberType.d.ts +10 -0
- package/lib/syntax/types/NumberType.js +27 -0
- package/lib/syntax/types/OptionalType.d.ts +13 -0
- package/lib/syntax/types/OptionalType.js +59 -0
- package/lib/syntax/types/PromiseType.d.ts +16 -0
- package/lib/syntax/types/PromiseType.js +62 -0
- package/lib/syntax/types/RecordType.d.ts +13 -0
- package/lib/syntax/types/RecordType.js +47 -0
- package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
- package/lib/syntax/types/ResultWrappingType.js +44 -0
- package/lib/syntax/types/StringType.d.ts +10 -0
- package/lib/syntax/types/StringType.js +35 -0
- package/lib/syntax/types/StructType.d.ts +14 -0
- package/lib/syntax/types/StructType.js +61 -0
- package/lib/syntax/types/TupleType.d.ts +12 -0
- package/lib/syntax/types/TupleType.js +39 -0
- package/lib/syntax/types/Type.d.ts +55 -0
- package/lib/syntax/types/Type.js +1 -0
- package/lib/syntax/types/VariantType.d.ts +19 -0
- package/lib/syntax/types/VariantType.js +75 -0
- package/lib/syntax/types/VoidType.d.ts +10 -0
- package/lib/syntax/types/VoidType.js +27 -0
- package/lib/syntax/types/getTypeAs.d.ts +2 -0
- package/lib/syntax/types/getTypeAs.js +12 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +126 -0
- package/lib/views/CppHybridViewComponent.d.ts +14 -0
- package/lib/views/CppHybridViewComponent.js +254 -0
- package/lib/views/createHostComponentJs.d.ts +3 -0
- package/lib/views/createHostComponentJs.js +27 -0
- package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
- package/lib/views/kotlin/KotlinHybridViewManager.js +229 -0
- package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
- package/lib/views/swift/SwiftHybridViewManager.js +131 -0
- package/lib/writeFile.d.ts +5 -0
- package/lib/writeFile.js +19 -0
- package/package.json +58 -29
- package/src/Logger.ts +63 -0
- package/src/autolinking/Autolinking.ts +9 -0
- package/src/autolinking/android/createCMakeExtension.ts +123 -0
- package/src/autolinking/android/createGradleExtension.ts +43 -0
- package/src/autolinking/android/createHybridObjectInitializer.ts +174 -0
- package/src/autolinking/createAndroidAutolinking.ts +28 -0
- package/src/autolinking/createIOSAutolinking.ts +24 -0
- package/src/autolinking/ios/createHybridObjectInitializer.ts +112 -0
- package/src/autolinking/ios/createPodspecRubyExtension.ts +76 -0
- package/src/autolinking/ios/createSwiftCxxBridge.ts +137 -0
- package/src/autolinking/ios/createSwiftUmbrellaHeader.ts +90 -0
- package/src/config/NitroConfig.ts +139 -0
- package/src/config/NitroUserConfig.ts +105 -0
- package/src/config/getConfig.ts +91 -0
- package/src/createGitAttributes.ts +15 -0
- package/src/createPlatformSpec.ts +176 -0
- package/src/getFiles.ts +31 -0
- package/src/getPlatformSpecs.ts +202 -0
- package/src/index.ts +146 -0
- package/src/init.ts +186 -0
- package/src/nitrogen.ts +246 -0
- package/src/prettifyDirectory.ts +32 -0
- package/src/syntax/BridgedType.ts +59 -0
- package/src/syntax/CodeNode.ts +24 -0
- package/src/syntax/HybridObjectSpec.ts +14 -0
- package/src/syntax/Method.ts +154 -0
- package/src/syntax/Parameter.ts +81 -0
- package/src/syntax/Property.ts +203 -0
- package/src/syntax/SourceFile.ts +80 -0
- package/src/syntax/c++/CppEnum.ts +128 -0
- package/src/syntax/c++/CppHybridObject.ts +165 -0
- package/src/syntax/c++/CppHybridObjectRegistration.ts +39 -0
- package/src/syntax/c++/CppStruct.ts +129 -0
- package/src/syntax/c++/CppUnion.ts +105 -0
- package/src/syntax/c++/getForwardDeclaration.ts +19 -0
- package/src/syntax/c++/includeNitroHeader.ts +40 -0
- package/src/syntax/createType.ts +365 -0
- package/src/syntax/getAllTypes.ts +18 -0
- package/src/syntax/getCustomTypeConfig.ts +71 -0
- package/src/syntax/getHybridObjectName.ts +48 -0
- package/src/syntax/getInterfaceProperties.ts +21 -0
- package/src/syntax/getReferencedTypes.ts +57 -0
- package/src/syntax/helpers.ts +79 -0
- package/src/syntax/isCoreType.ts +60 -0
- package/src/syntax/kotlin/FbjniHybridObject.ts +313 -0
- package/src/syntax/kotlin/JNINativeRegistrations.ts +19 -0
- package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +19 -0
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +942 -0
- package/src/syntax/kotlin/KotlinEnum.ts +130 -0
- package/src/syntax/kotlin/KotlinFunction.ts +277 -0
- package/src/syntax/kotlin/KotlinHybridObject.ts +205 -0
- package/src/syntax/kotlin/KotlinHybridObjectRegistration.ts +51 -0
- package/src/syntax/kotlin/KotlinStruct.ts +198 -0
- package/src/syntax/kotlin/KotlinVariant.ts +212 -0
- package/src/syntax/swift/SwiftCxxBridgedType.ts +874 -0
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +674 -0
- package/src/syntax/swift/SwiftEnum.ts +65 -0
- package/src/syntax/swift/SwiftFunction.ts +91 -0
- package/src/syntax/swift/SwiftHybridObject.ts +121 -0
- package/src/syntax/swift/SwiftHybridObjectBridge.ts +522 -0
- package/src/syntax/swift/SwiftHybridObjectRegistration.ts +75 -0
- package/src/syntax/swift/SwiftStruct.ts +85 -0
- package/src/syntax/swift/SwiftVariant.ts +67 -0
- package/src/syntax/types/ArrayBufferType.ts +49 -0
- package/src/syntax/types/ArrayType.ts +62 -0
- package/src/syntax/types/BigIntType.ts +35 -0
- package/src/syntax/types/BooleanType.ts +35 -0
- package/src/syntax/types/CustomType.ts +47 -0
- package/src/syntax/types/DateType.ts +43 -0
- package/src/syntax/types/EnumType.ts +130 -0
- package/src/syntax/types/ErrorType.ts +44 -0
- package/src/syntax/types/FunctionType.ts +167 -0
- package/src/syntax/types/HybridObjectBaseType.ts +54 -0
- package/src/syntax/types/HybridObjectType.ts +198 -0
- package/src/syntax/types/MapType.ts +49 -0
- package/src/syntax/types/NamedWrappingType.ts +33 -0
- package/src/syntax/types/NullType.ts +30 -0
- package/src/syntax/types/NumberType.ts +34 -0
- package/src/syntax/types/OptionalType.ts +66 -0
- package/src/syntax/types/PromiseType.ts +72 -0
- package/src/syntax/types/RecordType.ts +56 -0
- package/src/syntax/types/ResultWrappingType.ts +53 -0
- package/src/syntax/types/StringType.ts +44 -0
- package/src/syntax/types/StructType.ts +83 -0
- package/src/syntax/types/TupleType.ts +53 -0
- package/src/syntax/types/Type.ts +82 -0
- package/src/syntax/types/VariantType.ts +92 -0
- package/src/syntax/types/VoidType.ts +34 -0
- package/src/syntax/types/getTypeAs.ts +15 -0
- package/src/utils.ts +162 -0
- package/src/views/CppHybridViewComponent.ts +301 -0
- package/src/views/createHostComponentJs.ts +34 -0
- package/src/views/kotlin/KotlinHybridViewManager.ts +258 -0
- package/src/views/swift/SwiftHybridViewManager.ts +153 -0
- package/src/writeFile.ts +27 -0
- package/.jshintignore +0 -6
- package/.jshintrc +0 -3
- package/.npmignore +0 -3
- package/.travis.yml +0 -13
- package/LICENSE +0 -13
- package/browser/nitrogen-min.js +0 -3
- package/browser/nitrogen.js +0 -6369
- package/lib/apiKey.js +0 -67
- package/lib/blob.js +0 -57
- package/lib/commandManager.js +0 -350
- package/lib/device.js +0 -19
- package/lib/memoryStore.js +0 -24
- package/lib/message.js +0 -298
- package/lib/permission.js +0 -121
- package/lib/principal.js +0 -330
- package/lib/service.js +0 -349
- package/lib/session.js +0 -494
- package/lib/user.js +0 -20
- package/publish +0 -2
- package/scripts/build-documentation +0 -4
- package/scripts/build-module +0 -27
- package/scripts/module.js +0 -12
- package/scripts/postamble.js +0 -1
- package/scripts/preamble.js +0 -2
- package/scripts/run-test-server +0 -9
- package/test/config.js +0 -12
- package/test/fixtures/images/image.jpg +0 -0
- package/test/fixtures/images/motion0.jpg +0 -0
- package/test/fixtures/images/motion1.jpg +0 -0
- package/test/fixtures/images/motion2.jpg +0 -0
- package/test/fixtures/index.js +0 -76
- package/test/main.js +0 -5
- package/test/memoryStore.js +0 -22
- package/test/mocha.opts +0 -3
- package/test/units/apiKey.js +0 -46
- package/test/units/blob.js +0 -35
- package/test/units/commandManager.js +0 -67
- package/test/units/device.js +0 -26
- package/test/units/heartbeat.js +0 -28
- package/test/units/message.js +0 -79
- package/test/units/permissions.js +0 -43
- package/test/units/principal.js +0 -116
- package/test/units/service.js +0 -92
- package/test/units/session.js +0 -97
- package/test/units/user.js +0 -48
- package/yuidoc.json +0 -8
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createViewComponentShadowNodeFiles, getViewComponentNames, } from '../CppHybridViewComponent.js';
|
|
2
|
+
import { createFileMetadataString, escapeCppName, } from '../../syntax/helpers.js';
|
|
3
|
+
import { getUmbrellaHeaderName } from '../../autolinking/ios/createSwiftUmbrellaHeader.js';
|
|
4
|
+
import { getHybridObjectName } from '../../syntax/getHybridObjectName.js';
|
|
5
|
+
import { getHybridObjectConstructorCall } from '../../syntax/swift/SwiftHybridObjectRegistration.js';
|
|
6
|
+
import { indent } from '../../utils.js';
|
|
7
|
+
import { SwiftCxxBridgedType } from '../../syntax/swift/SwiftCxxBridgedType.js';
|
|
8
|
+
export function createSwiftHybridViewManager(spec) {
|
|
9
|
+
const cppFiles = createViewComponentShadowNodeFiles(spec);
|
|
10
|
+
const namespace = spec.config.getCxxNamespace('c++');
|
|
11
|
+
const swiftNamespace = spec.config.getIosModuleName();
|
|
12
|
+
const { HybridTSpec, HybridTSpecSwift, HybridTSpecCxx } = getHybridObjectName(spec.name);
|
|
13
|
+
const { component, descriptorClassName, propsClassName } = getViewComponentNames(spec);
|
|
14
|
+
const autolinking = spec.config.getAutolinkedHybridObjects();
|
|
15
|
+
const viewImplementation = autolinking[spec.name]?.swift;
|
|
16
|
+
if (viewImplementation == null) {
|
|
17
|
+
throw new Error(`Cannot create Swift HybridView ViewManager for ${spec.name} - it is not autolinked in nitro.json!`);
|
|
18
|
+
}
|
|
19
|
+
const propAssignments = spec.properties.map((p) => {
|
|
20
|
+
const name = escapeCppName(p.name);
|
|
21
|
+
const setter = p.getSetterName('swift');
|
|
22
|
+
const bridge = new SwiftCxxBridgedType(p.type, false);
|
|
23
|
+
const parse = bridge.parseFromCppToSwift(`newViewProps.${name}.value`, 'c++');
|
|
24
|
+
return `
|
|
25
|
+
// ${p.jsSignature}
|
|
26
|
+
if (newViewProps.${name}.isDirty) {
|
|
27
|
+
swiftPart.${setter}(${indent(parse, ' ')});
|
|
28
|
+
newViewProps.${name}.isDirty = false;
|
|
29
|
+
}
|
|
30
|
+
`.trim();
|
|
31
|
+
});
|
|
32
|
+
const mmFile = `
|
|
33
|
+
${createFileMetadataString(`${component}.mm`)}
|
|
34
|
+
|
|
35
|
+
#import "${component}.hpp"
|
|
36
|
+
#import <memory>
|
|
37
|
+
#import <react/renderer/componentregistry/ComponentDescriptorProvider.h>
|
|
38
|
+
#import <React/RCTViewComponentView.h>
|
|
39
|
+
#import <React/RCTComponentViewFactory.h>
|
|
40
|
+
#import <React/UIView+ComponentViewProtocol.h>
|
|
41
|
+
#import <NitroModules/NitroDefines.hpp>
|
|
42
|
+
#import <UIKit/UIKit.h>
|
|
43
|
+
|
|
44
|
+
#import "${HybridTSpecSwift}.hpp"
|
|
45
|
+
#import "${getUmbrellaHeaderName()}"
|
|
46
|
+
|
|
47
|
+
using namespace facebook;
|
|
48
|
+
using namespace ${namespace};
|
|
49
|
+
using namespace ${namespace}::views;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Represents the React Native View holder for the Nitro "${spec.name}" HybridView.
|
|
53
|
+
*/
|
|
54
|
+
@interface ${component}: RCTViewComponentView
|
|
55
|
+
@end
|
|
56
|
+
|
|
57
|
+
@implementation ${component} {
|
|
58
|
+
std::shared_ptr<${HybridTSpecSwift}> _hybridView;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
+ (void) load {
|
|
62
|
+
[super load];
|
|
63
|
+
[RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[${component} class]];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
+ (react::ComponentDescriptorProvider) componentDescriptorProvider {
|
|
67
|
+
return react::concreteComponentDescriptorProvider<${descriptorClassName}>();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (instancetype) init {
|
|
71
|
+
if (self = [super init]) {
|
|
72
|
+
std::shared_ptr<${HybridTSpec}> hybridView = ${getHybridObjectConstructorCall(spec.name)}
|
|
73
|
+
_hybridView = std::dynamic_pointer_cast<${HybridTSpecSwift}>(hybridView);
|
|
74
|
+
[self updateView];
|
|
75
|
+
}
|
|
76
|
+
return self;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
- (void) updateView {
|
|
80
|
+
// 1. Get Swift part
|
|
81
|
+
${swiftNamespace}::${HybridTSpecCxx}& swiftPart = _hybridView->getSwiftPart();
|
|
82
|
+
|
|
83
|
+
// 2. Get UIView*
|
|
84
|
+
void* viewUnsafe = swiftPart.getView();
|
|
85
|
+
UIView* view = (__bridge_transfer UIView*) viewUnsafe;
|
|
86
|
+
|
|
87
|
+
// 3. Update RCTViewComponentView's [contentView]
|
|
88
|
+
[self setContentView:view];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
- (void) updateProps:(const std::shared_ptr<const react::Props>&)props
|
|
92
|
+
oldProps:(const std::shared_ptr<const react::Props>&)oldProps {
|
|
93
|
+
// 1. Downcast props
|
|
94
|
+
const auto& newViewPropsConst = *std::static_pointer_cast<${propsClassName} const>(props);
|
|
95
|
+
auto& newViewProps = const_cast<${propsClassName}&>(newViewPropsConst);
|
|
96
|
+
${swiftNamespace}::${HybridTSpecCxx}& swiftPart = _hybridView->getSwiftPart();
|
|
97
|
+
|
|
98
|
+
// 2. Update each prop individually
|
|
99
|
+
swiftPart.beforeUpdate();
|
|
100
|
+
|
|
101
|
+
${indent(propAssignments.join('\n'), ' ')}
|
|
102
|
+
|
|
103
|
+
swiftPart.afterUpdate();
|
|
104
|
+
|
|
105
|
+
// 3. Update hybridRef if it changed
|
|
106
|
+
if (newViewProps.hybridRef.isDirty) {
|
|
107
|
+
// hybridRef changed - call it with new this
|
|
108
|
+
const auto& maybeFunc = newViewProps.hybridRef.value;
|
|
109
|
+
if (maybeFunc.has_value()) {
|
|
110
|
+
maybeFunc.value()(_hybridView);
|
|
111
|
+
}
|
|
112
|
+
newViewProps.hybridRef.isDirty = false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 4. Continue in base class
|
|
116
|
+
[super updateProps:props oldProps:oldProps];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@end
|
|
120
|
+
`;
|
|
121
|
+
return [
|
|
122
|
+
...cppFiles,
|
|
123
|
+
{
|
|
124
|
+
content: mmFile,
|
|
125
|
+
language: 'c++',
|
|
126
|
+
name: `${component}.mm`,
|
|
127
|
+
platform: 'ios',
|
|
128
|
+
subdirectory: ['views'],
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
}
|
package/lib/writeFile.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { capitalizeName } from './utils.js';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { Logger } from './Logger.js';
|
|
6
|
+
/**
|
|
7
|
+
* Writes the given file to disk and returns it's actual path.
|
|
8
|
+
*/
|
|
9
|
+
export async function writeFile(basePath, file) {
|
|
10
|
+
const filepath = path.join(basePath, ...file.subdirectory, file.name);
|
|
11
|
+
const language = capitalizeName(file.language);
|
|
12
|
+
Logger.debug(` ${chalk.dim(language)}: Creating ${file.name}...`);
|
|
13
|
+
const dir = path.dirname(filepath);
|
|
14
|
+
// Create directory if it doesn't exist yet
|
|
15
|
+
await fs.mkdir(dir, { recursive: true });
|
|
16
|
+
// Write file
|
|
17
|
+
await fs.writeFile(filepath, file.content.trim() + '\n', 'utf8');
|
|
18
|
+
return filepath;
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
"version": "0.29.4",
|
|
4
|
+
"description": "The code-generator for react-native-nitro-modules.",
|
|
5
|
+
"main": "lib/index",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"source": "src/index",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib",
|
|
11
|
+
"src",
|
|
12
|
+
"README.md"
|
|
10
13
|
],
|
|
11
|
-
"
|
|
14
|
+
"bin": "./lib/index.js",
|
|
12
15
|
"repository": {
|
|
13
16
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "git+https://github.com/mrousavy/nitro.git"
|
|
15
18
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"socket.io-client": "~0.9.16"
|
|
19
|
+
"author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/mrousavy/nitro/issues"
|
|
21
23
|
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"uglify-js": "~2.4.13",
|
|
26
|
-
"jsdox": "~0.2.6"
|
|
24
|
+
"homepage": "https://github.com/mrousavy/nitro#readme",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"postinstall": "bun build || exit 0;",
|
|
30
|
+
"build": "bun tsc",
|
|
31
|
+
"start": "tsc && node lib/index.js",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
34
|
+
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
|
|
35
|
+
"release": "release-it"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"chalk": "^5.3.0",
|
|
39
|
+
"react-native-nitro-modules": "^0.29.4",
|
|
40
|
+
"ts-morph": "^25.0.0",
|
|
41
|
+
"yargs": "^17.7.2",
|
|
42
|
+
"zod": "^4.0.5"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.8.4"
|
|
31
46
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
"release-it": {
|
|
48
|
+
"npm": {
|
|
49
|
+
"publish": true
|
|
50
|
+
},
|
|
51
|
+
"git": false,
|
|
52
|
+
"github": {
|
|
53
|
+
"release": false
|
|
54
|
+
},
|
|
55
|
+
"hooks": {
|
|
56
|
+
"before:init": "bun typecheck && bun lint",
|
|
57
|
+
"after:bump": "bun run build"
|
|
58
|
+
},
|
|
59
|
+
"plugins": {
|
|
60
|
+
"@release-it/bumper": {
|
|
61
|
+
"out": {
|
|
62
|
+
"file": "package.json",
|
|
63
|
+
"path": "dependencies.react-native-nitro-modules",
|
|
64
|
+
"versionPrefix": "^"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
40
69
|
}
|
package/src/Logger.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warning' | 'error'
|
|
2
|
+
const levelMap = {
|
|
3
|
+
debug: 0,
|
|
4
|
+
info: 1,
|
|
5
|
+
warning: 2,
|
|
6
|
+
error: 3,
|
|
7
|
+
} as const
|
|
8
|
+
let currentLogLevel: LogLevel = 'info'
|
|
9
|
+
|
|
10
|
+
export function isValidLogLevel(level: unknown): level is LogLevel {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
return typeof levelMap[level] === 'number'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setLogLevel(level: LogLevel) {
|
|
16
|
+
currentLogLevel = level
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isAtLeast(level: LogLevel): boolean {
|
|
20
|
+
return levelMap[level] >= levelMap[currentLogLevel]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let indentation = 0
|
|
24
|
+
|
|
25
|
+
function getIndentation(): string {
|
|
26
|
+
let string = ''
|
|
27
|
+
for (let i = 0; i < indentation; i++) {
|
|
28
|
+
string += ' '
|
|
29
|
+
}
|
|
30
|
+
return string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const Logger = {
|
|
34
|
+
withIndented(callback: () => void) {
|
|
35
|
+
try {
|
|
36
|
+
indentation++
|
|
37
|
+
callback()
|
|
38
|
+
} finally {
|
|
39
|
+
indentation--
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
debug(message: string, ...extra: unknown[]) {
|
|
44
|
+
if (isAtLeast('debug')) {
|
|
45
|
+
console.debug(getIndentation() + message, ...extra)
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
info(message: string, ...extra: unknown[]) {
|
|
49
|
+
if (isAtLeast('info')) {
|
|
50
|
+
console.info(getIndentation() + message, ...extra)
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
warn(message: string, ...extra: unknown[]) {
|
|
54
|
+
if (isAtLeast('warning')) {
|
|
55
|
+
console.warn(getIndentation() + message, ...extra)
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
error(message: string, ...extra: unknown[]) {
|
|
59
|
+
if (isAtLeast('error')) {
|
|
60
|
+
console.error(getIndentation() + message, ...extra)
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js'
|
|
2
|
+
import { indent, toLowerCamelCase, toUnixPath } from '../../utils.js'
|
|
3
|
+
import {
|
|
4
|
+
createFileMetadataString,
|
|
5
|
+
getRelativeDirectory,
|
|
6
|
+
getRelativeDirectoryGenerated,
|
|
7
|
+
isCppFile,
|
|
8
|
+
isNotDuplicate,
|
|
9
|
+
} from '../../syntax/helpers.js'
|
|
10
|
+
import type { SourceFile } from '../../syntax/SourceFile.js'
|
|
11
|
+
|
|
12
|
+
export interface CMakeFile extends Omit<SourceFile, 'language'> {
|
|
13
|
+
language: 'cmake'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getBuildingWithGeneratedCmakeDefinition(): string {
|
|
17
|
+
const moduleName = NitroConfig.current.getAndroidCxxLibName()
|
|
18
|
+
const upper = toLowerCamelCase(moduleName).toUpperCase()
|
|
19
|
+
return `BUILDING_${upper}_WITH_GENERATED_CMAKE_PROJECT`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createCMakeExtension(files: SourceFile[]): CMakeFile {
|
|
23
|
+
const name = NitroConfig.current.getAndroidCxxLibName()
|
|
24
|
+
const sharedFiles = files
|
|
25
|
+
.filter((f) => f.platform === 'shared' && isCppFile(f))
|
|
26
|
+
.map((f) => getRelativeDirectory(f))
|
|
27
|
+
.map((p) => toUnixPath(p))
|
|
28
|
+
.filter(isNotDuplicate)
|
|
29
|
+
const androidFiles = files
|
|
30
|
+
.filter((f) => f.platform === 'android' && isCppFile(f))
|
|
31
|
+
.map((f) => getRelativeDirectory(f))
|
|
32
|
+
.map((p) => toUnixPath(p))
|
|
33
|
+
.filter(isNotDuplicate)
|
|
34
|
+
const autolinkingFilePath = getRelativeDirectoryGenerated(
|
|
35
|
+
'android',
|
|
36
|
+
`${name}OnLoad.cpp`
|
|
37
|
+
)
|
|
38
|
+
const autolinkingFile = toUnixPath(autolinkingFilePath)
|
|
39
|
+
const buildingWithDefinition = getBuildingWithGeneratedCmakeDefinition()
|
|
40
|
+
|
|
41
|
+
const code = `
|
|
42
|
+
${createFileMetadataString(`${name}+autolinking.cmake`, '#')}
|
|
43
|
+
|
|
44
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
45
|
+
# to the current CMake project.
|
|
46
|
+
#
|
|
47
|
+
# To use it, add this to your CMakeLists.txt:
|
|
48
|
+
# \`\`\`cmake
|
|
49
|
+
# include(\${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/${name}+autolinking.cmake)
|
|
50
|
+
# \`\`\`
|
|
51
|
+
|
|
52
|
+
# Add all headers that were generated by Nitrogen
|
|
53
|
+
include_directories(
|
|
54
|
+
"../nitrogen/generated/shared/c++"
|
|
55
|
+
"../nitrogen/generated/android/c++"
|
|
56
|
+
"../nitrogen/generated/android/"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
60
|
+
target_sources(
|
|
61
|
+
# CMake project name (Android C++ library name)
|
|
62
|
+
${name} PRIVATE
|
|
63
|
+
# Autolinking Setup
|
|
64
|
+
${autolinkingFile}
|
|
65
|
+
# Shared Nitrogen C++ sources
|
|
66
|
+
${indent(sharedFiles.join('\n'), ' ')}
|
|
67
|
+
# Android-specific Nitrogen C++ sources
|
|
68
|
+
${indent(androidFiles.join('\n'), ' ')}
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Define a flag to check if we are building properly
|
|
72
|
+
add_definitions(-D${buildingWithDefinition})
|
|
73
|
+
|
|
74
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
75
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
76
|
+
target_compile_definitions(
|
|
77
|
+
${name} PRIVATE
|
|
78
|
+
-DFOLLY_NO_CONFIG=1
|
|
79
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
80
|
+
-DFOLLY_USE_LIBCPP=1
|
|
81
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
82
|
+
-DFOLLY_MOBILE=1
|
|
83
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
84
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
85
|
+
# Once we target android-23 above, we can comment
|
|
86
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
87
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Add all libraries required by the generated specs
|
|
91
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
92
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
93
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
94
|
+
|
|
95
|
+
# Link all libraries together
|
|
96
|
+
target_link_libraries(
|
|
97
|
+
${name}
|
|
98
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
99
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
100
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
104
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
105
|
+
target_link_libraries(
|
|
106
|
+
${name}
|
|
107
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
108
|
+
)
|
|
109
|
+
else()
|
|
110
|
+
target_link_libraries(
|
|
111
|
+
${name}
|
|
112
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
113
|
+
)
|
|
114
|
+
endif()
|
|
115
|
+
`.trim()
|
|
116
|
+
return {
|
|
117
|
+
content: code,
|
|
118
|
+
language: 'cmake',
|
|
119
|
+
name: `${name}+autolinking.cmake`,
|
|
120
|
+
platform: 'android',
|
|
121
|
+
subdirectory: [],
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js'
|
|
2
|
+
import { createFileMetadataString } from '../../syntax/helpers.js'
|
|
3
|
+
import type { SourceFile } from '../../syntax/SourceFile.js'
|
|
4
|
+
|
|
5
|
+
export interface GradleFile extends Omit<SourceFile, 'language'> {
|
|
6
|
+
language: 'gradle'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createGradleExtension(): GradleFile {
|
|
10
|
+
const name = NitroConfig.current.getAndroidCxxLibName()
|
|
11
|
+
|
|
12
|
+
const code = `
|
|
13
|
+
${createFileMetadataString(`${name}+autolinking.gradle`)}
|
|
14
|
+
|
|
15
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
16
|
+
/// to the current Gradle project.
|
|
17
|
+
///
|
|
18
|
+
/// To use it, add this to your build.gradle:
|
|
19
|
+
/// \`\`\`gradle
|
|
20
|
+
/// apply from: '../nitrogen/generated/android/${name}+autolinking.gradle'
|
|
21
|
+
/// \`\`\`
|
|
22
|
+
|
|
23
|
+
logger.warn("[NitroModules] 🔥 ${name} is boosted by nitro!")
|
|
24
|
+
|
|
25
|
+
android {
|
|
26
|
+
sourceSets {
|
|
27
|
+
main {
|
|
28
|
+
java.srcDirs += [
|
|
29
|
+
// Nitrogen files
|
|
30
|
+
"\${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`.trim()
|
|
36
|
+
return {
|
|
37
|
+
content: code,
|
|
38
|
+
language: 'gradle',
|
|
39
|
+
name: `${name}+autolinking.gradle`,
|
|
40
|
+
platform: 'android',
|
|
41
|
+
subdirectory: [],
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js'
|
|
2
|
+
import { createCppHybridObjectRegistration } from '../../syntax/c++/CppHybridObjectRegistration.js'
|
|
3
|
+
import { includeHeader } from '../../syntax/c++/includeNitroHeader.js'
|
|
4
|
+
import {
|
|
5
|
+
createFileMetadataString,
|
|
6
|
+
isNotDuplicate,
|
|
7
|
+
} from '../../syntax/helpers.js'
|
|
8
|
+
import { getJNINativeRegistrations } from '../../syntax/kotlin/JNINativeRegistrations.js'
|
|
9
|
+
import { createJNIHybridObjectRegistration } from '../../syntax/kotlin/KotlinHybridObjectRegistration.js'
|
|
10
|
+
import type { SourceFile, SourceImport } from '../../syntax/SourceFile.js'
|
|
11
|
+
import { indent } from '../../utils.js'
|
|
12
|
+
import { getBuildingWithGeneratedCmakeDefinition } from './createCMakeExtension.js'
|
|
13
|
+
|
|
14
|
+
export function createHybridObjectIntializer(): SourceFile[] {
|
|
15
|
+
const cxxNamespace = NitroConfig.current.getCxxNamespace('c++')
|
|
16
|
+
const cppLibName = NitroConfig.current.getAndroidCxxLibName()
|
|
17
|
+
const javaNamespace = NitroConfig.current.getAndroidPackage('java/kotlin')
|
|
18
|
+
const autolinkingClassName = `${NitroConfig.current.getAndroidCxxLibName()}OnLoad`
|
|
19
|
+
|
|
20
|
+
const jniRegistrations = getJNINativeRegistrations()
|
|
21
|
+
.map((r) => `${r.namespace}::${r.className}::registerNatives();`)
|
|
22
|
+
.filter(isNotDuplicate)
|
|
23
|
+
|
|
24
|
+
const autolinkedHybridObjects =
|
|
25
|
+
NitroConfig.current.getAutolinkedHybridObjects()
|
|
26
|
+
|
|
27
|
+
const cppHybridObjectImports: SourceImport[] = []
|
|
28
|
+
const cppRegistrations: string[] = []
|
|
29
|
+
for (const hybridObjectName of Object.keys(autolinkedHybridObjects)) {
|
|
30
|
+
const config = autolinkedHybridObjects[hybridObjectName]
|
|
31
|
+
|
|
32
|
+
if (config?.cpp != null) {
|
|
33
|
+
// Autolink a C++ HybridObject!
|
|
34
|
+
const { cppCode, requiredImports } = createCppHybridObjectRegistration({
|
|
35
|
+
hybridObjectName: hybridObjectName,
|
|
36
|
+
cppClassName: config.cpp,
|
|
37
|
+
})
|
|
38
|
+
cppHybridObjectImports.push(...requiredImports)
|
|
39
|
+
cppRegistrations.push(cppCode)
|
|
40
|
+
}
|
|
41
|
+
if (config?.kotlin != null) {
|
|
42
|
+
// Autolink a Kotlin HybridObject through JNI/C++!
|
|
43
|
+
const { cppCode, requiredImports } = createJNIHybridObjectRegistration({
|
|
44
|
+
hybridObjectName: hybridObjectName,
|
|
45
|
+
jniClassName: config.kotlin,
|
|
46
|
+
})
|
|
47
|
+
cppHybridObjectImports.push(...requiredImports)
|
|
48
|
+
cppRegistrations.push(cppCode)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const buildingWithDefinition = getBuildingWithGeneratedCmakeDefinition()
|
|
53
|
+
|
|
54
|
+
const includes = [
|
|
55
|
+
...getJNINativeRegistrations().map((r) => includeHeader(r.import)),
|
|
56
|
+
...cppHybridObjectImports.map((i) => includeHeader(i)),
|
|
57
|
+
]
|
|
58
|
+
.filter(isNotDuplicate)
|
|
59
|
+
.join('\n')
|
|
60
|
+
|
|
61
|
+
const hppCode = `
|
|
62
|
+
${createFileMetadataString(`${autolinkingClassName}.hpp`)}
|
|
63
|
+
|
|
64
|
+
#include <jni.h>
|
|
65
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
66
|
+
|
|
67
|
+
namespace ${cxxNamespace} {
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Initializes the native (C++) part of ${cppLibName}, and autolinks all Hybrid Objects.
|
|
71
|
+
* Call this in your \`JNI_OnLoad\` function (probably inside \`cpp-adapter.cpp\`).
|
|
72
|
+
* Example:
|
|
73
|
+
* \`\`\`cpp (cpp-adapter.cpp)
|
|
74
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
75
|
+
* return ${cxxNamespace}::initialize(vm);
|
|
76
|
+
* }
|
|
77
|
+
* \`\`\`
|
|
78
|
+
*/
|
|
79
|
+
int initialize(JavaVM* vm);
|
|
80
|
+
|
|
81
|
+
} // namespace ${cxxNamespace}
|
|
82
|
+
|
|
83
|
+
`
|
|
84
|
+
const cppCode = `
|
|
85
|
+
${createFileMetadataString(`${autolinkingClassName}.cpp`)}
|
|
86
|
+
|
|
87
|
+
#ifndef ${buildingWithDefinition}
|
|
88
|
+
#error ${autolinkingClassName}.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
89
|
+
#endif
|
|
90
|
+
|
|
91
|
+
#include "${autolinkingClassName}.hpp"
|
|
92
|
+
|
|
93
|
+
#include <jni.h>
|
|
94
|
+
#include <fbjni/fbjni.h>
|
|
95
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
96
|
+
|
|
97
|
+
${includes}
|
|
98
|
+
|
|
99
|
+
namespace ${cxxNamespace} {
|
|
100
|
+
|
|
101
|
+
int initialize(JavaVM* vm) {
|
|
102
|
+
using namespace margelo::nitro;
|
|
103
|
+
using namespace ${cxxNamespace};
|
|
104
|
+
using namespace facebook;
|
|
105
|
+
|
|
106
|
+
return facebook::jni::initialize(vm, [] {
|
|
107
|
+
// Register native JNI methods
|
|
108
|
+
${indent(jniRegistrations.join('\n'), ' ')}
|
|
109
|
+
|
|
110
|
+
// Register Nitro Hybrid Objects
|
|
111
|
+
${indent(cppRegistrations.join('\n'), ' ')}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
} // namespace ${cxxNamespace}
|
|
116
|
+
`.trim()
|
|
117
|
+
|
|
118
|
+
const kotlinCode = `
|
|
119
|
+
${createFileMetadataString(`${autolinkingClassName}.kt`)}
|
|
120
|
+
|
|
121
|
+
package ${javaNamespace}
|
|
122
|
+
|
|
123
|
+
import android.util.Log
|
|
124
|
+
|
|
125
|
+
internal class ${autolinkingClassName} {
|
|
126
|
+
companion object {
|
|
127
|
+
private const val TAG = "${autolinkingClassName}"
|
|
128
|
+
private var didLoad = false
|
|
129
|
+
/**
|
|
130
|
+
* Initializes the native part of "${cppLibName}".
|
|
131
|
+
* This method is idempotent and can be called more than once.
|
|
132
|
+
*/
|
|
133
|
+
@JvmStatic
|
|
134
|
+
fun initializeNative() {
|
|
135
|
+
if (didLoad) return
|
|
136
|
+
try {
|
|
137
|
+
Log.i(TAG, "Loading ${cppLibName} C++ library...")
|
|
138
|
+
System.loadLibrary("${cppLibName}")
|
|
139
|
+
Log.i(TAG, "Successfully loaded ${cppLibName} C++ library!")
|
|
140
|
+
didLoad = true
|
|
141
|
+
} catch (e: Error) {
|
|
142
|
+
Log.e(TAG, "Failed to load ${cppLibName} C++ library! Is it properly installed and linked? " +
|
|
143
|
+
"Is the name correct? (see \`CMakeLists.txt\`, at \`add_library(...)\`)", e)
|
|
144
|
+
throw e
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
`.trim()
|
|
150
|
+
|
|
151
|
+
return [
|
|
152
|
+
{
|
|
153
|
+
content: hppCode,
|
|
154
|
+
language: 'c++',
|
|
155
|
+
name: `${autolinkingClassName}.hpp`,
|
|
156
|
+
platform: 'android',
|
|
157
|
+
subdirectory: [],
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
content: cppCode,
|
|
161
|
+
language: 'c++',
|
|
162
|
+
name: `${autolinkingClassName}.cpp`,
|
|
163
|
+
platform: 'android',
|
|
164
|
+
subdirectory: [],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
content: kotlinCode,
|
|
168
|
+
language: 'kotlin',
|
|
169
|
+
name: `${autolinkingClassName}.kt`,
|
|
170
|
+
platform: 'android',
|
|
171
|
+
subdirectory: ['kotlin', ...javaNamespace.split('.')],
|
|
172
|
+
},
|
|
173
|
+
]
|
|
174
|
+
}
|