Sahil spent four years at Branch working as an Engineer and Product Manager. During this time, he put his technical expertise to use creating content for Branch’s blog.
Mar 13, 2017
As you probably know, React Native is a cross-platform development framework rapidly gaining followers. If you have a native SDK (an SDK written in Objective-C, Swift, or Java), you might find yourself requesting a React Native version in the near future. This article can serve as a guide to port your native modules into a React Native environment.
Branch realized this quickly, as a lot of our existing partners created new projects in React Native. We didn’t have the resources needed to design and implement a React Native component from scratch, so we solved it by leveraging our core Native SDKs, and wrapping them with packaged tools like NativeModules to make porting a breeze.
To begin, you must consider three high-level components when porting your existing native library into React:
For this post, we’ll use iOS examples, but the same high-level concepts apply to Android.
Because we implemented the necessary protocol, calling functions into Objective-C is straightforward:
What if you want to go the other way, and listen to incoming events from Objective-C? Using the native events library found in React, you can simply register event names and callbacks that are defined in the middleware object. Once the event emits, we’ll know about it.