React Native - Best way to send and receive events within Javascript thread - react-native

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.

Related

API calls are blocking other touchables in the screen - React Native

When a API call is happening, Im not able to click any touchables in the screen. They wont respond until the API call is done. Is there any solution for this?
I tried with many react native components like TouchableOpacity, TouchableHighlight, Pressable but the main issue is onPress itself is not trigger when the API call is in process.
You must use async/await or .then while making api calls. if you are not using these your app will stop working until api call completes or promise resolves.
Can you open the dev tool and set show perf monitor on and check the JS FPS?
Async functions usually don't block touchables while they are running in the background. Regardless if you use async/await or .then.
According to what you have provided, it seems that your JS thread is freezing which means there are many processes running in the background.
Can you please share a snippet of the code you are running?

How can I control push notification ON/OFF according to conditions? in React Native

I am making a push notification feature using reactnative push notification.
If I create a channel according to the reactnative push notification official statement, I can control it only when I enter the notification category in the application information of the application.
Can I use the reactnative push notifictaion library to control when I create a component within the app like Youtubemusic (below Image) and implement the push setting ON OFF control function? It doesn't seem to be in the official documentation.
I'm trying to implement this feature within the app, but I'm curious about how it's implemented in practice!
i'm not using local notification just remote
Basically, you have 2 way to achieve this: on backend side or on frontend side.
Backend
Send to backend current state of toggle settings inside your app. When backend want to send push to client, it is internally checks state of this toggle and make a decision send or not.
Frontend
All your push notifications must be send as data only and with high priority (contentAvailable: true, priority: 'high').
After that, only mobile app will control showing of push notifications, because data only push not display anything, just trigger mobile app about new message.
So, when your frontend app receive new push message, it check current user settings and make decision display it or not.

selecting react native push notification

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.

Sending events from JS to Native (Java)

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?

How to communicate message from debugger to react native component?

Interested in knowing if there is a way of passing an event with some payload to react native components through debugger console in chrome.
My use case is, while debugging I want to send a message to one of my react components.