-
I need a heavy calculating in a worklets function and I write the c++ native methods then call it in worklets, but it says the methods is undefined, please help me write a UI runtime c++ native module, I cannot find anything relate it in the document. files: import NativeCalcModule from '@root/tm/NativeCalcModule';
export const getPoint = (
current: number,
width: number,
max: number,
min: number,
step: number,
mode: 'round' | 'floor' = 'round',
) => {
'worklet';
const res = NativeCalcModule.getPoint(current, width, max, min, step, mode);
// Error, it says getPoint is undefined but it works in JS thread. c++ part: #include "NativeCalcModule.h"
namespace facebook::react
{
NativeCalcModule::NativeCalcModule(std::shared_ptr<CallInvoker> jsInvoker)
: NativeCalcModuleCxxSpec(std::move(jsInvoker)) {}
std::tuple<int, float, float> NativeCalcModule::getPoint(jsi::Runtime &rt, float current, float width, float max, float min, int step, std::string mode)
{
if (width <= 0)
{
return {0, 0, 0};
}
... TS interface export interface Spec extends TurboModule {
readonly getPoint: (
current: number,
width: number,
max: number,
min: number,
step: number,
mode: 'round' | 'floor',
) => Array<number>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('NativeCalcModule'); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey! Sorry for the late response but you may want to try this out:
import { TurboModuleRegistry } from 'react-native';
const NativeCalcModule = TurboModuleRegistry.get('NativeCalcModule');
const getPoint = NativeCalcModule.getPoint;
export const getPoint = (
current: number,
width: number,
max: number,
min: number,
step: number,
mode: 'round' | 'floor' = 'round',
) => {
'worklet';
const res = getPoint(current, width, max, min, step, mode); // This should work fine
} I did something similar with the Let me know if it helps you! |
Beta Was this translation helpful? Give feedback.
Hey!
Sorry for the late response but you may want to try this out:
TurboModuleRegistry
fromreact-native
:.get
method:I did som…