3

So I am creating a React native app and I want to call a JavaScript function from the native part of the App.

I know that I can use Native Modules to create a bridge between Native and React Native and I also know that from a Native Module I can emit an event that can be received by React Native.

But, any function call inside a Native Module can only occur from inside the React Native itself, since it needs a React native context, so I can only send an event from a Native Module if the React Native itself calls one of the Native module functions that contains the event emit. Can someone clarify how can I do this?

To be more clear, my final goal is to create an Android library using React native that will be used in an already created Native app, inside my Android Library I want to expose some of my JavaScript components/functions so I can have Native App -> Native part of React Native library -> JavaScript part of React Native library.

Thanks in advance!

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
Garoto Guibas
  • 33
  • 1
  • 4

1 Answers1

0

You can use HeadlessJs for it. React-Native already provides it.
Here you can see the example of HeadlessJs follow below link

https://facebook.github.io/react-native/docs/headless-js-android

It will help you. Have a great day.