<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by umang rathore on Medium]]></title>
        <description><![CDATA[Stories by umang rathore on Medium]]></description>
        <link>https://medium.com/@umangrathore70?source=rss-bf3bad59d9c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*wCa5Y36vZZHHgKSgPxVEyw.jpeg</url>
            <title>Stories by umang rathore on Medium</title>
            <link>https://medium.com/@umangrathore70?source=rss-bf3bad59d9c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 18:19:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@umangrathore70/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started With React]]></title>
            <link>https://medium.com/enappd/getting-started-with-react-55f0fd87106d?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/55f0fd87106d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 17:21:57 GMT</pubDate>
            <atom:updated>2019-11-14T17:21:57.780Z</atom:updated>
            <content:encoded><![CDATA[<h4>Build your First React JS app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hmZGoOaj29ay_x1lm56Bw.png" /><figcaption>React JS</figcaption></figure><blockquote>React is a <strong>JavaScript</strong> library created by <strong>Facebook</strong></blockquote><blockquote>React is a <strong>User Interface</strong> (UI) library</blockquote><blockquote>React is a tool for building <strong>UI components</strong></blockquote><p>React is an open-source Javascript library for building dynamic apps. MVC stands for Model View Controller, and React is the V, or View in this architecture.</p><p>React JS has come at a good time helping the developers to build highly engaging web apps and user interfaces within a quick time. It allows you to break down the components and create a single page application with less coding.</p><p>Moreover, the virtual DOM also integrates the performance and React JS is also known to be SEO friendly. You can develop large scale apps with frequently changing data. It is due to these major advantages that React JS has gained much spotlight.</p><h3>Getting Started:</h3><h4>Install NodeJS if not already present</h4><p>NodeJS is needed since the Libraries Required for React are downloaded using node package manager ( npm ). Refer to <a href="https://nodejs.org/en/">https://nodejs.org/en/</a> to install NodeJS.</p><h4>Install create-react-app Node Package</h4><p><strong>create-react-app</strong> node package helps to set up a React project. Install create-react-app node package globally using the following command.</p><pre>npm install -g create-react-app</pre><h4>Create The Project</h4><p>Getting started with React is simple. After it’s installed, you can just run the create-react-app on the command line, followed by the name of the app you want to create. This creates the react app, with all the necessary functionality you need, already built into the app. Then you can just cd into the react app and start it with npm start.</p><pre>npx create-react-app react-app-new</pre><p><strong>react-app-new</strong> is the name of the application. The above command creates a folder called <strong>react-app-new</strong> which is the project folder and then installs all dependency from the package.json file.</p><p>Here’s how that will look on the command line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_ognQ23AkUTwpNLsk7eMw.png" /><figcaption>Create basic React JS App</figcaption></figure><h4>A look at a Package.json</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfb7f538e28242f770fa62f6de329cfb/href">https://medium.com/media/bfb7f538e28242f770fa62f6de329cfb/href</a></iframe><p>Packages published to the registry must contain a <strong>package</strong>.<strong>json file</strong>. A <strong>package</strong>.<strong>json file</strong> lists the packages your project depends on, specifies versions of a <strong>package</strong> that your project can use, using<strong> </strong>semantic versioning rules.</p><p>At first glance it may look like there’s a lot going on, so let’s break it down, starting with the first three lines.</p><p>So what’s going on here? Well, the first three lines are very basic info about projects like name and version. The first being Name itself.</p><pre>&quot;name&quot;: &quot;react-app-new&quot;,</pre><pre>&quot;version&quot;: &quot;0.1.0&quot;,</pre><pre>&quot;private&quot;: true,</pre><p>Required name and version fields</p><p>A <strong>package.json</strong> file must contain <strong>name</strong> and <strong>version</strong> fields.</p><p>The <strong>name</strong> field contains your package’s name, and must be lowercase and one word, and may contain hyphens and underscores.</p><p>The <strong>version</strong> field must be in the form <strong>x.x.x</strong> and follow the <a href="https://docs.npmjs.com/about-semantic-versioning">semantic versioning guidelines</a>.</p><h4>The next block is dependencies.</h4><p>Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string that has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.</p><p><strong>Please do not put test harnesses or transpilers in your </strong><strong>dependencies object.</strong> See, <strong>devDependencies</strong> below.</p><p>See <a href="https://docs.npmjs.com/misc/semver">semver</a> for more details about specifying version ranges.</p><ul><li><strong>version</strong> Must match <strong>version</strong> exactly</li><li><strong>&gt;version</strong> Must be greater than <strong>version</strong></li><li><strong>&gt;=version</strong> etc</li><li><strong>&lt;version</strong></li><li><strong>&lt;=version</strong></li><li><strong>~version</strong> “Approximately equivalent to version” See <a href="https://docs.npmjs.com/misc/semver">semver</a></li><li><strong>^version</strong> “Compatible with version” See <a href="https://docs.npmjs.com/misc/semver">semver</a></li><li><strong>1.2.x</strong> 1.2.0, 1.2.1, etc., but not 1.3.0</li><li><strong>http://...</strong> See ‘URLs as Dependencies’ below</li><li><strong>*</strong> Matches any version</li><li><strong>&quot;&quot;</strong> (just an empty string) Same as <strong>*</strong></li><li><strong>version1 - version2</strong> Same as <strong>&gt;=version1 &lt;=version2</strong>.</li><li><strong>range1 || range2</strong> Passes if either range1 or range2 are satisfied.</li><li><strong>git...</strong> See ‘Git URLs as Dependencies’ below</li><li><strong>user/repo</strong> See ‘GitHub URLs’ below</li><li><strong>tag</strong> A specific version tagged and published as <strong>tag</strong> See <a href="https://docs.npmjs.com/cli/dist-tag"><strong>npm-dist-tag</strong></a></li><li><strong>path/path/path</strong> See <a href="https://docs.npmjs.com/files/package.json#local-paths">Local Paths</a> below</li></ul><pre>&quot;dependencies&quot;: {</pre><pre>&quot;react&quot;: &quot;^16.11.0&quot;,</pre><pre>&quot;react-dom&quot;: &quot;^16.11.0&quot;,</pre><pre>&quot;react-scripts&quot;: &quot;3.2.0&quot;</pre><pre>},</pre><h4>The next block scripts.</h4><p>The “scripts” property is a dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.</p><p>See <a href="https://docs.npmjs.com/misc/scripts"><strong>npm-scripts</strong></a> to find out more about writing package scripts.</p><pre>&quot;scripts&quot;: {</pre><pre>&quot;start&quot;: &quot;react-scripts start&quot;,</pre><pre>&quot;build&quot;: &quot;react-scripts build&quot;,</pre><pre>&quot;test&quot;: &quot;react-scripts test&quot;,</pre><pre>&quot;eject&quot;: &quot;react-scripts eject&quot;</pre><pre>},</pre><h4>Next block — eslintConfig</h4><p>ESLint is designed to be completely configurable, meaning you can turn off every rule and run only with basic syntax validation, or mix and match the bundled rules and your custom rules to make ESLint perfect for your project. <a href="http://eslint.org/docs/user-guide/configuring">There are two primary ways to configure ESLint</a></p><h4>Next block — Browserslist</h4><p>The config to share target browsers and Node.js versions between different front-end tools. It is used in:</p><ul><li><a href="https://github.com/postcss/autoprefixer">Autoprefixer</a></li><li><a href="https://github.com/babel/babel/tree/master/packages/babel-preset-env">Babel</a></li><li><a href="https://github.com/jonathantneal/postcss-preset-env">postcss-preset-env</a></li><li><a href="https://github.com/amilajack/eslint-plugin-compat">eslint-plugin-compat</a></li><li><a href="https://github.com/ismay/stylelint-no-unsupported-browser-features">stylelint-no-unsupported-browser-features</a></li><li><a href="https://github.com/jonathantneal/postcss-normalize">postcss-normalize</a></li><li><a href="https://github.com/ElemeFE/obsolete-webpack-plugin">obsolete-webpack-plugin</a></li></ul><p>All tools will find target browsers automatically when you add the following to package.json:</p><pre>&quot;browserslist&quot;: [</pre><pre>&quot;&gt;0.2%&quot;,</pre><pre>&quot;not dead&quot;,</pre><pre>&quot;not ie &lt;= 11&quot;,</pre><pre>&quot;not op_mini all&quot;</pre><pre>]</pre><h4>Run the project in the browser</h4><pre>cd react-app</pre><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aFiuZGePYBIL7rLXUoJjLQ.png" /></figure><p>Go to your browser and go the following URL <strong>localhost:3000</strong><br>You should be able to see that your application is running. The Application will look like this in your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mp0itJ1eRHYcIPxnOQg4Ww.png" /></figure><h4>Basic Folder Structure Explained</h4><p>When you created the project, you would have noticed that it created a bunch of files. Here I will list out some of the important files and folders that you should be aware of .</p><ol><li><strong>package.json: </strong>This File has the list of node dependencies which are needed.</li><li><strong>public/index.html: </strong>When the application starts this is the first page that is loaded. This will be the only html file in the entire application since React is generally Written using <strong>JSX </strong>which I will cover later. Also, this file has a line of code &lt;div id=”root”&gt;<strong>&amp;l</strong>t;/div&gt;. This line is very significant since all the application components are loade<strong>d i</strong>nto this div.</li><li><strong>src/index.js</strong>: This is the javascript file corresponding to index.html. This file has the following line of code which is very significant. ReactDOM.render(&lt;App /&gt;, document.getElementById(‘root’));</li><li>The above line of code is telling that <strong>App</strong> Component ( will cover App Component soon) has to be loaded into an html element with id <strong>root</strong>. This is nothing but the <strong>div element</strong> present in <strong>index.html.</strong></li><li><strong>src/index.css</strong>: The CSS file corresponding to index.js.</li><li><strong>src/App.js</strong> : This is the file for <strong>App</strong> Component. <strong>App</strong> Component is the main component in React which acts as a container for all other components.</li><li><strong>src/App.css</strong> : This is the CSS file corresponding to <strong>App</strong> Component</li><li><strong>build:</strong> This is the folder where the built files are stored. React Apps can be developed using either JSX, or normal JavaScript itself, but using JSX definitely makes things easier to code for the developer :). But browsers do not understand JSX. So JSX needs to be converted into javascript before deploying. These converted files are stored in the build folder after bundling and minification. In order to see the build folder Run the following command</li></ol><pre>npm run build</pre><h4>Congrats</h4><p>Now you know how to create a React Application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55f0fd87106d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/getting-started-with-react-55f0fd87106d">Getting Started With React</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference between redux and flux]]></title>
            <link>https://medium.com/enappd/difference-between-redux-and-flux-fad3c309a852?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fad3c309a852</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[flux]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Sat, 12 Oct 2019 09:48:14 GMT</pubDate>
            <atom:updated>2019-10-12T09:48:14.239Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*MZj98upz0EUO52VAB4B41Q.jpeg" /><figcaption>Redux V/S Flux</figcaption></figure><p>In this post, we’ll try to compare — Flux and Redux. Both technologies <strong>allow you to manage state in your app. </strong>Both<strong> </strong>are a great tool because they allow developers to quickly <strong>store</strong> and <strong>manage</strong> state in his app.</p><h3>What is Redux?</h3><p><a href="https://redux.js.org/"><strong>Redux</strong></a> is a standalone state management library, which can be used with any library or framework. If your background is <strong>React developer</strong>, then you have used the <strong>Redux library with React</strong>. The primary use of <strong>Redux</strong> is that we can use one application state as a global state and interact with the state from any react component is very easy whether they are siblings or parent-child.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*kwMieaTmikxMDhZfI-yeaw.png" /><figcaption>Redux Logo</figcaption></figure><blockquote><strong>Basic usage of Redux comes into picture when the app gets large and complex. In such apps, simple data management as parent-child becomes difficult using </strong><strong><em>props</em>. There are multiple components trying to communicate with multiple other components. In such cases, Redux comes in handy.</strong></blockquote><p>Redux can be broken down into few sections while building the application which is listed below.</p><p><strong>Actions: “</strong>are payloads of information that send data from your application to your store. They are the <em>only</em> source of information for the store.” this means if any state change necessary the change required will be dispatched through the actions.</p><p><strong>Reducers: “</strong>Actions<strong> </strong>describe the fact that <em>something happened</em>, but don’t specify how the application’s state changes in response. This is the job of reducers.” when an action is dispatched for state change its the reducers duty to make the necessary changes to the state and return the new state of the application.</p><p><strong>Store: </strong>with help of reducers a store can be created which holds the entire state of the application it is recommended to use a single store for the entire application than having multiple stores which will violate the use of redux which only has a single store.</p><p><strong>Components (UI): </strong>This<strong> </strong>is where the UI of the application is kept.</p><p><strong>Middlewares</strong>: middleware can be used for a variety of things, including asynchronous API calls. Middleware sounds much more complicated than it really is. The only way to really understand middleware is to see how the existing middleware works and try to write your own.we will cover middleware in the next blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*2--d_JqkSBPUBIe_TsppPA.jpeg" /><figcaption>Redux workflow in simple schematic</figcaption></figure><h3>What is the Flux?</h3><p>Flux is a Javascript architecture or pattern for UI which runs on unidirectional data flow and has a centralized dispatcher. It is useful when your project has dynamic data and you need to keep the data updated in an effective manner. It was created by Facebook and complements React as view. This model is used to ease maintenance. It has three primary components: Views, Stores, and Dispatcher. As the MVC application grows, we find many numbers of views as models, which are all talking to each other, making it difficult to manage and debug.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*ckGBd5Sn8jzaQOFrpD9-og.png" /><figcaption>Flux logo</figcaption></figure><p>Flux is more of a pattern than a framework and does not have any hard dependencies. However, we often use <a href="https://nodejs.org/api/events.html#events_class_events_eventemitter">EventEmitter</a> as a basis for Stores and <a href="https://github.com/facebook/react">React</a> for our Views. The one-piece of Flux not readily available elsewhere is the Dispatcher. This module, along with some other utilities, is available here to complete your Flux toolbox.</p><p>Flux can be broken down into few sections while building the application which is listed below.</p><p><strong>Actions: “</strong>are payloads of information that send data from your application to your store. They are the <em>only</em> source of information for the store.” this means if any state change necessary the change required will be dispatched through the actions.</p><p><strong>dispatcher</strong>: The dispatcher is a singleton, and operates as the central hub of data flow in a Flux application. It is essentially a registry of callbacks, and can invoke these callbacks in order. Each <em>store</em> registers a callback with the dispatcher. When new data comes into the dispatcher, it then uses these callbacks to propagate that data to all of the stores. The process of invoking the callbacks is initiated through the dispatch() method, which takes a data payload object as its sole argument.</p><p><strong>Store: </strong>In Flux, Stores are simply a place where data is read out from. More specifically, Views within a Flux architecture will be notified of changes within Stores via the <a href="https://en.wikipedia.org/wiki/Observer_pattern">Observer pattern</a>, and then query for those data in order to update their own states.</p><p><strong>View</strong> : This<strong> </strong>is where the UI of the application is kept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7qtRmuWoMmFyhpnyxoS3MA.png" /><figcaption>Flux Work Flow</figcaption></figure><pre>const someAction = {<br>  type: &quot;Test&quot;,<br>  payload: {user: &quot;Test User&quot;, age: 25},<br>}</pre><p>This is a generally accepted convention to have a type and a payload for an action. The payload can be any valid JS type (array, object, etc ).</p><h3>Top 10 Attributes to Consider While Selecting the State Management tool for any website.</h3><p>To decide which one is better for State Management, lets first define the attributes based on which we will compare all of the above. And, these are:</p><ul><li>Developed By</li><li>Stable Release</li><li>Initial Release</li><li>Github Stats</li><li>Store</li><li>Dispatcher</li><li>State</li><li>Workflow</li><li>Final Words (Pros and cons)</li></ul><h3>Developed By:-</h3><p>Redux was created by <strong>Dan Abramov</strong> and <strong>Andrew Clark</strong>. Abramov began writing the first Redux implementation while preparing for a conference talk at React Europe on hot reloading.</p><p>Flux was created by <strong>Facebook</strong> For forcing an unidirectional flow of data between a system’s components.</p><h3>Initial Release:-</h3><p>Redux:- 2, June 2015<br>Flux:- June 2011</p><h3>Stable Release:-</h3><p>Redux:- 4.0.0 in April 2017</p><p>The major changes in the stable release are around our TypeScript definitions, bundled CommonJS and ES builds, throwing if you subscribe or getState from a reducer, and a bunch of other smaller things. The full changes are listed below.</p><p>Flux:- 3.1.3 on Nov 2016</p><p>The major changes in the stable release are added support for React 16</p><h3>Github Stats:-</h3><h4>Flux:-</h4><p><strong>Github Stars</strong>:- 16331</p><p><strong>Contributors</strong>:- 114</p><p><strong>Total commits</strong>:- 394</p><p><strong>Total open issues</strong>:-10</p><p><strong>Total Closed Issues</strong>:-216</p><h4>React:-</h4><p><strong>Github Stars</strong>:- 50499</p><p><strong>Contributors</strong>:- 698</p><p><strong>Total commits</strong>:- 2094</p><p><strong>Total open issues:-</strong>27</p><p><strong>Total Closed Issues</strong>:-1648</p><h3>Store:-</h3><p>With <strong>Flux</strong> it is a convention to have <strong>multiple stores</strong> per application; each store is a singleton object. In <strong>Redux</strong>, the convention is to have a <strong>single store </strong>per application, usually separated into data domains internally (you can create more than one Redux store if needed for more complex scenarios).</p><p><strong>Flux</strong>:- Multiple Store</p><p><strong>Redux</strong>:- Single Store</p><h3>Dispatcher:-</h3><p><strong>Flux</strong> has a <strong>single</strong> <strong>dispatcher</strong> and all actions have to pass through that dispatcher. It’s a singleton object. A Flux application cannot have multiple dispatchers. This is needed because a Flux application can have multiple stores and the dependencies between those stores need a single manager, which is the dispatcher.</p><p><strong>Redux</strong> has <strong>no dispatcher</strong> entity. Instead, the store has the dispatching process baked in. A Redux store exposes a few simple API functions, one of them is to dispatch actions.</p><h3>State:-</h3><p>The other bigger constraint is that the store’s state in <strong>Redux</strong> cannot be <strong>mutable</strong> (or really, shouldn’t be). There is no such constraint in Flux, you can mutate the state as you wish. The state’s immutability, in Redux, is achieved easily by making the reducers pure functions (with no side effects). Redux reducers always copy the state they receive and returns a modified version of the state’s copy, not the original object itself. While this is a big constraint, it makes life much easier long term.</p><p><strong>Redux</strong>:- Immutable</p><p><strong>Flux</strong>:- Mutable</p><h3>Workflow:-</h3><p>Having a similar state, action and unidirectional data flow, the Flux and Redux do have some workflow differences. Let’s understand the two technologies one-by-one.</p><h3>How Flux Functions</h3><p>Flux, in simple term, allows unidirectional data flow which is an essential part of keeping things predictable. You can understand this; you need to know how MVC architecture functions. The MVC architecture includes;</p><p><strong><em>Action → Controller → Models →Views</em></strong></p><p>In which Models and Views do not follow the bidirectional data flow which becomes extremely tough when complexity gets higher. There will be no clue to find exactly where the changes occur and that in result give rise to bugs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/0*ovem8pM12nyt2TPG" /></figure><p>While unidirectional data flow abided by Flux empowers applications to avoid the shimmering effect, and the process takes place something like the diagram below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vgDSI5TkgcLpT_0G" /></figure><p>You may have got the precise idea of how Flux works.</p><h3>How Redux Functions</h3><p>As Redux is predictable state container for JavaScript apps, it has actions like Flux but here it’s a simple JavaScript object while using Redux, action will turn into functions and promises. It’s a small library and has been designed with a concept to be a predictable container for application state. Flux can be implemented along with a number of frameworks while Redux works to simplify and streamline the concept of (most of) Flux.</p><p><strong>Redux is built on the concept of;</strong></p><p><strong><em>Actions → Store → Reducers → Subscriptions</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*mKI6NN7F3ziJoous" /></figure><p>As you can see in some cases, Flux matches the Redux. The two technologies are also similar in terms of unidirectional data flow and aligning state implying ‘type’ field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*6oj0eeyO1bHWX71Gq3gQog.png" /></figure><h3>Final Words:-</h3><p>Flux and Redux are a very integral part of the development and it is equally important for developers to know their usages. They are a small but powerful tool which makes your applications’ user interface attractive and usable.</p><p>Some pros and cons of <strong>Redux</strong> and <strong>Flux</strong></p><h4>Redux</h4><ol><li>Predictable State</li><li>Work well with react</li><li>Easy Debugging</li><li>Log Everything</li><li>Test without browser</li><li>Hot reloading</li><li>State stored in a single object</li></ol><h4>Flux</h4><ol><li>Unidirectional Data flow</li><li>No MVCopen Source</li></ol><h3>Next Steps</h3><p>Now that you have learnt the major differences between Redux and flux for state management in your app, you can also try</p><ul><li><a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">React Native life cycle hooks</a></li><li>How To integrate in React Native — <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image picker</a>| <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li><li><a href="https://enappd.com/blog/firebase-push-notifications-in-react-native/81/">Firebase Push notifications in React Native Apps</a></li></ul><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fad3c309a852" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/difference-between-redux-and-flux-fad3c309a852">Difference between redux and flux</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase analytics in React native app]]></title>
            <link>https://medium.com/enappd/firebase-analytics-in-react-native-app-67d480a5b4e7?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/67d480a5b4e7</guid>
            <category><![CDATA[google-analytics]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[firebaseanalytics]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Tue, 17 Sep 2019 08:15:23 GMT</pubDate>
            <atom:updated>2020-01-29T18:57:12.954Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Firebase analytics in React native app" src="https://cdn-images-1.medium.com/max/1024/1*6atEBy6j_7p4cFkVLVK83A.png" /></figure><p>In this post, you’ll learn how to implement the easy to integrate Firebase Analytics in React Native apps.</p><blockquote><strong>Complete code of this post can be found in the Github repository </strong><a href="https://github.com/enappd/AnalyticsData.git"><strong>react-native-firebase-analytics</strong></a></blockquote><h3>What is analytics</h3><p><strong>Analysis</strong> is focused on understanding the past; what happened and why it happened. Analytics focuses on why it happened and what will happen next.</p><p><strong>Analytics</strong> is a free app measurement solution that provides insight on app usage and user engagement.</p><p>Organizations may apply analytics to business data to describe, predict, and improve business performance. Specifically, areas within analytics include <a href="https://en.wikipedia.org/wiki/Predictive_analytics">predictive analytics</a>, <a href="https://en.wikipedia.org/wiki/Prescriptive_analytics">prescriptive analytics</a>, <a href="https://en.wikipedia.org/wiki/Enterprise_decision_management">enterprise decision management</a>, descriptive analytics, cognitive analytics, Big Data Analytics, retail analytics, supply chain analytics, store assortment and <a href="https://en.wikipedia.org/wiki/Stock-keeping_unit">stock-keeping unit</a> optimization, marketing optimization and <a href="https://en.wikipedia.org/wiki/Marketing_mix_modeling">marketing mix modeling</a>, <a href="https://en.wikipedia.org/wiki/Web_analytics">web analytics</a>, call analytics, <a href="https://en.wikipedia.org/wiki/Speech_analytics">speech analytics</a>, sales force sizing and optimization, price and promotion modeling, predictive science, credit <a href="https://en.wikipedia.org/wiki/Risk_analysis_(business)">risk analysis</a>, and <a href="https://en.wikipedia.org/wiki/Fraud_detection">fraud analytics</a>. Since analytics can require extensive computation (see <a href="https://en.wikipedia.org/wiki/Big_data">big data</a>), the algorithms and software used for analytics harness the most current methods in computer science, statistics, and mathematics</p><h3>Why is analytics important?</h3><p>Internet marketing without analytics is like pointing at NYC and saying “the building is somewhere in there.” Internet marketing with analytics is akin to pinpointing the exact location of a specific building using satellite technology.</p><p><strong>Analytics</strong> allow you to quantify the effects of making a change to your marketing strategy, and that’s invaluable to the process of improving and optimizing online marketing campaigns. The biggest benefit of utilizing proper <strong>analytics</strong> is being able to identify strengths and weaknesses.</p><p><strong>Analytics</strong> essentially allow for a defined path of optimization that leads to better results on all fronts.</p><h3>What is React-Native</h3><p><strong>TLDR;</strong> — React Native (RN) apps are more “native” than webview apps made by Cordova / Ionic. But React Native is yet to release a stable (1.0.0_) version of the framework.</p><p>React Native is a JavaScript framework for writing natively rendering mobile applications. It’ is based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. Because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS.</p><p>React Native applications render using real mobile UI components, <em>not</em> webviews, and will look and feel like any other native mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera, or the user’s location. <a href="http://bit.ly/1YipO7A">Facebook</a>, <a href="http://bit.ly/1PPEiZH">Palantir</a>, <a href="http://bit.ly/1PPEjNg">TaskRabbit</a> etc are already using it in production for user-facing applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*8sJrsHqZSsLJ3UVBtuUGRA.jpeg" /><figcaption>React Native</figcaption></figure><h3>Firebase</h3><p>Firebase is a Backend-as-a-Service (BaaS) platform. It started as a <a href="http://blog.ycombinator.com/firebase-yc-s11-raises-5-dollars-dot-6m-series-a-from-union-square-ventures-and-flybridge">YC11 startup</a> and grew up into a next-generation app-development platform on Google Cloud Platform. It is getting popular by the day because of the ease of integration and a variety of functionalities available on it.</p><p>Some of the quick integrations available with Firebase are</p><ul><li>Email Authentication</li><li>Social logins</li><li>Real-time database</li><li><strong>Analytics</strong></li><li>Crashlytics</li><li>Push notifications</li><li>In-app messages</li><li>Remote config</li></ul><p>and much more. Firebase is quickly growing to become the most popular mobile app back-end platform.</p><p>Enough of story-telling, let’s dive into — how to implement analytics in React Native apps</p><h3>Structure</h3><p>I will go ahead in step-by-step fashion so you can follow easily.</p><ol><li>Create a Firebase project and find analytics options</li><li>Create a basic React Native app</li><li>Running the app on a device</li><li>Install firebase analytics dependency</li><li>Implement analytics in your app</li><li>Send analytics event from app to firebase dashboard</li><li>Check this event on Firebase dashboard.</li></ol><p>So let’s dive right in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*HfUjPCVB8Eer3q22lcuoew.gif" /><figcaption>Ouch! Let’s ….. not dive</figcaption></figure><h3>1. Create a Firebase project and find analytics options</h3><p>Go to <a href="https://console.firebase.google.com/">Firebase</a> and create your first project (or use an existing one). Your console should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Q1tzpM83Uq66TNZ9E28nYA.png" /><figcaption>Your Firebase projects all in one place</figcaption></figure><p><strong>Note</strong> — It’s really easy to create a Firebase project, but if you still face any issue, follow step 1–4 of <a href="https://enappd.com/blog/how-to-integrate-firebase-in-ionic-4-apps/23/">this blog</a></p><p>Click on your project and you’ll enter the project’s dashboard. Look for the <strong>Analytics</strong> tab. This is where the magic will happen!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*netbb70MBgLb3EsUzO6e8g.png" /><figcaption>Analytics dashboard</figcaption></figure><p>For setting up options, you’ll first have to create an Android app in Firebase console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZaRFHlVlWW03I_2XC6F5g.png" /><figcaption>Add a new Android app in Firebase</figcaption></figure><p>During the process, it will ask you to enter app’s <strong>package name</strong> and provide <strong>google-services.json. </strong>Make sure you keep the package name same as what you are setting in config.xml of your app. (If we create a new project called “<strong>HelloWorld</strong>” using react native CLI, by default package name for android project will be “<strong>com.helloworld</strong>” and default bundle identifier for iOS app will be “<strong>org.reactjs.native.example.HelloWorld</strong>”., don’t use the default package name)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtd51fTn_frvjGxUEkhiow.png" /><figcaption>Download google-services.json</figcaption></figure><h3>2. Create a basic React Native app</h3><p>First, make sure you have all pre-requisites to create a react-native app as per the <a href="https://facebook.github.io/react-native/docs/getting-started.html">official documentation</a>.</p><blockquote><strong>At the time of this post, I have React-Native version 0.60</strong></blockquote><p>Create a blank react-native app (Replace myApp with your own name)</p><pre>$ react-native init myApp</pre><p>This will create a basic React-native app which you can run in a device or simulator. (either Android or iOS)</p><h3>Step 3: Running the app on a device</h3><p>To run the iOS app, you should specify simulator</p><pre>react-native run-ios --simulator=”iPhone X”</pre><p>To run Android app, you should start emulator first, either via Android Studio or adb , then call</p><pre>react-native run-android</pre><p>You’ll see the default start screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*TnZfGsKdsWGBUac-0YutpA.jpeg" /><figcaption>Default start screen for React Native app</figcaption></figure><h3>4. Install firebase analytics dependency</h3><p>Install this module with Yarn:</p><pre>yarn add @react-native-firebase/analytics<br>yarn add @react-native-firebase/app</pre><p>Need to install the module manually? Follow this guide installation guides.</p><h4><strong>Android:-</strong></h4><p>The following steps are only required if you are using React Native &lt;= 0.59 or need to manually integrate the library.</p><p><strong>Update Gradle Settings</strong></p><p>Add the following to your projects /android/settings.gradle file:</p><pre>include &#39;:@react-native-firebase_analytics&#39;</pre><pre>project(&#39;:@react-native-firebase_analytics&#39;).projectDir = new File(rootProject.projectDir, &#39;./../node_modules/@react-native-firebase/analytics/android&#39;)</pre><p><strong>Update Gradle Dependencies</strong></p><p>Add the React Native Firebase module dependency to your /android/app/build.gradle file:</p><pre>dependencies {</pre><pre>...</pre><pre>implementation project(path: &quot;:@react-native-firebase_analytics&quot;)</pre><pre>}</pre><p><strong>Add package to the Android Application</strong></p><p>Import and apply the React Native Firebase module package to your /android/app/src/main/java/**/MainApplication.java file:</p><p><strong>Import the package:</strong></p><pre>import io.invertase.firebase.analytics.ReactNativeFirebaseAnalyticsPackage;</pre><p><strong>Add the package to the registry:</strong></p><pre>protected List&lt;ReactPackage&gt; getPackages() {</pre><pre>return Arrays.asList(</pre><pre>new MainReactPackage(),</pre><pre>new ReactNativeFirebaseAnalyticsPackage(),</pre><p><strong>Rebuild the project</strong></p><p>Once the above steps have been completed, rebuild your Android project:</p><pre>react-native run-android</pre><h4><strong>iOS:-</strong></h4><p>The following steps are only required if you are using React Native &lt;= 0.59 or need to manually integrate the library.</p><p>Installation can be done via CocoaPods (recommended) or via Frameworks:</p><h4>1. CocoaPods Installation</h4><p><strong>Add the RNFBAnalytics Pod</strong></p><p>Add the RNFBAnalytics Pod to your projects /ios/Podfile:</p><pre>target &#39;app&#39; do</pre><pre>...</pre><pre>pod &#39;RNFBAnalytics&#39;, :path =&gt; &#39;../node_modules/@react-native-firebase/analytics/ios&#39;</pre><pre>end</pre><p><strong>Update Pods &amp; rebuild the project</strong></p><p>You may need to update your local Pods in order for the RNFBAnalytics Pod to be installed in your project:</p><pre>$ cd /ios/</pre><pre>$ pod install --repo-update</pre><p>Once the Pods have installed locally, rebuild your iOS project:</p><pre>react-native run-ios</pre><h4>2. Manual Framework Installation</h4><p>If your environment does not have access to Cocopods, it is still possible to install the project via Frameworks.</p><p>TODO</p><p><strong>Device Identification</strong></p><p>If you would like to enable Firebase Analytics to generate automatic audience metrics for iOS (as it does by default in Android), you must link additional iOS libraries, <a href="https://support.google.com/firebase/answer/6318039">as documented by the Google Firebase team</a>. Specifically you need libAdIdAccess.a and AdSupport.framework.</p><p>The way to do this using Cocoapods is to add this to your Podfile (though please use <a href="https://cocoapods.org/pods/GoogleIDFASupport">the most current Pod version</a> supported by react-native-firebase):</p><p><strong>ios/Podfile</strong>:</p><pre>// ..</pre><pre>target &#39;app&#39; do</pre><pre>// ..</pre><pre>pod &#39;RNFBAnalytics&#39;, :path =&gt; &#39;../node_modules/@react-native-firebase/analytics/ios&#39;</pre><pre>pod &#39;GoogleIDFASupport&#39;, &#39;~&gt; 3.14.0&#39;</pre><pre>end</pre><h3>5. Implement analytics in your app</h3><p>The Analytics package will automatically start tracking events such as when users clear app data, dismiss notifications and more. To view the full list of automatic events, see <a href="https://support.google.com/firebase/answer/6317485">this page</a> of the official Firebase documentation.</p><p>The package also provides a JavaScript API to allow for logging custom events and metrics throughout your application.</p><p>Import the Cloud Functions package into your project:</p><pre>import analytics from &#39;@react-native-firebase/analytics&#39;;</pre><p>The package also provides access to the firebase instance:</p><pre>import { firebase } from &#39;@react-native-firebase/analytics&#39;;</pre><h4>Custom events</h4><p>To log a custom event, use the logEvent method:</p><pre>import analytics from &#39;@react-native-firebase/analytics&#39;;</pre><pre>async function onProductView() {</pre><pre>     await analytics().logEvent(&#39;product_view&#39;, {</pre><pre>                 id: &#39;123456789&#39;,<br>                 color: &#39;red&#39;, <br>                 via: &#39;ProductCatalog&#39;,<br>      });<br>}</pre><h4>Attaching user data</h4><p>User data can be attached to analytical events via the <a href="https://invertase.io/oss/react-native-firebase/v6/analytics/reference/module#setUserId">setUserId</a>, <a href="https://invertase.io/oss/react-native-firebase/v6/analytics/reference/module#setUserProperties">setUserProperties</a> and <a href="https://invertase.io/oss/react-native-firebase/v6/analytics/reference/module#setUserProperty">setUserProperty</a> methods. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties.</p><pre>import analytics from &#39;@react-native-firebase/analytics&#39;;</pre><pre>async function onSignIn(user) {</pre><pre> await Promise.all([</pre><pre>   analytics().setUserId(user.uid),</pre><pre>   analytics().setUserProperty(&#39;account_balance&#39;, user.balance),<br> ]);<br>}</pre><h4>Tracking screen names</h4><p>Similar to Analytics on the web, it’s important to understand the user’s journey within your application, for example, tracking drop off points during an e-commerce transaction flow. The Analytics package provides a method called setCurrentScreen to help track this.</p><pre>import React, { useEffect } from &#39;react&#39;;</pre><pre>import { View } from &#39;react&#39;;</pre><pre>import analytics from &#39;@react-native-firebase/analytics&#39;;</pre><pre>function BasketScreen() {</pre><pre>async function trackScreenView(screen) {</pre><pre>    // Set &amp; override the MainActivity screen name</pre><pre>    await analytics().setCurrentScreen(screen, screen);</pre><pre>}</pre><pre>// Track a screen view once the component has mounted<br>useEffect(() =&gt; {</pre><pre>    trackScreenView(&#39;BasketScreen&#39;);</pre><pre>}, []);</pre><pre>  return &lt;View /&gt;;</pre><pre>}</pre><h4>Resetting analytics data</h4><p>In some cases, resetting all analytics data is required on certain events such as signing out of the application. To achieve this call the resetAnalyticsData method.</p><pre>import analytics from &#39;@react-native-firebase/analytics&#39;;</pre><pre>async function onSignOut() {</pre><pre>    await analytics().resetAnalyticsData();</pre><pre>}</pre><h4>Reserved Events</h4><p>The Analytics package works out of the box, however a number of events are automatically reported to Firebase. These event names are called as ‘Reserved Events’. Attempting to send any custom event using the logEvent method with any of the following event names will throw an error.</p><p><strong>Reserved event list</strong></p><ul><li>app_clear_data</li><li>app_uninstall</li><li>app_update</li><li>error</li><li>first_open</li><li>first_visit</li><li>first_visit</li><li>first_open_time</li><li>first_visit_time</li><li>in_app_purchase</li><li>in_app_purchase</li><li>notification_dismiss</li><li>notification_foreground</li><li>notification_open</li><li>notification_receive</li><li>os_update</li><li>session_start</li><li>screen_view</li><li>user_engagement</li><li>ad_impression</li><li>ad_click</li><li>ad_query</li><li>ad_exposure</li><li>adunit_exposure</li><li>ad_activeiew</li></ul><h3>6. Send analytics event from app to firebase dashboard</h3><p>Prepare a simple event from our app and send it to all Firebase console. For sending app event to dashboard I am just creating one component named it <strong>Analytics.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fc71004774ff757f7779a8e613a44ef/href">https://medium.com/media/8fc71004774ff757f7779a8e613a44ef/href</a></iframe><p>Import this component to your <strong>app.js</strong> File like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eec3cde8a64161ee288f600c17cbe4a2/href">https://medium.com/media/eec3cde8a64161ee288f600c17cbe4a2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*5qY47XxItaWIYiF4AIuwDw.jpeg" /><figcaption>analytics screen</figcaption></figure><p>We have added three buttons here for three events</p><ol><li>Custom Event</li><li>Set User Event</li><li>Reset Analytics Data Event</li></ol><p>So when you click on any of these buttons you can your app events recorded in Firebase dashboard.</p><h3>7. Check this event on Firebase dashboard.</h3><p>Attention: if the app is running with -FIRDebugEnabled it shouldn&#39;t take more than a few seconds for events to start appearing on the DebugView.</p><h4>Dashboard View:-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QD9ovLuzaIQvwYuSpvjr3A.png" /><figcaption>Analytics Dashboard View</figcaption></figure><h4>Event View:-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NoUairmsrso6OIEzcelotQ.png" /></figure><h4>Event Details View:-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vRHpI6_IJd6jvG8DNxMwIw.png" /><figcaption>Event Details view</figcaption></figure><h3>Conclusion</h3><p>In this post, we learnt how to implement Analytics using Firebase in React native apps. We also learnt how to handle different types of actions and see their data in the dashboard.</p><blockquote><strong>Complete code of this post can be found in the Github repository </strong><a href="https://github.com/enappd/AnalyticsData.git"><strong>react-native-firebase-analytics</strong></a><a href="https://github.com/enappd/ionic-4-in-app-purchase"><strong>(master branch)</strong></a></blockquote><h3>Next Steps</h3><p>Now that you have learnt about setting up Analytics in React Native apps, here are some other topics you can look into</p><ul><li>Firebase — <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Push notifications</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Firebase CRUD</a></li><li>How To in React Native — <a href="https://enappd.com/blog/geolocation-geocoding-react-native-apps/84">Geolocation</a> | <a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">Life cycle hooks</a> | <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image Picker</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Redux implementation</a> | <a href="https://enappd.com/blog/how-to-make-api-calls-in-react-native-apps/125">Make API calls</a> | <a href="https://enappd.com/blog/navigations-in-react-native-app/124">Navigation</a> | <a href="https://enappd.com/blog/how-to-translate-in-react-native-app-globalization-internationalization-and-text-to-speech/120">Translation</a> | <a href="https://enappd.com/blog/react-native-qr-code-scanning-using-react-native-camera/117">Barcode &amp; QR code scan</a> | <a href="https://enappd.com/blog/send-read-and-delete-sms-in-react-native/107">Send &amp; Read SMS</a> | <a href="https://enappd.com/blog/google-vision-with-react-native/96">Google Vision</a></li><li>Payments — <a href="https://enappd.com/blog/implement-apple-pay-in-react-native-apps/93">Apple Pay</a> | <a href="https://enappd.com/blog/stripe-integration-in-react-native-apps-using-firebase/108">Stripe payments</a></li><li>Authentication — <a href="https://enappd.com/blog/google-login-in-react-native-android-apps-with-firebase/90">Google Login</a>| <a href="https://enappd.com/blog/facebook-login-in-react-native-apps/89">Facebook login</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Phone Auth</a> | <a href="https://enappd.com/blog/twitter-login-in-react-native-apps-using-firebase/95">Twitter login</a> | <a href="https://enappd.com/blog/anonymous-login-in-react-native-apps-with-firebase/129">Anonymous Login</a></li><li><a href="https://enappd.com/blog/how-to-make-stories-ui-like-instagram-and-whatsapp-in-react-native/123">Create Instagram / Whatsapp Story Feature in React Native</a></li><li><a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">React Native life cycle hooks</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Implement Redux</a> | <a href="https://enappd.com/blog/async-actions-with-redux-thunk-middleware-in-react-native-apps-1/100">Async actions with Redux</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li></ul><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /><figcaption>React Native Full App</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67d480a5b4e7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/firebase-analytics-in-react-native-app-67d480a5b4e7">Firebase analytics in React native app</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Async actions with Redux Thunk middleware in React Native apps]]></title>
            <link>https://medium.com/enappd/async-actions-with-redux-thunk-middleware-in-react-native-apps-9acf8a351596?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9acf8a351596</guid>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Mon, 09 Sep 2019 04:34:09 GMT</pubDate>
            <atom:updated>2020-01-29T18:57:56.973Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="Async actions with Redux Thunk middleware in React Native apps" src="https://cdn-images-1.medium.com/max/1024/1*yLtItjM5bTQjmEDb1Z7MxA.png" /></figure><p>This post will assist any developer to learn on how to implement async actions with the help of middleware (redux-thunk) in react native apps. We’ll approach the implementation by creating a simple application.</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/react-native-redux-thunk.git">React-native-redux-thunk-example</a></blockquote><h3>What Is React Native?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*hVemiPgn143L4vIdAevNvw.jpeg" /><figcaption>React Native logo</figcaption></figure><p>React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. In other words: web developers can now write mobile applications that look and feel truly “native,” all from the comfort of a JavaScript library that we already know and love. Plus, because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS.</p><p>Similar to React for the Web, React Native applications are written using a mixture of JavaScript and XML markup, known as JSX. Then, under the hood, the React Native “bridge” invokes the native rendering APIs in Objective-C (for iOS) or Java (for Android). Thus, your application will render using real mobile UI components, not webviews, and will look and feel like any other mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera, or the user’s location.</p><p>React Native currently supports both iOS and Android and has the potential to expand to future platforms as well. In this blog, we’ll cover both iOS and Android. The vast majority of the code we write will be cross-platform. And yes: you can really use React Native to build production-ready mobile applications! Some example: <a href="http://bit.ly/1YipO7A">Facebook</a>, <a href="http://bit.ly/1PPEiZH">Palantir</a>, and <a href="http://bit.ly/1PPEjNg">TaskRabbit</a> are already using it in production for user-facing applications.</p><h3>What is Redux?</h3><p><a href="https://redux.js.org/"><strong>Redux</strong></a> is a standalone state management library, which can be used with any library or framework. If your background is <strong>React developer</strong>, then you have used the <strong>Redux library with React</strong>. The primary use of <strong>Redux</strong> is that we can use one application state as a global state and interact with the state from any react component is very easy whether they are siblings or parent-child.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*kwMieaTmikxMDhZfI-yeaw.png" /><figcaption>Redux Logo</figcaption></figure><blockquote><strong>Basic usage of Redux comes into picture when the app gets large and complex. In such apps, simple data management as parent-child becomes difficult using </strong><strong><em>props</em>. There are multiple components trying to communicate with multiple other components. In such cases, Redux comes in handy.</strong></blockquote><p>Redux can be broken down into few sections while building the application which is listed below.</p><p><strong>Actions: “</strong>are payloads of information that send data from your application to your store. They are the <em>only</em> source of information for the store.” this means if any state change necessary the change required will be dispatched through the actions.</p><p><strong>Reducers: “</strong>Actions<strong> </strong>describe the fact that <em>something happened</em>, but don’t specify how the application’s state changes in response. This is the job of reducers.” when an action is dispatched for state change its the reducers duty to make the necessary changes to the state and return the new state of the application.</p><p><strong>Store: </strong>with help of reducers a store can be created which holds the entire state of the application it is recommended to use a single store for the entire application than having multiple stores which will violate the use of redux which only has a single store.</p><p><strong>Components (UI): </strong>This<strong> </strong>is where the UI of the application is kept.</p><p><strong>Middlewares</strong>: Redux allows us to put a middleware that sits between an action being dispatched and the <strong>action</strong> that reaches to the <strong>reducers</strong>. Two very popular middleware libraries that will allow for side effects and asynchronous activities are <a href="https://github.com/reduxjs/redux-thunk">Redux Thunk</a> and <a href="https://github.com/redux-saga/redux-saga">Redux Saga</a>. We’ll learn more about thunk here.</p><p><strong>Redux Thunk</strong> is the middleware that lets you call the action creators that return a function instead of the action object. That function then receives the store’s dispatch method, which is then used to dispatch the regular synchronous actions inside a body of the function once the asynchronous operations have completed. The <strong>thunk</strong> is a concept in programming where a function is used to delay the evaluation/calculation of an operation. I know it’s too much of jargon, so let’s see how it works in the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*2--d_JqkSBPUBIe_TsppPA.jpeg" /><figcaption>Redux workflow in a simple schematic</figcaption></figure><h3>Steps for Implementing Redux-thunk in React Native app</h3><p>We will follow these step-by-step instructions to create our React Native with Redux Thunk</p><p><strong>Step 1: Create a Basic React Native app</strong></p><p><strong>Step 2: Running app on a device</strong></p><p><strong>Step 3: Install the necessary packages to connect your app with redux.</strong></p><p><strong>Step 4: Create the necessary folders inside Root.</strong></p><p><strong>Step 5: Create Actions.</strong></p><p><strong>Step 6:- Create rootReducer and postReducer.</strong></p><p><strong>Step 6: Create a Redux Store.</strong></p><p><strong>Step 7: Pass the Store to the React Native app.</strong></p><p><strong>Step 8: Connect React Native app to Redux store.</strong></p><p><strong>Step 9: Test your app</strong></p><p><strong>Step 10: What is the basic difference between redux-thunk and redux-saga?</strong></p><p>So let’s dive right in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*HfUjPCVB8Eer3q22lcuoew.gif" /><figcaption>Ouch! Let’s ….. not dive</figcaption></figure><h3>1. Create a basic React Native app</h3><p>First, make sure you have all pre-requisites to create a react-native app as per the <a href="https://facebook.github.io/react-native/docs/getting-started.html">official documentation</a>.</p><blockquote><strong>At the time of this post, I have React-Native version 0.60</strong></blockquote><p>Create a blank react-native app (Replace myApp with your own name)</p><pre>$ react-native init myApp</pre><p>This will create a basic React-native app which you can run in a device or simulator. (either Android or iOS)</p><h3>Step 2: Running app on device</h3><p>To run the iOS app, you should specify simulator</p><pre>react-native run-ios --simulator=”iPhone X”</pre><p>To run Android app, you should start emulator first, either via Android Studio or adb , then call</p><pre>react-native run-android</pre><p>You’ll see the default start screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*TnZfGsKdsWGBUac-0YutpA.jpeg" /><figcaption>Default start screen for React Native app</figcaption></figure><h3><strong>Step 3: Install the necessary packages to connect your app with redux.</strong></h3><p><strong>npm</strong></p><pre>npm install redux react-redux redux-thunk</pre><p><strong>yarn</strong></p><pre>yarn add redux react-redux redux-thunk</pre><blockquote><a href="https://github.com/reduxjs/react-redux">React Redux</a> is the official <a href="https://reactjs.org/">React</a> binding for <a href="https://redux.js.org/">Redux</a>. It lets your React components read data from a Redux store, and dispatch actions to the store to update data.</blockquote><blockquote>As of React Native 0.18, React Redux 5.x should work with React Native. If you have any issues with React Redux 5.x on React Native, run <em>npm ls react</em> and make sure you don’t have a duplicate React installation in your <em>node_modules</em>. We recommend that you use <em>npm@3.x</em>which is better at avoiding these kinds of issues.</blockquote><p>The React Redux docs are now published at <a href="https://react-redux.js.org/">https://react-redux.js.org</a> .</p><p>If you want to know how it works, check out <a href="https://www.youtube.com/watch?v=VJ38wSFbM3A">this link</a></p><h3>Step 5: Create the necessary folders inside Root</h3><p>Let’s keep this image in mind to help us understand which parts of Redux are implemented at what step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Q3QdBDZL4cBrR5GXT6J5jA.jpeg" /></figure><p>To work with redux you can follow this folder structure for better code quality</p><p>Create the following folders.</p><ol><li><strong>actions</strong></li><li><strong>constants</strong></li><li><strong>reducers</strong></li><li><strong>components</strong></li></ol><h3>Step 6: Create Constants and Actions</h3><p><strong>6.1</strong> Inside the constants folder, create one file called <strong>index.js. </strong>Add the following line inside <strong>index.js.</strong></p><pre>const GET_PAGE_LIST = &#39;GET_PAGE_LIST&#39;;</pre><p><strong>6.2</strong> Inside the <strong>actions </strong>folder, create one file called <strong>pageList.js. </strong>Add the following code inside <strong>pageList.js.</strong></p><p>Actions are JavaScript objects that represent payloads of information that send data from your application to your Redux store.</p><p>Actions have a type and an optional payload. In our case, the type will be GET_PAGE_LIST and the payload pageList which we are assigning into our pageList variable in store.</p><pre>import { GET_PAGE_LIST } from &#39;../constants&#39;;</pre><pre>export function setPageList(pageList) {</pre><pre>return {</pre><pre>type: GET_PAGE_LIST,</pre><pre>payload: pageList,</pre><pre>};</pre><pre>}</pre><pre>export function getPageList() {</pre><pre>return async (dispatch) =&gt; {</pre><pre>try {</pre><pre>const apiReq = await fetch(&#39;http://dummy.restapiexample.com/api/v1/employees&#39;, {</pre><pre>method: &#39;GET&#39;</pre><pre>});</pre><pre>console.log(apiReq);</pre><pre>await dispatch(setPageList(apiReq));</pre><pre>return apiReq || [];</pre><pre>} catch (error) {</pre><pre>console.error(error);</pre><pre>}</pre><pre>};</pre><pre>}</pre><p>So, here we have defined an action that calls the API and gets a response from the server. Remember, the reducer is a pure function, and we do not want any asynchronous call inside reducer, all the asynchronous actions are called here inside actions.</p><p>But, we need to connect this action to our App.js component somehow. Otherwise, we cannot add the data into the Redux store. Also, we need to first create a store. But before that, we also need to create a reducer function. So, first, create a reducer → then create a store and → then connect the React Native application to the <strong>Redux</strong> store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Au_jHh1Ytm-WazqHqB1J-g.jpeg" /><figcaption>Actions created …</figcaption></figure><h3><strong>Step 6:- Create rootReducer and postReducer.</strong></h3><p>Now, inside the <strong>reducers folder, </strong>create one file called <strong>pageList.js.</strong></p><p>Write the following code inside the <strong>pageListReducer.js</strong>.</p><pre>import { GET_PAGE_LIST } from &#39;../constants&#39;;</pre><pre>const initialState = {<br>pageList: []<br>};</pre><pre>const <strong>pageListReducer </strong>= (state = initialState, action) =&gt; {<br>switch(action.type) {<br>case GET_PAGE_LIST:<br>return {<br>...state,<br>pageList: []<br>};<br>default:<br>return state;<br>}<br>}</pre><pre>export default <strong>pageListReducer</strong>;</pre><p>So, here, we have defined the function called <strong>pageListReducer </strong>that accepts the two arguments.</p><ol><li><strong>state</strong></li><li><strong>action</strong></li></ol><p>The first time, it will take the <strong>initial state</strong> of our application, and then we pass whatever argument, it takes that argument and operates based on the case execution. The second argument is <strong>action, </strong>which consists of <strong>type </strong>and <strong>payload. </strong>The <strong>payload</strong> is the count value, which assigned to count variable in store.</p><p>Remember here — we have returned a new state and not existing state. So we have modified the state in a pure manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Lm-NV5s_pxehZXR58XOM9w.jpeg" /><figcaption>Actions and reducer created</figcaption></figure><h3>Step 7:-Create a Redux Store.</h3><p>Inside the root folder, create one folder called <strong>store </strong>and inside this folder add one file called configureStore.js add the following code.</p><pre>import { createStore, combineReducers } from &#39;redux&#39;;</pre><pre>import pageReducer from &#39;../reducers/pageReducer&#39;;</pre><pre>import { applyMiddleware } from &#39;redux&#39;;</pre><pre>import thunk from &#39;redux-thunk&#39;;</pre><pre>const rootReducer = combineReducers(</pre><pre>{ pageList: pageReducer }</pre><pre>);</pre><pre>const configureStore = () =&gt; {</pre><pre>return createStore(rootReducer, applyMiddleware(thunk));</pre><pre>}</pre><pre>export default configureStore;</pre><p>Here, we have created the redux store and passed the reducer to that store. This store will ideally contain all the data that handles the app state.</p><p>The <strong>combineReducer </strong>function combines all the different reducers into one and forms the global state. So this is the global state of our whole application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*5T_3GIKODoO03mrqakOULw.jpeg" /></figure><h3>Step 8: Pass the Store to the React Native app.</h3><p>Inside the root folder, you will find one file called <strong>index.js </strong>and inside that file add the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff6bc89a99db23cbb73be550a660fbc8/href">https://medium.com/media/ff6bc89a99db23cbb73be550a660fbc8/href</a></iframe><p>It is almost the same as React web application, in which we pass the Provider as a root element and pass the store and then via react-redux’s <strong>connect</strong>() function, we can <strong>connect</strong> the any react component to <strong>redux</strong> store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*6kh_Lwo9EKVfsaZKtw3oTw.jpeg" /><figcaption>Store connected to the app</figcaption></figure><h3><strong>Step 8: Connect React Native app to Redux store.</strong></h3><p>Finally, we connect our <strong>App.js </strong>component to the <strong>Redux</strong> store. For that, we need the <strong>connect() </strong>function from the<strong> react-redux</strong> library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca1474e8f710b13c10bb87ab74b7cba3/href">https://medium.com/media/ca1474e8f710b13c10bb87ab74b7cba3/href</a></iframe><p><strong>Connect</strong> which needs to be imported from <em>react-redux </em>and with the help of connect the properties will be mapped to the UI component.</p><p><strong>mapStateToProps </strong>will contain all the state properties which will be available to the components of the app whatever properties that need to be accessed from the UI components need to be written into the <strong>mapStateToProps </strong>helper function.</p><p><strong>mapDispatchToProps </strong>will contain all the necessary functions wrapped with action creators which will be mapped to the props of the app and can be called directly. The directory containing the below file is ./actions/pageList.js</p><p>Here, when we click on the get employee button, we get the Employees value from props and change it and then send it to the action with that value. Now that action returned the object with the action type and payload and based on the type the reducer will be executed and add that values inside the store.</p><p>Now, if the store’s values are changed, then we need to update the UI based on the new values. That is why <strong>the mapStateToProps </strong>function is created. So, when the store’s count get the new value, render function executed again and update the UI.</p><h3>Step 10: Test your app:</h3><p>Once you run the application the below UI will be rendered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*7OV5yCea4w2qv9xDT6Cb-g.jpeg" /></figure><p>Once you click on any of the get employe buttons it will correctly fetch data from a server and render it on UI. Although, what we just did is nothing fancy for an app, remember everything is going through the whole <strong>“action-reducer-store-state”</strong> flow. This flow can handle large and complex apps, so you don’t get stuck in<strong> “props” </strong>loops.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*3FxIFMjmE0Bj2KyWxtp2BA.jpeg" /></figure><p>(If you are from an <strong>Angular</strong> background, for ease of understanding, you can understand actions as something similar to methods in services which we can call from any component or page. Reducers are also similar functions, but they change the central store of the app. Store can be assumed as something similar to a $rootscope object which stores all the data at one place, and can be accessed from any page. Don’t draw a direct comparison between these things, this is just to help you understand the concept in an easier way.)</p><p>Hope this blog helps you to implement redux with middleware (thunk) in react native apps.</p><h3><strong>Step 10: What is the basic difference between redux-thunk and redux-saga?</strong></h3><p>In terms of implementation, Redux-Thunk and Redux-Saga couldn’t possibly be more different. However, in terms of what you can do with them… well, they’re actually very very similar. But not the same. Redux-Thunk and Redux-Saga differ in a few important ways.</p><p>But, first, let’s cover some background.</p><p>Redux-thunk and Redux-saga are both <a href="https://redux.js.org/advanced/middleware">middleware</a> libraries for Redux. Redux middleware is code that intercepts actions coming into the store via the dispatch() method.</p><p>An action can be literally anything.</p><p>But if you’re following best practices, an action is a plain javascript object with a type field, and optional payload, meta, and error fields. E.g.</p><pre>const loginRequest = {</pre><pre>type: &#39;LOGIN_REQUEST&#39;,</pre><pre>payload: {</pre><pre>name: &#39;admin&#39;,</pre><pre>password: &#39;123&#39;,</pre><pre>},</pre><pre>};</pre><p>(by the way, this structure is called <a href="https://github.com/acdlite/flux-standard-action#actions">Flux Standard Action</a>)</p><p>This is what the type signature looks like in TypeScript</p><pre>type Action = {    <br>     type: string;    <br>     payload?: any;    <br>     meta?: any;    <br>     error?: boolean;<br>};</pre><h3>Redux-Thunk</h3><p>In addition to dispatching standard actions, Redux-Thunk middleware allows you to dispatch special functions, called <a href="https://en.wikipedia.org/wiki/Thunk">thunks</a>.</p><p>Thunks (in Redux) generally have the following structure:</p><pre>export const thunkName =   parameters =&gt;   <br>     (dispatch, getState) =&gt; {         <br>   // Your application logic goes here      <br> };</pre><p>That is, a thunk is a function that (optionally) takes some parameters and returns another function. The inner function takes a dispatch function and a getState function -- both of which will be supplied by the Redux-Thunk middleware.</p><p>Here we have an example thunk that attempts to call a login API with a username and password. The thunk first dispatches an action indicating that the request is starting. It then makes the call. Finally, it dispatches either a success action or a failure action depending on whether or not the API call succeeded.</p><pre>import * as api from &#39;api&#39;;</pre><pre>import { loginRequest, loginSuccess, loginFailure } from &#39;./loginActions&#39;;</pre><pre>export const loginThunk =</pre><pre>(name: string, password: string) =&gt;</pre><pre>(dispatch: Function) =&gt; {</pre><pre>   dispatch(loginRequest());</pre><pre>   try {</pre><pre>      api.login(name, password);</pre><pre>   }catch (err) {</pre><pre>     dispatch(loginFailure(err));</pre><pre>     return;</pre><pre>   }</pre><pre>   dispatch(loginSuccess());</pre><pre>};</pre><p>When you dispatch your thunk, e.g. dispatch(loginThunk(&#39;admin&#39;, &#39;secret&#39;)); Redux-Thunk calls your inner function, which is essentially:</p><pre>(dispatch: Function) =&gt; {</pre><pre>  dispatch(loginRequest());</pre><pre>  try {</pre><pre>     api.login(&#39;admin&#39;, &#39;secret&#39;); // values from closure</pre><pre>  }catch (err) {</pre><pre>    dispatch(loginFailure(err));</pre><pre>    return;</pre><pre>  }</pre><pre>  dispatch(loginSuccess());</pre><pre>};</pre><p>Now that we’ve covered the basics of Redux-thunk, let’s look at Redux-Saga</p><h3>Redux-Saga</h3><p>Redux-Saga middleware allows you to express complex application logic as <a href="https://en.wikipedia.org/wiki/Pure_function">pure functions</a> called sagas. Pure functions are desirable from a testing standpoint because they are predictable and repeatable, which makes them relatively easy to test.</p><p>Sagas are implemented through special functions called <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function%2A">generator functions</a>. These are a new feature of ES6 JavaScript. Basically, execution jumps in and out of a generator everywhere you see a yieldstatement. Think of a yield statement as causing the generator to pause and return the yielded value. Later on, the caller can resume the generator at the statement following the yield.</p><p>A generator function is one defined like this. Notice the asterisk after the function keyword.</p><pre>function* mySaga() {    // ...}</pre><p>We can rewrite the login functionality from before as a saga. It looks like this:</p><pre>import * as api from &#39;api&#39;;</pre><pre>import { LoginRequestAction, loginSuccess, loginFailure } from &#39;./loginActions&#39;;</pre><pre>function* loginSaga() {</pre><pre>const action: LoginRequestAction = yield take(&#39;LOGIN_REQUEST&#39;);</pre><pre>const { name, password } = action.payload;</pre><pre>try {</pre><pre>yield call(api.login, name, password);</pre><pre>}</pre><pre>catch (err) {</pre><pre>yield put(loginFailure(err));</pre><pre>return;</pre><pre>}</pre><pre>yield put(loginSuccess());</pre><pre>}</pre><p>Once the login saga is registered with Redux-Saga, it will begin executing immediately. But then the yield take on the the first line will pause the saga until an action with type &#39;LOGIN_REQUEST&#39; is dispatched to the store. Once that happens, execution will continue.</p><h3>The Biggest Difference</h3><p>You might think the biggest difference is in the syntax. Although it’s true that writing and reasoning about thunks and sagas are quite different, there’s something bigger.</p><p><strong>Thunks can never act in response to an action.</strong> Redux-Saga, on the other hand, subscribes to the store and can trigger a saga to run or continue when a certain action is dispatched.</p><h3>Conclusion</h3><p>In this post, you learned how to implement Redux with middleware(redux-thunk) in your React Native app. You learnt what are reducers, actions, and store, how the flow of data is managed in a Redux based app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*ceLX14cSsAZ-M7c2GHdlSA.gif" /><figcaption>Now, chill</figcaption></figure><p>And that’s it! The application now uses Redux and Redux Thunk to fetch and display the data!</p><p>That wasn’t too difficult, was it?</p><p>And you’re now a Redux master :D</p><p>Stay tuned for more Ionic and React Native blogs!</p><p>Happy Coding.🤓👍🏼</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/react-native-redux-thunk.git">React-native-redux-thunk-example</a></blockquote><h3>Next Steps</h3><p>Now that you have learnt about setting up Redux with middleware(redux-thunk) in React Native apps, here are some other topics you can look into</p><ul><li>Firebase — <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a> | <a href="https://enappd.com/blog/firebase-analytics-in-react-native-app/101">Analytics</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Push notifications</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Firebase CRUD</a></li><li>How To in React Native — <a href="https://enappd.com/blog/geolocation-geocoding-react-native-apps/84">Geolocation</a> | <a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">Life cycle hooks</a> | <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image Picker</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Redux implementation</a> | <a href="https://enappd.com/blog/how-to-make-api-calls-in-react-native-apps/125">Make API calls</a> | <a href="https://enappd.com/blog/navigations-in-react-native-app/124">Navigation</a> | <a href="https://enappd.com/blog/how-to-translate-in-react-native-app-globalization-internationalization-and-text-to-speech/120">Translation</a> | <a href="https://enappd.com/blog/react-native-qr-code-scanning-using-react-native-camera/117">Barcode &amp; QR code scan</a> | <a href="https://enappd.com/blog/send-read-and-delete-sms-in-react-native/107">Send &amp; Read SMS</a> | <a href="https://enappd.com/blog/google-vision-with-react-native/96">Google Vision</a></li><li>Payments — <a href="https://enappd.com/blog/implement-apple-pay-in-react-native-apps/93">Apple Pay</a> | <a href="https://enappd.com/blog/stripe-integration-in-react-native-apps-using-firebase/108">Stripe payments</a></li><li>Authentication — <a href="https://enappd.com/blog/google-login-in-react-native-android-apps-with-firebase/90">Google Login</a>| <a href="https://enappd.com/blog/facebook-login-in-react-native-apps/89">Facebook login</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Phone Auth</a> | <a href="https://enappd.com/blog/twitter-login-in-react-native-apps-using-firebase/95">Twitter login</a> | <a href="https://enappd.com/blog/anonymous-login-in-react-native-apps-with-firebase/129">Anonymous Login</a></li><li><a href="https://enappd.com/blog/how-to-make-stories-ui-like-instagram-and-whatsapp-in-react-native/123">Create Instagram / Whatsapp Story Feature in React Native</a></li><li><a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">React Native life cycle hooks</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Implement Redux</a> | <a href="https://enappd.com/blog/async-actions-with-redux-thunk-middleware-in-react-native-apps-1/100">Async actions with Redux</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li></ul><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9acf8a351596" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/async-actions-with-redux-thunk-middleware-in-react-native-apps-9acf8a351596">Async actions with Redux Thunk middleware in React Native apps</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement Redux in React Native apps]]></title>
            <link>https://medium.com/enappd/how-to-implement-redux-in-react-native-apps-cedd32dec4a3?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cedd32dec4a3</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux-saga]]></category>
            <category><![CDATA[state]]></category>
            <category><![CDATA[store]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 09:23:57 GMT</pubDate>
            <atom:updated>2020-01-29T18:58:11.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="How to implement Redux in React Native apps" src="https://cdn-images-1.medium.com/max/1024/1*GmgQZmygMWAOyJy8Inrz2A.png" /></figure><p>This post will assist any developer to learn on how <a href="https://redux.js.org/">Redux</a> works with react native by creating a simple application with basic data flow.</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/react-native-redux.git">React-native-redux-example</a></blockquote><h3>What Is React Native?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*hVemiPgn143L4vIdAevNvw.jpeg" /><figcaption>React Native logo</figcaption></figure><p>React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. In other words: web developers can now write mobile applications that look and feel truly “native,” all from the comfort of a JavaScript library that we already know and love. Plus, because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS.</p><p>Similar to React for the Web, React Native applications are written using a mixture of JavaScript and XML markup, known as JSX. Then, under the hood, the React Native “bridge” invokes the native rendering APIs in Objective-C (for iOS) or Java (for Android). Thus, your application will render using real mobile UI components, not webviews, and will look and feel like any other mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera, or the user’s location.</p><p>React Native currently supports both iOS and Android and has the potential to expand to future platforms as well. In this blog, we’ll cover both iOS and Android. The vast majority of the code we write will be cross-platform. And yes: you can really use React Native to build production-ready mobile applications! Some example: <a href="http://bit.ly/1YipO7A">Facebook</a>, <a href="http://bit.ly/1PPEiZH">Palantir</a>, and <a href="http://bit.ly/1PPEjNg">TaskRabbit</a> are already using it in production for user-facing applications.</p><h3>What is Redux?</h3><p><a href="https://redux.js.org/"><strong>Redux</strong></a> is a standalone state management library, which can be used with any library or framework. If your background is <strong>React developer</strong>, then you have used the <strong>Redux library with React</strong>. The primary use of <strong>Redux</strong> is that we can use one application state as a global state and interact with the state from any react component is very easy whether they are siblings or parent-child.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*kwMieaTmikxMDhZfI-yeaw.png" /><figcaption>Redux Logo</figcaption></figure><blockquote><strong>Basic usage of Redux comes into picture when the app gets large and complex. In such apps, simple data management as parent-child becomes difficult using </strong><strong>props. There are multiple components trying to communicate with multiple other components. In such cases, Redux comes in handy.</strong></blockquote><p>Redux can be broken down into few sections while building the application which is listed below.</p><p><strong>Actions: “</strong>are payloads of information that send data from your application to your store. They are the <em>only</em> source of information for the store.” this means if any state change necessary the change required will be dispatched through the actions.</p><p><strong>Reducers: “</strong>Actions<strong> </strong>describe the fact that <em>something happened</em>, but don’t specify how the application’s state changes in response. This is the job of reducers.” when an action is dispatched for state change its the reducers duty to make the necessary changes to the state and return the new state of the application.</p><p><strong>Store: </strong>with help of reducers a store can be created which holds the entire state of the application it is recommended to use a single store for the entire application than having multiple stores which will violate the use of redux which only has a single store.</p><p><strong>Components (UI): </strong>This<strong> </strong>is where the UI of the application is kept.</p><p><strong>Middlewares</strong>: middleware can be used for a variety of things, including asynchronous API calls. Middleware sounds much more complicated than it really is. The only way to really understand middleware is to see how the existing middleware works and try to write your own.we will cover middleware in the next blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*2--d_JqkSBPUBIe_TsppPA.jpeg" /><figcaption>Redux workflow in simple schematic</figcaption></figure><p>Without further explanation, let’s get into the coding aspects.</p><h3>Steps for Implementing Redux in React Native app</h3><p>We will follow these step-by-step instructions to create our React Native with Redux</p><p><strong>Step 1: Create a Basic React Native app</strong></p><p><strong>Step 2: Running app on device</strong></p><p><strong>‌Step 3: Add simple counter into the App.js.</strong></p><p><strong>Step 4: Install the necessary packages to connect your app with redux.</strong></p><p><strong>Step 5: Create the necessary folders inside Root.</strong></p><p><strong>Step 6: Create Actions and Reducer function.</strong></p><p><strong>Step 7: Create a Redux Store.</strong></p><p><strong>Step 8: Pass the Store to the React Native app.</strong></p><p><strong>Step 9: Connect React Native app to Redux store.</strong></p><p><strong>Step 10: Test your app</strong></p><p>So let’s dive right in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*HfUjPCVB8Eer3q22lcuoew.gif" /><figcaption>Ouch! Let’s ….. not dive</figcaption></figure><h3>1. Create a basic React Native app</h3><p>First, make sure you have all pre-requisites to create a react-native app as per the <a href="https://facebook.github.io/react-native/docs/getting-started.html">official documentation</a>.</p><blockquote><strong>At the time of this post, I have React-Native version 0.60</strong></blockquote><p>Create a blank react-native app (Replace myApp with your own name)</p><pre>$ react-native init myApp</pre><p>This will create a basic React-native app which you can run in a device or simulator. (either Android or iOS)</p><h3>Step 2: Running app on device</h3><p>To run the iOS app, you should specify simulator</p><pre>react-native run-ios --simulator=”iPhone X”</pre><p>To run Android app, you should start emulator first, either via Android Studio or adb , then call</p><pre>react-native run-android</pre><p>You’ll see the default start screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*TnZfGsKdsWGBUac-0YutpA.jpeg" /><figcaption>Default start screen for React Native app</figcaption></figure><h3>‌Step 3: Add simple counter into the App.js.</h3><p>Now we’ll changeApp.js to contain the UI required to render on the application with all the styling’s as shown below. The UI will contain two button’s and a text to show the count. All the class actions will be accessed using the this variable and all the state variable will be accessed using this.state which contain the current state of the app. Within the button onPress field, the actions will be called which are defined on the class in App.js.</p><p>So after adding this counter your App.js looks something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b82bdefc29b64a4d2f11c314f3f80c5/href">https://medium.com/media/7b82bdefc29b64a4d2f11c314f3f80c5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*C5riZSuBtgeRRAs5T71hVA.jpeg" /></figure><h3><strong>Step 4: Install the necessary packages to connect your app with redux</strong></h3><p>In order to get redux to work with react-native few packages need to be installed as shown below</p><p><strong>npm</strong></p><pre>npm install react-redux<br>npm install redux</pre><p><strong>yarn</strong></p><pre>yarn add react-redux<br>yarn add redux</pre><blockquote><a href="https://github.com/reduxjs/react-redux">React Redux</a> is the official <a href="https://reactjs.org/">React</a> binding for <a href="https://redux.js.org/">Redux</a>. It lets your React components read data from a Redux store, and dispatch actions to the store to update data.</blockquote><blockquote>As of React Native 0.18, React Redux 5.x should work with React Native. If you have any issues with React Redux 5.x on React Native, run npm ls react and make sure you don’t have a duplicate React installation in your node_modules. We recommend that you use npm@3.xwhich is better at avoiding these kinds of issues.</blockquote><p>The React Redux docs are now published at <a href="https://react-redux.js.org/">https://react-redux.js.org</a> .</p><p>If you want to know how it works, check out <a href="https://www.youtube.com/watch?v=VJ38wSFbM3A">this link</a></p><h3><strong>Step 5: Create the necessary folders inside Root</strong></h3><p>Let’s keep this image in mind to help us understand which parts of Redux are implemented at what step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Q3QdBDZL4cBrR5GXT6J5jA.jpeg" /></figure><p>To work with redux you can follow this folder structure for better code quality</p><p>Create the following folders.</p><ol><li><strong>actions</strong></li><li><strong>constants</strong></li><li><strong>reducers</strong></li><li><strong>components</strong></li></ol><h3><strong>Step 6: Create Constants, Actions, and Reducer function</strong></h3><p><strong>6.1</strong> Inside the constants folder, create one file called <strong>index.js. </strong>Add the following line inside <strong>index.js.</strong></p><pre>export const COUNTER_CHANGE = &#39;COUNTER_CHANGE&#39;</pre><p><strong>6.2</strong> Inside the <strong>actions </strong>folder, create one file called <strong>counts.js. </strong>Add the following code inside <strong>counts.js.</strong></p><p>Actions are JavaScript objects that represent payloads of information that send data from your application to your Redux store.</p><p>Actions have a type and an optional payload. In our case, the type will be COUNTER_CHANGE, and the payload count which we are assigning into our count variable in store.</p><pre>import { COUNTER_CHANGE } from &#39;../constants&#39;;</pre><pre>export function changeCount(count) {<br>  return {<br>    type: COUNTER_CHANGE,<br>    payload: count<br>  }<br>}</pre><p>The <strong>changeCount() </strong>function returns an action. Now based on that action, reducers function’s case is executed.</p><p>But, we need to connect this action to our App.js component somehow. Otherwise, we cannot add the data into the Redux store. Also, we need to first create a store. But before that, we also need to create a reducer function. So, first, create a reducer → then create a store and → then connect the React Native application to the <strong>Redux</strong> store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Au_jHh1Ytm-WazqHqB1J-g.jpeg" /><figcaption>Actions created …</figcaption></figure><p><strong>6.3</strong> Inside <strong>reducers </strong>function, create one file called <strong>countReducer.js. </strong>Add the following code inside it.</p><p>A reducer is a pure function that takes the previous state and an action as arguments and returns a new state. The reducer is instrumental in keeping the current state of count updated throughout our app as it changes.</p><pre>import { COUNTER_CHANGE } from &#39;../constants&#39;;</pre><pre>const initialState = {<br>  count: 0<br>};</pre><pre>const countReducer = (state = initialState, action) =&gt; {<br>  switch(action.type) {<br>    case COUNTER_CHANGE:<br>      return {<br>        ...state,<br>        count:action.payload<br>      };<br>    default:<br>      return state;<br>  }<br>}</pre><pre>export default countReducer;</pre><p>So, here, we have defined the function called <strong>countReducer</strong> that accepts the two arguments.</p><ol><li><strong>state</strong></li><li><strong>action</strong></li></ol><p>The first time, it will take the <strong>initial state</strong> of our application, and then we pass whatever argument, it takes that argument and operates based on the case execution. The second argument is <strong>action, </strong>which consists of <strong>type </strong>and <strong>payload. </strong>The <strong>payload</strong> is the count value, which assigned to count variable in store.</p><p>Remember here — we have returned a new state and not existing state. So we have modified the state in pure manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Lm-NV5s_pxehZXR58XOM9w.jpeg" /><figcaption>Actions and reducer created</figcaption></figure><h3>Step 7:-Create a Redux Store.</h3><p>Inside the root folder, create one folder called <strong>store </strong>and inside this folder add one file called configureStore.js add the following code.</p><pre>import { createStore, combineReducers } from &#39;redux&#39;;</pre><pre>import countReducer from &#39;../reducers/countReducer&#39;;</pre><pre>const rootReducer = combineReducers(</pre><pre>{ count: countReducer }</pre><pre>);</pre><pre>const configureStore = () =&gt; {</pre><pre>return createStore(rootReducer);</pre><pre>}</pre><pre>export default configureStore;</pre><p>Here, we have created the redux store and passed the reducer to that store. This store will ideally contain all the data that handles the app state.</p><p>The <strong>combineReducer </strong>function combines all the different reducers into one and forms the global state. So this is the global state of our whole application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*5T_3GIKODoO03mrqakOULw.jpeg" /></figure><h3>Step 8: Pass the Store to the React Native app.</h3><p>Inside the root folder, you will find one file called <strong>index.js </strong>and inside that file add the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3c7115734bf6821f9fdbe166a6cda74/href">https://medium.com/media/a3c7115734bf6821f9fdbe166a6cda74/href</a></iframe><p>It is almost the same as React web application, in which we pass the Provider as a root element and pass the store and then via react-redux’s <strong>connect</strong>() function, we can <strong>connect</strong> the any react component to <strong>redux</strong> store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*6kh_Lwo9EKVfsaZKtw3oTw.jpeg" /><figcaption>Store connected to the app</figcaption></figure><h3>Step 9: Connect React Native app to Redux store.</h3><p>Finally, we connect our <strong>App.js </strong>component to the <strong>Redux</strong> store. For that, we need the <strong>connect() </strong>function from the<strong> react-redux</strong> library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86060b85642dfac1436a6f16d2491af4/href">https://medium.com/media/86060b85642dfac1436a6f16d2491af4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*s7Zns1QN9G_w0O_rwNCNAA.jpeg" /><figcaption>And finally, store is now connected to UI via State</figcaption></figure><p><strong>Connect</strong> which needs to be imported from <em>react-redux </em>and with the help of connect the properties will be mapped to the UI component.</p><p><strong>mapStateToProps </strong>will contain all the state properties which will be available to the components of the app whatever properties that need to be accessed from the UI components need to be written into the <strong>mapStateToProps </strong>helper function.</p><p><strong>mapDispatchToProps </strong>will contain all the necessary functions wrapped with action creators which will be mapped to the props of the app and can be called directly. The directory containing the below file is ./actions/counts.js</p><p>Here, when we click on the increment or decrement button, we get the count value from props and change it and then send it to the action with that value. Now that action returned the object with the action type and payload and based on the type the reducer will be executed and add that values inside the store.</p><p>Now, if the store’s values are changed, then we need to update the UI based on the new values. That is why <strong>the mapStateToProps </strong>function is created. So, when the store’s count get the new value, render function executed again and update the UI.</p><h3><strong>Step 10: Test your app:</strong></h3><p>Once you run the application the below UI will be rendered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*C5riZSuBtgeRRAs5T71hVA.jpeg" /><figcaption>Basic Redux Example</figcaption></figure><p>Once you click on any of the buttons it will correctly increment and decrement the count. Although, what we just did is nothing fancy for an app, remember everything is going through the whole <strong>“action-reducer-store-state”</strong> flow. This flow can handle large and complex apps, so you don’t get stuck in<strong> “props” </strong>loops.</p><p>(If you are from an <strong>Angular</strong> background, for ease of understanding, you can understand actions as something similar to methods in services which we can call from any component or page. Reducers are also similar functions, but they change the central store of the app. Store can be assumed as something similar to a $rootscope object which stores all the data at one place, and can be accessed from any page. Don’t draw a direct comparison between these things, this is just to help you understand the concept in an easier way.)</p><p>Hope this blog helps you to implement redux with react native apps.</p><h3>Conclusion</h3><p>In this post, you learned how to implement Redux in your React Native app. You learnt what are reducers, actions and store, how the flow of data is managed in a Redux based app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*ceLX14cSsAZ-M7c2GHdlSA.gif" /><figcaption>Now, chill</figcaption></figure><p>Stay tuned for more Ionic and React Native blogs !</p><p>Happy Coding.🤓👍🏼</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/react-native-redux.git">React-native-redux-example</a></blockquote><p>The next post will be on how to implement async actions with the help of middlewares.</p><h3>Next Steps</h3><p>Now that you have learnt about setting up Redux in React Native apps, here are some other topics you can look into</p><ul><li>Firebase — <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a> | <a href="https://enappd.com/blog/firebase-analytics-in-react-native-app/101">Analytics</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Push notifications</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Firebase CRUD</a></li><li>How To in React Native — <a href="https://enappd.com/blog/geolocation-geocoding-react-native-apps/84">Geolocation</a> | <a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">Life cycle hooks</a> | <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image Picker</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Redux implementation</a> | <a href="https://enappd.com/blog/how-to-make-api-calls-in-react-native-apps/125">Make API calls</a> | <a href="https://enappd.com/blog/navigations-in-react-native-app/124">Navigation</a> | <a href="https://enappd.com/blog/how-to-translate-in-react-native-app-globalization-internationalization-and-text-to-speech/120">Translation</a> | <a href="https://enappd.com/blog/react-native-qr-code-scanning-using-react-native-camera/117">Barcode &amp; QR code scan</a> | <a href="https://enappd.com/blog/send-read-and-delete-sms-in-react-native/107">Send &amp; Read SMS</a> | <a href="https://enappd.com/blog/google-vision-with-react-native/96">Google Vision</a></li><li>Payments — <a href="https://enappd.com/blog/implement-apple-pay-in-react-native-apps/93">Apple Pay</a> | <a href="https://enappd.com/blog/stripe-integration-in-react-native-apps-using-firebase/108">Stripe payments</a></li><li>Authentication — <a href="https://enappd.com/blog/google-login-in-react-native-android-apps-with-firebase/90">Google Login</a>| <a href="https://enappd.com/blog/facebook-login-in-react-native-apps/89">Facebook login</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Phone Auth</a> | <a href="https://enappd.com/blog/twitter-login-in-react-native-apps-using-firebase/95">Twitter login</a> | <a href="https://enappd.com/blog/anonymous-login-in-react-native-apps-with-firebase/129">Anonymous Login</a></li><li><a href="https://enappd.com/blog/how-to-make-stories-ui-like-instagram-and-whatsapp-in-react-native/123">Create Instagram / Whatsapp Story Feature in React Native</a></li><li><a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">React Native life cycle hooks</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Implement Redux</a> | <a href="https://enappd.com/blog/async-actions-with-redux-thunk-middleware-in-react-native-apps-1/100">Async actions with Redux</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li></ul><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cedd32dec4a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/how-to-implement-redux-in-react-native-apps-cedd32dec4a3">How to implement Redux in React Native apps</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facebook login in React Native apps]]></title>
            <link>https://medium.com/enappd/facebook-login-in-react-native-apps-6ff5995e1932?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ff5995e1932</guid>
            <category><![CDATA[facebook-auth]]></category>
            <category><![CDATA[socialauth]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[social-login]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 17:40:15 GMT</pubDate>
            <atom:updated>2020-01-29T19:00:28.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Facebook login in React Native apps" src="https://cdn-images-1.medium.com/max/1024/1*KP3bOilGwv5uIXCJkSc1VQ.png" /></figure><p>In this post, you will learn how to implement a Facebook authentication in React native apps.</p><p>We will cook a sample app, where users can log in using their Facebook account. After login, the user can see their basic profile information on the home page.</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/facebook-login-rn.git"><em>React-native-facebook-Login-Starter</em></a></blockquote><h3>Social logins — What and why</h3><p>It’s helpful to use social sign-in with React Native for your users who would rather not create and remember another username/password combination. Instead, you can allow users to sign in with accounts they already own. You don’t need to store hashed passwords to compare, you don’t have to handle sending sign up emails, and you don’t need to reset passwords. The user’s chosen provider will handle all of this for you. Plus, in mobile apps, the Facebook login is automatically done with the pre-installed Facebook app.</p><h3>Facebook login — What and why</h3><p>There are several reasons why you should use a Facebook login in your app</p><ul><li><strong>Ease of use</strong> — When a new user uses your app, only two buttons clicks are required to log in using Facebook. In another scenario, the user will have to type in an email/password and login</li><li><strong>No “forgot password” </strong>— When your app uses Facebook login, the user does not have to worry about forgetting the password for your app’s login</li><li><strong>No “verify email”</strong> — If you use a custom-email authentication of your own, you will have to verify the email if it is a valid one or not. Facebook login will always have a valid email/phone number associated.</li><li><strong>Single solution — </strong>Facebook log in can allow your users to use single login credentials across multiple devices</li><li><strong>Facebook integration</strong> — If your app uses Facebook authentication, you can use Facebook APIs inside your app as well. This can include fetching user tweets etc.</li><li><strong>Trust</strong> — Nowadays, people generally trust social logins moreover custom email logins. Social logins follow standard privacy protocols and hence are more reliable for information sharing</li></ul><h3>React Native Authentication</h3><p>The React Native has been around for around 5 years and has been very popular among developers for its ease of usage over Swift / Java. Plus it requires you to have single source code for both an Android and an iOS app. What more can a developer ask for!</p><p>There are several ways of Authentication in React Native apps</p><ul><li><strong>Social logins </strong>— Social logins are a popular and easy way of authentication in mobile apps. You must have seen Google, Facebook, Instagram logins in almost all the modern apps. Social logins are easy to use and more reliable for quick integrations.</li><li><strong>Back-end as a Service (BaaS) — </strong>You<strong> </strong>can use pre-built BaaS platforms which allows easy integration of authentication in your apps. Basically, these platforms provide you a ready-made back-end, so you don’t have to make one on your own. Firebase, Parse, Back4App are some BaaS platforms.<br><strong><em>Firebase</em></strong> is the most popular among these for mobile apps</li><li><strong>Create your own back-end</strong> — You can create your own back-end in Node.js, Go, Django or Ruby-on-rails, and connect your app authentication to your own back-end. This method is favored by developers who need full control over user authentication. But this method is the most time taking one as well.</li></ul><h3>Steps for Facebook authentication</h3><p>We will follow these step-by-step instructions to create our React Native app with Facebook authentication</p><p><strong>Step 1: Create a basic React Native app</strong></p><p><strong>Step 2: Facebook Developer Console — Create your app</strong></p><p>‌‌<strong>Step 3: Add your Platforms to Facebook</strong></p><p>‌<strong>Step 4: Install the React Native FBSDK</strong> <strong>to connect your app with Facebook</strong></p><p><strong>Step 5: Running Apps</strong></p><p><strong>Step 6: Authenticate Users using Facebook</strong></p><p><strong>Step 7: Test your app on Android</strong></p><h3>1. Create a basic React Native app</h3><p>First, make sure you have all pre-requisites to create a react-native app as per the <a href="https://facebook.github.io/react-native/docs/getting-started.html">official documentation</a>.</p><blockquote><strong>At the time of this post, I have React-Native version 0.60</strong></blockquote><p>Create a blank react-native app (Replace myApp with your own name)</p><pre>$ react-native init myApp</pre><p>This will create a basic React-native app which you can run in a device or simulator. (either Android or iOS)</p><h3>Step 2: Facebook Developer Console</h3><p>The first thing we need to do is to create a new application in Facebook’s developer dashboard, and this app is the one that Facebook will use to ask our users for their permission when we try to log them into our React Native application.</p><p>For that, you’ll need to go to the <a href="https://developers.facebook.com/apps"><strong>F</strong></a><a href="https://developers.facebook.com/apps"><strong>acebook developer console</strong></a> and create a new app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*25XkXnSODKdAfMqY" /><figcaption>Create a new app in Facebook Developer console</figcaption></figure><p>Once we finish creating our app, we will go to the Facebook app dashboard and pick <strong>App Id</strong> from there. It will be required in installing the Facebook plugin in the app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QT4zATT8m2s_NfQI" /><figcaption>Facebook Developer Console — App ID on top-left</figcaption></figure><h3>‌‌Step 3: Add your Platforms to Facebook</h3><p>We need to let Facebook know which platforms we’ll be using (<em>if it’s just web, iOS, or Android</em>).</p><p>‌In our case, we will add all platforms iOS and Android.</p><p>‌To add the platforms, go ahead inside your Facebook dashboard and click on <strong>Settings</strong>, then right below the app’s information you’ll see a button that says <strong>Add Platform</strong>, click it.</p><p>You’ll see several options for the platforms you’re creating</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0VnMWKBszvJ5iwCf" /><figcaption>Options to create platforms</figcaption></figure><h4>Add Platforms in Facebook dashboard</h4><p>‌ <strong>Let’s start with iOS:-</strong> You’ll see a form asking you for some information, right now we just need the Bundle ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/0*aCcsrSi7qQNWASm0" /><figcaption>Create iOS app in Facebook console</figcaption></figure><p>‌Once you add the Bundle ID, just follow the process to create the app.</p><p>‌<strong>Android:-</strong> The difference is that instead of Bundle ID, Android calls it “Google Play Package Name.”</p><h3>‌Step 4: Install the React Native FBSDK to connect your app with Facebook</h3><h4>Installation</h4><p><strong>Install JavaScript packages</strong></p><p>Install the react-native-fbsdk package:</p><pre>yarn add react-native-fbsdk</pre><blockquote><em>Or, if using npm:</em></blockquote><pre>npm install react-native-fbsdk</pre><p>Finally, link the SDK to configure the iOS and Android projects:</p><pre>react-native link react-native-fbsdk</pre><h4>Configure projects</h4><p><strong>Android</strong></p><p>Assuming you have <a href="http://developer.android.com/sdk/index.html">Android Studio</a> installed, open the project with Android Studio.</p><p>Go to MainApplication.java under app/src/main/java/com/&lt;project name&gt;/ to complete setup.</p><p>Register SDK package in method getPackages().</p><pre>import com.facebook.reactnative.androidsdk.FBSDKPackage;</pre><pre>// ...</pre><pre>private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {<br>    @Override<br>    public boolean getUseDeveloperSupport() {<br>      return BuildConfig.DEBUG;<br>    }</pre><pre>@Override<br>    protected List&lt;ReactPackage&gt; getPackages() {<br>      return Arrays.&lt;ReactPackage&gt;asList(<br>          new MainReactPackage(),<br>          new FBSDKPackage()<br>      );<br>    }<br>};</pre><p>Also, you need to add in your settings.gradle:</p><pre>include &#39;:react-native-fbsdk&#39;<br>project(&#39;:react-native-fbsdk&#39;).projectDir = new File(rootProject.projectDir, &#39;../node_modules/react-native-fbsdk/android&#39;)</pre><p>Before you can run the project, follow the <a href="https://developers.facebook.com/docs/android/getting-started/">Getting Started Guide</a> for Facebook Android SDK to set up a Facebook app. You can skip the build.gradle changes since that’s taken care of by the rnpm link step above, but make sure you follow the rest of the steps such as updating strings.xml and AndroidManifest.xml.</p><p><strong>iOS</strong></p><p>The react-native-fbsdk has been linked by react-native link. The next step will be downloading and linking the native Facebook SDK for iOS.</p><p>Make sure you have the latest <a href="https://developer.apple.com/xcode/">Xcode</a> installed. Open the .xcodeproj in Xcode found in the ios subfolder from your project&#39;s root directory. Now, follow <em>all the steps except the pod install (Step 2)</em> in the <a href="https://developers.facebook.com/docs/ios/getting-started/">Getting Started Guide</a> for Facebook SDK for iOS. Along with FBSDKCoreKit.framework, don&#39;t forget to import FBSDKShareKit.framework and FBSDKLoginKit.frameworkinto your Xcode project.</p><p>If you’re using React Native’s RCTLinkingManager</p><p>The AppDelegate.m file can only have one method for openUrl. If you&#39;re also using RCTLinkingManager to handle deep links, you should handle both results in your openUrl method.</p><pre>- (BOOL)application:(UIApplication *)app<br>            openURL:(NSURL *)url<br>            options:(NSDictionary&lt;UIApplicationOpenURLOptionsKey,id&gt; *)options<br>{<br>  if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {<br>    return YES;<br>  }</pre><pre>if ([RCTLinkingManager application:app openURL:url options:options]) {<br>    return YES;<br>  }</pre><pre>return NO;<br>}</pre><h4>Troubleshooting</h4><blockquote>I cannot run the Android project.</blockquote><ul><li>Make sure you added the code snippet in step 3.1.</li><li>Make sure you set up a Facebook app and updated the AndroidManifest.xml and res/values/strings.xml with Facebook app settings.</li></ul><blockquote>I get a build error stating that one of the Facebook SDK files was not found — eg. <em>FBSDKLoginKit/FBSDKLoginKit.h file not found</em>.</blockquote><ul><li>Make sure that the Facebook SDK frameworks are installed in ~/Documents/FacebookSDK.</li><li>Make sure that FBSDK[Core, Login, Share]Kit.framework show up in the Link Binary with Libraries section of your build target&#39;s Build Phases.</li><li>Make sure that ~/Documents/FacebookSDK is in the Framework Search Path of your build target&#39;s Build Settings. You may have to select the All tab to see and search for the Framework Search Path.</li></ul><blockquote>I get build errors like <em>Warning: Native component for &quot;RCTFBLikeView&quot; does not exist</em>:</blockquote><ul><li>Make sure that libRCTFBSDK.a shows up in the Link Binary with Libraries section of your build target&#39;s Build Phases.</li></ul><blockquote>I get this build error: <em>no type or protocol named UIApplicationOpenURLOptionsKey</em>:</blockquote><ul><li>Your Xcode version is too old. Upgrade to Xcode 10.0+.</li></ul><h3>Step 5: Running Apps</h3><p>To run the iOS app, you should specify simulator</p><p>react-native run-ios — simulator=”iPhone X”</p><p>To run Android app, you should start emulator first, either via Android Studio or adb , then react-native run-android .</p><p>You’ll see the default start screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*TnZfGsKdsWGBUac-0YutpA.jpeg" /><figcaption>Default start screen for React Native app</figcaption></figure><p>Change the UI of this front page by changing app.js and the page will look like this</p><h3>Step 6: Authenticate Users using Facebook</h3><h4>Usage</h4><p><strong>Login</strong></p><pre>import React, { Component } from &#39;react&#39;;<br>import { View } from &#39;react-native&#39;;<br>import { LoginButton, AccessToken } from &#39;react-native-fbsdk&#39;;<br><br>export default class Login extends Component {<br>  render() {<br>    return (<br>      &lt;View&gt;<br>        &lt;LoginButton<br>          onLoginFinished={<br>            (error, result) =&gt; {<br>              if (error) {<br>                console.log(&quot;login has error: &quot; + result.error);<br>              } else if (result.isCancelled) {<br>                console.log(&quot;login is cancelled.&quot;);<br>              } else {<br>                AccessToken.getCurrentAccessToken().then(<br>                  (data) =&gt; {<br>                    console.log(data.accessToken.toString())<br>                  }<br>                )<br>              }<br>            }<br>          }<br>          onLogoutFinished={() =&gt; console.log(&quot;logout.&quot;)}/&gt;<br>      &lt;/View&gt;<br>    );<br>  }<br>};</pre><p><strong>Requesting additional permissions with Login Manager</strong></p><pre>// ...<br><br>import { LoginManager } from &quot;react-native-fbsdk&quot;;<br><br>// ...<br><br>// Attempt a login using the Facebook login dialog asking for default permissions.<br>LoginManager.logInWithPermissions([&quot;public_profile&quot;]).then(<br>  function(result) {<br>    if (result.isCancelled) {<br>      console.log(&quot;Login cancelled&quot;);<br>    } else {<br>      console.log(<br>        &quot;Login success with permissions: &quot; +<br>          result.grantedPermissions.toString()<br>      );<br>    }<br>  },<br>  function(error) {<br>    console.log(&quot;Login fail with error: &quot; + error);<br>  }<br>);</pre><p>Now that the app is all connected to Facebook Auth, let’s write the actual code to call login/logout, etc functions.</p><p>First of all, I have created a separate file LoginController.js and imported it in App.js , just to maintain a good code structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*M3YY9WkBmpmz6H-ZAiNKMw.png" /></figure><p>My App.js looks like following (nothing fancy, I’m not even gonna waste a gist here)</p><pre>import React, { Fragment } from &#39;react&#39;;<br>import LoginController from &#39;./LoginController&#39;;</pre><pre>const App = () =&gt; {return (&lt;LoginController/&gt;);};<br>export default App;</pre><p>Yes, that’s it 😆</p><h4>5.1 Implement a Facebook login button</h4><p>In the LoginController.js , I add the Facebook login button using the following code</p><pre>import { LoginButton, AccessToken } from &#39;react-native-fbsdk&#39;;</pre><pre>.....(inside render)<br> &lt;LoginButton<br>          onLoginFinished={<br>            (error, result) =&gt; {<br>              if (error) {<br>                console.log(&quot;login has error: &quot; + result.error);<br>              } else if (result.isCancelled) {<br>                console.log(&quot;login is cancelled.&quot;);<br>              } else {<br>                AccessToken.getCurrentAccessToken().then(<br>                  (data) =&gt; {<br>                    console.log(data.accessToken.toString())<br>                  }<br>                )<br>              }<br>            }<br>          }<br>          onLogoutFinished={() =&gt; console.log(&quot;logout.&quot;)}/&gt;<br>....</pre><p>This shows the beautiful Facebook-Button as per their marketing guidelines.</p><p>Overall, my LoginController.js file looks like this (a bit long, I know)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c41d6892832e3a44b4d0d5e58894588/href">https://medium.com/media/6c41d6892832e3a44b4d0d5e58894588/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*ESdpmUFHeFV_9g-3xxMRtg.jpeg" /><figcaption>Before Login</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*VDRkgnqlJhbf4P3pbdyc5Q.jpeg" /><figcaption>After login</figcaption></figure><h3>Step 7: Test your app on Android</h3><p>Let’s now build the app for iOS. I am using a simulator, but you can always use a real device as well.</p><p>Run the app on Android simulator using</p><pre>react-native run-android</pre><p>Here’s how my Facebook Login app works</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*KXhqHpz_VF8_1OjHpofGxg.gif" /><figcaption>Facebook Working</figcaption></figure><h3>Conclusion</h3><p>In this post, you learned how to implement Facebook login in your React Native app.</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/facebook-login-rn.git"><em>React-native-facebook-Login-Starter</em></a></blockquote><h3>Next Steps</h3><p>Now that you have learnt about setting up Push Notifications in React Native apps, here are some other topics you can look into</p><ul><li>Firebase — <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a> | <a href="https://enappd.com/blog/firebase-analytics-in-react-native-app/101">Analytics</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Push notifications</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Firebase CRUD</a></li><li>How To in React Native — <a href="https://enappd.com/blog/geolocation-geocoding-react-native-apps/84">Geolocation</a> | <a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">Life cycle hooks</a> | <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image Picker</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Redux implementation</a> | <a href="https://enappd.com/blog/how-to-make-api-calls-in-react-native-apps/125">Make API calls</a> | <a href="https://enappd.com/blog/navigations-in-react-native-app/124">Navigation</a> | <a href="https://enappd.com/blog/how-to-translate-in-react-native-app-globalization-internationalization-and-text-to-speech/120">Translation</a> | <a href="https://enappd.com/blog/react-native-qr-code-scanning-using-react-native-camera/117">Barcode &amp; QR code scan</a> | <a href="https://enappd.com/blog/send-read-and-delete-sms-in-react-native/107">Send &amp; Read SMS</a> | <a href="https://enappd.com/blog/google-vision-with-react-native/96">Google Vision</a></li><li>Payments — <a href="https://enappd.com/blog/implement-apple-pay-in-react-native-apps/93">Apple Pay</a> | <a href="https://enappd.com/blog/stripe-integration-in-react-native-apps-using-firebase/108">Stripe payments</a></li><li>Authentication — <a href="https://enappd.com/blog/google-login-in-react-native-android-apps-with-firebase/90">Google Login</a>| <a href="https://enappd.com/blog/facebook-login-in-react-native-apps/89">Facebook login</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Phone Auth</a> | <a href="https://enappd.com/blog/twitter-login-in-react-native-apps-using-firebase/95">Twitter login</a> | <a href="https://enappd.com/blog/anonymous-login-in-react-native-apps-with-firebase/129">Anonymous Login</a></li><li><a href="https://enappd.com/blog/how-to-make-stories-ui-like-instagram-and-whatsapp-in-react-native/123">Create Instagram / Whatsapp Story Feature in React Native</a></li><li><a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">React Native life cycle hooks</a> | <a href="https://enappd.com/blog/redux-in-react-native-app/92">Implement Redux</a> | <a href="https://enappd.com/blog/async-actions-with-redux-thunk-middleware-in-react-native-apps-1/100">Async actions with Redux</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li></ul><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ff5995e1932" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/facebook-login-in-react-native-apps-6ff5995e1932">Facebook login in React Native apps</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native vs Ionic vs Flutter in 2019]]></title>
            <link>https://medium.com/enappd/react-native-vs-ionic-vs-flutter-in-2019-65d895b97527?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/65d895b97527</guid>
            <category><![CDATA[comparison]]></category>
            <category><![CDATA[ionic-framework]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 09:32:50 GMT</pubDate>
            <atom:updated>2019-08-29T09:32:50.575Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Native V/s Ionic V/s Flutter in 2019</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Gfb_XNjEhdrPSKbIHInivg.png" /></figure><p>In this post, we’ll try to compare — Ionic, React Native and Flutter framework. All three technologies <strong>allow you to build mobile apps for both iOS and Android. </strong>All three are great frameworks because they allow developers to quickly prototype and publish apps on multiple platform with single source code.</p><p>The first great thing is — You can publish apps without the need to learn Swift, Objective-C, Java or Kotlin! Instead, you’ll use JavaScript (for React Native, and Ionic) and Dart (for Flutter). Hence you’re able to create native apps for both platforms with one language instead of two — this obviously reduces the learning effort you have to take to build your mobile app by a lot!</p><p>Great! So how do these technologies differ, which one is the best choice for your next mobile project? Let’s take a look…</p><h3>What is Ionic 4?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ZU1eWct801yP-QpUJOaI6Q.png" /><figcaption>Ionic Logo</figcaption></figure><p><strong>Ionic</strong> is a complete open-source SDK for hybrid mobile app development created by <a href="https://medium.com/u/a76fa51de1ba?source=post_page---------------------------">Max Lynch</a>, <a href="https://medium.com/u/14b1be5c1354?source=post_page---------------------------">Ben Sperry</a> and Adam Bradley of Drifty Co. in 2013. Ionic provides tools and services for developing hybrid mobile apps using Web technologies like CSS, HTML5, and Sass. Apps can be built with these Web technologies and then distributed through native app stores to be installed on devices by leveraging Cordova.</p><p>So, in other words — If you create Native apps in Android, you code in Java. If you create Native apps in iOS, you code in Obj-C or Swift. Both of these are powerful but complex languages. <strong>With Cordova (and Ionic) you can write a single piece of code for your app that can run on both iOS and Android </strong>(and windows!), that too with the simplicity of HTML, CSS, and JS.</p><h3>What Is React Native?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*R85ud_A5Ag7i52oQwemI6Q.png" /><figcaption>React native Logo</figcaption></figure><p>React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. In other words: web developers can now write mobile applications that look and feel truly “native,” all from the comfort of a JavaScript library that we already know and love. Plus, because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS.</p><p>Similar to React for the Web, React Native applications are written using a mixture of JavaScript and XML markup, known as JSX. Then, under the hood, the React Native “bridge” invokes the native rendering APIs in Objective-C (for iOS) or Java (for Android). Thus, your application will render using real mobile UI components, not webviews, and will look and feel like any other mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera, or the user’s location.</p><p>React Native currently supports both iOS and Android and has the potential to expand to future platforms as well. In this blog, we’ll cover both iOS and Android. The vast majority of the code we write will be cross-platform. And yes: you can really use React Native to build production-ready mobile applications! Some example: <a href="http://bit.ly/1YipO7A">Facebook</a>, <a href="http://bit.ly/1PPEiZH">Palantir</a>, and <a href="http://bit.ly/1PPEjNg">TaskRabbit</a> are already using it in production for user-facing applications.</p><h3>What is Flutter?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*gTqZ01Owzh7lMaW4vdkfSQ.png" /><figcaption>Flutter Logo</figcaption></figure><p>Flutter is Google’s portable UI toolkit for crafting high-quality native experiences for mobile, web and desktop in record time. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.</p><p>Flutter is built with C, C++, Dart, and Skia (a 2D rendering engine). See this <a href="https://docs.google.com/presentation/d/1cw7A4HbvM_Abv320rVgPVGiUP2msVs7tfGbkgdrTy0I/edit#slide=id.gbb3c3233b_0_162">architecture diagram</a> for a better picture of the main components.</p><p>For developers, Flutter lowers the bar to entry for building mobile apps. It speeds up the development of mobile apps and reduces the cost and complexity of app production across iOS and Android.</p><p>For designers, Flutter helps deliver the original design vision, without loss of fidelity or compromises. It also acts as a productive prototyping tool.</p><h3>What’s the point of comparing these 3 Best Tools for Modern App Development?</h3><p>When developers (or even non-developers) want to create an app for their startup or business, the first question that pops up in their mind is <strong>Which framework is best for app development</strong>. The question becomes important from cost, performance and time point-of-view.</p><p>We’ve got your back in case you are finding the best tool to develop a new mobile app or revamp existing app. This post tries to solve all your questions regarding best cross-platform app development tools and what to choose and when.</p><p>We also want to make one thing clear that what to choose and when always remains subjective and depends on many factors. But this post can help you decide the best framework according to your needs.</p><h3>Flutter vs. React Native vs. Ionic</h3><p>Flutter is a software development kit developed by Google by using the Dart programming language. React Native is an SDK developed by Facebook, and the designing of the mobile applications take place JavaScript. Ionic follows a different approach while compared to the other two. With Ionic, you will create a real native app using web app with HTML, JSS, and CSS. The wrapped web content ensures that you can re-use or re-code the code.</p><h3>Top 11 Attributes to Consider While Selecting the Platforms for Cross-platform Mobile App Development</h3><p>To decide which one is better for Cross-Platform Mobile App Development lets first define the attributes based on which we will compare all of the above. And, these are:</p><ul><li>The Language Stack</li><li>Do not repeat yourself(DRY)</li><li>Rich pre-styled Component Library</li><li>Performance</li><li>User Interface</li><li>Ecosystem / Third-Party Libraries</li><li>Market and Community</li><li>Accessing Native Device Features</li><li>Supported Platforms</li><li>Popular Apps</li><li>Pricing</li></ul><h3>1. The Language Stack</h3><p>With this metric, I want to explore which framework utilizes which programming languages and offer what benefits:</p><p><strong>React Native:</strong> It utilizes JavaScript which is at present one of the most popular, dynamic and high-level programming language. It combines the advantages of JavaScript and React.JS and is backed by Facebook.</p><p>The solid side of React Native that makes it best among the other three frameworks in terms of PL is that it allows writing a few components in Swift, Objective-C or Java when developers require them. Utilizing native modules and libraries in React Native applications, you can manage computationally heavy operations like video handling or image editing.</p><p><strong>Ionic framework:</strong> It uses HTML5, CSS, and JS to develop and run applications, and requires Cordova wrapper to access native platform controllers. Utilizing IONIC, you can also use TypeScript that improves the quality of the code.</p><p><strong>Flutter:</strong> It utilizes Dart to develop high-quality applications for Android, iOS and the web. Dart is an amazing Programming language that offers plenty of benefits and is based on C/C++ and java. Despite being new, the language is soon expected to take the industry by storm.</p><p>Here is how you can rank these frameworks based on the advantages offered by their programming languages:</p><ol><li>React Native (React)</li><li>Flutter (Dart)</li><li>Ionic Framework (Angular)</li></ol><h3>2. Do not repeat yourself (DRY)</h3><p>With this metric, I want to explore how much of the code you write can be re-used for both platforms.</p><p><strong>Ionic:</strong> Awesome re-usability! The “wrapped web app” concept ensures that you can easily re-use your code — you’re just building a wrapped web app in the end. The great component library of adaptive components (i.e. automatically styled for the platform the app runs on) also helps.</p><p><strong>Flutter:</strong> Also really great to re-use. The widgets it ships with often don’t adapt to the underlying platform, instead you use <a href="https://material.io/design/">Material Design</a> on both platforms by default. The Flutter team is providing more and more iOS-styled components though. You can find out on which platform you’re running and manually swap widgets but that’s, of course, a bit more work than required by Ionic. If you need platform-specific re-styling, you can move the position of Flutter on the slider further to the right.</p><p><strong>React Native:</strong> Also compiles to native defaults but only provides a basic set of components to start with. You have to style most of them on your own, hence more work is required to achieve appropriate styles on both platforms. Generally, code can be re-used though (since you still only use one language and libraries like <a href="http://redux.js.org/">Redux</a> need no adjustment).</p><p>Here is how you can rank these frameworks based on the Code Reusability</p><ol><li>Ionic Framework</li><li>Flutter</li><li>React Native</li></ol><h3>3. Rich pre-styled Component Library</h3><p>How easy is it to build beautiful UIs? Do you have to create and style a lot of components (UI elements) on your own or do you have a rich suite of pre-built ones? Are the components adapting to the underlying platform automatically? That’s what this metric is about.</p><p><strong>Ionic:</strong> Ionic in its core is a big set of pre-built (and pre-styled) components. The compiler/ toolchain which yields a native app is also part of the Ionic package (handled via its CLI) but it utilizes other packages like <a href="https://cordova.apache.org/">Cordova</a> or <a href="https://capacitor.ionicframework.com/">Capacitor</a>. The components provided by Ionic automatically adapt to the platform the app runs on and therefore, Ionic makes the creation of beautiful, native-looking apps a breeze!</p><p><strong>Flutter:</strong> Flutter also ships with a <a href="https://flutter.io/widgets/">comprehensive suite</a> of built-in widgets. These mostly use the Material Design, some Cupertino-style (iOS style) widgets exist, too. More and more iOS-styled components are getting added. With all these widgets, you can quickly create nice-looking UIs without doing too much manual styling. Only if you need different looks for different platforms, some effort can be required since the widgets don’t adapt automatically.</p><p><strong>React Native:</strong> A decent set of built-in components is provided but a lot of them need to be styled by you. And they’re non-adaptive, instead — just as with Flutter — you get alternatives for both operating systems. That requires adjustments in your code, where you have to choose, use and style widgets conditionally.</p><p>Here is how you can rank these frameworks based on the pre-styled Component Library</p><ol><li>Ionic Framework</li><li>Flutter</li><li>React Native</li></ol><h3>4. Performance</h3><p>This metric is the most important one and speaks for itself — how do the apps made in different frameworks perform from a run-time performance perspective?</p><p><strong>React Native:</strong> The performance it provides is very similar to native applications as it renders code elements specifically to the native APIs. React additionally allow developers to use native modules written in native languages to write code for complicated operations. However, they can’t be reused across two platforms; their main purpose is to provide higher performance.</p><p><strong>Ionic:</strong> In terms of performance, Ionic loses the game. Its performance isn’t as similar to React Native or flutter offers since it utilizes web technologies to render an application. This approach significantly decreases the speed. Also, it doesn’t utilize native components and tries to create a native look and feel by using web technologies.</p><p>The upside of Ionic is its quick testing process that runs instantly in a browser that streamlines the development process.</p><p>Ionic offers a poorer performance among these 3 as it’s a wrapped web app in the end. <strong>But this is often misunderstood!</strong> “Worse” sounds extremely bad but “worse” doesn’t actually mean “horrible” or even “bad”. Instead, you got worse performance than with the other approaches. In fact, on the devices we got these days, your app will probably run more than smooth! If you only (imaginary!) got 100fps instead of 105fps — would you notice a difference? You wouldn’t, so <strong>keep Ionic in your mind for your next app!</strong></p><p><strong>Flutter:</strong> When compared on the basis of app performance, it is the Flutter that takes the crown over its competitors. Because it has advantages of Dart and there is no JavaScript bridge for starting interactions with the device native components, the speed it offers is amazing.</p><p>Here is how you can rank these frameworks based on the performance they offer:</p><ol><li>Flutter</li><li>React Native</li><li>Ionic</li></ol><h3>5. User Interface</h3><p>Users judge apps within the first few seconds of usage and that’s why GUI of an app must be engaging while being easy — let’s see what these frameworks offer:</p><p><strong>React Native:</strong> React Native modules associated with native UI controllers, which gives amazing user experience that is very close to native apps. It additionally utilizes the ReactJS library with extensive UI elements and streamlines the UI development.</p><p><strong>Ionic:</strong> Ionic UI doesn’t utilize native elements at all and renders everything in HTML and CSS. Then it applies Cordova to give native mobile experience. Angular components that accompany the framework also enable Ionic apps look like the native ones.</p><p><strong>Flutter: </strong>Flutter provides the best User Interfaces<strong>. </strong>No doubt Ionic give us cross-platform apps but their efficiency and performance cannot beat Flutter and React Native. They stuck and lack in responsiveness if an app is heavy and more native UI components are used.</p><p>Here is how you can rank these frameworks based on the UI they offer:</p><ol><li>Flutter</li><li>React Native</li><li>Ionic</li></ol><h3>6. Ecosystem / Third-Party Libraries</h3><p>What does the ecosystem look like? Is it easy to find help (on <a href="https://stackoverflow.com/">Stackoverflow</a> etc) and are there enough third-party libraries available to add that one feature your app needs?</p><p><strong>Ionic:</strong> Ionic uses JavaScript for its logic — and whilst you can use it with any (or no) JavaScript framework, it provides especially great support for Angular. Therefore, you benefit from these ecosystems. And the JavaScript, as well as the Angular ecosystem, is huge! Thousands of threads on <a href="https://stackoverflow.com/">Stackoverflow</a> and packages on <a href="https://www.npmjs.com/">npm</a> help you solve your problems.</p><p><strong>Flutter:</strong> Flutter is seeing tremendous growth! You find quite a lot of discussions on Stackoverflow and third-party libraries and packages (on <a href="https://pub.dartlang.org/flutter">its own platform</a>). Despite being relatively new, it’s already quite mature and has a decent ecosystem.</p><p><strong>React Native:</strong> It uses JavaScript and React, hence you got those ecosystems available. Additionally, React Native on its own has quite a vibrant ecosystem and community, hence you find many threads on Stackoverflow and a lot of third-party packages that add missing functionalities. A downside is that you often need to rely on the ecosystem (like plugins, starters etc.) since only core features are included in React Native itself. React Native’s ecosystem in not as strong as others, and often keeps changing or the third-party plugins can’t keep pace with changing React Native</p><p>Here is how you can rank these frameworks based on the Ecosystem / Third-Party Libraries</p><ol><li>Ionic</li><li>Flutter</li><li>React Native</li></ol><h3>7. Market and Community</h3><p>Having a dynamic ecosystem is something worth being thankful for — but it matters how popular is an option? Let’s see:</p><p><strong>React Native:</strong> React Native is the king when it comes to market and community recognition. The network of its developers is quickly growing and as of now has many experienced React Native Engineers. This makes it easy to kick start a React project. It utilizes an amazingly popular library (React) and the most essential web development language (JavaScript) and provides real native applications. These qualities make it a strong platform and are the reasons behind its fame.</p><p><strong>Ionic:</strong> It is the second most popular framework after React. It empowers developers to build native mobile apps in the fastest possible way. Ionic has a huge community support, as well as a <a href="https://market.ionicframework.com/">great marketplace</a> where you can find a lot of starters and templates to jump start any app from <a href="https://market.ionicframework.com/starters/taxi-booking-complete-platform-ionic-4">Uber</a> to <a href="https://market.ionicframework.com/starters/ionic-4-spotify-pwa-and-app-starter">Spotify</a>.</p><p><strong>Flutter:</strong> Flutter is a new framework for community right now and not very popular. But, it’s intensely advertised by Google that shows they want to make it a major thing in mobile world. Whilst it still has some tingle points, using it is fun and you can go rapidly from idea to prototype to app.</p><p>Here is how you can rank these frameworks based on their industry recognition and reliability:</p><ol><li>React Native</li><li>Ionic</li><li>Flutter</li></ol><h3>8. Accessing Native Device Features</h3><p>Your mobile apps most likely need access to some native device feature like the camera or GPS. How easy is it to get that access? And how easy is it for relatively new features (e.g. AR APIs provided by Android/ iOS)?</p><p><strong>Ionic:</strong> Ionic uses Cordova or its own solution, Capacitor, to give you access to native device features. It provides a <a href="https://ionicframework.com/docs/native/">very decent set of packages</a> to access common native device functionalities like the camera. You can also write your own wrappers around native functionalities and then include them in your code of course. Also, Ionic/Cordova and/or Angular plugins are very stable, and update readily with platform updates.</p><p><strong>Flutter:</strong> Over the last year, the Flutter team put a lot of effort into providing official packages for some of the most common native device features you need access to. There also is a very vibrant ecosystem and hence you find a package for pretty much any native feature you might want to access. You can also write and connect real native code if you need to.</p><p><strong>React Native:</strong> Being the most popular solution, you find a rich set of third-party packages as well as some built-in APIs for accessing native platform functionalities. Relying on third-party packages (which you mostly have to do) of course has the disadvantage that the core maintainers of that package might quit, hence the support is not on the same level as it is with Ionic or NativeScript.</p><p>Here is how you can rank these frameworks based on the Accessing Native Device Features :</p><ol><li>Flutter</li><li>React Native</li><li>Ionic</li></ol><h3>9. Supported Platforms</h3><p><strong>React Native:</strong> Android 4.1+ , iOS 8+</p><p><strong>Ionic:</strong> Android 4.4+ , iOS 8+ , Windows 10</p><p><strong>Flutter</strong>: Not sure</p><h3>10. Popular Apps</h3><p><strong>React Native:</strong> Facebook, Instagram, UberEats, Airbnb (they later removed RN from usage. Read More here — <a href="https://softwareengineeringdaily.com/2018/09/24/show-summary-react-native-at-airbnb/">Why Airbnb left React Native</a>)</p><p><strong>Ionic:</strong> JustWatch, Pacifica, Nationwide and many more.</p><p><strong>Flutter:</strong> Hamilton</p><h3>11. Pricing</h3><p><strong>React Native:</strong> Completely open-source frameworks. Engineers can utilize this system and their libraries for free.</p><p><strong>Flutter: </strong>Completely open-source frameworks. Engineers can utilize this system and their libraries for free.</p><p><strong>Ionic:</strong> It is a free open source framework for developing cross-platform mobile applications. But, the organization offers its Pro Development Environment which is paid. The company guarantees that Ionic Pro accelerates the development process.</p><h3>Final Words</h3><h4>Which Framework Is Best, When, And Why?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NtbHYbdIapeJ1kmQcBLH-Q.png" /><figcaption>A broad comparison tell us this much</figcaption></figure><p>Ionic is popular for its easy learning curve due to web technologies while Flutter requires developers learning Dart to build apps. Also, Ionic is not a preferable choice for intense graphical apps or game development because of wrapper plugins that cause performance issues sometimes. Flutter is new and gradually growing with the support from best developers of Google and the community.</p><p>But, let us say that all these frameworks are best at their own. While choosing a framework for your cross-platform app development, you need to analyze many factors like budget, time, application size, platforms, and so on.</p><p>Let us know your views on different frameworks via comments below.</p><h3>Next Steps</h3><p>Now that you have learnt the major differences between Ionic framework, react native and flutter for mobile app development.</p><ul><li>How To in React Native — <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image picker</a>| <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a> | <a href="https://enappd.com/blog/react-native-firebase-crud-image-upload-and-phone-authentication/86">Push notifications</a> | <a href="https://enappd.com/blog/geolocation-geocoding-react-native-apps/84">Geolocation</a> | <a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">Life cycle hooks</a></li><li>How To in Ionic — <a href="https://enappd.com/blog/image-picker-in-ionic-4-app/67/">Image picker</a>| <a href="https://enappd.com/blog/how-to-integrate-firebase-in-ionic-4-apps/23/">Integrate Firebase</a> | <a href="https://enappd.com/blog/implement-ionic-4-firebase-push/34/">Push notifications</a> | <a href="https://enappd.com/blog/using-geolocation-geocoding-and-reverse-geocoding-in-ionic-4/45/">Geolocation</a> | <a href="https://enappd.com/blog/adding-video-player-in-ionic-4-app/64/">Video Player</a>| <a href="https://enappd.com/blog/rtl-right-to-left-use-in-ionic-4/50/">RTL</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li><li><a href="http://enappd.com/blog/ionic-4-full-app-how-to-make-ionic-4-apps-from-the-super-template/14/">Create Awesome Apps in</a> IONIC 4 using Full App</li></ul><p>If you need a base to start your next Ionic 4 app, you can make your next awesome app using <a href="https://store.enappd.com/product/ionic-4-full-app/">Ionic 4 Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*2BzL8TesnBHuazHr3VA4SQ.jpeg" /></figure><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /></figure><p>If you need a base to start your next Flutter app, you can make your next awesome app using <a href="https://store.enappd.com/product/flutter-full-app/">Flutter Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*m1R2sLQploihax1Vu99GQA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65d895b97527" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/react-native-vs-ionic-vs-flutter-in-2019-65d895b97527">React Native vs Ionic vs Flutter in 2019</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in Ionic React RC and how to use it]]></title>
            <link>https://medium.com/enappd/whats-new-in-ionic-react-rc-and-how-to-use-it-a0a8c3f75e01?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0a8c3f75e01</guid>
            <category><![CDATA[capacitor]]></category>
            <category><![CDATA[ionic-framework]]></category>
            <category><![CDATA[ionic4]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 10:46:05 GMT</pubDate>
            <atom:updated>2019-08-26T10:46:05.233Z</atom:updated>
            <content:encoded><![CDATA[<h3>What’s new in Ionic React RC (and how to use it)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hmZGoOaj29ay_x1lm56Bw.png" /><figcaption>Ionic React RC</figcaption></figure><p>If you are here, that means you have already heard about Ionic React RC is now out! and you are searching for <strong>how to create Ionic apps in react using Ionic React</strong>. If that’s true, then you are in the right place. Here I would be creating an Ionic app in React Using Ionic React. Need not worry, I would be taking you step by step how to make Ionic apps in React Using Ionic React.</p><p>The team behind Ionic announced the RC release of Ionic React. Developers can now make use of all the Ionic components in their React application. Ionic React ships with almost 70 components including buttons, cards, menus, tabs, alerts, modals, and much more. It also supports TypeScript type definitions.</p><h3>What is Ionic? and why is Ionic React special</h3><p>Ionic is an open source framework that consists of UI components for building cross-platform applications. These components are written in HTML, CSS, and JavaScript and can easily be deployed natively to iOS and Android devices, desktop with Electron, or to the web as a progressive web app.</p><p>Historically, Ionic has been associated with Angular, but this changed with its recent release, Ionic 4. Now, developers can use the Ionic app development framework alongside any frontend framework. The Ionic team has been working towards making Ionic work with React and Vue for a long time. React developers already have React Native to make native apps for <a href="https://subscribe.packtpub.com/learn-ios/">iOS</a> and <a href="https://subscription.packtpub.com/tech/android">Android</a>, but with Ionic React they will also be able to create hybrid mobile, desktop, and progressive web apps. In the future, the team is also planning to make React Native and Ionic work together.</p><p>The Ionic team also recommends users to use TypeScript in their apps to get a better developer experience.</p><h4>Ionic and React</h4><p><a href="https://ionicframework.com/"><strong>Ionic</strong></a> has been gaining popularity in the last few years, and rightfully so. Making apps in Ionic is a breeze compared to Native languages (Java / Swift). Ionic framework’s domain encompasses a huge variety of mobile app features which can create almost 90% of the apps today.</p><p><a href="https://reactjs.org/"><strong>React JS</strong></a> has come at a good time helping the developers to build highly engaging web apps and user interfaces quickly and efficiently. It allows you to break down the components and create a single page application with less coding. It is mostly popular for its shadow DOM, which it uses for limited scope DOM manipulation, which makes React apps faster. It is due to these major <strong>advantages</strong> that <strong>React JS</strong> has gained much spotlight.</p><p>For many years Ionic was stuck with Angular framework. But with Ionic 4, it has broken free of the framework restriction. Now Ionic 4 supports Angular, React and Vue JS frameworks.</p><p>In February 2019 the Ionic team announced <a href="https://ionicframework.com/blog/announcing-the-ionic-react-beta/">Beta of Ionic React</a>. Ionic React allows you to make your react frontend builds run everywhere, for example, iOS, Android, Electron and in the browser as a progressive web application (PWA) using any underlying framework.</p><h3>Why is Ionic React needed</h3><p>Explaining the motivation behind Ionic React, Ely Lucas, Software Engineer &amp; Dev Advocate at Ionic wrote in the <a href="https://ionicframework.com/blog/announcing-ionic-react-release-candidate/">announcement</a>,</p><blockquote>“<em>Ionic React RC marks the first major release of our vision to bring Ionic development to more developers on other frameworks</em>.”</blockquote><ul><li>Though it is possible to import the core Ionic components directly into React projects, this method does not provide a good developer experience. Also, when working with web components in React, you need to write some boilerplate code to properly communicate with the web components.</li><li>Ionic React will essentially work as a “thin wrapper” around the core components of Ionic and will export them as native React components. It will also handle the boilerplate code for you. However, you still need to write a few features in the native framework such as page lifetime management and lifecycle methods. You can do this by extending the <strong>react-router</strong> package with <strong>@ionic/react-router</strong>.</li></ul><p>Considering this is a release candidate, the team is not expecting many major changes. Sharing the team’s next steps, Lucas said,</p><blockquote><em>“We will be looking closely at any issues that pop up during the RC phase and working on some final code stabilization and minor bug fixes…We also plan on creating some more content and guides in the docs to help with some best practices we’ve found when working with Ionic React.</em>”</blockquote><p>The team is now seeking developer feedback before they come up with the final release. If you encounter any issues, you can report it on the <a href="https://github.com/ionic-team/ionic/issues">GitHub repo</a> and tag the issue with “package react”.</p><p>To know further updates on Ionic React, you can also have a chat with the team who will be present at <a href="https://www.reactrally.com/">React Rally</a> from August 22–23 at Salt Lake City, UT. This is a community conference that brings together developers of all backgrounds using React.js, React Native and related tools.</p><p>We at <a href="http://enappd.com/">Enappd</a>, already have an <a href="https://store.enappd.com/product/ionic-react-full-app-capacitor/">Ionic-React Starter Kit</a> with beta version. We are quickly updating it to work with RC version.</p><h3>Getting Started</h3><h4>1. Create a new react Project</h4><p>If you haven’t already done so, grab the latest <a href="https://ionicframework.com/blog/ionic-cli-v5-brings-react-beta-support/">v5 release</a> of the Ionic CLI:</p><pre>npm i ionic -g</pre><p>And create an Ionic React project by specifying the type of “react”:</p><pre>ionic start MyReactApp --type=react</pre><p>You will see that all of our standard starter templates are there, choose your favorite (I’ll choose a blank).</p><pre>[INFO] Next Steps:[INFO] Next Steps:</pre><pre>- Go to your cloned project: cd .\MyReactApp<br>       - Run ionic serve within the app directory to see your app<br>       - Build features and components: <a href="https://ion.link/scaffolding-docs">https://ion.link/scaffolding-docs</a><br>       - Get Ionic DevApp for easy device testing: <a href="https://ion.link/devapp">https://ion.link/devapp</a></pre><pre>- Go to your cloned project: cd .\MyReactApp<br>       - Run ionic serve within the app directory to see your app<br>       - Build features and components: <a href="https://ion.link/scaffolding-docs">https://ion.link/scaffolding-docs</a><br>       - Get Ionic DevApp for easy device testing: <a href="https://ion.link/devapp">https://ion.link/devapp</a></pre><h4>2. Open the Project in the code editor of your choice</h4><pre>$ cd react-ionic<br>$ code .</pre><h4>3. Run the project in the browser</h4><pre>ionic serve</pre><p>This command will search start script in your package.json file and run the command you mentioned in your start script. E.g.</p><pre>“start”: “react-scripts start”</pre><p><strong><em>react-scripts start</em></strong> will build your code in development mode and run it on your browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*jvDx_TUou5cSXdFyODUp0Q.jpeg" /><figcaption>Ionic Blank Starter</figcaption></figure><p>so now you can see this screen on your browser</p><h4>4. A look at a Package.json</h4><p>Packages published to the registry must contain a <strong>package</strong>.<strong>json file</strong>. A <strong>package</strong>.<strong>json file</strong> lists the packages your project depends on, specifies versions of a <strong>package</strong> that your project can use, using<strong> </strong>semantic versioning rules.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0f2549cbd3aa9166be0ca4b42039279/href">https://medium.com/media/f0f2549cbd3aa9166be0ca4b42039279/href</a></iframe><p>At first glance it may look like there’s a lot going on, so let’s break it down, starting with the first three lines.</p><p>So what’s going on here? Well, the first three lines are very basic info about projects like name and version. The first being Name itself.</p><pre>&quot;name&quot;: &quot;my-ionic-app&quot;,</pre><pre>&quot;version&quot;: &quot;0.1.0&quot;,</pre><pre>&quot;private&quot;: true,</pre><p>Required name and version fields</p><p>A <strong>package.json</strong> file must contain <strong>name</strong> and <strong>version</strong> fields.</p><p>The <strong>name</strong> field contains your package’s name, and must be lowercase and one word, and may contain hyphens and underscores.</p><p>The <strong>version</strong> field must be in the form <strong>x.x.x</strong> and follow the <a href="https://docs.npmjs.com/about-semantic-versioning">semantic versioning guidelines</a>.</p><h4>The next block is dependencies.</h4><p>Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.</p><p><strong>Please do not put test harnesses or transpilers in your </strong><strong>dependencies object.</strong> See <strong>devDependencies</strong>, below.</p><p>See <a href="https://docs.npmjs.com/misc/semver">semver</a> for more details about specifying version ranges.</p><ul><li><strong>version</strong> Must match <strong>version</strong> exactly</li><li><strong>&gt;version</strong> Must be greater than <strong>version</strong></li><li><strong>&gt;=version</strong> etc</li><li><strong>&lt;version</strong></li><li><strong>&lt;=version</strong></li><li><strong>~version</strong> “Approximately equivalent to version” See <a href="https://docs.npmjs.com/misc/semver">semver</a></li><li><strong>^version</strong> “Compatible with version” See <a href="https://docs.npmjs.com/misc/semver">semver</a></li><li><strong>1.2.x</strong> 1.2.0, 1.2.1, etc., but not 1.3.0</li><li><strong>http://...</strong> See ‘URLs as Dependencies’ below</li><li><strong>*</strong> Matches any version</li><li><strong>&quot;&quot;</strong> (just an empty string) Same as <strong>*</strong></li><li><strong>version1 - version2</strong> Same as <strong>&gt;=version1 &lt;=version2</strong>.</li><li><strong>range1 || range2</strong> Passes if either range1 or range2 are satisfied.</li><li><strong>git...</strong> See ‘Git URLs as Dependencies’ below</li><li><strong>user/repo</strong> See ‘GitHub URLs’ below</li><li><strong>tag</strong> A specific version tagged and published as <strong>tag</strong> See <a href="https://docs.npmjs.com/cli/dist-tag"><strong>npm-dist-tag</strong></a></li><li><strong>path/path/path</strong> See <a href="https://docs.npmjs.com/files/package.json#local-paths">Local Paths</a> below</li></ul><pre>&quot;dependencies&quot;: {</pre><pre>&quot;@ionic/react&quot;: &quot;^4.8.0-rc.0&quot;,</pre><pre>&quot;@ionic/react-router&quot;: &quot;^4.8.0-rc.0&quot;,</pre><pre>&quot;@types/jest&quot;: &quot;24.0.11&quot;,</pre><pre>&quot;@types/node&quot;: &quot;11.11.3&quot;,</pre><pre>&quot;@types/react&quot;: &quot;^16.9.1&quot;,</pre><pre>&quot;@types/react-dom&quot;: &quot;^16.8.5&quot;,</pre><pre>&quot;@types/react-router&quot;: &quot;^5.0.3&quot;,</pre><pre>&quot;@types/react-router-dom&quot;: &quot;^4.3.1&quot;,</pre><pre>&quot;ionicons&quot;: &quot;^4.6.2&quot;,</pre><pre>&quot;react&quot;: &quot;^16.9.0&quot;,</pre><pre>&quot;react-dom&quot;: &quot;^16.9.0&quot;,</pre><pre>&quot;react-router&quot;: &quot;^5.0.1&quot;,</pre><pre>&quot;react-router-dom&quot;: &quot;^5.0.1&quot;,</pre><pre>&quot;react-scripts&quot;: &quot;3.1.0&quot;,</pre><pre>&quot;typescript&quot;: &quot;3.5.3&quot;</pre><pre>}</pre><h4>The next block scripts.</h4><p>The “scripts” property is a dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.</p><p>See <a href="https://docs.npmjs.com/misc/scripts"><strong>npm-scripts</strong></a> to find out more about writing package scripts.</p><pre>&quot;scripts&quot;: {</pre><pre>&quot;start&quot;: &quot;react-scripts start&quot;,</pre><pre>&quot;build&quot;: &quot;react-scripts build&quot;,</pre><pre>&quot;test&quot;: &quot;react-scripts test&quot;,</pre><pre>&quot;eject&quot;: &quot;react-scripts eject&quot;</pre><pre>},</pre><h4>Next block — eslintConfig</h4><p>ESLint is designed to be completely configurable, meaning you can turn off every rule and run only with basic syntax validation, or mix and match the bundled rules and your custom rules to make ESLint perfect for your project. <a href="http://eslint.org/docs/user-guide/configuring">There are two primary ways to configure ESLint</a></p><h4>Next block — Browserslist</h4><p>The config to share target browsers and Node.js versions between different front-end tools. It is used in:</p><ul><li><a href="https://github.com/postcss/autoprefixer">Autoprefixer</a></li><li><a href="https://github.com/babel/babel/tree/master/packages/babel-preset-env">Babel</a></li><li><a href="https://github.com/jonathantneal/postcss-preset-env">postcss-preset-env</a></li><li><a href="https://github.com/amilajack/eslint-plugin-compat">eslint-plugin-compat</a></li><li><a href="https://github.com/ismay/stylelint-no-unsupported-browser-features">stylelint-no-unsupported-browser-features</a></li><li><a href="https://github.com/jonathantneal/postcss-normalize">postcss-normalize</a></li><li><a href="https://github.com/ElemeFE/obsolete-webpack-plugin">obsolete-webpack-plugin</a></li></ul><p>All tools will find target browsers automatically when you add the following to package.json:</p><pre>&quot;browserslist&quot;: [</pre><pre>&quot;&gt;0.2%&quot;,</pre><pre>&quot;not dead&quot;,</pre><pre>&quot;not ie &lt;= 11&quot;,</pre><pre>&quot;not op_mini all&quot;</pre><pre>]</pre><h4>5. React in our Ionic app</h4><p>We have already installed a plugin called <a href="https://www.npmjs.com/package/@ionic/react">@ionic/react</a> which has all the dependency related to React Component in ionic.</p><h4>6. React dependencies what we are using in this starter</h4><p>These plugins are already installed in this starter.</p><p>React router is required for navigation purpose.</p><pre>npm install react-router react-router-dom @types/react-router @types/react-router-dom</pre><h4>7. A look at a React Component</h4><p>The base of our app will be in the src directory, and the main entry point will be our index.tsx. If we open our project in a code editor and open src/index.tsx, we should see the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5013094478ac3540e5a2afa461ba3d30/href">https://medium.com/media/5013094478ac3540e5a2afa461ba3d30/href</a></iframe><p>So what’s going on here? Well, the first three lines are pulling in some dependencies.</p><ul><li>The first being React itself. This allows us to write components in an HTML-like syntax called <strong>JSX</strong>. We’ll talk about JSX a bit more later on.</li><li>The second import is for <strong>ReactDOM</strong>. The ReactDOM.render method is the browser/DOM specific way of taking our components and rendering it to a specified DOM node.</li><li>The last import is the <strong>root component</strong> for our app, simply named App. This is our first React component and will be used in the bootstrapping process for our React app.</li></ul><p>If we open App.tsx, we should see the following.</p><p>Let’s break it down too, starting with the first group of imports.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28830de989b1977f83a926d422b3b894/href">https://medium.com/media/28830de989b1977f83a926d422b3b894/href</a></iframe><pre>import React from &#39;react&#39;;<br>import { Route } from &#39;react-router-dom&#39;;<br>import { IonApp, IonPage, IonRouterOutlet } from &#39;@ionic/react&#39;;<br>import { IonReactRouter } from &#39;@ionic/react-router&#39;;<br>import Home from &#39;./pages/Home&#39;;</pre><p>Similar to index.tsx, we first must import React in order to use JSX.</p><ul><li>The next import is from react-router-dom. We&#39;re importing Route, which is how we’ll match the app’s URL with the components we want to render</li><li>Following ReactRouter, we next have our first imports for Ionic. To use a component in React, you must first import it. So for Ionic, this means anytime we want to use a Button or a Card, it must be added to our imports. In the case of our App component, we’re only using IonApp, IonPage, IonRouterOutlet, and IonReactRouter.</li><li>IonReactRouter is a component that wraps ReactRouter’s BrowserRouter component. It more or less behaves the same as BrowserRouter with a few differences. We have deeper guide that goes over these differences in our <a href="https://ionicframework.com/docs/react/navigation">React Navigation Docs</a>.</li><li>The last important import is the Home component import. This is a component that we will be able to navigate to in our app. We&#39;ll look at the navigation part a bit later.</li><li>The CSS import is pulling in the utility styles from Ionic for things like padding, typography, etc.</li></ul><p>After reviewing all of the imports, we now get to our first look at a React Component:</p><pre>const App: React.FunctionComponent = () =&gt; (</pre><pre>&lt;IonApp&gt;</pre><pre>&lt;IonReactRouter&gt;</pre><pre>&lt;IonPage&gt;</pre><pre>&lt;IonRouterOutlet&gt;</pre><pre>&lt;Route path=&quot;/home&quot; component={Home} exact={true} /&gt;</pre><pre>&lt;Route exact path=&quot;/&quot; render={() =&gt; &lt;Redirect to=&quot;/home&quot; /&gt;} /&gt;</pre><pre>&lt;/IonRouterOutlet&gt;</pre><pre>&lt;/IonPage&gt;</pre><pre>&lt;/IonReactRouter&gt;</pre><pre>&lt;/IonApp&gt;</pre><pre>);</pre><p>This React component sets up the initial routing for our app, as well as include some core Ionic components for animations and layout (IonRouterOutlet and IonApp). One thing that stands out is that in React, to do data-binding, the value is passed in curly braces ({}). So in the Route component, we can set the value of component to the Home component from earlier. This is how React will know that that value is not a string, but a reference to a component.</p><h4>8. Modify Current React Component</h4><p>Now the App does not really have a lot to modify here. It&#39;s a basic example of a container component. With the Router logic set, all it&#39;s responsible for is to render a component that matches the given URL route. Since we already have one component/router setup, let&#39;s go ahead and modify our Home component.</p><p>Currently, the Home component looks like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*jvDx_TUou5cSXdFyODUp0Q.jpeg" /><figcaption>Home Blank</figcaption></figure><p>For now, I am just creating a simple signup form with them of ionic/react component.</p><p>So after editing your file something look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d48abe3942909b244f00d3154cc99165/href">https://medium.com/media/d48abe3942909b244f00d3154cc99165/href</a></iframe><p>IonHeader is a bit self explanatory. It&#39;s a component that is meant to exist at the top of the page. IonHeader itself doesn&#39;t really do much by itself, aside from handling some <a href="https://www.w3schools.com/css/css3_flexbox.asp"><strong>flexbox</strong></a>-based layout. It&#39;s meant to hold other components, like IonToolbar or IonSearchbar.</p><p>IonContent is, as its name suggests, the main content area for our page. It&#39;s responsible for providing the scrollable content that users will interact with, plus any scroll events that could be used in an app.</p><p>Here in our IonContent, we&#39;re adding an IonList and a much more involved IonItemcomponent. Let&#39;s look at IonItem, as it&#39;s really the centerpiece here.</p><pre>&lt;IonList no-lines&gt;</pre><pre>&lt;IonItem&gt;</pre><pre>&lt;IonLabel color=&quot;primary&quot;&gt;Username&lt;/IonLabel&gt;</pre><pre>&lt;IonInput value={this.state.username} name=&quot;username&quot; type=&quot;text&quot; required&gt;</pre><pre>&lt;/IonInput&gt;</pre><pre>&lt;/IonItem&gt;</pre><pre>&lt;IonItem&gt;</pre><pre>&lt;IonLabel color=&quot;primary&quot;&gt;Password&lt;/IonLabel&gt;</pre><pre>&lt;IonInput value={this.state.password} name=&quot;password&quot; type=&quot;password&quot; required&gt;</pre><pre>&lt;/IonInput&gt;</pre><pre>&lt;/IonItem&gt;</pre><pre>&lt;/IonList&gt;</pre><p>And for input, we are using <strong>IonInput</strong></p><p>and we have imported all this component from <strong>@ionic/react</strong> something like this</p><pre>import { IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonInput, IonButton } from &#39;@ionic/react&#39;;</pre><p>So after all this editing, our UI is something look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*HIwmx2F-BgbMguqNqFFRyQ.jpeg" /><figcaption>Simple SIgn up from</figcaption></figure><h4>Creating a new Route</h4><p>Now that we have the pieces in place to navigate in our app, we need to create a new component and add the new route to our router declaration. Let’s open our App.tsx file and add the new route.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b64b6783b0a7bf5669e765d90d691aec/href">https://medium.com/media/b64b6783b0a7bf5669e765d90d691aec/href</a></iframe><p>With our router now having an entry for the route /login, we&#39;ll create the component needed, Login. This will exist in src/pages/Login.tsx</p><p>Let’s fill the Login.tsx with some placeholder content for the moment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aae901b06ed445947658b83edbb6d9d8/href">https://medium.com/media/aae901b06ed445947658b83edbb6d9d8/href</a></iframe><p>The content here is pretty straight forward, and should look familiar to the Home component. What is new is the IonBackButton component. This is used to navigate back to the previous route. Pretty straight forward? Ok, but what if we reload the page?</p><p>Well in this case, the in-memory history is lost, so the back button disappears. To address this, we can set the defaultHref attribute value to the URL we want to navigate to if there is no history.</p><pre>return (<br>  &lt;&gt;<br>    &lt;IonHeader&gt;<br>      &lt;IonToolbar&gt;<br>        &lt;IonButtons slot=&quot;start&quot;&gt;<br>          &lt;IonBackButton defaultHref=&quot;/home&quot; /&gt;<br>        &lt;/IonButtons&gt;<br>        &lt;IonTitle&gt;Log In&lt;/IonTitle&gt;<br>      &lt;/IonToolbar&gt;<br>    &lt;/IonHeader&gt;<br>    &lt;IonContent /&gt;<br>  &lt;/&gt;<br>);</pre><p>Here, when we reload, if there is no app history present, we’ll be able to navigate back to our home route.</p><h3>What&#39;s Next?</h3><p>Now that Ionic React RC is out, you can test it out and send the feedback to the developers. To report an issue or comment, head over to the <a href="https://github.com/ionic-team/ionic/issues">GitHub repo</a> and tag the issue with “package react”. You can also head over to the <a href="https://forum.ionicframework.com/">forums</a> to ask questions or start a discussion.</p><p>For the Ionic Team, the focus is set on releasing Ionic React final “soon”. They are not expecting any of the APIs to have any more significant changes.</p><p>We also plan on creating some more content and guides in the docs to help with some best practices we’ve found when working with Ionic React. We will soon upgrade our <a href="https://store.enappd.com/product/ionic-react-full-app-capacitor/">Ionic-React Starter App</a> from beta to RC (release-candidate)</p><blockquote><strong>To check how to create Ionic React app using Capacitor, check out my blog — </strong><a href="https://enappd.com/blog/how-to-make-ionic-apps-in-react-using-capacitor/26/"><strong>How to make apps in Ionic using React and Capacitor</strong></a></blockquote><p>To read the full announcement, visit <a href="https://blog.ionicframework.com/announcing-the-ionic-react-beta/">Ionic’s official website</a>.</p><h3>Next Steps</h3><p>Now that you have learnt how to start developing in Ionic-React RC, you can also try the following for Ionic Angular apps</p><ul><li>Ionic 4 Payment Gateways — <a href="https://enappd.com/blog/ionic-4-stripe-payment-integration-with-firebase-for-apps-and-pwa/17">Stripe</a> | <a href="https://enappd.com/blog/ionic-4-paypal-payment-integration-for-apps-and-pwa/16">PayPal</a> | <a href="https://enappd.com/blog/how-to-integrate-apple-pay-in-ionic-4-apps/21">Apple Pay</a> | <a href="https://enappd.com/blog/how-to-integrate-razorpay-in-ionic-4-apps-and-pwa/20">RazorPay</a></li><li>Ionic 4 Charts with — <a href="https://enappd.com/blog/ionic-4-charts-using-google-charts/66">Google Charts </a>| <a href="https://enappd.com/blog/adding-charts-in-ionic-4-apps-and-pwa-part-3/60">HighCharts</a> | <a href="https://enappd.com/blog/adding-charts-in-ionic-4-apps-and-pwa-part-2/54">d3.js</a> | <a href="https://enappd.com/blog/charts-in-ionic-4-apps-and-pwa-part-1/52">Chart.js</a></li><li>Ionic 4 Social Logins — <a href="https://enappd.com/blog/facebook-login-in-ionic-4-apps-using-firebase/25">Facebook</a> | <a href="https://enappd.com/blog/google-login-in-ionic-4-apps-using-firebase/39">Google</a> | <a href="https://enappd.com/blog/twitter-login-in-ionic-4-apps-using-firebase/24">Twitter</a></li><li>Ionic 4 Authentications — <a href="https://enappd.com/blog/email-authentication-with-firebase-in-ionic-4/38">Via Email</a> | <a href="https://enappd.com/blog/firebase-anonymous-login-in-ionic-4/37">Anonymous</a></li><li>Ionic 4 Features — <a href="https://enappd.com/blog/using-geolocation-geocoding-and-reverse-geocoding-in-ionic-4/45">Geolocation</a> | <a href="https://enappd.com/blog/qr-code-scanning-and-optical-character-recognition-ocr-in-ionic-4/9">QR Code reader </a>| <a href="https://enappd.com/blog/best-fitness-plugins-for-ionic-4-how-to-use-pedometer/15">Pedometer</a></li><li>Media in Ionic 4 — <a href="https://enappd.com/blog/spotify-like-music-in-ionic-4-apps/48">Audio</a> | <a href="https://enappd.com/blog/adding-video-player-in-ionic-4-app/64">Video</a> | <a href="https://enappd.com/blog/image-picker-in-ionic-4-app/67">Image Picker</a> | <a href="https://enappd.com/blog/how-to-add-image-cropper-in-ionic-4-app/68">Image Cropper</a></li><li>Ionic 4 Essentials — <a href="https://enappd.com/blog/ionic-4-save-and-retrieve-data-locally-on-device/59">Native Storage</a> | <a href="https://enappd.com/blog/how-to-translate-in-ionic-4-globalization-internationalization-and-localization/11">Translations</a> | <a href="https://enappd.com/blog/rtl-right-to-left-use-in-ionic-4/50">RTL</a></li><li>Ionic 4 messaging — <a href="https://enappd.com/blog/implement-ionic-4-firebase-push/34">Firebase Push</a> | <a href="https://enappd.com/blog/automatically-read-sms-in-ionic-4-apps/42">Reading SMS</a></li><li>Ionic 4 with Firebase — <a href="https://enappd.com/blog/how-to-integrate-firebase-in-ionic-4-apps/23">Basics</a> | <a href="https://enappd.com/blog/firebase-with-ionic-4-hosting-auth-and-db-connection/58">Hosting and DB</a> | <a href="https://enappd.com/blog/firebase-cloud-functions-in-ionic-4-complete-guide/32">Cloud functions</a></li></ul><p>If you need a base to start your next Ionic 4 app, you can make your next awesome app using <a href="https://store.enappd.com/product/ionic-4-full-app">Ionic 4 Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*2BzL8TesnBHuazHr3VA4SQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0a8c3f75e01" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/whats-new-in-ionic-react-rc-and-how-to-use-it-a0a8c3f75e01">What’s new in Ionic React RC and how to use it</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Geolocation, Geocoding and Reverse Geocoding in React Native Apps]]></title>
            <link>https://medium.com/enappd/geolocation-and-reverse-geocoding-in-react-native-7339b70496eb?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7339b70496eb</guid>
            <category><![CDATA[geocoding]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[expo]]></category>
            <category><![CDATA[reverse-geocoding]]></category>
            <category><![CDATA[geolocation]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 10:44:45 GMT</pubDate>
            <atom:updated>2019-09-26T10:08:32.761Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="How to use Geolocation, Geocoding and Reverse Geocoding in React Native Apps" src="https://cdn-images-1.medium.com/max/1024/1*ek9eMWI2YpoNEj7va0VUYQ.png" /></figure><p>In this post, you will learn how to implement Geolocation React native apps. We will also learn how to Convert Geocode in Location address (Reverse Geocoding) and Location Address into Geocode(Geocoding) in a simple React native app.</p><p>React Native lets you build mobile apps using only JavaScript. It uses the same design as React, letting you compose a rich mobile UI using declarative components.</p><h3>What Is React Native?</h3><p>React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. In other words: web developers can now write mobile applications that look and feel truly “native,” all from the comfort of a JavaScript library that we already know and love. Plus, because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS.</p><p>Similar to React for the Web, React Native applications are written using a mixture of JavaScript and XML markup, known as JSX. Then, under the hood, the React Native “bridge” invokes the native rendering APIs in Objective-C (for iOS) or Java (for Android). Thus, your application will render using real mobile UI components, not webviews, and will look and feel like any other mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera, or the user’s location.</p><p>React Native currently supports both iOS and Android and has the potential to expand to future platforms as well. In this blog, we’ll cover both iOS and Android. The vast majority of the code we write will be cross-platform. And yes: you can really use React Native to build production-ready mobile applications! Some example: <a href="http://bit.ly/1YipO7A">Facebook</a>, <a href="http://bit.ly/1PPEiZH">Palantir</a>, and <a href="http://bit.ly/1PPEjNg">TaskRabbit</a> are already using it in production for user-facing applications.</p><h3>What is Geolocation?</h3><p>The most famous and familiar location feature — Geolocation is the ability to track a device’s whereabouts using GPS, cell phone towers, WiFi access points or a combination of these. Since devices are used by individuals, geolocation uses positioning systems to track an individual’s whereabouts down to latitude and longitude coordinates, or more practically, a physical address. Both mobile and desktop devices can use geolocation.<br>Geolocation can be used to determine time zone and exact positioning coordinates, such as for tracking wildlife or cargo shipments.</p><p>Some famous apps using Geolocation are</p><ul><li>Uber / Lyft — Cab booking</li><li>Google Maps (of course) — Map services</li><li>Swiggy / Zomato — Food delivery</li><li>Fitbit — Fitness app</li><li>Instagram / Facebook — For tagging photos</li></ul><h3>What is Geocoding and Reverse geocoding?</h3><p><strong>Geocoding</strong> is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate.<br><strong>Reverse geocoding</strong> is the process of transforming a (latitude, longitude) coordinate into a (partial) address. The amount of detail in a reverse geocoded location description may vary, for example, one might contain the full street address of the closest building, while another might contain only a city name and postal code.</p><h3>Post structure</h3><p>We will go in a step-by-step manner to explore the anonymous login feature of Firebase. This is my break-down of the blog</p><p><strong>STEPS</strong></p><ol><li>Create a simple React Native app</li><li>Install Plugins for Geocoding and Geolocation and get User Location</li><li>Get User Current Location (Geocoding)</li><li>Convert User Geolocation into an address (Reverse Geocoding)</li><li>Convert User Entered Address into Geocode (Geocoding)</li></ol><p>We have three major objectives</p><ol><li>Get User Current Location which we will get in latitude and longitude (Geolocation)</li><li>Convert that latitude and longitude in Street Address (Reverse Geocoding)</li><li>And again convert Street address entered by the user into latitude and longitude (Geocoding)</li></ol><p><strong>Let’s dive right in!</strong></p><h3>Step 1: — Create a simple React Native app</h3><p>If you are coming from a web background, the easiest way to get started with React Native is with Expo tools because they allow you to start a project without installing and configuring Xcode or Android Studio. Expo CLI sets up a development environment on your local machine and you can begin writing a React Native app within minutes. For instant development, you can use <a href="https://snack.expo.io/">Snack</a> to try React Native out directly in your web browser.</p><p>If you are familiar with native development, you will likely want to use React Native CLI. It requires Xcode or Android Studio to get started. If you already have one of these tools installed, you should be able to get up and running within a few minutes. If they are not installed, you should expect to spend about an hour installing and configuring them.</p><p><strong>Expo CLI Quickstart</strong></p><p>Assuming that you have <a href="https://nodejs.org/en/download/">Node 10+</a> installed, you can use npm to install the Expo CLI command-line utility:</p><pre>npm install -g expo-cli</pre><p>Then run the following commands to create a new React Native project called “AwesomeProject”:</p><pre>expo init AwesomeProject</pre><pre>cd AwesomeProject<br>npm start # you can also use: expo start</pre><p>This will start a development server for you.</p><p><strong>React Native CLI Quickstart</strong></p><p>Assuming that you have <a href="https://nodejs.org/en/download/">Node 10+</a> installed, you can use npm to install the React Native CLI command-line utility:</p><pre>npm install -g react-native-cli</pre><p>Then run the following commands to create a new React Native project called “AwesomeProject”:</p><pre>react-native init AwesomeProject</pre><blockquote>For details you can check this <a href="https://facebook.github.io/react-native/docs/getting-started.html">link</a>.</blockquote><h3>Step 2 : — Install Plugins for Geocoding and Geolocation and get User Location</h3><blockquote><strong>In Bare React Native Apps</strong></blockquote><h4>react-native-geolocation-service</h4><p>This library is created in an attempt to fix the location timeout issue on android with the react-native’s current implementation of Geolocation API. This library tries to solve the issue by using Google Play Service’s new FusedLocationProviderClient API, which Google strongly recommends over android&#39;s default framework location API. It automatically decides which provider to use based on your request configuration and also prompts you to change the location mode if it doesn&#39;t satisfy your current request configuration.</p><blockquote><em>NOTE: Location request can still timeout since many android devices have GPS issue in the hardware level or in the system software level. Check the </em><a href="https://github.com/Agontuk/react-native-geolocation-service#faq"><em>FAQ</em></a><em> for more details.</em></blockquote><h4>Installation</h4><p>yarn</p><pre>yarn add react-native-geolocation-service</pre><p>npm</p><pre>npm install react-native-geolocation-service</pre><h4>Setup</h4><h4>Android</h4><p>No additional setup is required for Android</p><h4>iOS</h4><p>You need to include the NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation when using the app. In order to enable geolocation in the background, you need to include the NSLocationAlwaysUsageDescription key in Info.plist and add location as a background mode in the &#39;Capabilities&#39; tab in Xcode.</p><ul><li>Update your Podfile</li></ul><pre>pod &#39;react-native-geolocation&#39;, path: &#39;../node_modules/@react-native-community/geolocation&#39;</pre><ul><li>Then run pod install from ios directory</li></ul><blockquote><strong>In EXPO </strong><a href="https://docs.expo.io/versions/latest/introduction/managed-vs-bare/#managed-workflow"><strong>managed</strong></a><strong> apps,</strong></blockquote><p>you’ll need to run</p><pre>expo install expo-location</pre><h3>Step 3: — Get User Current Location (Geocoding)</h3><blockquote><strong>In Bare React Native Apps,</strong></blockquote><p>Since this library was meant to be a drop-in replacement for the RN’s Geolocation API, the usage is pretty straight forward, with some extra error cases to handle.</p><blockquote>One thing to note, this library assumes that location permission is already granted by the user, so you have to use PermissionsAndroid to request for permission before making the location request.</blockquote><p>For getting user location you have to import Geolocation API from react-native-geolocation-service package like this</p><pre>import Geolocation from &#39;react-native-geolocation-service&#39;;</pre><p>And add this function into your code</p><pre>if (hasLocationPermission) {<br>        Geolocation.getCurrentPosition(<br>            (position) =&gt; {<br>                console.log(position);<br>            },<br>            (error) =&gt; {<br>                // See error code charts below.<br>                console.log(error.code, error.message);<br>            },<br>            { enableHighAccuracy: true, timeout: 15000, maximumAge:          10000 }<br>        );<br>    }</pre><p>So after adding all this code your file something look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d98d8697e7f6b7070b00001e8e01a26/href">https://medium.com/media/5d98d8697e7f6b7070b00001e8e01a26/href</a></iframe><blockquote><strong>In EXPO </strong><a href="https://docs.expo.io/versions/latest/introduction/managed-vs-bare/#managed-workflow"><strong>managed</strong></a><strong> apps,</strong></blockquote><p>For getting user location you have to import Location API from expo-location package like this</p><pre>import * as Location from &#39;expo-location&#39;;</pre><p>And add this function into your code</p><pre>_getLocationAsync = async () =&gt; {<br>    let { status } = await Permissions.askAsync(Permissions.LOCATION);<br>    if (status !== &#39;granted&#39;) {<br>      this.setState({<br>        errorMessage: &#39;Permission to access location was denied&#39;,<br>      });<br>    }</pre><pre>let location = await Location.getCurrentPositionAsync({});<br>    this.setState({ location });<br>  };</pre><p>So after adding all this code your file something look like this.</p><blockquote>One thing to note, this library assumes that location permission is already granted by the user, so you have to use Permissions from ‘expo-permissions’ to request for permission before making the location request.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0018e354f858da9ecf59c9ee5944875/href">https://medium.com/media/b0018e354f858da9ecf59c9ee5944875/href</a></iframe><h3>Step 4: — Convert User Geolocation into an address (Reverse Geocoding)</h3><blockquote><strong>In Bare React Native Apps,</strong></blockquote><p>In this app, we are using react-native-geocoding package for <strong>Geocoding</strong> and <strong>Reverse Geocoding</strong></p><h4>react-native-geocoding</h4><p>A geocoding module for <a href="https://github.com/facebook/react-native">React Native</a> to transform a description of a location (i.e. street address, town name, etc.) into geographic coordinates (i.e. latitude and longitude) and vice versa.</p><p>This module uses the <a href="https://developers.google.com/maps/documentation/geocoding/intro">Google Maps Geocoding API</a> and requires an API key for purposes of quota management. Please check <a href="https://developers.google.com/maps/documentation/geocoding/get-api-key">this link</a> out to obtain your API key.</p><h4>Install</h4><pre>npm install --save react-native-geocoding</pre><p>For Geocoding and Reverse Geocoding in your app you import Geocoder API from react-native-geocoding package like this</p><pre>import Geocoder from &#39;react-native-geocoding&#39;;</pre><p>And Then you have to initialize the module in your app(needs to be done only once)</p><pre>Geocoder.init(&quot;xxxxxxxxxxxxxxxxxxxxxxxxx&quot;); // use a valid API key<br>// With more options<br>// Geocoder.init(&quot;xxxxxxxxxxxxxxxxxxxxxxxxx&quot;, {language : &quot;en&quot;}); // set the language</pre><p>And use this code respectively for Geocoding and reverse Geocoding</p><pre>Geocoder.from(41.89, 12.49)<br>		.then(json =&gt; {<br>        		var addressComponent = json.results[0].address_components[0];<br>			console.log(addressComponent);<br>		})<br>		.catch(error =&gt; console.warn(error));</pre><pre>// Works as well :<br>// ------------<br><br>// location object<br>Geocoder.from({<br>	latitude : 41.89,<br>	longitude : 12.49<br>});<br><br>// latlng object<br>Geocoder.from({<br>	lat : 41.89,<br>	lng : 12.49<br>});<br><br>// array<br>Geocoder.from([41.89, 12.49]);</pre><h4>Error Codes</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a5fd454c8769a3bddc9d72e4ed4627c/href">https://medium.com/media/1a5fd454c8769a3bddc9d72e4ed4627c/href</a></iframe><blockquote><strong>In EXPO </strong><a href="https://docs.expo.io/versions/latest/introduction/managed-vs-bare/#managed-workflow"><strong>managed</strong></a><strong> apps,</strong></blockquote><p>For geocoding of Address we are using react-native-geocoding so the installation and Initialize Steps are the same as Geolocation.</p><p>we will use this code for Reverse Geocoding</p><pre>_attemptReverseGeocodeAsync = async () =&gt; {<br>    this.setState({ inProgress: true });<br>    try {<br>      let result = await Location.reverseGeocodeAsync(<br>        this.state.selectedExample<br>      );<br>      this.setState({ result });<br>    } catch (e) {<br>      this.setState({ error: e });<br>    } finally {<br>      this.setState({ inProgress: false });<br>    }<br>  };</pre><h3>Step 5: — Convert User Entered Address into Geocode (Geocoding)</h3><p>For Reverse geocoding of Address, we are using expo-location so the installation and Initialize Steps are the same as Reverse Geocoding.</p><p>we will use this code for Geocoding</p><pre>Geocoder.from(&quot;Colosseum&quot;)<br>		.then(json =&gt; {<br>			var location = json.results[0].geometry.location;<br>			console.log(location);<br>		})<br>		.catch(error =&gt; console.warn(error));</pre><blockquote><strong>In EXPO </strong><a href="https://docs.expo.io/versions/latest/introduction/managed-vs-bare/#managed-workflow"><strong>managed</strong></a><strong> apps,</strong></blockquote><p>For geocoding of Address we are using react-native-geocoding so the installation and Initialize Steps are the same as Geolocation.</p><p>we will use this code for Geocoding</p><pre>_attemptGeocodeAsync = async () =&gt; {<br>    this.setState({ inProgress: true, error: null });<br>    try {<br>      let result = await Location.geocodeAsync(this.state.selectedExample);<br>      this.setState({ result });<br>    } catch (e) {<br>      this.setState({ error: e.message });<br>    } finally {<br>      this.setState({ inProgress: false });<br>    }<br>  };</pre><p>Working Example of Geocode and Reverse Geocing in Your App</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ad24e1b9ee025f22d3532e9ccf5a580/href">https://medium.com/media/5ad24e1b9ee025f22d3532e9ccf5a580/href</a></iframe><h3>Conclusion</h3><p>In this blog, we learned how to implement Geolocation React Native app. We also learnt how to Convert Geocode in Location address(Reverse Geocoding) and Location Address into Geocode(Geocoding) in a simple React Native app.</p><h3>Next Steps</h3><p>Now that you have learnt about how to implement Geolocation , Geocoding and Reverse Geocoding React Native app, here are some other topics you can look into</p><ul><li><a href="https://enappd.com/blog/react-native-life-cycle-hooks/79">React Native life cycle hooks</a></li><li>How To in React Native — <a href="https://enappd.com/blog/pick-images-from-camera-gallery-in-react-native-app/78">Image picker</a>| <a href="https://enappd.com/blog/intergrate-firebase-in-react-native-app/73">Integrate Firebase</a></li><li><a href="https://enappd.com/blog/guide-on-react-native-full-app/53">Create Awesome Apps in React Native</a> using Full App</li><li><a href="https://enappd.com/blog/firebase-push-notifications-in-react-native/81/">Firebase Push notifications in React Native Apps</a></li></ul><p>If you need a base to start your next React Native app, you can make your next awesome app using <a href="https://store.enappd.com/product/react-native-full-app/">React Native Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sWyEeAfCMk7ULOkLUCdSug.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7339b70496eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/geolocation-and-reverse-geocoding-in-react-native-7339b70496eb">How to use Geolocation, Geocoding and Reverse Geocoding in React Native Apps</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Camera and Image picker in Ionic 4 app]]></title>
            <link>https://medium.com/enappd/camera-and-image-picker-in-ionic-4-app-d68acd064589?source=rss-bf3bad59d9c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d68acd064589</guid>
            <category><![CDATA[photos]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[ionic4]]></category>
            <category><![CDATA[gallery]]></category>
            <dc:creator><![CDATA[umang rathore]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 12:05:37 GMT</pubDate>
            <atom:updated>2019-09-26T10:16:24.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Camera and Image picker in Ionic 4 app" src="https://cdn-images-1.medium.com/max/1024/1*18ChsJZ9ik1WHH-tz7K8Ug.png" /></figure><h4>Summary</h4><p>This is Part-1 of two post series. In this post, you will learn how to implement an Image picker in Ionic 4 app. Part 2 of the series discusses how to Crop those images in IONIC 4 app🔥</p><p>We will create a sample app, where users can pick an image from there gallery or camera. After picking, the user can crop his image.</p><blockquote>Complete source code of this tutorial is available in the <a href="https://github.com/enappd/ImageCrooper.git">Image picker and cropper in IONIC 4 app</a></blockquote><h3>What is Ionic 4?</h3><p>You probably already know about Ionic, but put this section in every blog just for the sake of beginners. <strong>Ionic</strong> is a complete open-source SDK for hybrid mobile app development. Ionic provides tools and services for developing hybrid mobile apps using Web technologies like CSS, HTML5, and Sass. Apps can be built with these Web technologies and then distributed through native app stores to be installed on devices.</p><p>In other words — If you create native apps in Android, you code in <strong>Java</strong>. If you create native apps in iOS, you code in <strong>Obj-C</strong> or <strong>Swift</strong>. Both of these are powerful, but complex languages. With Cordova (and Ionic) you can write a single piece of code for your app that can run on both iOS and Android (and windows!), that too with the simplicity of HTML, CSS, and JS. I’m a huge fan of Ionic and been developing Ionic apps for last 4 years.</p><h3>Structure</h3><p>We’ll follow a stepped approach to create a Music player app in Ionic 4. We’ll use an IONIC native plugin for music playback. Following are the steps</p><ul><li>Step 1 — Create a basic Ionic 4 app</li><li>Step 2 — Setup Image Picker plugin</li><li>Step 3— Use Image Picker Plugin In App</li><li>Step 4 — Build the app in Android and Test</li><li>Step 5— Various Image Picker Features</li></ul><p>So let’s dive right in!</p><h3>Step 1 — Create a basic Ionic 4 app</h3><blockquote>I have covered this topic in detail in <a href="https://enappd.com/blog/how-to-create-an-ionic-4-app-for-beginners/13/">this blog</a>.</blockquote><p>In short, the steps you need to take here are</p><ul><li>Make sure you have node installed in the system (V10.15.3 at the time of this blog post)</li><li>Install <strong>ionic CLI </strong>using npm (my Ionic version is 4.12.0 currently)</li><li>Create an Ionic app using ionic start</li></ul><p>You can create a sidemenu starter for the sake of this tutorial. On running ionic start ionic-4-chartjs sidemenu , node modules will be installed. Once the installation is done, run your app on browser using</p><pre>$ ionic serve</pre><p>The app will launch on the browser. You can go to Inspect -&gt; Device Mode to see the code in a mobile layout. Next, we’ll add the chart library to our app.</p><h3>Step 2 — Setup Image Picker plugin</h3><p>Requires the Cordova plugin: cordova-plugin-camera. For more info, please see the <a href="https://github.com/apache/cordova-plugin-camera">Cordova Camera Plugin Docs</a>.</p><p>[Warning] Since IOS 10 the camera requires permissions to be placed in your config.xml add</p><pre>&lt;config-file parent=&quot;NSCameraUsageDescription&quot; platform=&quot;ios&quot; target=&quot;*-Info.plist&quot;&gt;<br> &lt;string&gt;You can take photos&lt;/string&gt;<br>&lt;/config-file&gt;</pre><p>inside of the &lt;platform name=’ios&gt; section</p><h4>Installation</h4><p>‌For that, open your terminal and type</p><pre>ionic cordova plugin add cordova-plugin-camera</pre><p>‌It’s a bit clumsy to work with Cordova plugin so the ionic team created <strong>Ionic Native</strong>, which is a wrapper for the Cordova plugins so we can use them in a more “Angular/Ionic” way.</p><p>‌So now we will open our terminal and try this command‌ to install Facebook package from Ionic Native</p><pre>npm install @ionic-native/camera</pre><p>For read/write access to files residing on the device. you also need File plugin. The File class implements static convenience functions to access files and directories.</p><p>so for installation of this plugin open your terminal and type,</p><pre>ionic cordova plugin add cordova-plugin-file</pre><p>and</p><pre>npm install @ionic-native/file</pre><h3>Step 3 — Use Image Picker Plugin In App</h3><p>Using this plugin The first step you will need to do is add this plugin to your app’s module</p><p>Import these plugins like this</p><pre>import { Camera } from &#39;@ionic-native/Camera/ngx&#39;;<br>import { File } from &#39;@ionic-native/file/ngx&#39;;</pre><p>and add this to providers of your app Like this</p><pre>providers: [</pre><pre>StatusBar,</pre><pre>File,</pre><pre>SplashScreen,</pre><pre>Camera,</pre><pre>File,</pre><pre>{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }</pre><pre>],</pre><p>So after Adding Your app.module.ts look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05d53fe36aa60195011128c8e293c9f2/href">https://medium.com/media/05d53fe36aa60195011128c8e293c9f2/href</a></iframe><p>Now time to import this plugin in your home.ts where we will use this plugin</p><p>So for using this plugin in our home.ts first, we will import the plugin like this</p><pre>import { Camera, CameraOptions } from &#39;@ionic-native/Camera/ngx&#39;;</pre><p>and inject it in your Constructor (Dependency injection) like this</p><pre>constructor(</pre><pre>private camera: Camera,</pre><pre>public actionSheetController: ActionSheetController,</pre><pre>private file: File</pre><pre>) { }</pre><p>And use this code for Adding Image Picker in IONIC App</p><pre>pickImage(sourceType) {</pre><pre>const options: CameraOptions = {</pre><pre>quality: 100,</pre><pre>sourceType: sourceType,</pre><pre>destinationType: this.camera.DestinationType.FILE_URI,</pre><pre>encodingType: this.camera.EncodingType.JPEG,</pre><pre>mediaType: this.camera.MediaType.PICTURE</pre><pre>}</pre><pre>this.camera.getPicture(options).then((imageData) =&gt; {</pre><pre>// imageData is either a base64 encoded string or a file URI</pre><pre>// If it&#39;s base64 (DATA_URL):</pre><pre>// let base64Image = &#39;data:image/jpeg;base64,&#39; + imageData;</pre><pre>this.cropImage(imageData)</pre><pre>}, (err) =&gt; {</pre><pre>// Handle error</pre><pre>});</pre><pre>}</pre><p>So after Adding this code your home.ts something looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86de464e7ed27071232cd49eb9ae8609/href">https://medium.com/media/86de464e7ed27071232cd49eb9ae8609/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*mu733H2SSMBwTW-zX16rRA.jpeg" /><figcaption>Home page before picking any image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*-jSh2IvaTBPk7WvY4ng5uA.jpeg" /><figcaption>Pick image from camera or Image Picker</figcaption></figure><h3>Step 4 — Build your app on Android and test</h3><p>If you have carried out the above steps correctly, Android build should be a breeze.</p><p>Run the following command to create Android platform</p><pre>$ ionic cordova platform add android</pre><p>Once platform is added, run the app on device (Make sure you have a device attached to the system).</p><pre>$ ionic cordova run android</pre><p>Once your app is up and running on the device, you can start testing all the functions. The images shown below are taken from a real Android device 😎</p><h3>Step 5 — Various Image Picker Features</h3><h4>Camera.DestinationType : enum</h4><p>Defines the output format of Camera.getPicture call. <em>Note:</em> On iOS passing DestinationType.NATIVE_URI along withPictureSourceType.PHOTOLIBRARY or PictureSourceType.SAVEDPHOTOALBUM will disable any image modifications (resize, quality change, cropping, etc.) due to implementation-specific.</p><p><strong>Kind</strong>: static enum property of <a href="https://github.com/apache/cordova-plugin-camera#module_Camera">Camera</a></p><p><strong>Properties</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71d7b5b16e01db0be81c72306330afe4/href">https://medium.com/media/71d7b5b16e01db0be81c72306330afe4/href</a></iframe><h4>Camera.EncodingType : enum</h4><p><strong>Kind</strong>: static enum property of <a href="https://github.com/apache/cordova-plugin-camera#module_Camera">Camera</a><br><strong>Properties</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c75a91d49c830086258f141a502f63f1/href">https://medium.com/media/c75a91d49c830086258f141a502f63f1/href</a></iframe><h4>Camera.MediaType : enum</h4><p><strong>Kind</strong>: static enum property of <a href="https://github.com/apache/cordova-plugin-camera#module_Camera">Camera</a><br><strong>Properties</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35f03245d8c7445dac0d7f21e8f9f4a5/href">https://medium.com/media/35f03245d8c7445dac0d7f21e8f9f4a5/href</a></iframe><h4>Camera.PictureSourceType : enum</h4><p>Defines the output format of Camera.getPicture call. <em>Note:</em> On iOS passing PictureSourceType.PHOTOLIBRARY or PictureSourceType.SAVEDPHOTOALBUM along with DestinationType.NATIVE_URI will disable any image modifications (resize, quality change, cropping, etc.) due to implementation-specific.</p><p><strong>Kind</strong>: static enum property of <a href="https://github.com/apache/cordova-plugin-camera#module_Camera">Camera</a><br><strong>Properties</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53a7da9b207ca06a4115945358d2394b/href">https://medium.com/media/53a7da9b207ca06a4115945358d2394b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*-defMPdQ-F2RZNLaAgLh9w.jpeg" /><figcaption>Use camera to click images</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*VdbiYQwsVaakWiTgHAa_9w.jpeg" /><figcaption>Image Picker and cropper in Android</figcaption></figure><h3>Conclusion</h3><p>In this post, you learned how to implement Image Picker in your Ionic 4 app. In the next part of this post, you’ll learn how to crop Image in IONIC 4 app.</p><blockquote><em>Complete source code of this tutorial is available in the </em><a href="https://github.com/enappd/ImageCrooper.git"><em>ionic-4-image-picker-cropper</em></a></blockquote><h3>Next Steps</h3><p>Now that you have learned the implementation of Camera and Image gallery in Ionic 4, you can also try</p><ul><li>Ionic 4 Payment Gateways — <a href="https://enappd.com/blog/ionic-4-stripe-payment-integration-with-firebase-for-apps-and-pwa/17">Stripe</a> | <a href="https://enappd.com/blog/ionic-4-paypal-payment-integration-for-apps-and-pwa/16">PayPal</a> | <a href="https://enappd.com/blog/how-to-integrate-apple-pay-in-ionic-4-apps/21">Apple Pay</a> | <a href="https://enappd.com/blog/how-to-integrate-razorpay-in-ionic-4-apps-and-pwa/20">RazorPay</a></li><li>Ionic 4 Charts with — <a href="https://enappd.com/blog/ionic-4-charts-using-google-charts/66">Google Charts </a>| <a href="https://enappd.com/blog/adding-charts-in-ionic-4-apps-and-pwa-part-3/60">HighCharts</a> | <a href="https://enappd.com/blog/adding-charts-in-ionic-4-apps-and-pwa-part-2/54">d3.js</a> | <a href="https://enappd.com/blog/charts-in-ionic-4-apps-and-pwa-part-1/52">Chart.js</a></li><li>Ionic 4 Social Logins — <a href="https://enappd.com/blog/facebook-login-in-ionic-4-apps-using-firebase/25">Facebook</a> | <a href="https://enappd.com/blog/google-login-in-ionic-4-apps-using-firebase/39">Google</a> | <a href="https://enappd.com/blog/twitter-login-in-ionic-4-apps-using-firebase/24">Twitter</a></li><li>Ionic 4 Authentications — <a href="https://enappd.com/blog/email-authentication-with-firebase-in-ionic-4/38">Via Email</a> | <a href="https://enappd.com/blog/firebase-anonymous-login-in-ionic-4/37">Anonymous</a></li><li>Ionic 4 Features — <a href="https://enappd.com/blog/using-geolocation-geocoding-and-reverse-geocoding-in-ionic-4/45">Geolocation</a> | <a href="https://enappd.com/blog/qr-code-scanning-and-optical-character-recognition-ocr-in-ionic-4/9">QR Code reader </a>| <a href="https://enappd.com/blog/best-fitness-plugins-for-ionic-4-how-to-use-pedometer/15">Pedometer</a></li><li>Media in Ionic 4 — <a href="https://enappd.com/blog/spotify-like-music-in-ionic-4-apps/48">Audio</a> | <a href="https://enappd.com/blog/adding-video-player-in-ionic-4-app/64">Video</a> | <a href="https://enappd.com/blog/how-to-add-image-cropper-in-ionic-4-app/68">Image Cropper</a></li><li>Ionic 4 Essentials — <a href="https://enappd.com/blog/ionic-4-save-and-retrieve-data-locally-on-device/59">Native Storage</a> | <a href="https://enappd.com/blog/how-to-translate-in-ionic-4-globalization-internationalization-and-localization/11">Translations</a> | <a href="https://enappd.com/blog/rtl-right-to-left-use-in-ionic-4/50">RTL</a></li><li>Ionic 4 messaging — <a href="https://enappd.com/blog/implement-ionic-4-firebase-push/34">Firebase Push</a> | <a href="https://enappd.com/blog/automatically-read-sms-in-ionic-4-apps/42">Reading SMS</a> | <a href="https://enappd.com/blog/local-notifications-in-ionic-4/69">Local notification</a></li><li>Ionic 4 with Firebase — <a href="https://enappd.com/blog/how-to-integrate-firebase-in-ionic-4-apps/23">Basics</a> | <a href="https://enappd.com/blog/firebase-with-ionic-4-hosting-auth-and-db-connection/58">Hosting and DB</a> | <a href="https://enappd.com/blog/firebase-cloud-functions-in-ionic-4-complete-guide/32">Cloud functions</a></li></ul><p>If you need a base to start your next Ionic 4 app, you can make your next awesome app using <a href="https://store.enappd.com/product/ionic-4-full-app">Ionic 4 Full App</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvh4PRFmNar6eSHB20VJTg.jpeg" /><figcaption>Make your next awesome app with Ionic 4 Full App</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d68acd064589" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enappd/camera-and-image-picker-in-ionic-4-app-d68acd064589">Camera and Image picker in Ionic 4 app</a> was originally published in <a href="https://medium.com/enappd">Enappd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>