how to call js function without defined in native side - react-native

I notice from calling-react-native-functions-from-native-events that I could call js function or event with defined prop in native side
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
but how could I call js function without any defined in native side?
for example, if I wrap my project as sdk which be embedded in others'app, and I want to dynamic add new method in js side without modify any sdk native code, so the app will directly call changed logic without update sdk package framework after hotfix.
how should I implement it?
thanks for your time,
regards.

Related

Best Way To Globally Instantiate Ably Connection in React Native

I am building a React Native game with multiple screens. I am trying to instantiate Ably one time and use it throughout the application without having to call new Ably('api-key') on every screen, as this is creating multiple new connections and making it impossible to keep a single connectionId. Is there a way to architect this so that I can define
const client = new Ably('api-key')
one time in App.js and use it throughout the other screens? Either by passing it as props through React Navigation props or using Context? The documentation on this is sparse as most of their documentation only uses this on one page.
Redux will not work. You can create an Ably client and pass it to other components using props, or just use React context to make it available to the whole application. Using redux to store an Ably client will cause an error since Ably clients aren’t serialisable.
See https://reactjs.org/docs/context.html for more info.
Here are some examples:
https://github.com/ably-labs/react-hooks
https://ably.com/blog/ably-react-hooks-npm-package
Cheers,
Richie

pass data between javascript and native code (iOS - obj c, Android - java) in react-native?

Is there any way to pass data between my react-native Javascript code to native code? I want to run perform an HTTP request with a user ID when the app terminates, but from what I can see, there is no way to do that in Javascript, so the only way to do that would be within the native code. But is there any way I can get the user ID from the native code?

Create wrapper around plugin in React Native

I'm using a plugin in React Native that doesn't contain all of the props that I need.
Ideally I'd like to modify the library and create a pull request, but I don't have time to wait for approvals.
How can I create a wrapper around the library in order to modify certain files?

Is it possible to use code push when native code has changed?

If I add a package that requires changes in the native code, like MainActivity for android, is it still possible to use codepush to update the app?
I don't think that's possible, since code-push runtime on the device can only replace the javascript part and not the native parts.

pass a javascript function onto native

Is it possible to pass a javascript function from React Native onto iOS Native components such as a UIButton and execute there?
It is possible, but using events and not by sending JS to native components. Check out react-native docs for detailed information, but generally:
React Native enables you to perform cross-language function calls. You
can execute custom native code from JS and vice versa. Unfortunately,
depending on the side we are working on, we achieve the same goal in
different ways. For native - we use events mechanism to schedule an
execution of a handler function in JS, while for React Native we
directly call methods exported by native modules.