<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adrian Hartanto on Medium]]></title>
        <description><![CDATA[Stories by Adrian Hartanto on Medium]]></description>
        <link>https://medium.com/@AdrianHartanto?source=rss-fa19648adca7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OL5N549ELs_5kUKULQ2Iww.png</url>
            <title>Stories by Adrian Hartanto on Medium</title>
            <link>https://medium.com/@AdrianHartanto?source=rss-fa19648adca7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:50:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@AdrianHartanto/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Native at Traveloka: Native UI Components]]></title>
            <link>https://medium.com/traveloka-engineering/react-native-at-traveloka-native-ui-components-c6b66f789f35?source=rss-fa19648adca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6b66f789f35</guid>
            <category><![CDATA[traveloka]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Adrian Hartanto]]></dc:creator>
            <pubDate>Fri, 18 Jun 2021 05:57:19 GMT</pubDate>
            <atom:updated>2021-09-29T08:51:23.974Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaeEt54w7qfqj0aElUhuGA.png" /></figure><p><em>Editor’s Note:</em></p><p><em>One of the challenges with managing multiplatform software development is the laborious efforts of creating &amp; maintaining parity for every identical component constantly across platforms. Adrian would like to share with us today the journey (through examples, problems, &amp; solutions) that he &amp; his team took to overcome that challenge with a cross-platform interoperability implementation.</em></p><p><em>Adrian Hartanto is a React Native Software Engineer with the Multiplatform Infra Team that maintain &amp; improve the React Native architecture for Traveloka main app &amp; B2B. The team is also currently designing &amp; building React Native interoperability for Android, iOS, &amp; Web.</em></p><p>In this article, we will share about a Native UI Components project called Reverse Osmosis that was briefly covered previously in <a href="https://medium.com/@junius.ang/387d6e68becf">React Native at Traveloka: Bridging the Past and the Future</a>.</p><p>Reverse Osmosis, the opposite of the Osmosis project that will be covered in a follow-up article, aims to provide interoperability between React Native and native developments (iOS/Android). While Osmosis allows React Native components inside native pages, Reverse Osmosis, as its prefix implies, allows native components inside React Native pages. By doing so, we can share more components between platforms and also provide flexibility to develop components.</p><h4>Why <strong>Reverse Osmosis</strong>?</h4><p>We have been using a hybrid approach in developing the Traveloka application as explained in <a href="https://medium.com/traveloka-engineering/react-native-adoption-3-31146e3f59f1">React Native at Traveloka: Hybrid Development Experience</a>. It affords us the flexibility to develop a feature using either React Native or native iOS/Android. However, when there’s a requirement to use iOS/Android components in React Native products, we need to recreate the components in React Native, which could cause a <em>feature parity</em> problem between platforms. Reverse Osmosis was created to address that problem.</p><p>Nevertheless, such a challenge allowed us to learn how to create native UI components, how they work, and how to integrate them with React Native. Actually, this is not a new concept since React Native already has guides (<a href="https://reactnative.dev/docs/native-components-ios">iOS</a>/<a href="https://reactnative.dev/docs/native-components-android">Android</a>) to create custom native UI components by wrapping existing native components and integrating them with React Native.</p><p>Another issue that Reverse Osmosis would solve was the constant repetition of defining view’s or component’s size manually in order to avoid a blank screen. Not to mention, native components need to manage their own layout too.</p><p>In summary, here were the challenges that we wanted to solve:</p><ol><li>Modifying native components just to be interoperable with React Native. In Traveloka, each team maintains their own code. So, the fewer constraints coming from React Native’s needs, the better.</li><li>Manual (re)sizing. Native components require less user intervention over its lifetime in React Native since any modification including UI-related, doesn’t need update on our part. When we use native components in React Native, it’s normally required to set their width and height either by specifying flex:1 or hard-code them. It would be powerful if we could come up with an implementation that allows components to determine their own size dynamically.</li></ol><p>So, the goal was to make React Native be self-aware of layout updates that happen on native components so that we can have dynamic-sized native components. In this article, we are gonna share our learning experience and what worked for us to overcome those challenges.</p><h3>Native Components Showcase</h3><p>These are three native component examples that are being used in Traveloka application.</p><h4>Booking Price</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnBmwDXspUduAm_iy576CQ.png" /><figcaption>Figure 1. Booking price components on insurance’s booking detail page in Android (left) and iOS (right). Red and green outlines are native and React Native components respectively.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-JgcE2uH4ADoKfCyfg9ZQ.png" /><figcaption>Figure 2. Booking price modal component on insurance’s booking detail page in Android (left) and iOS (right). Red outlines are native components.</figcaption></figure><p>Those are the first native components chosen as Proof of Concept for this project. Although simple components, we were able to confirm that native modal and navigation capabilities work without any modification in React Native side.</p><h4>Merchandising</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l81Md5jn08WDWGVNEcMfUQ.png" /><figcaption>Figure 3. Merchandising component on a promo detail page in Android (left) and iOS (right). Red and green outlines are native and React Native components respectively.</figcaption></figure><p>Merchandising is a concept of Common View Language we have in Traveloka that allows us to render sets of items with predefined rules and styling from the back-end by using JSON as a data source. Common View Language expects us to adhere to its requirement of rendering identical components regardless of platforms. Initially, we built merchandising in Android, iOS, Web, &amp; React Native. Keeping this component in sync for every iteration in all platforms made managing feature parity even more challenging. As React Native products don’t utilize merchandising as much as products running on native pages, React Native’s merchandising components tend to fall behind their native counterparts and it becomes harder over time to justify making updates for the sake of feature parity. Therefore, we explored the possibility to replace obsolete merchandising in React Native with up-to-date native implementation through Reverse Osmosis. We have two actionables here:</p><ol><li>The previously used data to render in React Native side needs to be passed to the native side so that native merchandising can render normally.</li><li>React Native must dynamically allocate any size required by the components.</li></ol><p>We managed to complete the actionables and migrated all React Native old merchandising into Reverse Osmosis implementation. Since then, any change in native sides is also applied in React Native automatically.</p><h4>View Slider</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6D1YwWxGM_0SWnESDMlPcg.gif" /><figcaption>Figure 4.<em> </em>View Slider Component on Bebas Handal Insurance Page in Android (left) and iOS (right).</figcaption></figure><p>View Slider is a container that receives two layouts but shows only one at a time. It can slide up &amp; down to show the other layout. This container already exists in native platforms and our product team requested the same capability in React Native. At first, we created similar behavior using ScrollView that works well in the iOS version. Although it could also work in the Android version, the performance was not as good as we expected and the gesture handling was also not smooth enough. Hence, we opted to use Reverse Osmosis. After we were successful in Android, we found that iOS implementation was heavily coupled with too many native codes and refactoring the code would eventually kill the purpose of Reverse Osmosis, which was designed to limit modification of the actual components. At the end, we had a View Slider with Reverse Osmosis for Android only (you would need a good component abstraction in React Native to create a partial Reverse Osmosis implementation).</p><p>This container will naturally stretch to cover the whole screen. So, size manipulation was not needed here. The learning in this implementation was to pass React Native components to native side and how to properly manage it.</p><h3><strong>Four Obstacles</strong></h3><h4><strong>The Lack of Documentation/Article About Dynamic Sized Native Component</strong></h4><p>Even though it’s common to create native components as many libraries have already done, native component implementation doesn’t manage its own size. It requires you to define the component size such as using flex:1 or hard-coded width and height. Therefore, it’s quite difficult to find documentation related to dynamic-sized native components and we need to teach ourselves how native components actually work.</p><h4><strong>Different Component API Between Platforms</strong></h4><p>Reusing native components in React Native was not as straightforward as we imagined. Many of our native components preceded our establishment of React Native in Traveloka. Long ago, we didn’t think it was possible to reuse components outside the platform. So, it’s common that some iOS and Android components have a different API because those were created without the foresight of sharing. Even for a property that has the same name, Android and iOS can expect different data types. For example, BookingPrice component has a property called entryPoint with different data types on both platforms, string on iOS and object on Android. When this happens, we need to make some adjustments in the React Native or ViewManager layer to fulfill the component’s requirements with data type conversion.</p><p>In our cases, either you find both implementations easy to tinker with or one platform is dwarfed by another in terms of difficulty.</p><h4>iOS Auto Layout</h4><p>During our research, we found out that Auto Layout was not working well when used inside React Native. For example, React Native couldn’t get a new layout after the component constraints were updated. React Native internally uses Yoga as its layout engine. Actually, we’ve asked <a href="https://twitter.com/shergin">Shergin</a>, the former React Native team member about this issue on this twitter <a href="https://twitter.com/ericlewis/status/1143151522194305024">thread</a>. Based on his answer, the problem is that React Native runs layout on a background thread while our native components that use UIKit run on the main thread. To date, there’s still no solution to this problem. Since most iOS components at Traveloka are developed using Auto Layout, we needed to find a workaround to solve this problem before we can reuse iOS native components in React Native.</p><h4><strong>Android Performance Problem</strong></h4><p>On Android, we initially planned to use Android’s layout listener such as <a href="https://developer.android.com/reference/android/view/ViewTreeObserver">ViewTreeObserver</a> or <a href="https://developer.android.com/reference/android/view/View.OnLayoutChangeListener">View.OnLayoutChangeListener</a> to listen to layout updates so that we don’t need to modify existing components when we want to use them in React Native.</p><ol><li>ViewTreeObserver:<br>We expected that ViewTreeObserver could observe layout updates in the view tree and we could use it to notify React Native about the updates. But, as the ViewTreeObserver observes the layout of the whole view tree, ViewTreeObserver listeners can be called multiple times in any layout update. Because we depended on this observer, there’re so many notifications sent to React Native that affected the render result.</li><li>View.addOnLayoutChangeListener:<br>Beside ViewTreeObserver, we also tried View.addOnLayoutChangeListener to listen to layout updates. Unfortunately, this listener was only called once in component creation. Therefore, it couldn’t be used to detect layout changes.</li></ol><p>We spent a lot of time improving this approach because we thought negating the need to modify existing components is an ideal approach. Unfortunately, this listener concept was scrapped from our final solution.</p><h3>Solutions</h3><p>After tinkering with several approaches for each obstacle that we have mentioned, we finally settled on a solution that focused on these two key topics:</p><ol><li>Notifying React Native for any size update on native components:<br>Native UI components on React Native are managed by ViewManager that is responsible to create native components and set or update properties of the components. As we want to have dynamic sized native components, we need to set the size of the components on native side. Since ViewManager is responsible for managing native components, it’s necessary to let ViewManager be aware of any size update on the native components.<br>Initially, we were using these approaches to get size update and notify ViewManager:<br>a. Expose listeners on native component:<br>This approach can be done by exposing listeners related to layout updates such as update component layout or api call started/finished so ViewManager can recalculate the component size every time the listener is triggered.<br>While this approach is quite straightforward, it also has some caveats. You need to be aware of all possibilities that might affect layout and should expose it as listeners. This means that you also need to modify existing components if there’s no listeners provided. Beside that, its maintainability is a thing we should note, as over time, component modification might cause regression and require you to make some adjustments.<br>b. KVO on iOS:<br>On iOS, we can also utilize <a href="https://developer.apple.com/documentation/swift/cocoa_design_patterns/using_key-value_observing_in_swift">KVO</a> to listen to size updates. ViewManager will act as an observer of the component size properties. In our case, we use KVO to get the Merchandising component’s size by observing the contentSize of UICollectionView. You can also use this to observe component’s bounds to get bounds updates but sometimes, the result is not as expected such as bounds always return zero. However, we cannot generalize the properties that should be observed. For example, not every component uses UICollectionView.<br>Even though these two options were far from ideal, they can be used to fulfill our requirements and we’ve used these in our application for several application versions.<br>After quite some time, we finally came into an approach that we think it’s better than the previous one. On this approach, we introduced a new component called WrapperView that will manage layouting of the native component. WrapperView will be responsible for layouting the native child component and updating React Native view hierarchy. This way, we can generalize our approach for iOS and Android and remove requirements to expose listeners and use KVO.</li><li>Updating React Native view hierarchy:<br>The next step is to update the React Native view hierarchy. Without it, the layout can’t be correctly rendered since the native component is still assumed to not have any size yet. Thus, it can’t provide the space the component actually needs.<br>React Native view hierarchy is managed by UIManager, represented by <a href="https://github.com/facebook/react-native/blob/master/React/Modules/RCTUIManager.h">RCTUIManager</a> class on iOS and <a href="https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java">UIManagerModule</a> class on Android. Lucky for us, UIManager already has a method (<a href="https://github.com/facebook/react-native/blob/master/React/Modules/RCTUIManager.h#L80">iOS</a>/<a href="https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java#L483">Android</a>) that can be used to update the size of the native components and the view hierarchy. We just need to pass the new size to it. Then, UIManager will update the view hierarchy accordingly.</li></ol><p>We’ll be moving on to the implementation of our research. The implementation explanation will start from the React Native side so it will be easier to get the bigger picture of what we are trying to achieve.</p><h3>React Native Implementation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*4VwECwx9Z2nf8geyIrBdxg.gif" /><figcaption>Figure 5. Reverse Osmosis Component Example.</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d60ecd258b38890c2b3486791779797/href">https://medium.com/media/9d60ecd258b38890c2b3486791779797/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03b9dc9c9dde26160592a527a8c6d038/href">https://medium.com/media/03b9dc9c9dde26160592a527a8c6d038/href</a></iframe><p>We need to create React Native module that imports the iOS/Android ViewManager that has been created. This module will act as an interface layer between iOS/Android and React Native.</p><p>In this module, you need to call requireNativeComponent to access the iOS/Android native views. This method takes the name of native view that is registered on ViewManager, getName on Android or RCT_EXPORT_MODULE on iOS. As explained in the<a href="https://reactnative.dev/docs/native-components-ios#styles"> docs</a>, React Native views is a subclass of UIView. Therefore, you can style native components like any React Native component.</p><p>Since we already handled layout updates of native component on native side, there’s no need to use flex:1 or define width/height of the native component.</p><h3>iOS Implementation</h3><p>Exposing native components on iOS requires you to do these five steps as described on the official<a href="https://reactnative.dev/docs/native-components-ios#ios-mapview-example"> guide</a>:</p><ol><li>Subclass RCTViewManager class that will be responsible as manager for the component.</li><li>Add RCT_EXPORT_MODULE macro to register component to the bridge.</li><li>Override — (UIView *)view method to return the view.</li><li>Expose view property using RCT_CUSTOM_VIEW_PROPERTY macro.</li><li>Implement JavaScript module.</li></ol><p>In most cases, you can follow this guide to create native UI components and define component size to make it work. Since we want to have a dynamic-sized native component, we need to make some adjustments on how we create the component.</p><p>Native component on iOS generally consist of two parts:</p><ol><li>View<br>iOS view that will be exported as native component in React Native.</li><li>ViewManager<br>ViewManager is represented by the RCTViewManager class. It is responsible to manage the component, such as manage props, send/receive events, etc.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*DwkBi-b-5kL8UCII" /><figcaption><em>Figure 6. </em>iOS file structures.</figcaption></figure><h4>Create WrapperView</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73020c0942c09a05175ff382ac11ec8c/href">https://medium.com/media/73020c0942c09a05175ff382ac11ec8c/href</a></iframe><p>WrapperView will act as a parent of the native component. This will be responsible for handling layouting of the native component and notifying size updates to ViewManager.</p><p>Native components will be added as a subview and fill the parent, WrapperView. In the layoutSubviews lifecycle, we can get the subview of the WrapperView, which is the native component. This way, we can get the updated size of the native component and update the React Native view hierarchy by calling the setSize method on UIManager.</p><h4>Running Module Methods on Main Thread</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e5f6ac0e99e8d60ebf206efbb58dd96/href">https://medium.com/media/2e5f6ac0e99e8d60ebf206efbb58dd96/href</a></iframe><p>We can tell ViewManager to run on the main thread by overriding methodQueue since our component will interact with UIKit. By doing this, methods in our component will be executed on the main thread.</p><h4>Wrap Native Component with WrapperView</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db3a5bc2ed3c631d7b5a2da9cfd2784/href">https://medium.com/media/3db3a5bc2ed3c631d7b5a2da9cfd2784/href</a></iframe><p>Instead of returning native component on the view method, we need to wrap it inside WrapperView first. As mentioned earlier, WrapperView will handle layouting of the native component.</p><h3>Android Implementation</h3><p>Moving on to Android implementation, React Native also has official<a href="https://reactnative.dev/docs/native-components-android"> guide</a> to create native components:</p><ol><li>Create a ViewManager subclass, it can be either SimpleViewManager or ViewGroupManager.</li><li>Override createViewInstance method to return the view.</li><li>Expose view property using @ReactProp annotation.</li><li>Register ViewManager in thecreateViewManagers method of the application package.</li><li>Implement a JavaScript module.</li></ol><p>This implementation also works in most cases. But, you still need to define component size when using it in React Native.</p><p>Similar with iOS, Native component on Android also consist of two parts:</p><ol><li>View<br>Android View that will be exported as native component in React Native.</li><li>ViewManager<br>ViewManager on Android is represented by SimpleViewManager/ViewGroupManager. It is responsible to manage the component, such as manage props, send/receive events, etc.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/0*KtlEfs0fhunhFAHl" /><figcaption><em>Figure 7.</em> Android file structures</figcaption></figure><h4>Create WrapperView</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf3abfce4e981f925658746ca0220851/href">https://medium.com/media/bf3abfce4e981f925658746ca0220851/href</a></iframe><p>On Android, we also need to create a WrapperView that’s responsible for handling layouting native components. We need to override onMeasure to manually calculate the size of the native component and update the React Native view hierarchy. This can be done by calling updateNodeSize from the UIManagerModule class.</p><h4>Wrap Native Component with WrapperView</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c769352093e6cfddd4c88c5341712aa0/href">https://medium.com/media/c769352093e6cfddd4c88c5341712aa0/href</a></iframe><p>Similar to the iOS implementation, we need to wrap native components with WrapperView to handle the layouting process.</p><h4>Bonus: Pass React Native Component to Native Component</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a193d5c4af1f5ccc0e490d69bd41e45/href">https://medium.com/media/2a193d5c4af1f5ccc0e490d69bd41e45/href</a></iframe><p>Besides<a href="https://reactnative.dev/docs/native-components-android#3-expose-view-property-setters-using-reactprop-or-reactpropgroup-annotation"> primitive data types</a> that can be passed as props to native components, you can also pass React Native components to native components. This approach was inspired from<a href="https://github.com/react-native-maps/react-native-maps/blob/703e0c7e0891e4b4248e8f99f2188c3b059caca7/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapMarkerManager.java#L273-L283"> react-native-maps</a> implementation and being used for View Slider native component that can receive React Native components. You can pass React Native component as a child of native component and override addView method to get the component as a child.</p><p>Working example of this implementation can be accessed <a href="https://github.com/traveloka/react-native-reverse-osmosis-demo">here</a>.</p><h3>Summary</h3><p>This sums up our learning about native UI components and how we use it to reuse existing native components in React Native. This can be used as an alternative to develop components in React Native. We also managed to have dynamic-sized native components so that they can be used in our application.</p><p>We’re still gathering more use cases and improving our solution to have dynamic-sized native components when React Native releases their new architecture in the future. For now, this approach works well for us and also fulfills our existing requirements.</p><p>It was indeed a challenging research project to have dynamic-sized native components. This will be useful if you want to reuse existing native components in your React Native application. This also gives you flexibility to develop components, whether using React Native or using native components.</p><p>If this kind of topic is something of an interest to you, please take a look at our <a href="https://www.traveloka.com/en-id/careers">career page</a>. We are always excited to meet new people, who share the same passion to join with us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6b66f789f35" width="1" height="1" alt=""><hr><p><a href="https://medium.com/traveloka-engineering/react-native-at-traveloka-native-ui-components-c6b66f789f35">React Native at Traveloka: Native UI Components</a> was originally published in <a href="https://medium.com/traveloka-engineering">Traveloka Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native at Traveloka: Hybrid Development Experience]]></title>
            <link>https://medium.com/traveloka-engineering/react-native-adoption-3-31146e3f59f1?source=rss-fa19648adca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/31146e3f59f1</guid>
            <category><![CDATA[traveloka]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Adrian Hartanto]]></dc:creator>
            <pubDate>Tue, 04 Dec 2018 02:06:01 GMT</pubDate>
            <atom:updated>2018-12-04T02:06:01.037Z</atom:updated>
            <content:encoded><![CDATA[<h4>Our experience introducing React Native to existing Native (iOS/Android) codebase</h4><h3>Into Brownfield App</h3><p>As you may know, Traveloka already has iOS &amp; Android application and we have been researching about React Native since October 2016. The goal is to reap the benefit of React Native in our main application. Integrating React Native into brownfield/existing application means we need to be careful to develop our workflow so we don’t disrupt iOS &amp; Android development.</p><blockquote>3 weeks to integrate, strictly no disruption to native development.</blockquote><p>That’s the deal we have to signed with the stakeholders. To make it possible, we came up with the idea to host React Native repository as the parent repository for native repositories, to keep it similar to common React Native structure.</p><h4>Git Submodules to the Rescue</h4><p>We are aware that we need to make each workflow isolated to prevent development interruption.</p><p>To achieve this expectation, we relied on <a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules">git submodules</a> to manage our development workflow. We decided to make iOS &amp; Android repository as our submodules so we can use them in our codebase and we won’t affect them. By doing so, we keep our workflow separated for each platform and we can maintain our agility because we don’t interfere each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*HegOjdNCXsZVv-7jBx6zLQ.png" /><figcaption>Traveloka Application Structure</figcaption></figure><p>Even though we got benefits using git submodules to manage our repository and currently suitable for our use case, we don’t suggest to use git submodules because it may be not suitable for your use case.</p><p><strong>Git submodules pros:</strong></p><ul><li>We can work independently on each repository without interrupting each other, as each submodule treated as separate repository</li><li>No changes required to existing Native workflow</li></ul><p><strong>Git submodules cons:</strong></p><ul><li>Using submodules is harder to understand; People tend to forget to update their iOS/Android submodule when switching branch so it might cause an error</li><li>Complexity added to our development/deployment pipeline to handle git submodules workflow. For example, we need to set up CI/CD to pull latest branch from submodule with same branch name if exists or fallback to default branch in case we forget to update our submodule</li></ul><h3>Introducing React Native to Existing Codebase</h3><p>After we managed to setup our workflow, the next challenge is how to <strong>inject </strong>our React Native codebase into Native codebase (read details <a href="https://facebook.github.io/react-native/docs/integration-with-existing-apps">here</a>). We worked together with iOS &amp; Android core team to get the best solution for this integration. We discussed about navigation, managing third party libraries, bridging data, and native modules that could be shared to React Native side and also deployment workflow.</p><p>Currently we are using multiple React Native roots to make each module separated. Using this approach, we can split navigation and redux state so it won’t intermingle with each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VEjv-cZY0AGkKl_Cxzdtw.png" /><figcaption>Multiple React Native Roots</figcaption></figure><h4>Noticeable Increment of Application Size in Android</h4><p>In the early implementation, adding React Native to Native codebase led to ±15MB addition of the APK size. It was a really messed up situation, so we began to analyze our implementation that end up with lot of unused libraries and codes, that exists since our early learning period. In the next release we were able to cut nearly ±7MB from our APK size.</p><p>We need to solve this issue as soon as possible because application size is one of the factors that matters when user want to download our application.</p><h4>React Native Context Preloading in Android</h4><p>Beside huge increment to the application size, our React Native activity took almost <strong>3 seconds</strong> to start. We thought that should be optimized because we don’t want user to wait for that long. Luckily, we found this <a href="https://medium.com/@william.liu/preloading-react-native-bridge-2d9c109440a4">article</a> that explains how to preload React Native context in main activity. Using this approach, we managed to reduce start up time to become <strong>100–200 milliseconds!</strong></p><h4><strong>How Do We Communicate to Each Other — Native and React Native</strong></h4><p>Sometimes we need to perform communication between platforms to notify each other. For example, Native should notify React Native regarding changes on user session. This can be achieved by creating bridges or native modules on <a href="https://facebook.github.io/react-native/docs/native-modules-ios">iOS</a> &amp; <a href="https://facebook.github.io/react-native/docs/native-modules-android">Android</a> so React Native can access platform specific API.</p><p>When creating native modules on iOS &amp; Android, we need to make sure that we expose the same API for both platform so it will be easier when we use it on React Native. We are using modules from Native iOS &amp; Android and bridge it so we can consume it and make development becomes much easier.</p><h4>Third Party Dependencies Version Conflict with Native iOS/Android</h4><p>Sometimes we face conflicts regarding third party dependencies with Native iOS/Android because we use different version. Resolving this problem can be achieved in several ways:</p><blockquote><strong>Update dependency — if possible.</strong></blockquote><p>It is the easiest solution to solve version conflict. You just need to update the version as required on both platforms</p><blockquote><strong>Sometimes we need to fork and maintain library, so we can adjust it to what we need</strong></blockquote><p>Currently we are maintaining React Native <a href="https://github.com/traveloka/react-native">fork</a> to adjust YogaKit version because iOS team already use their own version of YogaKit. Therefore, we need to modify React.podspec to follow our existing Yoga version and using this forked repository as dependency on Cocoapods.</p><h4>JavaScript Third Party Resolution on Native</h4><p>It’s common in React Native to use node_modules when defining dependency on iOS’s Podfile and Android’s Gradle. But there’s a requirement that Native developer should be able to run their code as usual without having to do any additional setup (node.js installation) in their development environment.</p><blockquote><strong>Use Third Party Repository as Pod Source on iOS</strong></blockquote><p>As described in Cocoapods <a href="https://guides.cocoapods.org/syntax/podfile.html#pod">documentation</a>, we can use git repository as Pod source. Git repository will replace node_modules to define any third party that will be used on React Native.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZbasBn_oQDcVOj2JYQhzQ.png" /></figure><blockquote><strong>No-op Modules on Android</strong></blockquote><p>On Android, we solved this issue by using no-op modules. No-op modules is being used to mock implementation of real module as described <a href="https://medium.com/traveloka-engineering/3-years-of-android-in-traveloka-a65a5ee3881d">here</a> — <em>no-op modules part</em>. Android developers will use React Native no-op implementation because they don’t need any JavaScript code but we still require dependencies from node_modules when using our real implementation.</p><p>Sometimes it will cause problem when Android team updating their architecture (Gradle update, Refactoring code, etc) with our module being mocked. Error will only be discovered after we update Android submodule. To resolve this issue, Android team create integration test that use our real implementation so we can catch the problem faster.</p><h4>Daily Build to Catch Deployment Problem Before Release</h4><p>We also learned it the hard way from our experience that we had a problem when we were going to deploy our app to production. Error only occurred on production and we are not aware about that until our CI told us that it was failed. Imagine you cannot build production APK several hours before app submission. We then scheduled daily release build in our pipeline to catch any deployment problem, so we can react faster if there’s a problem in release build.</p><p>After this implementation, there has been 4 release cycles that is going smoothly without any deployment problem.</p><h3>Conclusion</h3><p>Brownfield application has much more complexities in implementation when compared to greenfield application. You need to have more preparation and processes to have a smooth brownfield integration.</p><p>However, almost all of the difficulties are one-time only. The benefits that we get by giving product team more choices in their tool of development outweighs the initial setup cost we need to pay.</p><p>We can develop new features faster because most of the code will be shared on both platforms (iOS &amp; Android). <a href="https://facebook.github.io/react-native/docs/native-modules-ios">Native Modules</a> also give us flexibility to reuse existing iOS &amp; Android modules on React Native. It also provide <a href="https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html">hot reloading</a>, so we can iterate faster when developing products and get better development experience. Read on to <a href="https://medium.com/traveloka-engineering/react-native-adoption-4-31fd46814945">Part 4</a> of our article series to get detailed explanations of benefits we get by adopting React Native!</p><p><em>This is the Part 3 in a series of articles about React Native Adoption at Traveloka.</em></p><ul><li><a href="https://medium.com/traveloka-engineering/react-native-adoption-1-165d236dd88f"><em>Part 1 — An Introduction</em></a></li><li><a href="https://medium.com/traveloka-engineering/react-native-adoption-2-c37053a78c42"><em>Part 2 — Traveloka, React Native, District System</em></a></li><li><a href="https://medium.com/traveloka-engineering/react-native-adoption-3-31146e3f59f1"><em>Part 3 — Hybrid Development Experience</em></a></li><li><a href="https://medium.com/traveloka-engineering/react-native-adoption-4-31fd46814945"><em>Part 4 — Boosting Agility in Product Development with React Native</em></a></li><li><a href="https://medium.com/traveloka-engineering/react-native-adoption-5-21d3353e1367"><em>Part 5 — Building Content-Rich Pages on React Native</em></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31146e3f59f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/traveloka-engineering/react-native-adoption-3-31146e3f59f1">React Native at Traveloka: Hybrid Development Experience</a> was originally published in <a href="https://medium.com/traveloka-engineering">Traveloka Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>