Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Native: Things we learned the Hard way

gauravkaushik
September 13, 2017

React Native: Things we learned the Hard way

These are the slides from a talk I gave at Fragments (formerly, droidCon India) 2017, explaining our learnings at Myntra in embracing React Native

gauravkaushik

September 13, 2017
Tweet

Other Decks in Technology

Transcript

  1. Where are we with RN? • More than 80% of

    iOS, and 60% of android on RN
  2. Where are we with RN? • More than 80% of

    iOS, and 60% of android on RN • 95% of our RN codebase common across both platforms
  3. Where are we with RN? • More than 80% of

    iOS, and 60% of android on RN • 95% of our RN codebase common across both platforms • All new features taken up in RN (eg: Myntra Shopping Groups)
  4. What is React Native? • React Native lets you build

    mobile apps using only JavaScript
  5. What is React Native? • React Native lets you build

    mobile apps using only JavaScript • Native & Declarative
  6. What is React Native? • React Native lets you build

    mobile apps using only JavaScript • Native & Declarative • Developer friendly; Learn Once, write anywhere
  7. Basic render flow XML/ Storyboard Native View Hierarchy On-screen render

    Native Tree of React components Native View Hierarchy On-screen render JSX React JS Bridge JS Engine Native UI Thread
  8. Benefits • Saved build times, instant refresh (HMR, Live reload)

    • Over-the-air (OTA) updates, users needn’t update their apps
  9. Benefits • Saved build times, instant refresh (HMR, Live reload)

    • Over-the-air (OTA) updates, users needn’t update their apps • Faster product iteration, and even faster bug-fixes (just like web!)
  10. Benefits • Saved build times, instant refresh (HMR, Live reload)

    • Over-the-air (OTA) updates, users needn’t update their apps • Faster product iteration, and even faster bug-fixes (just like web!) • Cross-platform code sharing
  11. Benefits • Saved build times, instant refresh (HMR, Live reload)

    • Over-the-air (OTA) updates, users needn’t update their apps • Faster product iteration, and even faster bug-fixes (just like web!) • Cross-platform code sharing • Saved costs, same dev owns the feature irrespective on both platforms
  12. Managing heavy computational tasks To get JS bridge logs, enable

    SPY mode from MessageQueue module (MessageQueue.spy(true)) JS is single-threaded (and no planned support for web workers in RN)
  13. Managing heavy computational tasks For heavy computational tasks, offload computation

    to native via Native Modules For moderate computation tasks, use InteractionManager.runAfterInteractions()
  14. Managing heavy computational tasks For heavy computational tasks, offload computation

    to native via Native Modules For moderate computation tasks, use InteractionManager.runAfterInteractions() Make sure traffic on your JS bridge is as smooth as possible
  15. Initial screen load time: android Safari RN app iOS JSC

    Engine Already initialised by the OS apps (UIWebView)
  16. Initial screen load time: android Chrome Other apps (WebView) android

    Already initialised by the OS Chrome V8 engine
  17. Initial screen load time: android Chrome Other apps (WebView) android

    Already initialised by the OS Chrome V8 engine JSC Engine Packaged with the app
  18. Initial screen load time: android Our app Chrome Other apps

    (WebView) android Already initialised by the OS Chrome V8 engine JSC Engine Packaged with the app
  19. Initial screen load time: android JS engine/runtime initialisation (~400ms on

    low- end devices) Loading of bundle onto engine and eventual execution (time depends on bundle size and kind of device)
  20. Initial screen load time: android JS engine/runtime initialisation (~400ms on

    low- end devices) Loading of bundle onto engine and eventual execution (time depends on bundle size and kind of device) More on this later
  21. Navigation in a hybrid (RN+N) app React Native React React

    All existing solutions based on the assumption that entire app in built ground up in RN (eg: reactNavigation, ex-navigation, react-router etc)
  22. Navigation in a hybrid (RN+N) app React Native React React

    All existing solutions based on the assumption that entire app in built ground up in RN (eg: reactNavigation, ex-navigation, react-router etc)
  23. Navigation in a hybrid (RN+N) app React Native React React

    All existing solutions based on the assumption that entire app in built ground up in RN (eg: reactNavigation, ex-navigation, react-router etc)
  24. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation
  25. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation
  26. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation
  27. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation
  28. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation Can we do better?
  29. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation Unnecessary initialisation of two ReactActivities/VCs Can we do better?
  30. Navigation in a hybrid (RN+N) app React Native React React

    Our implementation: Wrap each react screen in its own activity/ ViewController and let a NativeModule handle navigation Unnecessary initialisation of two ReactActivities/VCs Enter react-native-navigation by wix Can we do better?
  31. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 major bug gets reported Release branch
  32. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 March 1.3.0 major bug gets reported fix with this release Release branch
  33. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 March 1.3.0 major bug gets reported fix with this release RN world fix with this release Release branch
  34. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 March 1.3.0 major bug gets reported fix with this release RN world push fix for 1.1.0 push fix for 1.2.0 fix with this release Release branch
  35. Bundle updates on already installed apps dev Jan 1.1.0 app

    version jsbundle-1.1.0 JS bundle name
  36. Bundle updates on already installed apps dev Jan 1.1.0 app

    version jsbundle-1.1.0 JS bundle name 1.0.0 JS bundle version
  37. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 app version jsbundle-1.2.0 jsbundle-1.1.0 JS bundle name 1.0.0 1.0.0 JS bundle version
  38. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 major bug app version jsbundle-1.2.0 jsbundle-1.1.0 JS bundle name 1.0.0 1.0.0 JS bundle version
  39. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 major bug app version jsbundle-1.2.0 jsbundle-1.1.0 JS bundle name 1.0.0 1.0.0 JS bundle version 1.0.1
  40. Bundle updates on already installed apps dev Jan Feb 1.1.0

    1.2.0 major bug app version jsbundle-1.2.0 jsbundle-1.1.0 JS bundle name 1.0.0 1.0.0 JS bundle version 1.0.1 1.0.1
  41. Bundle updates on already installed apps dev 1.1.0 batbelt version

    dev Jan Feb 1.1.0 1.2.0 app version Native repos Batbelt repo 1.2.0
  42. Bundle updates on already installed apps major bug dev 1.1.0

    batbelt version dev Jan Feb 1.1.0 1.2.0 app version Native repos Batbelt repo 1.2.0
  43. Bundle updates on already installed apps major bug dev 1.1.0

    batbelt version dev Jan Feb 1.1.0 1.2.0 app version Native repos Batbelt repo 1.2.0
  44. Bundle updates on already installed apps major bug dev 1.1.0

    batbelt version dev Jan Feb 1.1.0 1.2.0 app version Native repos Batbelt repo 1.2.0
  45. Bundle updates on already installed apps major bug dev 1.1.0

    batbelt version dev Jan Feb 1.1.0 1.2.0 app version Native repos Batbelt repo 1.2.0 1.1.1 1.2.1
  46. Bundle updates on already installed apps initially on dev branch

    checkout to 1.1.0 branch update versions in package.json, generate and publish bundle
  47. Bundle updates on already installed apps • Target internal audience

    (@myntra.com IDs) for a day or two, and then do percentage rollouts to external users
  48. Bundle updates on already installed apps • Target internal audience

    (@myntra.com IDs) for a day or two, and then do percentage rollouts to external users • Support at most last 3 (android) & last 2 (iOS) app versions
  49. Bundle updates on already installed apps • Target internal audience

    (@myntra.com IDs) for a day or two, and then do percentage rollouts to external users • Support at most last 3 (android) & last 2 (iOS) app versions • Ensure new features are released simultaneously on both platforms
  50. Product requirements Managing your Product Managers And UX designers Given

    this newfound power, accommodating their ever evolving experiments/requirements
  51. Future plans • Move the rest of the app to

    RN • Ideal state: Single React Activity/VC & Single WebView
  52. Future plans • Move the rest of the app to

    RN • Ideal state: Single React Activity/VC & Single WebView • Divide our bundles into core and feature bundles
  53. Future plans • Move the rest of the app to

    RN • Ideal state: Single React Activity/VC & Single WebView • Divide our bundles into core and feature bundles • OTA diff updates (Sending only what is necessary)
  54. Future of RN landscape • React Fiber, React VR •

    ReactXP by microsoft • A fresh, end to end alternative to REST based implementations (React + Relay + GraphQL)
  55. Future of RN landscape • React Fiber, React VR •

    ReactXP by microsoft • A fresh, end to end alternative to REST based implementations (React + Relay + GraphQL) • Ever growing and active community
  56. Future of RN landscape • React Fiber, React VR •

    ReactXP by microsoft • A fresh, end to end alternative to REST based implementations (React + Relay + GraphQL) • Ever growing and active community • More companies now use it in prod (Instagram, Airbnb, Amazon, Walmart, Flipkart, to name a few)
  57. Conclusion and our take • Cross-platform code-sharing, OTA updates, impeccable

    dev experience • We are android/ios/web mobile developers
  58. Conclusion and our take • Cross-platform code-sharing, OTA updates, impeccable

    dev experience • We are android/ios/web mobile developers • We think react-native and PWAs are the game changing technologies to come out in recent years of mobile evolution