avatarTrevor-Indrek Lasn

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4192

Abstract

developer.android.com/studio/install.html">Android Studio</a> (Android) — <a href="https://www.youtube.com/watch?v=Q0dERWCzoi0">Watch this tutorial to properly setup the android simulator!</a></li><li>Optional: <a href="https://expo.io/">Expo</a>— I do recommend this.</li><li>I also recommend getting the <a href="https://docs.expo.io/versions/latest/workflow/expo-cli/">Expo CLI</a> tooling.</li></ul><p id="2718">Make sure you have everything required before continuing.</p><h1 id="a0b1">Installing and Setting Up Our Native App Development Environment</h1><p id="8910">Open your terminal and run a couple of commands for installing React Native and launching your preferred simulator.</p><p id="6698"><code> npm install -g create-react-native-app</code></p><p id="75fc"><code> create-react-native-app react-native-redux-crypto-tracker && cd react-native-redux-crypto-tracker</code></p><p id="b104">You should end up with something close to this:</p><figure id="dc39"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*paVZ5nMedCRkQD_lQDLt7w.png"><figcaption><b>Installing react-native and creating a react-native project</b></figcaption></figure><p id="b84b">We’re almost there.</p><p id="2b72">Next up, we need to just serve our project. Type the next command in the terminal. You can choose between iOS or Android simulators. Press <code>I</code> for iOS and <code>a</code> for Android.</p><p id="97af">I have chosen iOS for this guide, but it works on both operating systems! I personally like both iPhone and Android phones, and you can choose per your preference.</p><ul><li>(simulator)<i></i><code> npm run ios</code> — iOS</li><li>(simulator )<i>— </i><code> npm run android</code> — Android</li><li>(Physical device )— <code>$ npm run start</code> — QR code<b> </b>and<b> </b>options. Open your mobile camera and point it to the QR code. Also, you’re going to need the <a href="http://expo.io">expo</a> app as well. <a href="https://play.google.com/store/apps/details?id=host.exp.exponent&amp;hl=en">Expo for Android</a><a href="https://apps.apple.com/us/app/expo-client/id982107779">Expo for iOS</a></li></ul><figure id="7c8b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7yGyQfu1Ka4cCLTvjF3Esw.png"><figcaption></figcaption></figure><figure id="3dc2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*nT_fr_Sii85qX3DMjQkOoA.png"><figcaption></figcaption></figure><figure id="5b41"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*A0ggyftqjj7BJwBw4tJjnA.png"><figcaption></figcaption></figure><p id="74d6">The iPhone X simulator works beautifully in harmony with RN. Thanks Facebook team for the great implementation and execution! 👍</p><p id="211d">As we can see, there are quite a lot of things going on. From the top, we can see</p><p id="6995"><code>import { StyleSheet, Text, View } from ‘react-native’;</code></p><p id="c655">What is this exactly?</p><h1 id="ec55"><Text></h1><p id="af48"><code>Text</code> is <a href="https://reactjs.org/docs/introducing-jsx.html">JSX</a> — a syntax for embedding XML within JavaScript.</p><p id="0d7b">Many frameworks use a special templating language that lets you embed code inside markup language. In React, this is reversed. JSX lets you write your markup language inside the code.</p><p id="74f0">It looks like HTML on the web, except instead of web things like <code><div></code> or <code><span></code>, you use React components. In this case, <code><Text></code> is a built-in component that just displays some text.</p><p id="dc66">TL;DR: A React component for displaying text.</p><h1 id="a347"><View></h1><p id="7aac">The most fundamental component for building a UI. <code>View</code> is a container that supports layout with <a href="https://facebook.github.io/react-native/docs/flexbox.html">flexbox</a>, <a href="https://facebook.github.io/react-native/docs/style.html">style</a>, <a href="https://facebook.github.io/react-native/docs/handling-touches.html">some touch handling</a>, and <a href="https://facebook.github.io/react-native/docs/accessibility.html">accessibility</a> controls.</p><p id="7566"><

Options

code>View</code> maps directly to the native view equivalent to whatever platform React Native is running on — whether that is a <code>UIView</code>, <code><div></code>, <code>android.view</code>, or other.</p><p id="280f"><code>View</code> is designed to be nested inside other views and can have from zero to many children of any type.</p><p id="6cfb">This example creates a <code>View</code> that wraps two colored boxes and a text component in a row with padding.</p><h1 id="803e">Style Sheet</h1><p id="2163">A style sheet is an abstraction similar to CSS style sheets.</p><p id="0b1f">It creates a new style sheet. Styling for RN is flexbox based. It u<a href="https://facebook.github.io/yoga/">ses the Yoga layout engine.</a> We pass styles to elements through the <code>style</code> prop.</p><h1 id="bbb8">Building the App</h1><p id="20a3">Start by making a <code>src</code> directory where we place all our code.</p><p id="f26f"><code>$ mkdir src && cd src</code></p><p id="756f">Inside <code>src</code>, create a <code>components</code> directory. Inside the <code>components</code> we’ll place our views.</p><figure id="920d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1XeTgJKL4_6hTuz9a-dATw.png"><figcaption></figcaption></figure><h1 id="8491">Implementing the Header</h1><p id="9210">Make two files inside <code>src/components</code><code>Header.js </code>and <code>index.js</code>.</p><p id="7161"><code>Header.js</code> is for the header of the app, and <code>index.js</code> is for making an import export cleaner.</p><p id="8046">Inside <code>Header.js</code>, implement a stateless component. Try to do it yourself — the most efficient way of learning is actually doing.</p><figure id="bd98"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*FiY8UJ3zklHtb7TcFJ5NWQ.png"><figcaption></figcaption></figure><figure id="916e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*enKifJBTLaAArl2Hm9TDsQ.png"><figcaption></figcaption></figure><p id="79d0">Next up — import the <code>Header.js</code> to the <code>App.js</code> and display it!</p><figure id="58d9"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*fYhxhTaMD2a3bj9s4o6gxA.png"><figcaption></figcaption></figure><p id="f6e9">It works! But wait... why is the title almost hidden by the iPhone default text? We will fix that in the <a href="https://readmedium.com/tutorial-react-native-redux-native-mobile-app-for-tracking-cryptocurrency-bitcoin-litecoin-810850cf8acc">next chapter!</a></p><div id="67a7" class="link-block"> <a href="https://readmedium.com/tutorial-react-native-redux-native-mobile-app-for-tracking-cryptocurrency-bitcoin-litecoin-810850cf8acc"> <div> <div> <h2>Let’s Build: Cryptocurrency Native Mobile App With React Native + Redux — Chapter II</h2> <div><h3>Welcome back! Here’s the chapter I.</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*_i_Yd7kHAn3D03mqD47kuQ.png)"></div> </div> </div> </a> </div><h1 id="2260">Source Code</h1><div id="1a54" class="link-block"> <a href="https://github.com/indreklasn/react-native-redux-crypto-tracker"> <div> <div> <h2>indreklasn/react-native-redux-crypto-tracker</h2> <div><h3>💎 Learn how to build a Redux + React Native cryptocurrency app - indreklasn/react-native-redux-crypto-tracker</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*f2xUdhVpCAGBg2c8)"></div> </div> </div> </a> </div><p id="77bc">If you want to bring your JavaScript to the next level, start from <a href="https://amzn.to/2k7AZHj"><i>this book</i></a>. Find the kindle version <a href="https://amzn.to/2XJ0KQY"><i>here</i></a>.</p><p id="de05">Thanks for reading!</p></article></body>

Let’s Build: Cryptocurrency Native Mobile App With React Native + Redux

Demo — What we’ll be building

The final product

I’m going to teach you how to write a native mobile app with React Native and Redux. Let’s dive in!

Become a Medium Member to directly support my work. You’ll also get full access to every story on Medium. Thanks in advance!

What is React Native?

React Native lets you build mobile apps using only JavaScript. It uses the same design as React, letting you compose a rich mobile UI from declarative components.

Why Are We Using React Native Instead of Swift, Kotlin, Java or Objective-C?

It all comes down to preference really. Here are the main scenarios:

  • Perhaps you already know some React. In this case, building React Native apps will be an absolute pleasure. RN tooling is great.
  • Cross platform. Learn once, write anywhere. Instead of writing your Android app in Kotlin and your iOS app in Swift — you can write both of them in React Native and save a huge chunk of time and budget.
  • Easier to transition into mobile development from a web background.
  • JavaScript — one language to rule all.
  • Ability to quickly push updates directly to a published app — bypassing the app store review process and timeline.

Please keep in mind that, in the end, only one thing matters — whatever works best for you and makes you happy.

It’s fair to say React Native is mature by now. A lot of companies have adapted to RN (including Facebook native apps) — the demand is very high in the job market.

RN Showcase

What is Redux?

Redux is a predictable state container for JavaScript apps.

If you’re not too familiar with Redux, the article below is a nice tutorial on how to apply Redux to React apps.

Why Are We Using Redux?

  • Redux makes the complicated parts (state management) more predictable and easier to reason about.
  • Decouple state from views. What I mean by that exactly, is to let React handle the views and Redux handle the state of the app.
  • Clean code and best practices.
  • Great tooling and middleware to make developing more enjoyable.

Let’s start!

Prerequisites:

Make sure you have everything required before continuing.

Installing and Setting Up Our Native App Development Environment

Open your terminal and run a couple of commands for installing React Native and launching your preferred simulator.

$ npm install -g create-react-native-app

$ create-react-native-app react-native-redux-crypto-tracker && cd react-native-redux-crypto-tracker

You should end up with something close to this:

Installing react-native and creating a react-native project

We’re almost there.

Next up, we need to just serve our project. Type the next command in the terminal. You can choose between iOS or Android simulators. Press I for iOS and a for Android.

I have chosen iOS for this guide, but it works on both operating systems! I personally like both iPhone and Android phones, and you can choose per your preference.

  • (simulator)$ npm run ios — iOS
  • (simulator )$ npm run android — Android
  • (Physical device )— $ npm run start — QR code and options. Open your mobile camera and point it to the QR code. Also, you’re going to need the expo app as well. Expo for AndroidExpo for iOS

The iPhone X simulator works beautifully in harmony with RN. Thanks Facebook team for the great implementation and execution! 👍

As we can see, there are quite a lot of things going on. From the top, we can see

import { StyleSheet, Text, View } from ‘react-native’;

What is this exactly?

<Text>

Text is JSX — a syntax for embedding XML within JavaScript.

Many frameworks use a special templating language that lets you embed code inside markup language. In React, this is reversed. JSX lets you write your markup language inside the code.

It looks like HTML on the web, except instead of web things like <div> or <span>, you use React components. In this case, <Text> is a built-in component that just displays some text.

TL;DR: A React component for displaying text.

<View>

The most fundamental component for building a UI. View is a container that supports layout with flexbox, style, some touch handling, and accessibility controls.

View maps directly to the native view equivalent to whatever platform React Native is running on — whether that is a UIView, <div>, android.view, or other.

View is designed to be nested inside other views and can have from zero to many children of any type.

This example creates a View that wraps two colored boxes and a text component in a row with padding.

Style Sheet

A style sheet is an abstraction similar to CSS style sheets.

It creates a new style sheet. Styling for RN is flexbox based. It uses the Yoga layout engine. We pass styles to elements through the style prop.

Building the App

Start by making a src directory where we place all our code.

$ mkdir src && cd src

Inside src, create a components directory. Inside the components we’ll place our views.

Implementing the Header

Make two files inside src/componentsHeader.js and index.js.

Header.js is for the header of the app, and index.js is for making an import export cleaner.

Inside Header.js, implement a stateless component. Try to do it yourself — the most efficient way of learning is actually doing.

Next up — import the Header.js to the App.js and display it!

It works! But wait... why is the title almost hidden by the iPhone default text? We will fix that in the next chapter!

Source Code

If you want to bring your JavaScript to the next level, start from this book. Find the kindle version here.

Thanks for reading!

React Native
Bitcoin
Mobile App Development
JavaScript
Programming
Recommended from ReadMedium