<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nedim Becirovic</title>
    <description>The latest articles on DEV Community by Nedim Becirovic (@nedimb86).</description>
    <link>https://dev.to/nedimb86</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F56320%2F607d57fd-e132-4144-b9ba-862ac0369196.jpeg</url>
      <title>DEV Community: Nedim Becirovic</title>
      <link>https://dev.to/nedimb86</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nedimb86"/>
    <language>en</language>
    <item>
      <title>React Native — Platform specific code</title>
      <dc:creator>Nedim Becirovic</dc:creator>
      <pubDate>Sun, 13 May 2018 05:39:30 +0000</pubDate>
      <link>https://dev.to/nedimb86/react-native--platform-specific-code-o89</link>
      <guid>https://dev.to/nedimb86/react-native--platform-specific-code-o89</guid>
      <description>&lt;p&gt;With React Native we are writing the code for both, iOS and Android. And it won’t pass long to notice that we need to differ one from another.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F353%2F1%2A27A-seCkORB2P4QyEWIZUQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F353%2F1%2A27A-seCkORB2P4QyEWIZUQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F405%2F1%2Azsngww4SLJp5W5CcwD2xvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F405%2F1%2Azsngww4SLJp5W5CcwD2xvg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F274%2F1%2Aq6svgsA7XjoEX1t2zUw-BQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F274%2F1%2Aq6svgsA7XjoEX1t2zUw-BQ.png"&gt;&lt;/a&gt;Right: Android Emulator Nexus 5 API 23 1080x1920: xxhdpi x86_64&lt;/p&gt;

&lt;p&gt;As we can see, our &lt;em&gt;Header&lt;/em&gt; component, that has the simple task of displaying text behaves differently on Android and iOS. Clearly, we need to have two different styles for the two. So, how can we accomplish this? Good people from the React Native team have provided us with a quite simple solution. They have offered us a module called &lt;strong&gt;&lt;em&gt;Platform&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;All we need to do is to import &lt;em&gt;Platform&lt;/em&gt; from &lt;em&gt;react-native&lt;/em&gt; and we are good to go. The &lt;em&gt;Platform&lt;/em&gt; has &lt;strong&gt;&lt;em&gt;OS&lt;/em&gt;&lt;/strong&gt; property which tells us either we are running our app on &lt;strong&gt;&lt;em&gt;iOS (ios)&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;Android (android)&lt;/em&gt;&lt;/strong&gt;. Furthermore, &lt;em&gt;Platform&lt;/em&gt; comes with a method &lt;em&gt;select&lt;/em&gt; which given an object with a key of &lt;em&gt;Platform.OS&lt;/em&gt; will return the value for the platform we are running our code on.&lt;/p&gt;

&lt;p&gt;Enough talk. Let’s see those in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { View, Text, StyleSheet, Platform } from 'react-native';

export const Header = () =&amp;gt; (
  &amp;lt;View style={styles.header}&amp;gt;
    &amp;lt;Text style={styles.text}&amp;gt;I am Header&amp;lt;/Text&amp;gt;
  &amp;lt;/View&amp;gt;
);

const styles = StyleSheet.create({
  header: {
    height: Platform.OS === 'android' ? 76 : 100,
    marginTop: Platform.OS === 'ios' ? 0 : 24,
    ...Platform.select({
      ios: { backgroundColor: '#f00', paddingTop: 24},
      android: { backgroundColor: '#00f'}
    }),
    alignItems: 'center',
    justifyContent: 'center'
  },
  text: {
    color: '#fff',
    fontSize: 24
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the result of running such code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F558%2F1%2AF4oppM9YhvpThAadRb9LDQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F558%2F1%2AF4oppM9YhvpThAadRb9LDQ.png"&gt;&lt;/a&gt;Header after style applied&lt;/p&gt;

&lt;p&gt;Let’s break down our code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;height: Platform.OS === 'android' ? 76 : 100,
marginTop: Platform.OS === 'ios' ? 0 : 24,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing fancy here. We have already mentioned that &lt;em&gt;Platform.OS&lt;/em&gt; returns &lt;em&gt;ios&lt;/em&gt; or &lt;em&gt;android&lt;/em&gt; depending on the platform it is running on. Combining that with the ternary operator gave us this nice code which helped us set height/margin of our &lt;em&gt;Header&lt;/em&gt;. This code is equivalent to &lt;code&gt;height: 76, marginTop: 24&lt;/code&gt; on Android and &lt;code&gt;height:100, marginTop: 0&lt;/code&gt; on iOS&lt;/p&gt;

&lt;p&gt;Moving along we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...Platform.select({
 ios: { backgroundColor: '#f00', paddingTop: 24},
 android: { backgroundColor: '#00f'}
 }),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we mentioned &lt;em&gt;Platform.select&lt;/em&gt; will return the value given the key from &lt;em&gt;Platform.OS&lt;/em&gt;. So in our case this code becomes &lt;code&gt;...{ backgroundColor: '#f00', paddingTop: 24}&lt;/code&gt; for iOS, and &lt;code&gt;...{ backgroundColor: '#00f'}&lt;/code&gt; for Android.&lt;/p&gt;

&lt;p&gt;So to sum it up, or styles are going to look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Android:
const styles = StyleSheet.create({
 header: {
 height: 76,
 marginTop: 24,
 backgroundColor: '#00f',
 alignItems: 'center',
 justifyContent: 'center'
 },
 text: {
 color: '#fff',
 fontSize: 24
 }
});

-----------------------------------

iOS:
const styles = StyleSheet.create({
 header: {
 height: 100,
 marginTop: 0,
 backgroundColor: '#f00', 
 paddingTop: 24,
 alignItems: 'center',
 justifyContent: 'center'
 },
 text: {
 color: '#fff',
 fontSize: 24
 }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have not come to an end with &lt;em&gt;Platform.select&lt;/em&gt;. The cool thing about it is that it accepts any value, so you can use this to your advantage to return components for iOS/Android. In our case, we have created &lt;em&gt;BodyAndroid.js, BodyIOS.js, and Body.js&lt;/em&gt;. We have replaced default text in &lt;em&gt;App.js&lt;/em&gt; with &lt;em&gt;Body&lt;/em&gt; component. So, our &lt;em&gt;App.js&lt;/em&gt; look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { View} from 'react-native';
import {styles} from "./src/theme/Style";
import { Header } from './src/components/Header';
import { Body } from "./src/components/Body";

export default class App extends React.Component {
  render() {
    return (
      &amp;lt;View style={styles.container}&amp;gt;
        &amp;lt;Header /&amp;gt;
        &amp;lt;Body /&amp;gt;
      &amp;lt;/View&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rest of our code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BodyAndroid.js
import React from 'react';
import { View, Text} from 'react-native';
import {styles} from "../theme/Style";

export const BodyAndroid = () =&amp;gt; (
  &amp;lt;View style={styles.body}&amp;gt;
    &amp;lt;Text style={styles.h1}&amp;gt;This is Android App!&amp;lt;/Text&amp;gt;
  &amp;lt;/View&amp;gt;
);
--------------------------------
BodyIOS.js
import React from 'react';
import { View, Text} from 'react-native';
import {styles} from "../theme/Style";

export const BodyIOS = () =&amp;gt; (
  &amp;lt;View style={styles.body}&amp;gt;
    &amp;lt;Text style={styles.h1}&amp;gt;This is iOS App!&amp;lt;/Text&amp;gt;
  &amp;lt;/View&amp;gt;
);
--------------------------------
Body.js
import { Platform } from 'react-native';

import { BodyAndroid } from './BodyAndroid';
import { BodyIOS } from './BodyIOS'

export const Body = Platform.select({
  ios: BodyIOS,
  android: BodyAndroid
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F510%2F1%2A-jQkLNSm62SMjnpSB_zOQg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F510%2F1%2A-jQkLNSm62SMjnpSB_zOQg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As good as this looks I do not consider it the best solution. There is something called &lt;strong&gt;&lt;em&gt;Platform-specific extension&lt;/em&gt;&lt;/strong&gt; which I prefer. So in the case of iOS, we want to have &lt;code&gt;.ios.&lt;/code&gt; extension, while for Android we will have &lt;code&gt;.android.&lt;/code&gt;. This will help React Native determine which component to use for what platform.&lt;/p&gt;

&lt;p&gt;Let’s illustrate this with an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F353%2F1%2AbNqv2IwY33y28DWwCw_WlQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F353%2F1%2AbNqv2IwY33y28DWwCw_WlQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F660%2F1%2A0D5GGp57xaqUKxfZTbgRPg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F660%2F1%2A0D5GGp57xaqUKxfZTbgRPg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F274%2F1%2AvOY86XGPoRv2OveCzL3MjQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F274%2F1%2AvOY86XGPoRv2OveCzL3MjQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code for our &lt;em&gt;Footer&lt;/em&gt; is very similar to our &lt;em&gt;Header,&lt;/em&gt; therefore, I will not be pasting it here. What is important for us to nice is this simple line &lt;code&gt;import { Footer } from './src/components/Footer';&lt;/code&gt;. As we can notice in the components directory we do not have Footer file, but righter &lt;em&gt;Footer.ios&lt;/em&gt; and &lt;em&gt;Footer.android&lt;/em&gt;. React Native is smart enough to determine which one to use, depending on what platform we are building our app for.&lt;/p&gt;

&lt;p&gt;We have seen how we can add our component using the &lt;em&gt;Platform-specific&lt;/em&gt; extension and &lt;em&gt;Platform.select&lt;/em&gt; method. Was it all that &lt;em&gt;Platform module&lt;/em&gt; can do? Well, no. There is one more thing left and you might have guessed it. It is detecting the version of Android/iOS. So let’s modify our Body message by appending to it the version number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F528%2F1%2AJ-WyBmyljd0UgkcHo7UEvQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F528%2F1%2AJ-WyBmyljd0UgkcHo7UEvQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Showing &lt;em&gt;Platform&lt;/em&gt; version is as simple as calling &lt;strong&gt;&lt;em&gt;Platform.Version&lt;/em&gt;&lt;/strong&gt;. Well… there is a catch. While Android returns the version as an integer, iOS is not so friendly and will give us the version as a string. It should not be difficult to covert it to the integer if we need to compare it (which is the most likely scenario if we need a version number). If we just want to display it we are safe to go with what we get.&lt;/p&gt;

&lt;p&gt;To make everything more interesting, React Native comes with build in components and APIs, some of which are Android/iOS specific. To mention few, for Android we have: &lt;em&gt;DatePickerAndroid, ProgressBarAndroid, ViewPagerAndroid&lt;/em&gt;; as for iOS we have: &lt;em&gt;AlertIOS, ImagePickerIOS, TabBarIOS&lt;/em&gt;. Furthermore, we can write Native modules for our Platform, but that is topic for itself.&lt;/p&gt;

&lt;p&gt;Honorary mention goes to component parameters. Some components have Platform specific parameters which we will cover as we mention each component or set of components.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;To Platform or not to Platform, that is the difficult question. Usage of the platform-specific code is quite simple when it comes to React Native. As we have seen we have the variety of the choices. Either to create a platform-specific component or to make modification in component by determining OS. So it is all up to us, and our case scenario.&lt;/p&gt;

&lt;p&gt;The code used in this article can be found at :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nedimb86/RNPlatform" rel="noopener noreferrer"&gt;nedimb86/RNPlatform&lt;/a&gt;&lt;/p&gt;




</description>
      <category>reactnative</category>
      <category>platformmodule</category>
    </item>
    <item>
      <title>React Native — Intro</title>
      <dc:creator>Nedim Becirovic</dc:creator>
      <pubDate>Thu, 10 May 2018 18:46:04 +0000</pubDate>
      <link>https://dev.to/nedimb86/react-native--intro-1n5i</link>
      <guid>https://dev.to/nedimb86/react-native--intro-1n5i</guid>
      <description>&lt;p&gt;Following my previous &lt;a href="https://dev.to/nedimb86/starting-with-react-native-2edb"&gt;article&lt;/a&gt;, we are going to continue with an introduction to React Native. Assuming you have everything set up and ready, and you have created your first project and have seen “Hello world!” on the screen, what’s next?&lt;br&gt;&lt;br&gt;
Well… We have been instructed to open &lt;strong&gt;App.js&lt;/strong&gt; and make our modifications. So, let’s look into the project folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F538%2F1%2A5taeffaDQ4KwCq98Tf1g2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F538%2F1%2A5taeffaDQ4KwCq98Tf1g2g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F304%2F1%2AaC-F0fHpOv5qTmZ5L0L-8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F304%2F1%2AaC-F0fHpOv5qTmZ5L0L-8Q.png"&gt;&lt;/a&gt;Project folder structure and initial screen — created using create-react-native-app&lt;/p&gt;

&lt;p&gt;Before we continue I would like to mention that for this lesson I am using &lt;strong&gt;create-react-native-app&lt;/strong&gt;, therefore if you have created your project using &lt;strong&gt;react-native-cli&lt;/strong&gt; or &lt;strong&gt;ignite-cli,&lt;/strong&gt; project folder will differ from what I will be referring to.&lt;br&gt;&lt;br&gt;
There it is. App.js. And as much as it is tempting to open it, let’s first see what we can learn from &lt;strong&gt;README.md&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If we want to keep our project up-to-date we will need to update our dependencies, which should be quite a simple task. But beware of &lt;a href="https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md" rel="noopener noreferrer"&gt;dependency compatibility&lt;/a&gt;. Create React Native App relies on 3 dependencies: &lt;strong&gt;react-native, react&lt;/strong&gt; and &lt;strong&gt;expo&lt;/strong&gt;, each being compatible with a narrow version of other two. Not to forget, the expo also needs to have specific &lt;strong&gt;&lt;em&gt;SDK version&lt;/em&gt;&lt;/strong&gt;, which can be set in the &lt;strong&gt;&lt;em&gt;app.json&lt;/em&gt;&lt;/strong&gt; file. Beside specifying SDK version, app.json can help us to name our app, give it an icon, version, specify supported platform, build details, &lt;a href="https://docs.expo.io/versions/latest/guides/configuration.html" rel="noopener noreferrer"&gt;and set many other settings&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Moving along we will see that we have 5 predefined scripts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npm start or yarn start used to run the app in development mode. If you need to clear cache run npm start --reset-cache flag.&lt;/li&gt;
&lt;li&gt;npm test used for running test. The project is set up to use &lt;strong&gt;jest&lt;/strong&gt;, but you are free to change it to your likening. If you decide to continue with jest, all you need to do is to create files inside a &lt;em&gt;__test__&lt;/em&gt; folder or with &lt;em&gt;.test&lt;/em&gt; extension, and your tests will be ready running.&lt;/li&gt;
&lt;li&gt;npm run ios used to run the project on iOS Simulator. The same can be achieved with npm start since one of the available options is to run the app on iOS Simulator as well.&lt;/li&gt;
&lt;li&gt;npm run android will run the app on Android device or emulator. Keep in mind that you will need a device connected or emulator started before running this script. As for the previous script, same goes for this one, the app can be run on Android with npm start as well.&lt;/li&gt;
&lt;li&gt;npm run eject if you find yourself that you need to add native code, do not worry, running this script will put you on the same track as if you have created your app with react-native-cli, but make sure that you have react-native-cli installed globally.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are unlucky one and everything does not run smoothly on the first try, there is a list of &lt;a href="https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md#troubleshooting" rel="noopener noreferrer"&gt;&lt;strong&gt;troubleshooting&lt;/strong&gt;&lt;/a&gt; suggestions related to &lt;em&gt;networking, iOS Simulator not running, and QR Code not scanning&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We have prolonged opening &lt;em&gt;App.js&lt;/em&gt; enough. So let’s check it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      &amp;lt;View style={styles.container}&amp;gt;
        &amp;lt;Text&amp;gt;Open up App.js to start working on your app!&amp;lt;/Text&amp;gt;
        &amp;lt;Text&amp;gt;Changes you make will automatically reload.&amp;lt;/Text&amp;gt;
        &amp;lt;Text&amp;gt;Shake your phone to open the developer menu.&amp;lt;/Text&amp;gt;
      &amp;lt;/View&amp;gt;
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What do we have here?
&lt;/h4&gt;

&lt;p&gt;First of all, we can notice that code is written using &lt;strong&gt;&lt;em&gt;ES6&lt;/em&gt;&lt;/strong&gt;. I am assuming that we are all familiar with it to some degree. For those that want to learn more please check out &lt;a href="https://babeljs.io/learn-es2015/" rel="noopener noreferrer"&gt;&lt;em&gt;this link&lt;/em&gt;&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
React Native comes with ES6 support so there is no need to worry about compatibility. To ensure you how it is much simpler to write the code using ES6, here is &lt;em&gt;a&lt;/em&gt; &lt;a href="https://babeljs.io/repl/#?babili=false&amp;amp;browsers=&amp;amp;build=&amp;amp;builtIns=false&amp;amp;code_lz=JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoUSWOAbzgGUYBPAGyQYAskkYAaOABUkAD35wAasCQB3OAF842XASLoYAWgB2KGMABuSMuXKjq8ACZJMKAK6t4aVigDOLuAEEwYOKJhItC3dkdQA6AGFcSC0A-FpyODgiQKQoAAoASjoExKTeWygtODSc3LgAHilZOBcWdgBeWlq2JBdQtAgtGBRgGKh5AD5SsorhMQGAeTAAuFsfLzBQgCt3GAga7poZaABrXoBzOE64ZggCuBRvAEJygHoxmCGR3PKHgfDOFC191pOzuBAKB2SDgMmArFYF1sa0BejQKAhzDyrAgKAsoTub2GZVefgGXCBINO5zAnE6ILWR2mRRg3DgVkMKOmUABAVsGPueOxFVuVRkT1yGQoiXk5FF5A6WlqGxa7nqjDqHG4vHaan8aXiiUl3V6qQAXNkyph2CIDQBGPjDABG6B2-xwtkCkRRUAN-AAxJgvfhLWUEcB9loAJL-EAuN1oWKpH3DJa2WrATDMSJdWIRqNQGMiy3yIVAA&amp;amp;debug=false&amp;amp;forceAllTransforms=false&amp;amp;shippedProposals=false&amp;amp;circleciRepo=&amp;amp;evaluate=false&amp;amp;fileSize=true&amp;amp;lineWrap=true&amp;amp;presets=es2015%2Creact%2Cstage-2&amp;amp;prettier=false&amp;amp;targets=&amp;amp;version=6.26.0&amp;amp;envVersion=" rel="noopener noreferrer"&gt;&lt;em&gt;link&lt;/em&gt;&lt;/a&gt; to our code after it is compiled.&lt;/p&gt;

&lt;p&gt;Moving along we can see &amp;lt;Text&amp;gt;Lorem Ipsum&amp;lt;/Text&amp;gt;, which might be unusual to some of us. This is &lt;strong&gt;&lt;em&gt;JSX&lt;/em&gt;&lt;/strong&gt; , &lt;em&gt;React&lt;/em&gt; feature for embedding &lt;em&gt;XML&lt;/em&gt; within &lt;em&gt;JavaScript&lt;/em&gt;. Contrary to other framework languages that let you embed your code inside markup language &lt;em&gt;React&lt;/em&gt; lets us write markup language inside the code. This is one of the reasons why we have &lt;em&gt;React&lt;/em&gt; as one of our dependencies.&lt;/p&gt;
&lt;h3&gt;
  
  
  React
&lt;/h3&gt;

&lt;p&gt;As we have already seen we need to know of &lt;em&gt;React&lt;/em&gt; if we want to write &lt;em&gt;React Native&lt;/em&gt;, but do not worry, if you do not know &lt;em&gt;React&lt;/em&gt; you will still be able to follow along. That being said, we will look into two types of data that control &lt;em&gt;React&lt;/em&gt; component and two different types of components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import { Text, View } from 'react-native';

const Greeting = ({name}) =&amp;gt; &amp;lt;Text&amp;gt;Hello {name}!&amp;lt;/Text&amp;gt;;

export default class GreetPeople extends Component {
    constructor(props) {
        super(props);
        this.state = {
            doeName: 'Doe'
        };
    }
    render() {
        const janesName = 'Jane';
        return (
            &amp;lt;View style={{marginTop:40, marginLeft:20}}&amp;gt;
                &amp;lt;Greeting name='John' /&amp;gt;
                &amp;lt;Greeting name={janesName} /&amp;gt;
                &amp;lt;Greeting name={this.state.doeName} /&amp;gt;
            &amp;lt;/View&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above is all we need, so let’s break it down.&lt;/p&gt;

&lt;h4&gt;
  
  
  Functional Components
&lt;/h4&gt;

&lt;p&gt;Also known as presentational or stateless components. They are dump components that should not contain any complex logic and should be used for displaying a specific part of context or as wrappers to apply specific styles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Greeting = (props) =&amp;gt; {
return (
 &amp;lt;Text&amp;gt;Hello {props.name}!&amp;lt;/Text&amp;gt;
 )
};

----- or after shortening the code -----

const Greeting = ({name}) =&amp;gt; &amp;lt;Text&amp;gt;Hello {name}!&amp;lt;/Text&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Class Components
&lt;/h4&gt;

&lt;p&gt;More complex components that should deal with all necessary logic for displaying the content. &lt;em&gt;React&lt;/em&gt; has something called &lt;em&gt;component lifecycle&lt;/em&gt; and those should be handled inside class components. One of the &lt;em&gt;lifecycle&lt;/em&gt; examples is the &lt;em&gt;constructor&lt;/em&gt;. Some of the others are &lt;em&gt;componentDidMount, componentWillUnmonut,&lt;/em&gt; and others. We will cover them as we need them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default class GreetPeople extends Component {
    constructor(props) {
        super(props);
        this.state = {
            doeName: 'Doe'
        };
    }
render() {
        const janesName = 'Jane';
        return (
            &amp;lt;View style={{marginTop:40, marginLeft:20}}&amp;gt;
                &amp;lt;Greeting name='John' /&amp;gt;
                &amp;lt;Greeting name={janesName} /&amp;gt;
                &amp;lt;Greeting name={this.state.doeName} /&amp;gt;
            &amp;lt;/View&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I would like to note that we do not need to have the constructor in every class component.&lt;/p&gt;

&lt;h4&gt;
  
  
  Props
&lt;/h4&gt;

&lt;p&gt;Props are used for customizing the components. In our case, &amp;lt;Greeting /&amp;gt; component has a prop name, and as we have seen we can pass it a string directly or we can pass it a constantan inside curly braces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const janesName = 'Jane';
    return (
        &amp;lt;View style={{marginTop:40, marginLeft:20}}&amp;gt;
            &amp;lt;Greeting name='John' /&amp;gt;
            &amp;lt;Greeting name={janesName} /&amp;gt;
        &amp;lt;/View&amp;gt;
    );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we are passing prop, let say fullName, to a class component we will access it with &lt;em&gt;this.props.fullName&lt;/em&gt;, while in a functional component we will use &lt;em&gt;props.fullName&lt;/em&gt; (we will omit &lt;em&gt;this&lt;/em&gt; keyword).&lt;/p&gt;

&lt;h4&gt;
  
  
  State
&lt;/h4&gt;

&lt;p&gt;While &lt;em&gt;props&lt;/em&gt; are passed from parent to child, the &lt;em&gt;state&lt;/em&gt; is what we are going to use with the component itself. We can initialize the &lt;em&gt;state&lt;/em&gt; in the &lt;em&gt;constructor&lt;/em&gt;, but if we want to change it we should use this.setState() function. It accepts two parameters, object that will update the state, and a callback function that will execute once the state is updated. We should not worry about re-rendering the component since it will re-render every time the state or the props for the component have been changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;constructor(props) {
    super(props);
    this.state = {
        doeName: 'Doe'
    };
}

componentDidMount(){
    setTimeout(
        () =&amp;gt; this.setState({doeName:'Alex'}),
        3000
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok! I think we had enough of &lt;em&gt;React&lt;/em&gt; for now. Let’s go back to &lt;em&gt;React Native&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Styling
&lt;/h3&gt;

&lt;p&gt;Well, sooner or later we will get bored at looking at same style over and over. So, what can we do about it? It’s easy. We will create CSS file, add our style, and… NO! &lt;em&gt;React Native&lt;/em&gt; does not play that way. But not to worry. Styling &lt;em&gt;React Native&lt;/em&gt; is not at all more complex. We will write our styles using JavaScript.&lt;/p&gt;

&lt;p&gt;All of the core components accept prop named &lt;em&gt;style&lt;/em&gt; which accepts an object that contains our styling, that we write similar to CSS. The difference is that instead of dashes we are using camel casing (instead of font-family we will have fontFamily) and that our values unless they are only numeric, need to be surrounded by quotations (color: blue is color: 'blue'). With further ado, let’s look how we style &lt;em&gt;React Native&lt;/em&gt; component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class LotsOfStyles extends Component {
    render() {
        return (
            &amp;lt;View style={{margin:40}}&amp;gt;
                &amp;lt;Text style={styles.red}&amp;gt;just red&amp;lt;/Text&amp;gt;
                &amp;lt;Text style={styles.bigblue}&amp;gt;just bigblue&amp;lt;/Text&amp;gt;
                &amp;lt;Text style={[styles.bigblue, styles.red]}&amp;gt;bigblue, then red&amp;lt;/Text&amp;gt;
                &amp;lt;Text style={[styles.red, styles.bigblue]}&amp;gt;red, then bigblue&amp;lt;/Text&amp;gt;
                &amp;lt;Text style={{color:'yellow'}}&amp;gt;yellow&amp;lt;/Text&amp;gt;
                &amp;lt;Text style={[styles.bigblue, {color:'green'}]}&amp;gt;bigblue, then green&amp;lt;/Text&amp;gt;
            &amp;lt;/View&amp;gt;
        );
    }
}

const styles = StyleSheet.create({
    bigblue: {
        color: 'blue',
        fontWeight: 'bold',
        fontSize: 30,
    },
    red: {
        color: 'red',
    },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we have seen we can have two different approaches, somewhat similar to the inline style and class-based style. Also lets notice that we can easily combine styles by passing an array of objects to &lt;em&gt;style&lt;/em&gt; prop instead of an object.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dimensions
&lt;/h3&gt;

&lt;p&gt;It should not be strange to us that we can use height and width to determine component size on the screen. Also, we can assume that our dimension can be fixed and flexible. So, how we are setting each in &lt;em&gt;React Native.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As for fixed, it is as simple as setting height and width. The trick is that all dimension in &lt;em&gt;React Native&lt;/em&gt; are &lt;strong&gt;unitless&lt;/strong&gt; and represent &lt;strong&gt;density-independent pixels&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import { View } from 'react-native';

export default class FlexDimensionsBasics extends Component {
    render() {
        return (
            &amp;lt;View style={{flex: 1}}&amp;gt;
                &amp;lt;View style={{flex: 3, backgroundColor: 'powderblue'}} &amp;gt;
                    &amp;lt;View style={{width: 50, height: 50, backgroundColor: 'orange'}} /&amp;gt;
                    &amp;lt;View style={{width: '50%', height: 50, backgroundColor: 'green'}} /&amp;gt;
                    &amp;lt;View style={{width: 150, height: 50, backgroundColor: 'red'}} /&amp;gt;
                &amp;lt;/View&amp;gt;
                &amp;lt;View style={{flex: 2, backgroundColor: 'skyblue'}} /&amp;gt;
                &amp;lt;View style={{flex: 1, backgroundColor: 'steelblue'}} /&amp;gt;
            &amp;lt;/View&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets now check out flexible dimensions. This can be achieved with &lt;em&gt;flex&lt;/em&gt; property.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://facebook.github.io/react-native/docs/height-and-width.html" rel="noopener noreferrer"&gt;&lt;strong&gt;A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/height-and-width.html" rel="noopener noreferrer"&gt;&lt;strong&gt;width and&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/height-and-width.html" rel="noopener noreferrer"&gt;&lt;strong&gt;height or&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/height-and-width.html" rel="noopener noreferrer"&gt;&lt;strong&gt;flex, the parent will have dimensions of 0 and the&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/height-and-width.html" rel="noopener noreferrer"&gt;&lt;strong&gt;flex children will not be visible.&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While talking about flex, we need to say that we can use flexbox principles to layout our components. And something that we need to keep in mind is that flexbox in React Naive slightly differs from what we are used on the web.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://facebook.github.io/react-native/docs/flexbox.html" rel="noopener noreferrer"&gt;&lt;strong&gt;Flexbox works the same way in React Native as it does in CSS on the web, with a few exceptions. The defaults are different, with&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/flexbox.html" rel="noopener noreferrer"&gt;&lt;strong&gt;flexDirection defaulting to&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/flexbox.html" rel="noopener noreferrer"&gt;&lt;strong&gt;column instead of&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/flexbox.html" rel="noopener noreferrer"&gt;&lt;strong&gt;row, and the&lt;/strong&gt;&lt;/a&gt;&lt;a href="https://facebook.github.io/react-native/docs/flexbox.html" rel="noopener noreferrer"&gt;&lt;strong&gt;flex parameter only supporting a single number.&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;p&gt;Now we know how to apply a basic style to our app. Where to next? Well… we will need something to style. And that something is &lt;em&gt;React Native&lt;/em&gt; components. So let’s have a look into few.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt; : the most fundamental component for building UI — as div for web&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Text:&lt;/strong&gt; used for displaying text — heading, and paragraphs for web&lt;br&gt;&lt;br&gt;
&lt;strong&gt;TextInput:&lt;/strong&gt; used for inputting text into the app via keyboard — input for web&lt;br&gt;&lt;br&gt;
&lt;strong&gt;StyleSheet:&lt;/strong&gt; creates styles — acts style tag for web&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Image:&lt;/strong&gt; used for displaying images — same as img on web&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Button:&lt;/strong&gt; gives us buttons — acts like button for web&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Platform:&lt;/strong&gt; helps us to determine either we are running our code on Android or iOS&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Alert / AlertIOS:&lt;/strong&gt; the name says it — as JavaScript alert message&lt;br&gt;&lt;br&gt;
&lt;strong&gt;ScrollView:&lt;/strong&gt; helps us to scroll the content that is higher or wider than our device&lt;br&gt;&lt;br&gt;
&lt;strong&gt;FlatList:&lt;/strong&gt; displays similarly structured data; unlike ScrollView it renders only visible items&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Touchable “components”:&lt;/strong&gt; creates touchable views — similar to anchor tags on web&lt;/p&gt;

&lt;p&gt;Let’s not go overboard with listing components. Those are some basic ones that we will be using the most. As for other, we will mention them as appropriate to our case.&lt;/p&gt;

&lt;p&gt;We have already seen how we can style &lt;em&gt;Text&lt;/em&gt; and &lt;em&gt;View&lt;/em&gt; in our examples. Styling others is not much different. For the full list of styling attributes, you can check the official documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I think we have covered enough in this article. We now know how to create a project using &lt;em&gt;create-react-native-app&lt;/em&gt; and we have a basic understanding of what we get out of the box when doing so. We have learned just enough React to be able to write code for our app. And we have shown how to style React Native component, as well as how to give it dimensions. In addition to that, we have mentioned fundamental React Native components to have us up and ready when we want to build a simple app.&lt;/p&gt;

&lt;p&gt;The code used here can be found on my GitHub repository:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nedimb86/MyReactNativeApp" rel="noopener noreferrer"&gt;nedimb86/MyReactNativeApp&lt;/a&gt;&lt;/p&gt;




</description>
      <category>react</category>
      <category>jsx</category>
      <category>reactnative</category>
      <category>expo</category>
    </item>
    <item>
      <title>Starting with React Native</title>
      <dc:creator>Nedim Becirovic</dc:creator>
      <pubDate>Sun, 29 Apr 2018 20:43:46 +0000</pubDate>
      <link>https://dev.to/nedimb86/starting-with-react-native-2edb</link>
      <guid>https://dev.to/nedimb86/starting-with-react-native-2edb</guid>
      <description>

&lt;p&gt;Since I was working as React developer it was just a matter of time when I would check out React Native. My first touch with it did not go out good at all. And I am not talking about writing code, but starting demo project.&lt;/p&gt;

&lt;p&gt;I admit. Everything was my fault. Trying to act too smart and just scanning documentation was more than enough to waste few hours. To be clear, I was trying to run “AwesomeProject” generated with react-native-cli on Android emulator on Windows. This simple task is not so simple if you are trying to use “the latest” versions.&lt;/p&gt;

&lt;p&gt;While getting advice from a good old friend &lt;a href="https://stackoverflow.com/"&gt;StackOverfow&lt;/a&gt; I came across a comment that cites official &lt;a href="https://facebook.github.io/react-native/docs/getting-started.html"&gt;documentation&lt;/a&gt; stating that I need to use &lt;strong&gt;Android 6.0&lt;/strong&gt;. I had it enough and went back to the roots, followed instructions to the letter, and believe it or not, everything worked just fine.&lt;/p&gt;

&lt;p&gt;A couple of the months down the road I found myself trying to help others start with the React Native and hence this article. So, how should one start?&lt;/p&gt;

&lt;p&gt;I found three different approaches that I am going to cover here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create-react-native-app&lt;/li&gt;
&lt;li&gt;react-native-cli&lt;/li&gt;
&lt;li&gt;ignite-cli&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Create React Native App
&lt;/h3&gt;

&lt;p&gt;This should be more than enough for the beginner that wants to check basic concepts of React Native. All you need is &lt;a href="https://nodejs.org/en/download/"&gt;Node&lt;/a&gt; on your machine and &lt;a href="https://expo.io/"&gt;Expo&lt;/a&gt; client app on your device and you are ready to go. Next step is to run npm i -g create-react-native-app. Once this is done you will need to run&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create-react-native-app MyReactNativeApp

.........

cd MyReactNativeApp npm start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Almost there. Start Expo on your device (ensure that your machine and device are on the same IP address) and scan QR code. Congratulations! You have just entered into the world of React Native.&lt;/p&gt;

&lt;p&gt;So what is the catch?&lt;/p&gt;

&lt;p&gt;Well… There are some limitations what you can do due to not building any native code. Not to worry thou, you will be able to do quite a lot, and once you need to take it up the notch you can “eject” project and create native builds. This comes with the price of having to install Xcode (for iOS) and JDK and Android Studio (for Android), besides some other requirements which differ from macOS, Windows, and Linux.&lt;/p&gt;

&lt;h3&gt;
  
  
  React Native CLI
&lt;/h3&gt;

&lt;p&gt;One more time. Be sure to follow instructions as mentioned in the &lt;a href="https://facebook.github.io/react-native/docs/getting-started.html"&gt;documentation&lt;/a&gt;. So, once you have run out of “OS-specific installations” and have you cli installed globally by running npm i -g react-native-cli, you are ready to create your first project.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native init MyReactNativeApp

.......

cd MyReactNativeApp

----------

react-native run-ios

------or--------

react-native run-android
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is that simple. Just be sure that you have your Android emulator running or that your device is connected, before running app for Android.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignite CLI
&lt;/h3&gt;

&lt;p&gt;Even for &lt;a href="https://github.com/infinitered/ignite"&gt;Ignite&lt;/a&gt;, you will need to go through the same setup as for react-native-cli. Creating the project is a bit more complex than with react-native-cli. First install it globally npm i -g ignite-cli. Then let it run its magic&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ignite new ILoveIgniteApp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You will be prompted with a couple of yes/no questions to let you chose what you want to install.&lt;/p&gt;

&lt;p&gt;So, why would you choose something that seems more complex?&lt;/p&gt;

&lt;p&gt;For starters ignite comes with a bunch of boilerplates that you can install from as easy as running ignite new MyNewAppName -b 'name of boilerplate'. Moreover, there is a number of plugins (npm packages) that are easily added by ignite. For beginners, it can be a source of learning how to organize the project. Ignite generates the code with clear instructions on how to modify the code so the app will work. For advanced users, it saves time with some copy-paste processes when adding native related dependencies, like google maps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Sooner or later you will need to set up the environment, either to extend your app with native modules or to build it for AppStore or PlayStore or both. Even though you can use Expo and physical device for create-react-native-app, you can also use emulators to run your app. So do not postpone this painless, time-consuming process.&lt;/p&gt;

&lt;p&gt;As for me, I like using create-react-native-app for trying out any non-native module related thing. When it comes to project I prefer ignite-cli since it speeds up my work. But when using a native module for the first time or playing with them, I like creating a new project with react-native-cli just to be sure I won’t miss anything that ignite will do for me.&lt;/p&gt;

&lt;p&gt;It does not matter what approach will you chose, as long as you have chosen any.&lt;/p&gt;


</description>
      <category>ignite</category>
      <category>createreactapp</category>
      <category>reactnative</category>
    </item>
  </channel>
</rss>
