I'm using react native for an sdk. I need to be able to send an event from JavaScript to the native layer when a particular action has occurred.
The docs mention that it's possible to send events to JS, but I need to be able to send events in the other direction.
Any ideas?
Related
I want to know which is the best way to send and receive events only within the JS stack. The event which is being emitted should not reach the react-native bridge or simply I don't want the event to reach the android/iOS stack.
I know using NativeEventEmitter, we can send and receive event inside JS stack, but unsure whether this will pass the data through react native bridge. I want a optimised way of sending and receiving events within the JS stack.
Please help me find the right approach.
Thanks.
I am using react native and trying to add push notification.
My application need push notification because of chatting. I just need push notification to appear whenever the user receives chat message.
I've searched couple of libraries about push notification and found out firebase and react-native-push-notification.
Which one is proper library for this case and please tell me if there is other better way to solve this problem.
We're using invertase firebase notification library which is working so far better without any issues.
You'll get almost all the options which you needed for push notification customization like badges, etc.
I have a react native app that uses SMS verification and I want to have a listener for incoming SMSs to read the code automatically.
I've used react-native-android-sms-listener but it doesn't work for Android 8 and above. Can anyone help?
you can use react-native-sms-retriever instead it supports for all versions
or else you can use react-native-get-sms-android to get all the user message in JSON and extract the data out of it.
I'm trying to develop an app in react-native that should use android's foreground dispatch system to intercept nfc events before any other activity does.
The android part is not a problem, I have done it in a native app.
What would the correct way of doing this be in an app that uses react-native?
I ended up adding creation of pending intent and adding of tag/NDEF filters to MainActivity. Then onNewIntent parses the relevant data and relays it to js via
getReactInstanceManager()
.getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("nfcTagEvent", params);
Then, in my main RN component
DeviceEventEmitter.addListener('nfcTagEvent', event =>
// do something with event
);
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.