How to reuse the same react native instance across multiple actvities? - react-native

I have a brownfield Android application that has multiple activities, some of which are native and some of them react native.
What I wanted to know is that is there a way I can reuse the same react instance across all of my react native activities?
Right now, whenever we are creating a new activity that uses React Native, we have to initialize a new React Native instance and sync a lot of data along with rehydrating our entire redux store. This process is painfully slow and also consumes a lot of memory.

Related

Getting the current state of transition in #react-navigation/native-stack

I am developing a library consisting of React Native components and this library is used by a React Native application. I have a problem where I want to avoid rendering WebViews during transitions since it is causing crashes on Android. My problem occurs when the application switches to a new screen and renders a component from this component library. The component adds listeners for transitionEnd and beforeRemove. And the problem is that the transitionEnd listener doesn't always seem to get initialised soon enough for me to be able to recognise that the transition has ended and I am not able to determine if I can safely render a WebView.
Do you see a solution that already exists in react-navigation or is this perhaps a feature that should exist?

Applock using react native

I am very new to react-native. I want to create an app which can lock and unlock other apps similar to applock, but I want to add custom logic which will do this.
Is it possible to create with React native?

React Native: Access Redux store from Native side (swift/objective C)

Part of our React Native App lets users use it in the background while they use other apps.
If the user then force quits the app while our app is in the background we want to do some cleanup and send some analytics. Since we can't get the applicationWillTerminate event in React Native we need to do this cleanup in the native side.
So we were wondering if there is a way to access the Redux store in this event. Or what is the suggested way to handle this?

Why Should I Adopt React Native in Old Projects?

I've been digging deep in React Native for the past week to decide if I and the team should adopt it. And I gotta say it seems promising. I've also learned about its ability to integrate with existing native projects and its incremental adoption to change existing native projects.
My question is what are the cases/reasons that would make me wanna convert my completed old native projects (iOS/Android) into React Native?
Edit: Just to clarify, our team is currently building native apps only.
It depends on what type of app you are building. But you can always use bits of code from native or react native. Since you all can code in native, anything you cannot find you could make a native component.
The advantages of React Native show up with code reuse between iOS and Android so that your team can iterate faster working together. Many big apps have achieved 80% or more code reuse.
You will find flexbox so easy to quickly create views to specs and to change quickly with styles. Plus they are all in code and that plays nice with git.
See edit below:
Now in saying this I have never used React Native inside a native project but to call actions and such you would need to expose functions to call from the JavaScript side. I don't know if a singleton is generally used or just an import of the controller functions or delegated you want to expose but it has to call back to the native application . It is easy to use a native component inside a React native application and I have done this so I am sure it can work the other way.
Edit: Out of curiosity I added some react native views to a test project and it works surprisingly well. No singleton needed Javascript maps the view tag and the exported functions. Crazy. The concerns below still exist but I think if you are changing to change that is wrong but if you have UI changes you want to make then it could definitely benefit as your reuse can grow across your platforms.
Drawbacks I have seen- sometimes transition animations can be laggy if you are not using the native navigation methods. Using both native and React Native adds size to your app so you would need to keep an eye on that. Also start up time can hurt and so monitor that as well.
With all that said I have built a fair bit with React Native lately and it is, at times, beautiful and frustrating for a native developer.
Here is a great article on Instagram and React Native.
Also AirBnb heavily uses RN. They may be completely RN now but I am not sure. They do drive a lot of the outside frameworks in RN for example the maps component in RN. They also just released Lottie and it is very cool. Here is an article about AirBnb.

Using React Native within existing iOS app for some views only

Is it possible to use React Native only for one view within the project?
I've successfully added React view for particular iOS app screen (using instructions from "Integration with existing iOS project" docs), but i don't know how to get data from that screen and call other (objective-c) code. For example I want to replace old storyboard-based Search Form to React view and then call storyboard-based screens when user clicks "Search".
Or it is intended to make all views in React and convert existing non-React views into 'native' components (very huge work for big apps)?
This is easily accomplished via the Native Module concept which is described here - https://facebook.github.io/react-native/docs/nativemodulesios.html
You can export obj-c methods to JS via a single call.
I've solved my issue in following way:
Create Native Module wrapper around NSNotificationCenter, so
javascript code could publish iOS events.
Subscribe for that event within ReactController-wrapper around React-Native code.
Raise event when user clicked «Search» (when we need to give control back to objective-c) with needed data to pass as dictionary.
Catch event, process data, open other controllers/etc