Skip to content

How can I call c++ native methods in worklets? #6625

Answered by MatiPl01
doublelam asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

Sorry for the late response but you may want to try this out:

  1. Import TurboModuleRegistry from react-native:
import { TurboModuleRegistry } from 'react-native';
  1. Load the module by name with the .get method:
const NativeCalcModule = TurboModuleRegistry.get('NativeCalcModule');
  1. Assign a function exported in your module to a separate variable
const getPoint = NativeCalcModule.getPoint;
  1. Use this function inside a worklet
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 som…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by doublelam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants