-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5655a91
commit 52a4e63
Showing
6 changed files
with
36 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
#include "react-native-rapier.h" | ||
#include "macros.h" | ||
|
||
namespace facebook::react { | ||
|
||
namespace callstack { | ||
namespace react_native_rapier { | ||
void install(jsi::Runtime& rt) { | ||
auto multiply = HOSTFN("multiply", 2) { | ||
auto num1 = args[0].asNumber(); | ||
auto num2 = args[1].asNumber(); | ||
return jsi::Value(num1 + num2); | ||
}); | ||
ReactNativeRapier::ReactNativeRapier(std::shared_ptr<CallInvoker> jsInvoker) | ||
: NativeReactNativeRapierCxxSpecJSI(jsInvoker), _callInvoker(jsInvoker) {} | ||
|
||
auto rapier = jsi::Object { rt }; | ||
rapier.setProperty(rt, "multiply", std::move(multiply)); | ||
|
||
rt.global().setProperty(rt, "__RapierProxy", std::move(rapier)); | ||
} | ||
} | ||
double ReactNativeRapier::multiply(jsi::Runtime &rt, double a, double b) { | ||
return a * b; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
#pragma once | ||
|
||
#include <ReactCommon/TurboModule.h> | ||
#include <RNReactNativeRapierSpecJSI.h> | ||
|
||
namespace facebook::react { | ||
|
||
using namespace facebook; | ||
|
||
namespace callstack { | ||
namespace react_native_rapier { | ||
void install(jsi::Runtime& rt); | ||
} | ||
} | ||
class ReactNativeRapier : public NativeReactNativeRapierCxxSpecJSI { | ||
public: | ||
explicit ReactNativeRapier(std::shared_ptr<CallInvoker> jsInvoker); | ||
|
||
public: | ||
double multiply(jsi::Runtime &rt, double a, double b) override; | ||
constexpr static auto kModuleName = "ReactNativeRapier"; | ||
|
||
private: | ||
std::shared_ptr<CallInvoker> _callInvoker; | ||
}; | ||
|
||
} // namespace facebook::react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,14 @@ | ||
#import "ReactNativeRapier.h" | ||
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h> | ||
|
||
|
||
@interface ReactNativeRapier () <RCTTurboModuleWithJSIBindings> | ||
@end | ||
#include <ReactCommon/CxxTurboModuleUtils.h> | ||
|
||
@implementation ReactNativeRapier | ||
|
||
RCT_EXPORT_MODULE() | ||
|
||
#pragma mark - RCTTurboModuleWithJSIBindings | ||
|
||
- (void)installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime | ||
{ | ||
callstack::react_native_rapier::install(runtime); | ||
} | ||
|
||
// Don't compile this code when we build for the old architecture. | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
{ | ||
return std::make_shared<facebook::react::NativeReactNativeRapierSpecJSI>(params); | ||
+ (void)load { | ||
facebook::react::registerCxxModuleToGlobalModuleMap( | ||
std::string(facebook::react::ReactNativeRapier::kModuleName), | ||
[&](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) { | ||
return std::make_shared<facebook::react::ReactNativeRapier>(jsInvoker); | ||
}); | ||
} | ||
#endif | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import type { TurboModule } from 'react-native'; | ||
import { TurboModuleRegistry } from 'react-native'; | ||
|
||
export interface Spec extends TurboModule {} | ||
export interface Spec extends TurboModule { | ||
multiply(a: number, b: number): number; | ||
} | ||
|
||
export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeRapier'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters