SlideShare a Scribd company logo
React Native: Building
Shared Components for
Android and iOS
Calum Gathergood
https://www.linkedin.com/in/calumgathergood/@cgathergood
React Native
Learn once, write anywhere: Build mobile apps
with React
https://facebook.github.io/react-native/
Learn once, write anywhere
Sound familiar?
Write once debug everywhere
React native: building shared components for Android and iOS
React native: building shared components for Android and iOS
StackOverflow Official Developer
Survey 2017
https://insights.stackoverflow.com/survey/2017
72% of respondents labelled themselves as
Web Developers (23% mobile developers)
Javascript is the most popular language for
the 5th year in a row
React is the most loved technology of 2017
Calum’s Unofficial Domain Developer
Survey 2017
5 Android Developers
8 iOS Developers
30 React Developers
Motivations
Don’t trust the sales pitch
Understand the technology
Validate how useful RN can be with our ‘brownfield’
apps
Agent Profiles
React native: building shared components for Android and iOS
Basic Component import React, { Component } from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default class MyComponent extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.paragraph}>
Hello Android Meetup!
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
},
paragraph: {
fontSize: 18,
textAlign: 'center',
color: '#34495e',
},
});
Props
// Main Component
<WelcomeComponent name='Calum' />
// Welcome Component (inside render method)
<Text>Welcome {this.props.name}</Text>
<AgentProfile agentId={1234} />
@Override
protected String getMainComponentName() {
return "AgentProfile";
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName())
{
@Nullable @Override
protected Bundle getLaunchOptions() {
Bundle initialProps = new Bundle();
initialProps.putString("agentId",
getIntent().getStringExtra(EXTRA_AGENT_PROFILE_ID));
return initialProps;
}
};
}
private let props: [String: String]
private lazy var rootView: RCTRootView = {
let releaselocation = RCTBundleURLProvider.sharedSettings().jsBundleURL()
return RCTRootView(bundleURL: releaselocation, moduleName: "AgentProfile",
initialProperties: self.props, launchOptions: nil)
}()
init(agencyId: Int) {
var buildProps: [String: String] = [:]
buildProps["agentId"] = String(describing: agencyId)
self.props = buildProps
super.init(nibName: nil, bundle: nil)
}
React native: building shared components for Android and iOS
enquiryInput: {
fontSize: 18,
marginTop: 20,
color: '#000',
fontFamily: typography.FONT.REGULAR,
...Platform.select({
ios: {
borderRadius: 2,
borderWidth: 1,
borderColor: '#A9AFBA',
},
android: {
marginTop: 18,
},
}),
},
Styling Components
How do we track stats and report
errors?
@ReactMethod
public void trackEvent(String category, final
String action) {
trackingManager.event(category, action);
}
trackEvent(categoryName, eventName) {
TrackingModule.trackEvent(categoryName,
eventName);
}
@objc(trackEvent:eventName:)
public func trackEvent(category: String, eventName: String) {
TrackingController.trackEvent(category, eventName: eventName)
}
Native Bridging
Implementing tracking events
natively:
- Create a native tracking module
- Define methods (match name
with JS)
- Use parameters with existing
tracking managers
Caveats
Debugging
Performance Issues
Learning Curve for initial setup/configuration
Managing multiple components in
a monorepo
"dependencies": {
"react-native-monorepo": "1.2.3",
...
}
Monorepo
Separate development environment
Debugging works
Demo App Available
Our Conclusion
Low barrier for entry (we have heaps of React devs)
Better than a webview - “I can’t believe it’s not Native”
You don’t have to commit to using React Native
Developer Velocity - Write once run everywhere...
Future of RN - React as a platform
React Primitives - Web + Mobile + VR
Codepush
Further development of native components
React Native: Bringing modern web techniques to mobile (Facebook)
Powering UberEats with React Native and Uber Engineering
Leland Richardson - React Native in the "Brown Field" - React Conf 2017
How Airbnb Is Using React Native
React Native at Instagram
create-react-native-app
Try it out now - https://expo.io/
Useful Resources
Thanks!
https://www.linkedin.com/in/calumgathergood/@cgathergood

More Related Content

PPTX
Angular 2 with TypeScript
PDF
Building End-to-End Apps Using Typescript
PDF
Automated Testing with GHUnit and KIF
PDF
Angular.js for beginners
PDF
Stock Price Predictor - Python with AI Student Project
PDF
Basic overview of Angular
PPT
JAX 08 - Agile RCP
PPTX
React Native
Angular 2 with TypeScript
Building End-to-End Apps Using Typescript
Automated Testing with GHUnit and KIF
Angular.js for beginners
Stock Price Predictor - Python with AI Student Project
Basic overview of Angular
JAX 08 - Agile RCP
React Native

Similar to React native: building shared components for Android and iOS (20)

PDF
React Native
PPTX
React Native: Introduction
PPTX
React native tour
PPTX
React Native Building Mobile Apps with React.pptx
PDF
Pieter De Baets - An introduction to React Native
PDF
Mobile Day - React Native
PDF
Introduzione a React Native - Facebook Developer Circle Rome
PPTX
React Native for ReactJS Devs
PDF
React Native
PPTX
JS Fest 2018. Илья Иванов. Введение в React-Native
PPTX
Getting Started With React Native Presntation
PPT
PPTX
Introduction to React Native
PDF
What Is React Native? Guide to Mobile App Development
PPTX
React native
PPTX
React Native.pptx (2)
PDF
Workshop 24: React Native Introduction
PPTX
Creating books app with react native
PPTX
React nativebeginner1
PDF
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
React Native
React Native: Introduction
React native tour
React Native Building Mobile Apps with React.pptx
Pieter De Baets - An introduction to React Native
Mobile Day - React Native
Introduzione a React Native - Facebook Developer Circle Rome
React Native for ReactJS Devs
React Native
JS Fest 2018. Илья Иванов. Введение в React-Native
Getting Started With React Native Presntation
Introduction to React Native
What Is React Native? Guide to Mobile App Development
React native
React Native.pptx (2)
Workshop 24: React Native Introduction
Creating books app with react native
React nativebeginner1
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
1. Introduction to Computer Programming.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Per capita expenditure prediction using model stacking based on satellite ima...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Programs and apps: productivity, graphics, security and other tools
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
1. Introduction to Computer Programming.pptx
Empathic Computing: Creating Shared Understanding
SOPHOS-XG Firewall Administrator PPT.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
Ad

React native: building shared components for Android and iOS

  • 1. React Native: Building Shared Components for Android and iOS Calum Gathergood https://www.linkedin.com/in/calumgathergood/@cgathergood
  • 2. React Native Learn once, write anywhere: Build mobile apps with React https://facebook.github.io/react-native/
  • 3. Learn once, write anywhere Sound familiar?
  • 4. Write once debug everywhere
  • 7. StackOverflow Official Developer Survey 2017 https://insights.stackoverflow.com/survey/2017 72% of respondents labelled themselves as Web Developers (23% mobile developers) Javascript is the most popular language for the 5th year in a row React is the most loved technology of 2017
  • 8. Calum’s Unofficial Domain Developer Survey 2017 5 Android Developers 8 iOS Developers 30 React Developers
  • 9. Motivations Don’t trust the sales pitch Understand the technology Validate how useful RN can be with our ‘brownfield’ apps
  • 12. Basic Component import React, { Component } from 'react'; import { Text, View, StyleSheet } from 'react-native'; export default class MyComponent extends Component { render() { return ( <View style={styles.container}> <Text style={styles.paragraph}> Hello Android Meetup! </Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', }, paragraph: { fontSize: 18, textAlign: 'center', color: '#34495e', }, });
  • 13. Props // Main Component <WelcomeComponent name='Calum' /> // Welcome Component (inside render method) <Text>Welcome {this.props.name}</Text>
  • 15. @Override protected String getMainComponentName() { return "AgentProfile"; } @Override protected ReactActivityDelegate createReactActivityDelegate() { return new ReactActivityDelegate(this, getMainComponentName()) { @Nullable @Override protected Bundle getLaunchOptions() { Bundle initialProps = new Bundle(); initialProps.putString("agentId", getIntent().getStringExtra(EXTRA_AGENT_PROFILE_ID)); return initialProps; } }; }
  • 16. private let props: [String: String] private lazy var rootView: RCTRootView = { let releaselocation = RCTBundleURLProvider.sharedSettings().jsBundleURL() return RCTRootView(bundleURL: releaselocation, moduleName: "AgentProfile", initialProperties: self.props, launchOptions: nil) }() init(agencyId: Int) { var buildProps: [String: String] = [:] buildProps["agentId"] = String(describing: agencyId) self.props = buildProps super.init(nibName: nil, bundle: nil) }
  • 18. enquiryInput: { fontSize: 18, marginTop: 20, color: '#000', fontFamily: typography.FONT.REGULAR, ...Platform.select({ ios: { borderRadius: 2, borderWidth: 1, borderColor: '#A9AFBA', }, android: { marginTop: 18, }, }), }, Styling Components
  • 19. How do we track stats and report errors?
  • 20. @ReactMethod public void trackEvent(String category, final String action) { trackingManager.event(category, action); } trackEvent(categoryName, eventName) { TrackingModule.trackEvent(categoryName, eventName); } @objc(trackEvent:eventName:) public func trackEvent(category: String, eventName: String) { TrackingController.trackEvent(category, eventName: eventName) } Native Bridging Implementing tracking events natively: - Create a native tracking module - Define methods (match name with JS) - Use parameters with existing tracking managers
  • 21. Caveats Debugging Performance Issues Learning Curve for initial setup/configuration
  • 22. Managing multiple components in a monorepo "dependencies": { "react-native-monorepo": "1.2.3", ... }
  • 24. Our Conclusion Low barrier for entry (we have heaps of React devs) Better than a webview - “I can’t believe it’s not Native” You don’t have to commit to using React Native Developer Velocity - Write once run everywhere...
  • 25. Future of RN - React as a platform React Primitives - Web + Mobile + VR Codepush Further development of native components
  • 26. React Native: Bringing modern web techniques to mobile (Facebook) Powering UberEats with React Native and Uber Engineering Leland Richardson - React Native in the "Brown Field" - React Conf 2017 How Airbnb Is Using React Native React Native at Instagram create-react-native-app Try it out now - https://expo.io/ Useful Resources

Editor's Notes

  • #2: Intro - who am I, what do I do?
  • #3: React = a js library for building user interfaces: component based, React - 2013 RN - 2015
  • #4: Write Once, run anywhere - Sun microsystems 1996 on Java Previous attempts at x platform development have mostly been webviews
  • #5: Predominantly renders into a webview (with the exception of Xamarin)
  • #6: Establish definition of brownfield vs greenfield Greenfield apps - Uber Eats Instagram + Airbnb
  • #7: If you have interacted with these screens then you have used React Native After this we were curious to understand the technology
  • #8: Over 64,000 respondents Javascript’s 5th year in a row at number 1 (select all that apply) Java is high (3rd after SQL) Swift vs Obj C is pretty even No Kotlin :(
  • #10: Taking a skeptical approach
  • #11: Real estate Agents like to see their faces Single Page showing agent profile information Would have traditionally used a webview Good use case Relatively low traffic (we have existing stats on this) Images, text, lists of property listings Currently able to send enquiry or phone
  • #13: JSX is a preprocessor step that adds XML syntax to JavaScript.
  • #15: The props is the agentId We want our native apps to render this
  • #16: Agent React Activity - extends ReactActivity
  • #17: AgentViewController.swift
  • #18: Different styles?
  • #19: Platform specific styling
  • #20: Domain is data driven We want to maintain our google analytics session - don’t break the flow In order to do this we want the react component to communicate back to each native app
  • #21: Native Bridge (Tracking) Shows how to define ReactMethods - extends ReactContextBaseJavaModule Links in with existing tracking SafeModule App flow is uninterrupted (analytics) Also catches errors in Fabric
  • #22: Android Images use fresco under the hood Flatlist issues Native devs had to JS / JS devs had to learn native ecosystems to a minor degree
  • #23: Single NPM module Centralised repo - minimal JS in the native codebases In the package.json Native PR is only a version number increase
  • #24: Separate Demo App - allows React developers to work away from the Native codebases Debugging is possible here Hot reloading + live reload - no recompiling here
  • #25: Ultimately RN is rendered natively Good for atomic single uses i.e. low-traffic screen Don’t have to go all in! With our monorepo react devs can work on it without interfering with the native teams
  • #26: React Primitives - This library attempts to propose an ideal set of primitives around building React applications, regardless of Platform. Codepush - is a cloud service that enables Cordova and React Native developers to deploy mobile app updates directly to their users’ devices. It works by acting as a central repository that developers can publish certain updates to (e.g. JS, HTML, CSS and image changes), and that apps can query for updates from (using our provided client SDKs).