SlideShare a Scribd company logo
1
React-Native
custom
components
2
Who are you?
3
Jeremy Grancher
Front-end developer since 4 years
iOS developer for a year ¯_(ツ)_/¯
Enjoying work at
Loving kittens and Game of Thrones
Holler
http://twitter.com/jgrancher
http://github.com/jgrancher
4
What are you talking about?
The current state of the React-Native components
The need of creating a native component
How to do it
Lessons learned from creating react-native-sketch
5
The {this.state.components}
Good pun, eh?
6
 The growth
Rapid adoption...
Pull requests / month over the year
7
 The growth
...and still ongoing
The spread doesn't slow down
8
 The growth
The core components are awesome...
ActivityIndicatorIOS
DatePickerIOS
DrawerLayoutAndroid
Image
ListView
MapView
Modal
Navigator
NavigatorIOS
PickerIOS
Picker
ProgressBarAndroid
ProgressViewIOS
RefreshControl
ScrollView
SegmentedControlIOS
Slider
SliderIOS
StatusBar
Switch
TabBarIOS
TabBarIOS.Item
Text
TextInput
ToolbarAndroid
TouchableHighlight
TouchableNativeFeedback
TouchableOpacity
TouchableWithoutFeedback
View
ViewPagerAndroid
WebView
9
 The Growth
...and still evolving
(╯°□°)╯︵ ┻━┻)
10
 The Growth
Some explanation:
The rst commit code
On the docs: Navigator comparison
First look: React-Native Navigator Experimental
11
 The Growth
RNPM though.
12
 The Growth
Experimental swipeable list view?
Capture from react-native-swipeable
13
So, I get your point.
React-Native by itself is great.
Solid built-in components list
Overwhelming community
⚡ Moves and evolves quickly
Prioritized features requests in Product Pain
14
But you might need more.
15
 The expansion
Some important components have been built by the community...
<Camera /> component by Loch Wansbrough - ★1130
16
 The expansion
Some important components have been built by the community...
<Maps /> component by Leland Richardson - ★912
17
 The expansion
Some important components have been built by the community...
<Video /> component by Brent Vatne - ★689
18
 The expansion
Some important components have been built by the community...
var RNFS = require('react-native-fs');
// Create a path you want to write to
var path = RNFS.DocumentDirectoryPath + '/test.txt';
// Write the file
RNFS.writeFile(path, 'Hello React-Native Sydney!', 'utf8')
.then((success) => console.log('Valar Morghulis!'))
.catch((err) => console.log('You know nothing.', err.message));
A le-system access by Johannes Lumpe - ★349
19
 The expansion
...and will stay that way.
¯_(ツ)_/¯
20
So, when will you need
a custom component?
21
 The customisation
When you need a wrapper not found in...
The core components (UIKit classes: View, Button, TabBar...)
The community components (Camera, Maps, ActionSheet,
FileSystem...)
Bad luck.
You'll have to build that logic in Objective-C / Java yourself...
22
Nooooooo
Catelyn Stark didn't know anything about iOS development.
23
 The customisation
... or...
You have built a native iOS / Android component that you want to
use in JS without reimplementing the logic.
Lucky you.
Because react-native will let you create a bridge for it.
24
25
 The customisation
A native component can be...
A "utility" that plays with the platform API (ie. FileSystem)
A "UI component" that renders a native view along with it (ie. Maps)
26
How to create a custom
component?
27
DEMO
28
The iOS code explained
29
Creating a custom utility component
In the root of your project, use this CLI command to generate your
native component:
// In your react-native project
$ react-native new-library --name MyComponent
That will create a sample component here (not in ./Libraries?)
./node_modules/react-native/Libraries/MyComponent
30
Creating a custom utility component
Then, you need link it to your application:
Drag and drop your component's .xcodeproj le into 'Libraries'
31
Creating a custom utility component
Finally, add your static library to the libraries linked to the binary.
Drag and drop your component's .a le into 'Build Phases'
32
Creating a custom utility component
The important things:
The class has to extend the protocol:<RCTBridgeModule>
// MyComponent.h
#import "RCTBridgeModule.h"
@interface MyComponent : NSObject <RCTBridgeModule>
@end
That will automagically allow this class to access the React world.
33
Creating a custom utility component
The important things:
The class has to call the RCT_EXPORT_MODULE() macro:
// MyComponent.m
@implementation MyComponent
RCT_EXPORT_MODULE(); // Default module name: Same as class name
@end
That will allow you to access, in JS, the module named:
<MyComponent />
34
Creating a custom utility component
The important things:
The class has to call RCT_EXPORT_METHOD() macro if you want to
call a method from your JS code.
// MyComponent.m
RCT_EXPORT_METHOD(doSomethingWithThatString:(NSString *)string)
{
RCTLogInfo(@"A man needs a string: %@", string);
}
That will allow you to do, in JS:
MyComponent.doSomethingWithThatString('Hello');
35
Creating a custom utility component
We can (we have to!) nally wrap our module in a React component.
// MyComponent.ios.js
var NativeComponent = require('NativeModules').MyComponent;
var MyComponent = {
declaringYourLoveTo: function(string) {
// You can do a check here, pass a default parameter, etc...
NativeComponent.doSomethingWithThatString(string);
}
};
module.exports = MyComponent;
Finally, in your code:
MyComponent.declaringYourLoveTo('React Native');
36
Creating a custom utility component
A bit more...
RCTConvert is your friend.
#import "RCTConvert.h"
// ...
RCT_EXPORT_METHOD(doSomethingWithThatColor:(NSString *)hexaColor)
{
UIColor *color = [RCTConvert UIColor:hexaColor];
}
That will allow you to do, in JS:
MyComponent.doSomethingWithThatColor('#123456');
37
Creating a custom utility component
A bit more...
The return type of bridge methods is always void.
If you need to get some data from a native method,
you'll have to use Promises, as the bridge is asynchronous.
RCT_EXPORT_METHOD(findSomethingAsynchronous,
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
NSArray *results = ...
if (results) { resolve(results); }
else {
NSError *error = ...
reject(@"no_results", @"There were no results", error);
}
}
That will allow you to do, in JS:
MyComponent.findSomethingAsynchronous().then((r) => console.log(r));
38
Creating a custom utility component
Your module can also..
Specify which thread its methods should be run on
Export constants to JS
Send events to JS
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
@implementation MyComponent
@synthesize bridge = _bridge;
- (void)methodThatSendsAnEvent
{
[self.bridge.eventDispatcher sendAppEventWithName:@"CheeseReminder"
body:@{@"content": "I love cheese"}];
}
@end
// In JS
NativeAppEventEmitter.addListener('CheeseReminder', (reminder) => {
console.log(reminder.content);
});
39
40
Creating a custom UI component
A UI component is a custom component that renders something.
Same as before, but...
41
Creating a custom UI component
You will create a new class that extends UIView.
Your manager (kind of view controller, but singleton) has now to
be a subclass of RCTViewManager.
// MyComponentManager.h
#import "RCTViewManager.h"
@interface MyComponentManager : RCTViewManager
@end
42
Creating a custom UI component
The manager is responsible of the view.
// MyComponentManager.m
#import "MyComponentManager.h"
#import "MyComponentView.h"
@implementation MyComponentManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
return [[MyComponentView alloc] init];
}
...
// Your other RCT_EXPORT_METHOD methods here...
@end
43
Creating a custom UI component
Use RCT_EXPORT_VIEW_PROPERTY() to set things in your view.
// MyComponentManager.m
RCT_EXPORT_VIEW_PROPERTY(lovingCheese, BOOL)
// MyComponentView.h
@interface MyComponentView: UIView
@property (nonatomic, assign) bool lovingCheese;
@end
// MyComponent.ios.js
MyComponent.propTypes = {
lovingCheese: React.PropTypes.bool,
};
44
React-Native-Sketch
A react-native component for touch-based drawing.
45
React-Native-Sketch
Lessons learned by creating my own custom component:
It's really cool to publish something to npm
The frequent changes to the API forces you to be reactive
It's harder than I thought to get feedbacks & contributions
46
Conclusion
Custom components can solve a feature request uncovered. Yet.
Facebook has created a great tool to allow us extend their tool.
If you have to build your own, check the docs regularly.
Don't be afraid of native code.
47
Resources
Native Modules documentation
Native UI Components documentation
React-Native View Components (by Brent Vatne)
Building Custom React Native Components From Scratch (by Jay
Garcia)
How to Bridge an Objective-C View Component (by Jason Brown)
Awesome React-Native
JS.Coach
48
Other components from the community
react-native-activity-view
react-native-custom-segmented-control
react-native-device-info
react-native-icons
react-native-overlay
react-native-search-bar
react-native-sound
49
Merci.
@jgrancher
Link of this presentation: goo.gl/fpmXem
50
Questions?

More Related Content

What's hot (20)

PDF
Optimizing React Native views for pre-animation
ModusJesus
 
PDF
Introduction to React Native
Rami Sayar
 
PDF
React Native +Redux + ES6 (Updated)
Chiew Carol
 
PDF
React Native: React Meetup 3
Rob Gietema
 
PDF
Workshop 15: Ionic framework
Visual Engineering
 
PDF
Lo mejor y peor de React Native @ValenciaJS
Marcel Kalveram
 
PDF
An Overview of the React Ecosystem
FITC
 
PPTX
How native is React Native? | React Native vs Native App Development
Devathon
 
PDF
React Native in a nutshell
Brainhub
 
PDF
Angular 2 Essential Training
Patrick Schroeder
 
PDF
Introduction to React Native & Redux
Barak Cohen
 
PDF
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
Kobkrit Viriyayudhakorn
 
PPTX
React Native
Heber Silva
 
PDF
Angular2 Development for Java developers
Yakov Fain
 
PDF
Intro to react native
ModusJesus
 
PDF
Workshop 24: React Native Introduction
Visual Engineering
 
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Codemotion
 
PDF
Angular 2 overview
Jesse Warden
 
PPTX
Android jetpack compose | Declarative UI
Ajinkya Saswade
 
PDF
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 
Optimizing React Native views for pre-animation
ModusJesus
 
Introduction to React Native
Rami Sayar
 
React Native +Redux + ES6 (Updated)
Chiew Carol
 
React Native: React Meetup 3
Rob Gietema
 
Workshop 15: Ionic framework
Visual Engineering
 
Lo mejor y peor de React Native @ValenciaJS
Marcel Kalveram
 
An Overview of the React Ecosystem
FITC
 
How native is React Native? | React Native vs Native App Development
Devathon
 
React Native in a nutshell
Brainhub
 
Angular 2 Essential Training
Patrick Schroeder
 
Introduction to React Native & Redux
Barak Cohen
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
Kobkrit Viriyayudhakorn
 
React Native
Heber Silva
 
Angular2 Development for Java developers
Yakov Fain
 
Intro to react native
ModusJesus
 
Workshop 24: React Native Introduction
Visual Engineering
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Codemotion
 
Angular 2 overview
Jesse Warden
 
Android jetpack compose | Declarative UI
Ajinkya Saswade
 
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 

Viewers also liked (20)

PDF
React native - What, Why, How?
Teerasej Jiraphatchandej
 
PDF
Intro To React Native
FITC
 
PPTX
React Native
Artyom Trityak
 
PDF
The mobile-web-at-a-snails-pace
Marcel Kalveram
 
PDF
Developing Apps With React Native
Alvaro Viebrantz
 
PDF
Locly Native Theme Examples
Locly
 
PDF
Navigation in React Native
Sambhu Lakshmanan
 
PDF
[React-Native Tutorial] Lecture 8: Midterm Exam Discussion, Feedback, and Ter...
Kobkrit Viriyayudhakorn
 
PPTX
Chapter 15 terms
Emma Rogers
 
PPT
Mapa de Áreas Prioritárias para a Biodiversidade - Amazônia - Ronaldo Weigand
Ronaldo Weigand Jr
 
DOCX
Esquema comparativo
Angel Guerrero
 
PPTX
Mapa conceptual
Blanca Castillo
 
DOCX
Ensayo web.2
Angel Guerrero
 
DOC
Normes i hàbits
escola lescases
 
PPTX
Trevo de Triagem Norte - Obra na Ponte do Bragueto - Brasília
Ronaldo Weigand Jr
 
PDF
Interactúa 2017. Proyecto.
Consejería de Educación - Comunidad de Madrid
 
PDF
Successful case for haima automotive grill part
Alisa Chen
 
ODP
Os Vertebrados
empaul_harris
 
React native - What, Why, How?
Teerasej Jiraphatchandej
 
Intro To React Native
FITC
 
React Native
Artyom Trityak
 
The mobile-web-at-a-snails-pace
Marcel Kalveram
 
Developing Apps With React Native
Alvaro Viebrantz
 
Locly Native Theme Examples
Locly
 
Navigation in React Native
Sambhu Lakshmanan
 
[React-Native Tutorial] Lecture 8: Midterm Exam Discussion, Feedback, and Ter...
Kobkrit Viriyayudhakorn
 
Chapter 15 terms
Emma Rogers
 
Mapa de Áreas Prioritárias para a Biodiversidade - Amazônia - Ronaldo Weigand
Ronaldo Weigand Jr
 
Esquema comparativo
Angel Guerrero
 
Mapa conceptual
Blanca Castillo
 
Ensayo web.2
Angel Guerrero
 
Normes i hàbits
escola lescases
 
Trevo de Triagem Norte - Obra na Ponte do Bragueto - Brasília
Ronaldo Weigand Jr
 
Successful case for haima automotive grill part
Alisa Chen
 
Os Vertebrados
empaul_harris
 
Ad

Similar to React Native custom components (20)

PDF
React Native for multi-platform mobile applications
Matteo Manchi
 
PPTX
Making React Native UI Components with Swift
Ray Deck
 
PDF
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Codemotion
 
PPTX
Lecture 2 Styling and Layout in React Native.pptx
GevitaChinnaiah
 
PDF
React native: building native iOS apps with javascript
Polidea
 
PDF
Mobile Day - React Native
Software Guru
 
PDF
Introduzione a React Native - Facebook Developer Circle Rome
Matteo Manchi
 
PDF
Pieter De Baets - An introduction to React Native
tlv-ios-dev
 
PDF
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Codemotion
 
PDF
React Native Components Building Blocks for Dynamic Apps.pdf
Gargi Raghav
 
PPTX
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
PPTX
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
PDF
Philip Shurpik "Architecting React Native app"
Fwdays
 
PDF
JSAnkara Swift v React Native
Muhammed Demirci
 
PDF
"React Native" by Vanessa Leo e Roberto Brogi
ThinkOpen
 
PDF
GITS Class #20: Building A Fast and Responsive UI in React Native
GITS Indonesia
 
PPTX
React native introduction (Mobile Warsaw)
Jarek Potiuk
 
PDF
Strategies for Using React Native in a Brownfield App
Harry Tormey
 
PPTX
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
Codemotion
 
PDF
Top react native libraries to watch out for in 2022 overview and offerings
Shelly Megan
 
React Native for multi-platform mobile applications
Matteo Manchi
 
Making React Native UI Components with Swift
Ray Deck
 
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Codemotion
 
Lecture 2 Styling and Layout in React Native.pptx
GevitaChinnaiah
 
React native: building native iOS apps with javascript
Polidea
 
Mobile Day - React Native
Software Guru
 
Introduzione a React Native - Facebook Developer Circle Rome
Matteo Manchi
 
Pieter De Baets - An introduction to React Native
tlv-ios-dev
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Codemotion
 
React Native Components Building Blocks for Dynamic Apps.pdf
Gargi Raghav
 
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
Philip Shurpik "Architecting React Native app"
Fwdays
 
JSAnkara Swift v React Native
Muhammed Demirci
 
"React Native" by Vanessa Leo e Roberto Brogi
ThinkOpen
 
GITS Class #20: Building A Fast and Responsive UI in React Native
GITS Indonesia
 
React native introduction (Mobile Warsaw)
Jarek Potiuk
 
Strategies for Using React Native in a Brownfield App
Harry Tormey
 
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
Codemotion
 
Top react native libraries to watch out for in 2022 overview and offerings
Shelly Megan
 
Ad

Recently uploaded (20)

PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Executive Business Intelligence Dashboards
vandeslie24
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 

React Native custom components