Learning React Native Building Native Mobile Apps With JavaScript 1 (Early Release) Edition Bonnie Eisenman Instant Download
Learning React Native Building Native Mobile Apps With JavaScript 1 (Early Release) Edition Bonnie Eisenman Instant Download
https://ebookname.com/product/learning-react-native-building-
native-mobile-apps-with-javascript-1-early-release-edition-
bonnie-eisenman/
https://ebookname.com/product/enyo-up-and-running-build-native-
quality-cross-platform-javascript-apps-2nd-edition-roy-sutton/
https://ebookname.com/product/building-android-apps-with-html-
css-and-javascript-2nd-edition-jonathan-stark/
https://ebookname.com/product/the-new-path-third-edition-my-life-
with-paramhansa-yogananda-swami-kriyananda/
New World Babel Languages and Nations in Early America
Edward G. Gray
https://ebookname.com/product/new-world-babel-languages-and-
nations-in-early-america-edward-g-gray/
https://ebookname.com/product/beginning-t-sql-3rd-edition-kathi-
kellenberger/
https://ebookname.com/product/intelligent-quantum-information-
processing-1st-edition-siddhartha-bhattacharyya/
https://ebookname.com/product/parables-and-conflict-in-the-
hebrew-bible-1st-edition-jeremy-schipper/
https://ebookname.com/product/top-10-los-angeles-andrea-schulte/
Emily Post s Etiquette 17th Edition Peggy Post
https://ebookname.com/product/emily-post-s-etiquette-17th-
edition-peggy-post/
Learning React Native
Building Mobile Applications with Javascript
Bonnie Eisenman
Boston
{{ title }}
by Author Name
Copyright © 2015
This is a legal notice of some kind. You can add notes about the kind of license you are using for your
book (e.g., Creative Commons), or anything else you feel you need to specify.
If your book has an ISBN or a book ID number, add it here as well.
Table of Contents
1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
How Does React Native Work? 10
The Virtual DOM in React 10
Extending the Virtual DOM 11
The Implications of “Native” 12
Why Use React Native? 13
Learn once, write anywhere 13
Leveraging the native platform 14
Developer tools 14
Using existing platform knowledge 16
Risks and Drawbacks 16
Summary 17
Native VS React for Web 17
The React Native Lifecycle 17
Working with Views in React Native 18
Styling Native Views 20
JSX and React Native 21
Thinking about host platform APIs 21
Summary 22
2. Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Setting Up Your Environment 23
Installing React Native 24
Creating a New Application 24
Running a React Native Application 25
Uploading to Your Device 27
iii
Summary 30
Exploring the Sample Code 30
Attaching a component to the view 31
Imports in React Native 31
The FirstProject Component 32
Summary 32
Introduction to the Tools 32
Using the Chrome Debugger 33
Targeting Different Devices 33
Type-Checking with Flow 34
Testing with Jest 34
Summary 35
Building a Weather App 36
Handling User Input 38
Displaying Data 39
Adding a Background Image 40
Fetching Data from the Web 42
Putting it Together 43
Summary 46
4. Styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Declaring and Manipulating Styles 85
Inline Styles 86
Styling with Objects 86
Using Stylesheet.Create 87
Style Concatenation 87
Organization and Inheritance 89
Exporting Style Objects 89
iv | Table of Contents
Passing Styles as Props 90
Reusing and Sharing Styles 91
Positioning and Designing Layouts 91
Layouts with Flexbox 91
Using Absolute Positioning 97
Putting it Together 98
Summary 102
Table of Contents | v
Preface Title
This Is an A-Head
Congratulations on starting your new project! We’ve added some skeleton files for
you, to help you get started, but you can delete any or all of them, as you like. In the
file called chapter.html, we’ve added some placeholder content showing you how to
markup and use some basic book elements, like notes, sidebars, and figures.
vii
CHAPTER 1
Introduction
9
How Does React Native Work?
The idea of writing mobile applications in Javascript feels a little odd. How is it possi‐
ble to use React in a mobile environment? In this section, we will explore the techni‐
cal underpinnings that enable React Native. We will first need to recall one of React’s
features, the Virtual DOM, and understand how it relates to React Native for mobile.
In the context of React on the web, most developers think of the Virtual DOM pri‐
marily as a performance optimization. Indeed, the Virtual DOM was one of React’s
early claims to fame, and most articles discussing React’s benefits mention perfor‐
mance and the Virtual DOM in the same breath. This focus makes a lot of sense,
given the context. At the time of React’s release, the Virtual DOM approach to ren‐
dering gave it a large performance advantage over existing Javascript frameworks,
especially when dealing with changing data or otherwise render-intensive applica‐
tions. (Since then, React’s model for DOM updates has started to be adopted by other
10 | Chapter 1: Introduction
frameworks, such as Ember.js’s new Glitter engine, though React maintains a strong
lead when it comes to performance.)
12 | Chapter 1: Introduction
and any given host platform can add support for other platforms as well, so it will be
interesting to see where Native expands to next.
For developers accustomed to working on the web with React, this means that you
can write mobile apps with the performance and look-and-feel of a native application,
while using the tools that you know and love. This in turn has huge implications for
how we think about cross-platform application development, prototyping, and code
reuse.
Developer tools
The React Native team has baked strong developer tools and meaningful error mes‐
sages into the framework, so that working with robust tools is a natural part of your
development experience. As a result, React Native is able to remove many of the pain
points associated with mobile development.
14 | Chapter 1: Introduction
For instance, because React Native is “just” Javascript, you do not need to rebuild
your application in order to see your changes reflected; instead, you can hit CMD+R
to refresh your application just as you would any other webpage. Having worked with
both Android and iOS development previously, I always cringe to think about how
much wasted time was spent waiting to recompile my applications for testing. React
Native shrinks that delay from minutes to milliseconds, allowing you to focus on your
actual development work.
Additionally, React Native lets you take advantage of intelligent debugging tools and
error reporting. If you are comfortable with Chrome or Safari’s developer tools, you
will be happy to know that you can use them for mobile development, as well. Like‐
wise, you can use whatever text editor you prefer for Javascript editing: React Native
does not force you to work in Xcode to develop for iOS, or Android Studio for
Android development.
16 | Chapter 1: Introduction
Summary
React Native has much to offer for any developer, but a lot will depend on your indi‐
vidual situation. If you are already comfortable working with React, the value propo‐
sition of React Native is clear: it gives you a low-investment way to transfer your skills
and write for multiple platforms, without the usual drawbacks of cross-platform
development frameworks. Even for developers who are comfortable building tradi‐
tional native mobile applications, there is a lot of appeal here, too. On the other hand,
if total platform stability is a must for you, React Native might not be the best choice.
That being said, with React Native applications doing quite well in the iOS App Store
already, this is a less risky proposition than you might think. Facebook, at least, is bet‐
ting heavily on the React Native approach to mobile development. Though the main
Facebook mobile applications are still written traditionally, you can see React Native
succeeding in the wild by downloading Facebook’s Groups app for iOS, which fea‐
tures a blend of React Native and Objective-C code; or the Ads Manager for iOS,
which is a 100% React Native application.
Hopefully all of this has left you excited to begin working with React Native! In the
next section, we will tackle the information you will need to know in order to work
with React Native as opposed to React in the browser.
After that, React handles the rendering and re-rendering of your component as nec‐
essary.
<div/> <View/>
<span/> <TextView/>
<img/> <ImageView/>
Other components are platform-specific. For instance, the <DatePickerIOS /> com‐
ponent (predictably) renders the iOS standard date picker. Here is an excerpt from
18 | Chapter 1: Introduction
the UIExplorer sample app, demonstrating an iOS Date Picker. The usage is straight‐
forward, as you would expect from React:
<DatePickerIOS
date={this.state.date}
mode="date"
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
/>
This renders to the standard iOS date picker:
Because all of our UI elements are now React components, rather than basic HTML
elements like the <div/>, you will need to explicitly import each component you wish
to use. For instance, we needed to import the <DatePickerIOS /> component like so:
var React = require('react-native');
var {
DatePickerIOS
} = React;
The UIExplorer application, which is bundled into the standard React Native exam‐
ples, allows you to view all of the supported UI elements. I encourage you to examine
the various elements included in the UIExplorer app. It also demonstrates many styl‐
ing options and interactions.
Because these components vary from platform to platform, how you structure your
React components becomes even more important when working in React Native. In
20 | Chapter 1: Introduction
as opposed to stylesheets, takes some mental adjustments, and changes the way you
need to approach writing styles. However, in the context of React Native, it is a useful
shift. We will be discussing styling best practices and workflow later on. Just try not to
be surprised when you see them in use!
Summary
React Native represents a new and intriguing way of using Javascript to target other
platforms. For a web developer familiar with React, it is a tantalizing opportunity to
get up-and-running with mobile app development with very little overhead. There’s a
lot to like about React Native’s approach, as well as plenty of unknowns to explore.
In order to fully take advantage of React Native, there is a lot to learn. The good news
is that your experience with working with React on the web will give you the founda‐
tion you need to be successful with React Native. As we begin writing iOS apps with
React Native in the next chapter, I think you will be pleasantly surprised by how at
home you feel working on a mobile platform. We will begin by tackling the basics of
getting up and running, and learning how to adjust your React best practices to work
on mobile. By the last chapter, you will be ready to deploy a robust iOS application to
the App Store.
22 | Chapter 1: Introduction
CHAPTER 2
Getting Started
In this chapter, we will cover how to set up your local development environment for
working with React Native. Then, we will go through the basics of creating a simple
iOS application, which you will then be able to deploy to your own iOS device.
Though this book uses iOS for the examples, most of the content covered applies
equally well to React Native for other platforms. If you are working with React Native
for Android, or another platform, feel free to skip the environment setup steps. You
can install React Native in accordance with the online documentation and then jump
directly into the React Native code examples.
23
Exploring the Variety of Random
Documents with Different Content
viimeiset helmet ja kultakoristeet, jotka hänellä olivat säilyneet jälelle
suistuneen loistonsa ajoilta, ja antoi ne pojalleen, — ne vähät rahat,
jotka hän Liuksialassa säästelemällä oli saanut kootuksi, oli hän jo
ennen tälle antanut. Pitihän pojan taas yksin ja mierona lähteä
vaeltamaan maailman kylmää, koditonta taivalta, maanpakolaisen
ilotonta vaellusta, jossa hän sai puutetta kärsiä, hänen hyväkseen oli
sureva äiti valmis uhraamaan kaikki… Ja taas he vaipuivat pitkään
syleilyyn.
Myrsky vinkumassa.
*****
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com