Skip to content

Commit

Permalink
Initialize CxxTurboModule
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jun 21, 2024
1 parent d07ac57 commit 1976454
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
hermes-engine: 01d3e052018c2a13937aca1860fbedbccd4a41b7
NitroModules: 3bb6f5df53f09431fb9257638f6b8707f788c076
NitroModules: 90fea041cca2091fbacef9f78094bc59230b084f
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: b03c35057846b685b3ccadc9bfe43e349989cdb2
RCTRequired: 194626909cfa8d39ca6663138c417bc6c431648c
Expand Down
12 changes: 8 additions & 4 deletions packages/react-native-nitro-modules/NitroModules.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ Pod::Spec.new do |s|

# VisionCamera Core C++ bindings
s.source_files = [
"cpp/**/*.{h,c}",
"cpp/**/*.{hpp,cpp}",
# Shared C++ codebase
"cpp/**/*.{h,hpp}",
"cpp/**/*.{c,cpp}",
# iOS codebase
"ios/**/*.{h,hpp}",
"ios/**/*.{m,mm}",
"ios/**/*.swift",
"ios/**/*.h",
"ios/**/*.modulemap",
]
s.public_header_files = [
"cpp/core/**/*.{h,hpp}",
"cpp/threading/**/*.{h,hpp}",
"cpp/utils/**/*.{h,hpp}"
"cpp/utils/**/*.{h,hpp}",
"cpp/turbomodule/RegisterNativeNitroModules.hpp",
]

s.pod_target_xcconfig = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// RegisterNativeNitroModules.cpp
// DoubleConversion
//
// Created by Marc Rousavy on 21.06.24.
//

#include "RegisterNativeNitroModules.hpp"
#include "NativeNitroModules.hpp"
#include <React-callinvoker/ReactCommon/CallInvoker.h>
#include <ReactCommon/ReactCommon/CxxTurboModuleUtils.h>

namespace margelo {

void RegisterNativeNitroModules::registerNativeNitroModules() {
facebook::react::registerCxxModuleToGlobalModuleMap(
std::string(facebook::react::NativeNitroModules::kModuleName),
[&](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<facebook::react::NativeNitroModules>(jsInvoker);
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// RegisterNativeNitroModules.hpp
// DoubleConversion
//
// Created by Marc Rousavy on 21.06.24.
//

#pragma once

namespace margelo {

class RegisterNativeNitroModules {
public:
/**
Registers the native NitroModules TurboModule into the React Runtime.
This can be called from Swift/Objective-C.
*/
static void registerNativeNitroModules();
};

} // namespace margelo
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// NitroModuleOnLoad.mm
// DoubleConversion
//
// Created by Marc Rousavy on 21.06.24.
//

#import <Foundation/Foundation.h>
#import "RegisterNativeNitroModules.hpp"

@interface NitroModulesOnLoad : NSObject
@end

@implementation NitroModulesOnLoad

+ (void)load {
// When this Objective-C class is loaded, it registers the CxxTurboModule in the react module system.
// We need Objective-C here because these things do not get compiled out - meaning this will always be
// called when the app starts.
margelo::RegisterNativeNitroModules::registerNativeNitroModules();
}

@end

0 comments on commit 1976454

Please sign in to comment.