-
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
Showing
5 changed files
with
73 additions
and
15 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
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,12 +1,49 @@ | ||
#include "react-native-rapier.h" | ||
#include "macros.h" | ||
#include "wasm-rt.h" | ||
|
||
namespace facebook::react { | ||
|
||
std::shared_ptr<RapierModuleContext> tryGetRapierContext(jsi::Runtime& rt, const jsi::Object& rapierObject) { | ||
if (!rapierObject.hasNativeState(rt)) { | ||
return nullptr; | ||
} | ||
|
||
auto context = std::dynamic_pointer_cast<RapierModuleContext>(rapierObject.getNativeState(rt)); | ||
return context; | ||
} | ||
|
||
ReactNativeRapier::ReactNativeRapier(std::shared_ptr<CallInvoker> jsInvoker) | ||
: NativeReactNativeRapierCxxSpecJSI(jsInvoker), _callInvoker(jsInvoker) {} | ||
|
||
double ReactNativeRapier::multiply(jsi::Runtime &rt, double a, double b) { | ||
return a * b; | ||
jsi::Object ReactNativeRapier::create(jsi::Runtime &rt, jsi::Object importObject) { | ||
jsi::Object mod { rt }; | ||
|
||
if (!wasm_rt_is_initialized()) { | ||
wasm_rt_init(); | ||
} | ||
|
||
auto inst = std::make_shared<RapierModuleContext>(rt, std::move(importObject)); | ||
wasm2c_rapier__wasm3d__bg_instantiate(&inst->ctx, &inst->wbg); | ||
|
||
mod.setNativeState(rt, inst); | ||
|
||
// Fill Exports | ||
jsi::Object exports {rt}; | ||
|
||
/* export: 'rawimpulsejointset_new' */ | ||
exports.setProperty(rt, "rawimpulsejointset_new", HOSTFN("rawimpulsejointset_new", 0) { | ||
auto nativeState = tryGetRapierContext(rt, thisValue.getObject(rt)); | ||
auto res = w2c_rapier__wasm3d__bg_rawimpulsejointset_new(&nativeState->ctx); | ||
return jsi::Value { (double)res }; | ||
})); | ||
u32 w2c_rapier__wasm3d__bg_rawimpulsejointset_new(w2c_rapier__wasm3d__bg*); | ||
|
||
exports.setNativeState(rt, inst); | ||
mod.setProperty(rt, "exports", std::move(exports)); | ||
|
||
// end full exports | ||
return mod; | ||
} | ||
|
||
} |
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
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,8 +1,9 @@ | ||
import type { TurboModule } from 'react-native'; | ||
import { TurboModuleRegistry } from 'react-native'; | ||
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; | ||
|
||
export interface Spec extends TurboModule { | ||
multiply(a: number, b: number): number; | ||
create(importObject: UnsafeObject): UnsafeObject; | ||
} | ||
|
||
export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeRapier'); |