<?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 Jaka Tertinek on Medium]]></title>
        <description><![CDATA[Stories by Jaka Tertinek on Medium]]></description>
        <link>https://medium.com/@jaka-tertinek?source=rss-b65ce11233a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qNNYMRoXINPlzRk-jfVhJg.png</url>
            <title>Stories by Jaka Tertinek on Medium</title>
            <link>https://medium.com/@jaka-tertinek?source=rss-b65ce11233a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:36:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaka-tertinek/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[Remove console logs from your release React Native builds]]></title>
            <link>https://jaka-tertinek.medium.com/remove-console-logs-from-your-release-react-native-builds-b9e5cf9e3f6f?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9e5cf9e3f6f</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-security]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Thu, 25 Apr 2024 10:07:37 GMT</pubDate>
            <atom:updated>2024-04-25T10:08:41.292Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*_FFbV0johzGJxJZBXUnAQQ.png" /></figure><p>Every developer who had their app audited by a security expert knows about the issue of console.logs appearing in release builds of a React Native app. Unintentionally this data was printed out via console.log, console. error, console. warn… that might be useful while debugging the app can give valuable information to bad actors looking to gain access our application.</p><h4><strong>How do we view console.logs for apps built in release mode</strong></h4><p>First of all, let’s create a simple welcome/login screen. This will contain a welcome text and a login button. When the button is pressed a session is initialised and a JWT token is returned. Let’s say we made a mistake somewhere in the app while we were grinding the midnight oil trying to fix that last issue before our go-live deadline, and we forgot to remove a console.log that was printing out that JWT token.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36a3bd34193e8b8ea03dfc90749e6f30/href">https://medium.com/media/36a3bd34193e8b8ea03dfc90749e6f30/href</a></iframe><p>How can we view the console logs while the app is in release mode even without Metro running? This is very simple.</p><p>In Android Studio in the bottom left corner, you can find a tool called Logcat. This enables you to view all the logs your connected device emits and it doesn’t only pertain to your application but to every app and service run on your device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*SfU56NpFshmd66qsgiy0Rw.png" /><figcaption>Logcat location in AndroidStudio</figcaption></figure><p>If we now run our app and press the “Login” button you can see in Logcat that the console.log prints out: <strong><em>Production JWT token =&gt; ‘, ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IllvdSBzaG91bGQgbm90IHNlZSB0aGlzIiwiaWF0IjoxNTE2MjM5MDIyfQ.sDU0LN8C8KkCf95uJsfKylMbDeFTZCBAzPu3Kr5x7Vo’</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpwZLL39Jg0nGr-G5rETtw.png" /><figcaption>Example of Logcat in Android studio printing out the console.log we forgot to remove.</figcaption></figure><h4>How to remove console logs from the release build</h4><p>How do we remove all console logs from release mode? Manually going through the whole app and deleting all of them is inefficient. Luckily there is a simple tool that does that for us. It’s called <a href="https://babeljs.io/docs/babel-plugin-transform-remove-console/"><strong>babel-plugin-transform-remove-console</strong></a><strong>.</strong></p><p>First start by adding it your project with:</p><pre>yarn add babel-plugin-transform-remove-console --dev</pre><p>Then navigate to <strong>babel.config.js</strong> (create one if you don’t have it already) and add <strong>transform-remove-console</strong>. I suggest also adding an environment tag to only remove logs from the production/release builds.</p><pre>module.exports = {<br>  env: {<br>    production: {<br>      plugins: [&#39;transform-remove-console&#39;],<br>    },<br>  },<br>};</pre><p>If we run the same test as before all console.logs, console.errors, console.warn… are automatically removed and do not appear in Logcat.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9e5cf9e3f6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload files from React Native app to AWS S3]]></title>
            <link>https://jaka-tertinek.medium.com/upload-files-from-react-native-app-to-aws-s3-3d3cb85e9d4?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d3cb85e9d4</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-amazon]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-s3]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 10:22:11 GMT</pubDate>
            <atom:updated>2023-10-13T10:22:11.160Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*hLBnjIsaoUSjudFirivPDA.jpeg" /></figure><p>In today’s mobile app landscape, file handling is a common requirement. Users often need to upload and access various types of files, such as images, PDFs, and documents. In this article, we’ll address a specific scenario: uploading images from a React Native app to AWS S3, Amazon’s cloud storage service. We’ll guide you through the necessary steps in three chapters.</p><h4>1. How to open a file explorer and select a file?</h4><p>Now, this is the simplest part. The React Native community has already prepared libraries that help us achieve this. In this article, we will use <a href="https://github.com/rnmods/react-native-document-picker">react-native-document-picker</a>.</p><p>As demonstrated in the example, opening a file explorer is straightforward. However, please note that, for the sake of simplicity, we are limiting the app to using images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1861aaedb6de8297be2ad15bbcd6ccaf/href">https://medium.com/media/1861aaedb6de8297be2ad15bbcd6ccaf/href</a></iframe><h4>2. How to upload a file directly to AWS S3?</h4><p>Amazon S3 or <a href="https://aws.amazon.com/s3/">Amazon Simple Storage Service</a> is an <a href="https://en.wikipedia.org/wiki/Object_storage">object storage</a> service.</p><blockquote>Amazon S3 can store any type of object, which allows uses like storage for Internet applications, backups, disaster recovery, data archives, <a href="https://en.wikipedia.org/wiki/Data_lake">data lakes</a> for analytics, and <a href="https://en.wikipedia.org/wiki/Cloud_computing#Hybrid_cloud">hybrid cloud storage</a>.</blockquote><p>In layman’s terms its a service provided by AWS that allows the storing and management of files trough a web service interface. Now the question is how do we connect to it? Again, because this is React Native there are many packages that allow you to connect to AWS and AWS S3 specifically. But because this is Javascript after-all we can just use the already provided package from Amazon directly. Because setting up AWS would greatly extend this article we are not going to cover the detailed steps here. You can find detailed steps how to achieve this <a href="https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started-react-native.html">here</a>.</p><p>First of all, let’s install the official AWS SDK for JavaScript. Since this is a very large package, as it needs to include all services provided by AWS, there is also a separate package that focuses solely on <a href="https://www.npmjs.com/package/@aws-sdk/client-s3">AWS S3</a>.</p><p>npm install @aws-sdk/client-s3</p><p>And some peer dependancies:</p><p>npm i react-native-get-random-values</p><p>npm i react-native-url-polyfill</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94c6cbf59e5617e4fe616182dafa913f/href">https://medium.com/media/94c6cbf59e5617e4fe616182dafa913f/href</a></iframe><p>Further reading and other usefull links</p><p><a href="http://react-native-document-picker/">[1] react-native-document-picker</a></p><p><a href="https://aws.amazon.com/s3/">[2] Amazon Simple Storage Service</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d3cb85e9d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a reusable global alert in React Native]]></title>
            <link>https://towardsdev.com/create-a-reusable-global-alert-in-react-native-92c1b57c8634?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/92c1b57c8634</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 15:22:14 GMT</pubDate>
            <atom:updated>2022-04-25T11:41:40.495Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PfxUv0YEJQzx0leH5B5DJg.jpeg" /><figcaption>Global alert</figcaption></figure><p>Every developer who has ever created an application has come across a scenario where they were required to display an alert that something did not go as planned or that some information was missing, or maybe just tell the user that his request was successful.</p><p>There are many possible solutions how to handle this. The simplest solution is the <a href="https://reactnative.dev/docs/alert">Alert</a> dialogue that comes included with the React Native framework. But what, we want more control over how the alert looks and feels. At the end of the day, you want to have a common design language across your application.</p><p>There already is a <a href="https://github.com/react-native-modal/react-native-modal">very popular package</a> and a standard <a href="https://reactnative.dev/docs/modal">component in React Native</a> called “Modal”. That gives you an easy way to customise the alert to your liking, making it easy to position the modal on the screen and adopt its design. I like this component. But it comes with a<a href="https://github.com/react-native-modal/react-native-modal#i-cant-show-multiple-modals-one-after-another"> fatal flaw</a>. The way the component is designed (the same goes for the build-in component and the package) does not allow you to have two modals open simultaneously. I encountered this issue when I implemented a form inside a modal that extended from the bottom. When the user filled out the form and pressed the submit button, the form closed, and a standard modal alert should pop up notifying them that the request was successful or not. Now for some reason, this always froze my app. It took me quite a while before I figured out that react-native-modal had this limitation.</p><p>I asked myself, what should I do now? Should I refactor all my modals that contain a form to a normal screen, or should I rework the alert? Of course, there is only one feasible option: creating your own alert. From the code below, you can see it is relatively easy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36d185caba26089dd44b3443ea69c495/href">https://medium.com/media/36d185caba26089dd44b3443ea69c495/href</a></iframe><p>This CustomAlert looks like a regular component. And it is. What makes it look like an alert is the <strong>“absolute style”</strong>. Property position: ‘absolute’ lays the alert over others on the screen, and with properties top, left, bottom and right, we set where the alert should be displayed. In this case, we centre the View on the screen. The style modalElementsContainer is then the one that sets the size of the alert. Here, we want the alert to take 90% of the screen’s width and adapt its height according to the elements inside it.</p><p>But this does not make it a “<strong>Global</strong>” alert. We would still have to create the component in each screen we want to display it. Again this is easily solvable using Redux or any global state management tool.</p><p>But this does not make it a “<strong>Global</strong>” alert. We would still have to create the component in each screen we want to display it. Again this is easily solvable using Redux or any global state management tool.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb4a69ff1d7fb5d54c2a83f085869714/href">https://medium.com/media/cb4a69ff1d7fb5d54c2a83f085869714/href</a></iframe><p>Setup the component only once in your<a href="https://reactnative.dev/docs/appregistry"> js entry point</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebd8ac40b3005e7c93bcf601ff737418/href">https://medium.com/media/ebd8ac40b3005e7c93bcf601ff737418/href</a></iframe><p>And then call it from anywhere you like by simply dispatching an action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2d468d8ea11b49407d5fefb2cda5419/href">https://medium.com/media/c2d468d8ea11b49407d5fefb2cda5419/href</a></iframe><p>From the code, we can see how easy this is. With this component, we can now display a simple alert with a title and subtitle anywhere inside the app. The next step would be to expand this and allow more customisation. For example, we could add “children” or a button with a custom on-press function. But this is a problem for another day and out of scope for this article.</p><h4>Further reading</h4><p>(a) <a href="https://reactnative.dev/docs/appregistry">App Registry</a></p><p>(b) <a href="https://reactnative.dev/docs/modal">Modal component included in the React Native framework</a></p><p>(c) <a href="https://github.com/react-native-modal/react-native-modal">react-native-modal</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92c1b57c8634" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/create-a-reusable-global-alert-in-react-native-92c1b57c8634">Create a reusable global alert in React Native</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where to store user information after login — React Native]]></title>
            <link>https://jaka-tertinek.medium.com/where-to-store-user-information-after-login-react-native-e870905f3011?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e870905f3011</guid>
            <category><![CDATA[keychain]]></category>
            <category><![CDATA[react-native-database]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[react-native-secure-data]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Thu, 29 Jul 2021 11:53:26 GMT</pubDate>
            <atom:updated>2021-07-29T11:53:26.911Z</atom:updated>
            <content:encoded><![CDATA[<h3>Where to store user information after login — React Native</h3><blockquote>If you want to start developing right away and not think about adding a secure storage plus other useful functionalities(navigation, state management, Typescript), you can check out the <a href="https://jaka-tertinek.medium.com/react-native-starter-project-a20eafd552be">starter project</a> that I created.</blockquote><figure><img alt="Code for storing user information after login." src="https://cdn-images-1.medium.com/max/489/1*bAJCTNc1KwiVicR9jwek6Q.jpeg" /></figure><p>Here comes the long-debated question about what to do with user information once the user logins. In other more “technical” words, where should we store some data indicating that the user has already logged in? This also includes data used for connecting with the back-end.</p><p>Now securely saving information is frowned upon. We don’t want users to think that their data is freely available for everybody to see. If they do not feel that they can trust our application, they will reluctantly use it or not use it at all.</p><p>What information should be stored permanently on the phone depends on each use case. What we can say with certainty is that if we have a login functionality build into our application we have to store some information about the authenticated user. This usually includes a user ID, user email/username and a token or ID used for communicating with the back-end. This way our backend knows that the user was already authenticated.</p><h4>What are our options for storing sensitive information?</h4><p>Usually, the first solution that developers think about is <a href="https://github.com/react-native-async-storage/async-storage">AsyncStorage</a>. It’s a simple key/value database. AsyncStorage simply saves data into documents on the phone’s hard drive, and therefore anyone with access to the phone’s file system can read that data. On iOS, the data is indeed only available to the app that wrote it, because of Apple’s sandboxing policy. This doesn’t stop jailbroken iPhones with root access to the file system from getting whatever they want, since AsyncStorage does not encrypt any of its data. But in general, don’t save sensitive data to AsyncStorage, for the same reason you shouldn’t hard code sensitive data in your javascript code, since it can be easily decompiled and read. [1]</p><p>So we can agree that AsyncStorage is not an option. Wouldnt it be great if there would be a solution similar to AsyncStorage just secure? Luckily, there are quite many libraries that can be used. For example, there are <a href="https://github.com/oblador/react-native-keychain">react-native-keychain</a> and <a href="https://github.com/emeraldsanto/react-native-encrypted-storage">react-native-encrypted-storage</a>. At the end of the day, all of them use the same native functionalities to achieve the goal. Which one to use comes down to personal preference. My personal favourite is <a href="https://github.com/emeraldsanto/react-native-encrypted-storage">react-native-encrypted-storage</a>, but I encourage you to check out the others as well.</p><h4>How do react-native-encrypted-storage and other similar packages securely store data?</h4><p>They do not use any new technologies developed exclusively for React Native and they do not use encryption. What they do is create a bridge between JavaScript and Keychain Services (iOS) and Secure Shared Preferences (Android) or Keystore (Android).</p><p><strong>iOS — Keychain Services</strong></p><p><a href="https://developer.apple.com/documentation/security/keychain_services">Keychain Services</a> allows you to securely store small chunks of sensitive info for the user. This is an ideal place to store certificates, tokens, passwords, and any other sensitive information that doesn’t belong in Async Storage. [2]</p><p><strong>Android — Secure Shared Preferences</strong></p><p><a href="https://developer.android.com/reference/android/content/SharedPreferences">Shared Preferences</a> is the Android equivalent for a persistent key-value data store. Data in Shared Preferences is not encrypted by default, but <a href="https://developer.android.com/topic/security/data">Encrypted Shared Preferences</a> wraps the Shared Preferences class for Android, and automatically encrypts keys and values. [2]</p><h4>Example using react-native-encrypted-storage</h4><p>The easiest way to manage data is to create a <a href="https://www.martinfowler.com/eaaCatalog/tableDataGateway.html">gateway</a>. In general, we only need three simple functions that help us to save, load and remove data. It works pretty much the same as AsyncStorage. Keep in mind that “user_session” in the example is the key with which we access data. It can be anything you want.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0a62ea9c0c04d05c8a67d0465790c61/href">https://medium.com/media/b0a62ea9c0c04d05c8a67d0465790c61/href</a></iframe><h4>Further reading</h4><p>(a)<a href="https://github.com/oblador/react-native-keychain"> react-native-keychain</a></p><p>(b) <a href="https://www.instamobile.io/react-native-tutorials/asyncstorage-example-react-native/">AsyncStorage Example — Persisting Login Credentials in React Native</a></p><p>(c) <a href="https://stackoverflow.com/questions/45547657/what-is-the-best-way-to-store-private-data-in-react-native">What is the best way to store private data in react-native?</a></p><p>(d) <a href="https://reactnative.dev/docs/security">React Native Security</a></p><h4>Bibliography</h4><p>[1] <a href="https://stackoverflow.com/questions/39148714/is-react-natives-async-storage-secure">https://stackoverflow.com/questions/39148714/is-react-natives-async-storage-secure</a></p><p>[2]<a href="https://reactnative.dev/docs/security">https://reactnative.dev/docs/security</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e870905f3011" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to handle SVG images in React Native]]></title>
            <link>https://jaka-tertinek.medium.com/how-to-handle-svg-images-in-react-native-127eb3cdeb9a?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/127eb3cdeb9a</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[svg-images-react-native]]></category>
            <category><![CDATA[reactnativeappdevelopment]]></category>
            <category><![CDATA[react-native-svg]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Wed, 28 Jul 2021 13:59:11 GMT</pubDate>
            <atom:updated>2021-07-29T11:50:43.180Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>If you want to start developing right away and not think about adding support for SVG images plus other useful functionalities(navigation, state management, Typescript), you can check out the <a href="https://jaka-tertinek.medium.com/react-native-starter-project-a20eafd552be">starter project</a> that I created.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*hD8JbHAZz04Tn7rCv3h3zA.jpeg" /><figcaption>Image file types.</figcaption></figure><p>Displaying images in React Native and native mobile development, in general, has always been harder as it should have been. Preparing 3 different image sizes for iOS and 5 for Android is time-consuming. The time that would be better spent elsewhere is now wasted with exporting different image sizes or having a back and forth with a designer. Now all of this hassle can be minimized by just using images that are in the SVG format. Both native Android and iOS have added support in the past couple of years. What about React Native? The process is a bit more complicated than on iOS (where you can drag and drop SVG images into Xcode and the IDE will handle everything) but still straightforward and easy to use once you set everything up.</p><h4>1. Installing dependencies</h4><p>Let’s assume you have already set up your project with react-native init or any other way. Now you want to add SVG image support. The first thing to do is to install the required dependencies.</p><ol><li>Run npm install</li></ol><pre>npm i react-native-svg react-native-svg-transformer</pre><p><a href="https://github.com/react-native-svg/react-native-svg">react-native-svg</a> provides SVG support to React Native on iOS and Android and a compatibility layer for the web.</p><p><a href="https://github.com/kristerkari/react-native-svg-transformer">react-native-svg-transformer </a>allows you to import SVG files in your React Native project the same way that you would in a Web application when using a library like <a href="https://github.com/smooth-code/svgr/tree/master/packages/webpack#svgrwebpack">SVGR</a> to transform your imported SVG images into React components.</p><p>2. Run pod install</p><p>Navigate to your ios folder and install pods.</p><pre>cd ios &amp;&amp; pod install</pre><p>3. Add metro.config file</p><p>Open your metro.config.js file or create one and add support for SVGR.</p><pre>const { getDefaultConfig } = require(&quot;metro-config&quot;);<br><br>module.exports = (async () =&gt; {<br>  const {<br>    resolver: { sourceExts, assetExts }<br>  } = await getDefaultConfig();<br>  return {<br>    transformer: {<br>      babelTransformerPath: require.resolve(&quot;react-native-svg-transformer&quot;)<br>    },<br>    resolver: {<br>      assetExts: assetExts.filter(ext =&gt; ext !== &quot;svg&quot;),<br>      sourceExts: [...sourceExts, &quot;svg&quot;]<br>    }<br>  };<br>})();</pre><p>4. (Optional) Add support for Typescript</p><p>Open your declaration.d.ts file or create it and add support for SVG files. This way you won&#39;t get errors when import SVG images into a TypeScript file.</p><pre>declare module &quot;*.svg&quot; {<br>  import React from &#39;react&#39;;<br>  import { SvgProps } from &quot;react-native-svg&quot;;<br>  const content: React.FC&lt;SvgProps&gt;;<br>  export default content;<br>}</pre><p>These are all the steps that need to be done. As you can see there are not that many steps and generally, once you set it up it works without any issues.</p><h3>2. Usage</h3><pre>import CarIcon from &#39;../../assets/images/CarIcon.svg&#39;</pre><pre>&lt;View&gt;<br>  &lt;CarIcon height = {20} width = {20}/&gt;<br>&lt;/View&gt;</pre><h3>3. Final thoughts</h3><p>As you can see from the tutorial it’s very simple to add support SVG images.</p><p>Further reading and useful links:</p><p>[1] <a href="https://jaka-tertinek.medium.com/react-native-starter-project-a20eafd552be">React Native starter project</a></p><p>[2] <a href="https://github.com/react-native-svg/react-native-svg">React Native SVG (react-native-svg)</a></p><p>[3]<a href="https://github.com/kristerkari/react-native-svg-transformer"> React Native SVG Transformer (react-native-svg-transformer)</a></p><p>[4] <a href="https://www.youtube.com/watch?v=e3AooTp6AYc">Talk about using SVG in React Native</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=127eb3cdeb9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Should you use the official Stripe package in your React Native app]]></title>
            <link>https://jaka-tertinek.medium.com/should-you-use-the-official-stripe-package-in-your-react-native-app-95a559c8b65a?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a559c8b65a</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[payment-processing]]></category>
            <category><![CDATA[stripe]]></category>
            <category><![CDATA[stripe-integration]]></category>
            <category><![CDATA[react-native-stripe]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Wed, 14 Jul 2021 16:39:57 GMT</pubDate>
            <atom:updated>2021-07-26T07:16:07.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4ivWhYY8DkIedXI9bpHmg.png" /><figcaption>Example of Stripe prebuilt UI</figcaption></figure><p>Managing payments in React Native has always been more difficult as it should have been. Your options were either to use Google Pay and/or Apple Pay, implement the payment process yourself through a web-view component or use a 3-party package that uses common payment services like Stripe. The latter (my arguments are based on my experience using <a href="https://github.com/tipsi/tipsi-stripe">tipsi-stripe</a>) were easy to use once you figure out how it works but offered limited functionality and support. Above all, there is this nagging feeling of mistrust. At the end of the day, I admit they aren’t responsible to provide a 100% secure service and offer 24/7 support.</p><p>Given the fast-paced nature of working at a startup where decisions have to be made quickly, I reluctantly choose the path of least resistance (in my case this is using tipsi-stripe) and hoped that one-day Stripe will offer their own package. Well, that day has finally come. The project is of course still in beta (tested version v0.1.4) as in the moment of writing this article but having tested it extensively in development as well in production I can, without doubt, say it is good to use. Keep in mind that the package was first released a couple of months ago so not all functionalities are supported. The most noticeable of them is the<strong> absence of Android Pay. </strong>But other important functionalities like Apple Pay and <a href="https://stripe.com/docs/payments/3d-secure">3D Secure authentication</a> are supported and work great.</p><p>Things to keep in mind before switching to the official Stripe React Native package:</p><ol><li>The project is still in beta so there might be some unresolved bugs. In my case after everything was setup, the payment process (we used the <a href="https://stripe.com/docs/payments/accept-a-payment?platform=react-native&amp;ui=payment-sheet">prebuilt single step UI</a>) <strong>worked without any issues</strong>.</li><li>Setup might take longer than expected. I had to increase my minimum deployment target to 11 and update the platform version line Podfile file to 11. Other issues might occur.</li><li>The component that is going to display the payment UI <strong>must be implemented inside a functional component</strong>. There is no option to use a class component because Stripe uses hooks. For example:</li></ol><pre>const { confirmPayment } = useStripe();</pre><pre>or</pre><pre>const { initPaymentSheet, presentPaymentSheet } = useStripe();</pre><p>4. If you are using tipsi-stripe and are thinking of switching to the new package, the code on the backend is essentially identical. On the front end, the code is very different although error handling is similar.</p><h4>Useful links</h4><ol><li><a href="https://stripe.com/docs/payments/accept-a-payment?platform=react-native&amp;ui=payment-sheet">Official docs from Stripe</a>,</li><li><a href="https://github.com/stripe/stripe-react-native">GitHub repository</a>,</li><li><a href="https://www.youtube.com/watch?v=qiEwO_UrOro">Add Stripe to a React Native application tutorial from Stripe</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a559c8b65a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native starter project]]></title>
            <link>https://medium.com/codex/react-native-starter-project-a20eafd552be?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a20eafd552be</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react-navigation]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[reactnativeappdevelopment]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 11:10:58 GMT</pubDate>
            <atom:updated>2021-07-29T12:03:24.145Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick guide on how to set up a starter project so you don’t have to deal with the installation and setup of libraries you always need.</h4><blockquote>You can find the project on <a href="https://github.com/trta2352/starter_project/tree/master">GitHub</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2G91BPUvxxri0U8RwUdMeg.jpeg" /></figure><p>This article is a work in progress and will be updated shortly. Currently, we have setup:</p><ol><li>DONE: Initialise the project with react-native init,</li><li>DONE: Add Typescript support</li><li>DONE: Create basic project structure and add React Navigation support</li><li>TODO: Redux support</li><li>DONE: SVG image support</li><li>DONE: Secure storage support</li></ol><p>Does this sound familiar. You have a great idea that you want to test out. After a while of programming, you realise how much time is going to take before you have the basics set up. You lose your interest and decide to continue working on the project some other time.</p><p>Well if you are like me, this has happened to you more than once. I decided enough is enough it’s time to deal with this problem once and for all. Let’s create a starter project which has everything you need to start developing your idea right away. So what do we need? We need some sort of navigation and state management. Let’s also add .svg picture support, Typescript and encrypted storage for securing login tokens.</p><h4>1. Using react-native init &lt;&lt;PROJECT NAME&gt;&gt; to initialise our project</h4><p>There is no need to reinvent the wheel here, let us use react-native init to initialise our project. It creates a basic working application that has one home screen.</p><pre>react-native init starter_project</pre><figure><img alt="Project structure after running react-native init" src="https://cdn-images-1.medium.com/max/306/1*-XCQrr10o1NX99neSwpXiQ.png" /><figcaption>Image 1: Project file structure after running react-native init.</figcaption></figure><h4>2. Installing Typescript and React Navigation</h4><p>There is no need to install Typescript after project initialization. You can use the Typescript template provided by react-native (more on that <a href="https://github.com/react-native-community/react-native-template-typescript">here</a> ). The issue with that lies in that you always have to check if the versions of the template are up to date plus it adds code that we do not need. So It’s best to add Typescript yourself. This can be achieved very easily in 3 steps.</p><ol><li>Navigate to your project in terminal (or cmd) and run the following command:</li></ol><pre>npm install -D typescript @types/jest @types/react @types/react-native @types/react-test-renderer</pre><p>2. Add a TypeScript config file. Create a <strong>tsconfig.json</strong> at the root of your project:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;allowJs&quot;: true,<br>    &quot;allowSyntheticDefaultImports&quot;: true,<br>    &quot;esModuleInterop&quot;: true,<br>    &quot;isolatedModules&quot;: true,<br>    &quot;jsx&quot;: &quot;react&quot;,<br>    &quot;lib&quot;: [&quot;es6&quot;],<br>    &quot;moduleResolution&quot;: &quot;node&quot;,<br>    &quot;noEmit&quot;: true,<br>    &quot;strict&quot;: true,<br>    &quot;target&quot;: &quot;esnext&quot;<br>  },<br>  &quot;exclude&quot;: [<br>    &quot;node_modules&quot;,<br>    &quot;babel.config.js&quot;,<br>    &quot;metro.config.js&quot;,<br>    &quot;jest.config.js&quot;<br>  ]<br>}</pre><p>3. Create a <strong>jest.config.js</strong> file to configure Jest to use TypeScript</p><pre>module.exports = {<br>  preset: &#39;react-native&#39;,<br>  moduleFileExtensions: [&#39;ts&#39;, &#39;tsx&#39;, &#39;js&#39;, &#39;jsx&#39;, &#39;json&#39;, &#39;node&#39;]<br>};</pre><p>You can find a more in-depth explanation of these steps on the official <a href="https://reactnative.dev/docs/typescript">React Native website</a>.</p><h4>3. Creating a basic project structure and adding React Navigation</h4><p>How a React Native project should be structured is a hot debate that has been going since its first release. There was some interest in adapting common architecture patterns, like MVC (Model — View — Controller), that didn’t make much sense at the end and increased the complexity of an application without significant benefits.</p><figure><img alt="Image 2:Basic structure of a source folder." src="https://cdn-images-1.medium.com/max/165/1*n0tT0J0g_Uv33obZRYA0rA.png" /><figcaption>Image 2:Basic structure of a source folder.</figcaption></figure><p>What I like to do is a basic project structure consisting of folders: “assets”, “components”, “redux”, “screens” and “utils”. The names together with what the folders contain is self-explanatory but for those that are just starting here is a brief explanation:</p><ul><li>assets: contains all your static files like pictures, fonts colours and global styles.</li><li>components: contains separate folders for every component type. For example, you can create folders for your buttons, alerts, modals, inputs …</li><li>redux: houses logic for redux state management. Is further divided into folders for your actions and reducers,</li><li>screens: contains your main screen/view logic</li><li>utils: includes files for database management, API management, support function and so on…</li></ul><figure><img alt="3: Example how a source folder might look like after application is developed." src="https://cdn-images-1.medium.com/max/337/1*7XNsprbfNdqfglieECmh0A.png" /><figcaption>Image 3: Example of how a source folder might look like after the application is developed.</figcaption></figure><p>In Image 2 you can see that we have a file called “navigator.tsx”. This is down to preference but I like to have one file that contains all the navigation inside the application. React Native already has a built-in navigator library for navigating mobile applications but it’s very rarely used. The go-to libraries are <a href="https://reactnavigation.org/">React Navigation</a> and <a href="https://wix.github.io/react-native-navigation/docs/basic-navigation">react-native-navigation</a>. Both do the job fine, but there are some differences. It’s up to you to decide which one you like better and find it easier to use. For me, the clear winner is React Navigation. Mostly because of its ease of use.</p><p>To install React Navigation run the following command:</p><pre>npm install <a href="http://twitter.com/react">@react</a>-navigation/native <a href="http://twitter.com/react">@react</a>-navigation/stack react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view</pre><p>This installs React Navigation together with Stack navigator (react-navigation/stack) and all of its many dependencies. Depending on your case you might also need <a href="https://reactnavigation.org/docs/tab-based-navigation">tab navigator</a> and/or a <a href="https://reactnavigation.org/docs/drawer-based-navigation">drawer navigator</a>. Given this is just a starter project we don’t have anything more than the stack navigator.</p><p>Now that we have installed everything related to navigation let’s write some code. I’m not going to go into detail and explain how React Navigation works and what parts of the code mean. There are more detailed articles out there.</p><p>In the following snippet, you can see how we imported “Home screen” and then created a “HomeStack” and main “Navigator”. You can add multiple screens to the HomeStack or create a separate stack for login/registration screens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da62efc1068ff33f328c106359bb41b5/href">https://medium.com/media/da62efc1068ff33f328c106359bb41b5/href</a></iframe><p>I suggest that you create your own screen template that contains everything that you might need or like to use (class components for example instead of functional components)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8efc75ade0d446281075501f75860f14/href">https://medium.com/media/8efc75ade0d446281075501f75860f14/href</a></iframe><h4>4. Adding support for SVG images</h4><p>If you are interested in learning more about adding support for SVG images you can check out this <a href="https://jaka-tertinek.medium.com/how-to-handle-svg-images-in-react-native-127eb3cdeb9a">article</a>.</p><p>To add support for SVG images run the following command:</p><pre>npm i react-native-svg react-native-svg-transformer</pre><pre>and </pre><pre>cd ios &amp;&amp; pod install</pre><p>This installs <a href="https://github.com/react-native-svg/react-native-svg">react-native-svg</a>(allows the displaying of images) and <a href="https://github.com/kristerkari/react-native-svg-transformer">react-native-svg-tranformer</a> (allows you to import SVG files in your project).</p><p>Just installing a transformer by itself will not automatically transform SVG images to PNGs when building the project. We need a way to tell the compiler to transform the images. We do this by adding or modifying our metro.config file.</p><pre>const { getDefaultConfig } = require(&quot;metro-config&quot;);<br><br>module.exports = (async () =&gt; {<br>  const {<br>    resolver: { sourceExts, assetExts }<br>  } = await getDefaultConfig();<br>  return {<br>    transformer: {<br>      babelTransformerPath: require.resolve(&quot;react-native-svg-transformer&quot;)<br>    },<br>    resolver: {<br>      assetExts: assetExts.filter(ext =&gt; ext !== &quot;svg&quot;),<br>      sourceExts: [...sourceExts, &quot;svg&quot;]<br>    }<br>  };<br>})();</pre><p>If we try to import an SVG file into a TSX file we will get an error. This is an indication that the project is missing a declaration file.</p><p>Open your declaration.d.ts file or create it and add support for SVG files. This way you won’t get errors when import SVG images into a TypeScript file.</p><pre>declare module &quot;*.svg&quot; {<br>  import React from &#39;react&#39;;<br>  import { SvgProps } from &quot;react-native-svg&quot;;<br>  const content: React.FC&lt;SvgProps&gt;;<br>  export default content;<br>}</pre><h4>5. Adding secure storage for storing user login information</h4><p>If you are interested in learning more about different possibilities for securely storing data you can check out this <a href="https://jaka-tertinek.medium.com/where-to-store-user-information-after-login-react-native-e870905f3011">article</a>.</p><p>What information should be stored permanently on the phone depends on each use case. What we can say with certainty is that if we have a login functionality build into our application we have to store some information about the authenticated user. This usually includes a user ID, user email/username and a token or ID used for communicating with the back-end. This way our backend knows that the user was already authenticated.</p><p>There are quite many libraries that can be used. For example, there are <a href="https://github.com/oblador/react-native-keychain">react-native-keychain</a> and <a href="https://github.com/emeraldsanto/react-native-encrypted-storage">react-native-encrypted-storage</a>. At the end of the day, all of them use the same native functionalities to achieve the goal (iOS-<a href="https://developer.apple.com/documentation/security/keychain_services">Keychain Services</a> and Android-<a href="https://developer.android.com/reference/android/content/SharedPreferences">Shared Preferences</a>). Which one to use comes down to personal preference. My personal favourite is <a href="https://github.com/emeraldsanto/react-native-encrypted-storage">react-native-encrypted-storage</a>, but I encourage you to check out the others as well.</p><pre>npm i react-native-encrypted-storage</pre><pre>and</pre><pre>cd ios &amp;&amp; pod install</pre><p>The easiest way to manage data is to create a <a href="https://www.martinfowler.com/eaaCatalog/tableDataGateway.html">gateway</a>. In general, we only need three simple functions that help us to save, load and remove data. It works pretty much the same as AsyncStorage. Keep in mind that “user_session” in the example is the key with which we access data. It can be anything you want.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0a62ea9c0c04d05c8a67d0465790c61/href">https://medium.com/media/b0a62ea9c0c04d05c8a67d0465790c61/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a20eafd552be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/react-native-starter-project-a20eafd552be">React Native starter project</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom bottom tab navigator React Native]]></title>
            <link>https://jaka-tertinek.medium.com/custom-bottom-tab-navigator-react-native-cda675172dac?source=rss-b65ce11233a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/cda675172dac</guid>
            <category><![CDATA[react-navigation]]></category>
            <category><![CDATA[bottom-tab-navigator]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Jaka Tertinek]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 10:05:42 GMT</pubDate>
            <atom:updated>2023-10-13T14:22:46.460Z</atom:updated>
            <content:encoded><![CDATA[<h3>Custom bottom tab navigator bar in React Native</h3><p>A bottom tab bar is one of the most used types of navigation inside apps. It offers an easy and user intuitive way of moving through screens. But how do we customize it?</p><p>In this example, we will be creating a simple app for money management. The bottom tab bar will consist of 5 buttons, where 4 of them represent one screen. The middle one opens up a custom modal window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*_qDyjC8PBuO5wqRAJSO8Mg.png" /><figcaption>Bottom tab navigator for Money management app Scrooge</figcaption></figure><p>Let’s get straight to business. Given that you are reading this I expect that you already know how to set up a new app.</p><p>For us to add a tab navigator install this packages in your project folder.</p><pre>npm i @react-navigation/native @react-navigation/bottom-tabs @react-navigation/stack react-native-gesture-handler</pre><p>If required install other packages as well.</p><p>Before we continue adding our navigation code, let’s create screens “home”, “analytics”, “notes” and “settings”. Here the code does not need to be anything special.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b10ffd4e343782e8b3e2bb9d2bcdb07/href">https://medium.com/media/1b10ffd4e343782e8b3e2bb9d2bcdb07/href</a></iframe><p>Lets then create a new file called <strong>navigator.tsx</strong>. This file will contain everything your app needs for navigation. After we import everything that we need we move on to creating our HomeTabs function. How tab navigator works and how we add it to our app is very well explained on the official react-navigation website: <a href="https://reactnavigation.org/docs/bottom-tab-navigator/">https://reactnavigation.org/docs/bottom-tab-navigator/</a>.</p><p>After we did all this our code looks something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88a5cb5b28678740a47a721a4a6c234f/href">https://medium.com/media/88a5cb5b28678740a47a721a4a6c234f/href</a></iframe><p>Now that we have set all this up let’s create our custom bottom tab navigator.</p><p>Function component tabBar.tsx receives “state”, “descriptors” and “navigation” as props. Under state.routes we have all the “routes” or. screens we need to map as buttons in our tab navigator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d997af97da987164d4919ad5336161e/href">https://medium.com/media/6d997af97da987164d4919ad5336161e/href</a></iframe><p>But what about the middle button? Well, that will be a little tricky. For our “custom middle button” to be displayed we need to map it. But the problem is that only components added in the tab navigator get mapped to buttons. So how to add another button without adding another screen? <strong>We create a placeholder tab screen</strong>. After adding the custom tab bar to the “tabBar” prop in Tab.Navigator our HomeTabs function look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bef55d5819d7cec9558d6e564da89911/href">https://medium.com/media/bef55d5819d7cec9558d6e564da89911/href</a></iframe><p>3 things to note:</p><ol><li>Dont forget to add props to our custom TabBar,</li><li>Add “PlaceholderScreen” where you want it to render.</li><li>Why does “PlaceholderScreen” still have a component prop and why is the same as “home”. <strong>Well, this it is a mandatory prop, but it does not matter at the end because we don&#39;t navigate to it in our custom TabBar component. </strong>So you could add any component that you wanted.</li></ol><p>The last thing left for us to do is to add the new “PlaceholderScreen” button to our TabBar code. This is simply done with an if statement where we ask if route.name equals “PlaceholderScreen” then return this View.</p><pre>if(route.name ==&quot;PlaceholderScreen&quot;){</pre><pre>   return (</pre><pre>      &lt;View key={index} style={styles.mainItemContainer}&gt;</pre><pre>         &lt;SelectWheel /&gt;</pre><pre>      &lt;/View&gt;</pre><pre>   );</pre><pre>}</pre><p>Finished tab bar component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2242dea6a9f688b3f88ab9b9038ba48/href">https://medium.com/media/c2242dea6a9f688b3f88ab9b9038ba48/href</a></iframe><p>And this is it! We have created a bottom tab navigator with a special middle button. You can customise what this button does as much as you want. In my case, it displays two additional buttons that enable the user to quickly add an expense or additional funds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*DPlkRuMdtf-qZY8RR2RPIg.png" /><figcaption>Select wheel</figcaption></figure><p>If you have any questions regarding this tutorial please leave a comment.</p><p>See my latest article <a href="https://medium.com/@jaka-tertinek/upload-files-from-react-native-app-to-aws-s3-3d3cb85e9d4">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cda675172dac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>