Read Part 1 here!
In part I we discussed how we may decompose a large complex React Native app into smaller React Native mini apps (using Electrode Native), and how mini apps can be combined together to build larger apps. Mini apps allow development using separate code repositories for each mini app, and mini apps can be centered around a particular business feature. This also allows separate teams to work on each mini app.
We also discussed on-device data storage options when using React Native, and Realm database emerged as a viable contender.
We sourced various articles and forums to examine and abstract some common performance issues encountered when using React Native and explored possible solutions that will mitigate this.
In part II we will explore some deeper implementation issues in building mini apps with React Native, and focus on
The aim is still to achieve a microservices approach to building mobile applications, thereby allowing separate teams to work on different parts of a mobile application, and a loosely coupled mobile app that may be deployed in separate increments, rather than a single monolithic mobile app.
React Native is great when you are starting a new mobile app from scratch. However, it also works well for adding a single view or user flow to existing native applications. With a few steps, you can add new React Native based features, screens, views, etc.
Also, when building apps using React Native sometimes it may be required to access the native platform API or simply to interact with some native code. This may be due to a number of reasons.
For example, you can create an Image component that is a bridged native component that uses SDWebImage under the hood, so that we can share an image cache for thumbnails with the native side of the app. It works by:
Swift doesn’t have support for macros so exposing it to React Native requires a bit more setup but works relatively the same.
Can you use Objective C and Swift in a single project file in iOS?
Objective-C and Swift files can coexist in a single project, whether the project was originally an Objective-C or Swift project.
Whenever you mix Swift and Objective-C in an iOS project, you will need an additional bridging file, known as a bridging header, to expose the Objective-C files to Swift. Xcode will offer to create this header file for you if you add your Swift file to your app through the Xcode File>New File menu option. You will need to import RCTBridgeModule.h in this header file. Care should be taken when mixing the two languages in Xcode as the bridge can be leaky if not properly implemented.
Push notifications are hard and presents a unique problem in React Native apps. This is another segment of React Native that may need to be customized for the particular platform one is using.
While researching Push Notifications in React Native i came across two awesome tutorials by Spencer Carli on Local Push Notification (using react-native-push-notification) and Remote Push Notification (using OneSignal)
Further research showed that there are several open source npm libraries for local notification setup including,
react-native-notifications, react-native-push-notifications, react-native-onesignal, and many others.
I came across another interesting article that compared OneSignal , UrbanAirship and Amazon SNS Mobile Push.
The questions now became
1. How do you incorporate push notifications in the macro app that is built using a collection of mini apps.
The solution seemed to be to build the notification for the macro app rather than within each of the constituent mini apps. However here we are venturing into the rarified atmosphere, since many of these features of React Native and Electrode Native are still new and evolving and i have yet to come across teams that have confidently implemented this approach. Although connecting the pieces in this fashion seems to be the logical approach.
2. Can one use Amazon SNS Mobile Push vs OneSignal or other competing products, as the MBaaS for Push Notifications to React Native Apps.
Here research showed that Amazon released its support for push notifications for React Native Apps in late 2017. This meant that you can create a mobile end point for the React Native app within the Amazon SNS Mobile Push (by using the iOS credentials for iOS support and Google Firebase Registration ID for Android support).
Thus using Amazon SNS Mobile Push as the service to push to the macro app (built using constituent mini apps) seemed to be a viable approach to implementing push notifications within apps built using the microservices approach. Keep in mind though that at this point this is merely conjecture and our teams have not implemented this as a thorough test. These technology platforms and paradigms are relatively new, however connecting them in this way seems to be a possible viable approach.
Persistent user session is a common feature in mobile apps, where a user must login to access protected content within the app. The user session must be properly managed by the app for a seamless user experience, so that the user is not logged out every time they launch the app.
I came across the following article where the author implemented a simple persistent user session management using React Native Async storage and react-native-router-flux. The approach was simple
This approach is elegant for its simplicity and can be used within the macro app, with Async or Realm database as the underlying persistent storage. The persistent user session and token can also be used by the mini apps to access protected content within individual mini apps.
Another possible alternative is to use AWS mobile hub IAM management service to manage user sessions. This of course uses Amazon Cognito as the authentication backend.
Mini Apps in React Native are a viable approach to developing mobile apps that implement the microservices paradigm. In addition to the cross platform benefits that React Native provides, mini apps allow for separate code repositories, team separation based on business functionality and ability to scale and deploy parts of a mobile app separately. It is possible also to Code-pushify(now Visual Studio App Center) an app that is built using React Native, which allows for the app to be updated on the users phone without having to go through the app store. This can be useful when pushing out hot fixes or for A/B testing or canary releases.
Mini Apps and macro apps can use Async Storage or Realm database for on-device data persistency. This may be leveraged for persistent user session management, to avoid having the user to login every time the app is opened on the phone.
Understanding the nuances of React Native is important to get the most out of React Native performance. To this end it is important to identify the number of passes over the React Native bridge and to keep this number low.
In case of brownfield development React Native allows interfacing of React Native code with already existing native code, and native modules allow developers to access native platform API from the JS code.
Push notification implementation for mini apps can be done at the macro app level, rather than at the mini app level. There are several libraries that allow for local notification implementation in React Native and platforms like OneSignal that allow for remote notifications, however this implementation is still relatively new and uncharted waters.
Amazon SNS Mobile Push along with npm libraries can be used to implement push notification services. It is important to note that platform specific code will need to added to React Native, and APNs will be used in case of the iOS implementation of the App and GCM or Firebase for the Android implementation. The backend pipes can be connected to Amazon SNS Mobile Push as a mobile end point, which can in turn be connected to the Amazon SNS publisher or triggered from AWS Lambda services or other SQS services if required.
Found this post useful? Hit the 👏 button below to show how much you liked it :)
Follow me on Medium for the latest updates and posts!
Create your free account to unlock your custom reading experience.