<?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 Yassir Hartani on Medium]]></title>
        <description><![CDATA[Stories by Yassir Hartani on Medium]]></description>
        <link>https://medium.com/@hartaniyassir?source=rss-26fa966be9a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7HMSQP7GEGPyNrMxy3GeBQ.jpeg</url>
            <title>Stories by Yassir Hartani on Medium</title>
            <link>https://medium.com/@hartaniyassir?source=rss-26fa966be9a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:18:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hartaniyassir/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[Understanding has_many through in rails]]></title>
            <link>https://hartaniyassir.medium.com/understanding-has-many-through-in-rails-aa3af86fb970?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa3af86fb970</guid>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Sat, 30 Mar 2024 15:36:00 GMT</pubDate>
            <atom:updated>2024-03-30T15:36:00.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M7KkROOsXxNsVY_0" /><figcaption>Photo by <a href="https://unsplash.com/@aleksandr_barsukov?utm_source=medium&amp;utm_medium=referral">Aleksandr Barsukov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you are struggling to understand the <strong><em>has_many through</em></strong> in rails, I am confident that these three sections will help you have a clear idea on <em>why we use</em> and <em>when to use</em> this helper.</p><ol><li>Understanding the fundamentals of the many to many relationship in the relational database management system(RDMB) specially the join table.</li><li>We’ll Create an example where we’ll add basic functionalities(Create/Delete) without using the has_many through.</li><li>Then add the helper and refactor the code.</li></ol><h4>Understanding the many to many relationship</h4><p>Let’s take an Ecommerce business as an example where we have products and orders.</p><p>A user can place an order with many products, and a product can be in many orders, so it’s a many to many relationship between the order and the product.</p><p>Now let’s represent this relationship.</p><p>In the RDBM the only way to represent this is by creating a new table(Joining table or Join table), this table will have two columns the <strong><em>order_id</em></strong> and the <strong><em>product_id. </em></strong>Let’s name this table <strong><em>order_product </em></strong>(It’s a convention to name the table by combining the two other table names).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/0*Q3FqEEW1lkRtvwrN" /></figure><p>To visualize how this relationship works, let’s make a small example.<br>A customer created an order with 4 products, <strong><em>order_id </em></strong>is 3 and <strong><em>products_ids </em></strong>are (1 | 2 | 3 |4).</p><p>In our order_product table we will insert 4 rows with order_id of 4 and with the relevant product_id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*aEkLcex13qpz3gUz" /></figure><p>Now when we’ll query the order products, we have to filter the products based on the order_id = 3.</p><p>To learn more about the many to many relationship, I encourage you to read this article.<br><a href="https://dzone.com/articles/how-to-handle-a-many-to-many-relationship-in-datab">https://dzone.com/articles/how-to-handle-a-many-to-many-relationship-in-datab</a></p><p>Now let’s Code it.</p><h4>Create a Rails project with the models and associations</h4><p>In this section, we’ll create a rails project and generate three models <strong>order</strong>, <strong>product,</strong> and the join table <strong>order_product</strong>.</p><p>First, go and create a new rails project, when the project is created let’s generate the models.</p><pre>rails generate model order status:string user:references</pre><pre>rails generate model product name:string price:decimal</pre><pre>rails generate model order_product order:references product:references</pre><p>Finally, run <strong>rails db:migrate </strong>to create our tables in the DB.</p><p>Now we’ll need to add the associations inside the models.</p><p>Remember that the main association is between products and orders by using the join table <strong>order_product</strong>, so the <strong>orders </strong>and <strong>products</strong> will have many <strong>order_product</strong>, but the <strong>order_product </strong>model will belong to both <strong>orders</strong> and <strong>products</strong>. Let’s add it!</p><pre>class Order &lt; ApplicationRecord<br>   has_many :order_product<br>end</pre><pre>class Product &lt; ApplicationRecord<br>   has_many :order_product<br>end</pre><pre>class OrderProduct &lt; ApplicationRecord<br> belongs_to :order<br> belongs_to :product<br>end</pre><p>Now let’s Jump into the command line and start adding functionalities.<br>Open the console rails console and first let’s generate some data</p><pre>50.times do<br>   Product.create(name: “product_name”, price: 10)<br>end<br><br>10.times do<br>   order = orders.create()<br>   5.times do<br>       OrderProduct.create(order_id: order.id, product_id: Product.find(rand(1...50).id))<br>   end<br>end</pre><p>This will generate 50 products and 10 orders each order with 5 products.</p><p>Adding basic functionalities without has_many through</p><p>The functionalities that we’ll add are</p><ul><li>Query all the products in an order</li><li>Adding a product to an order</li></ul><p><strong>Query all the products from the order</strong></p><p>first, let’s get the order id we want to query the products from</p><pre><br>order_id = Order.first.id</pre><p>Then we will query the data from the OrderProduct by passing the order_id and mapping through the data to return just the product.</p><pre>OrderProduct.where(order_id: order_id).map {|item| item.product }</pre><p><strong>Adding a product to an order</strong></p><pre>order_id = Order.first.id<br>product_id = Product.find(20)<br><br>OrderProduct.create(order_id: order_id, product_id: product_id)</pre><p>Whenever we want to query or insert a product we need to use the OrderProduct model and pass the required parameters, when using the has_many through method we won’t need to use it anymore and the code will be much simpler and cleaner.</p><h4>Using the has_many through</h4><p>Let’s add the method to model/order.rb</p><pre>class Order &lt; ApplicationRecord<br>   has_many :order_product<br>   has_many :products, through: :order_product<br>end</pre><p>Let’s jump to the rails console again(refresh the rails console using <strong>reload</strong>! command.)</p><p><strong>Query all the products from the order</strong></p><pre>Order.first.products</pre><p><strong>Adding a product to an order</strong></p><pre><br>Order.first.products &lt;&lt; Product.find(22)</pre><p>Sweet, no more interacting with the join model.</p><h4>Conclusion</h4><p>The rails documentation is the best place to learn, but sometimes to understand the use of a certain method you must create an example with and without the method this way you will have a deep knowledge than just reading about it.</p><p>Thanks for reading !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa3af86fb970" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Troubleshooting Detox Hang from Animations: 3 Practical Solutions]]></title>
            <link>https://hartaniyassir.medium.com/troubleshooting-detox-hang-from-animations-3-practical-solutions-49d891d76f1d?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/49d891d76f1d</guid>
            <category><![CDATA[e2e-testing]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 07:44:38 GMT</pubDate>
            <atom:updated>2023-09-05T07:44:38.745Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently had to add E2E testing using Detox to an existing application, the tests were smooth and easy to add until I had to add them to a specific screen then problems started to occur.</p><p>In this particular screen, the tests stopped running and Detox logged that the app was busy doing some tasks. By default, Detox synchronizes with the app by waiting for all the performing actions to complete and the app to become Idle, these actions can be network requests, animations, etc… see the list of actions in <a href="https://wix.github.io/Detox/docs/troubleshooting/synchronization#what-operations-do-we-try-to-synchronize-with-automatically">Detox docs</a>.</p><p>In my case, I had two performing actions that were running in a loop which caused tests to hang, an Animation loop, and a Carousel list.</p><p>I found 3 ways to work around this case.</p><h4>1. Disable the Synchronization</h4><p>As Detox handles Synchronization by default, we can disable it in certain places and enable it again.</p><p>Disable:</p><pre>await device.disableSynchronization();</pre><p>Enable:</p><pre>await device.enableSynchronization();</pre><p>While this workaround can do the trick, you’ll need to manually wait for a test to complete especially if it requires network requests or any other action that changes the state of the screen.</p><h4>2 . Mocking</h4><p>In the case of the Animation loop, we have to mock the Animated API(in my case from the react-native)</p><p>Detox mocking is different from Jest. Detox mocking is related to React Native and Metro.</p><p>First, let’s create a folder named <strong>local_modules, </strong>then inside it create another folder with the name <strong>react-native-reanimated</strong> and inside it create two files, <strong><em>index.js</em></strong> and <strong><em>index.mock.js</em></strong>.</p><p>Inside the index.js we will export the react native package</p><pre>export * from &#39;react-native&#39;</pre><p>Inside index.mock.js, we will export the mocked Animated API using the AnimatedMock from react-native.</p><pre>import AnimatedMock from &#39;react-native/Libraries/Animated/AnimatedMock&#39;;<br>module.exports = { Animated: AnimatedMock, };</pre><p>Then in our component, we will change the Animated import to point to the local_modules/react-native</p><pre>import {Animated} from &#39;local_modules/react-native-animated&#39;</pre><p>Then we will need to configure the Metro resolver to use the mock.ts when running e2e tests by using an env variable, in our case I named it MY_APP_MODE.</p><pre>resolver: {<br>sourceExts: process.env.MY_APP_MODE === &#39;mocked&#39;<br>? [&#39;mock.ts&#39;, …defaultSourceExts]<br>: defaultSourceExts,<br>},</pre><p>Finally, to make this work you can either run</p><pre># in case of running e2e tests in dev mode<br>export MY_APP_MODE=mocked &amp;&amp; react-native start<br><br># or in case of a release build.<br>export MY_APP_MODE=mocked &amp;&amp; your_detox_build_command</pre><h4>3 . Hard Code</h4><p>This option consists of adding conditions to make or prevent a certain piece of code from running when testing, for example in the carousel issue, I didn’t want to spend so much time mocking the flatlist scrollTo method, so I just added one condition and Voila problem solved.</p><p><strong>Some thoughts<br></strong>I am sure that Mocking the animated API could be achieved using a better solution. Maybe by keeping the imports from react-native and configuring metro to pick the mocked animated API on testing, I didn’t find a way to configure such behavior in Metro but If you know how to do that please keep a comment below or reach out to me on <a href="https://twitter.com/hartaniyassir">Twitter</a>.</p><p>Thanks for reading !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49d891d76f1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to quickly setup multiple Graphql endpoints in Apollo Client and Codegen [React]]]></title>
            <link>https://hartaniyassir.medium.com/how-to-quickly-setup-multiple-graphql-endpoints-in-apollo-client-and-codegen-react-24bba2e2f941?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/24bba2e2f941</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-client]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Thu, 10 Nov 2022 20:32:55 GMT</pubDate>
            <atom:updated>2022-11-10T20:32:55.555Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I had to add a new Graphql endpoint, as I was using Codegen and typescript I had to make sure that I’ll benefit from type-checking on both of the endpoints.</p><p>In this post, you will learn how to quickly setup a new Graphql endpoint in 2 easy Steps.</p><h3>Step1: Add the new endpoint to Apollo Client</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c0603ac6302c146703a454bc6fd7dde/href">https://medium.com/media/2c0603ac6302c146703a454bc6fd7dde/href</a></iframe><p>If you don’t use Typescript and Codegen this step is all you need, here you just need to add the clientName in every query and mutation the request needs to goes to the <strong><em>endpoint2.</em></strong><br><em>Credit should go to the owner of this </em><a href="https://stackoverflow.com/a/69629525/7951454"><em>StackOverflow answer</em></a><em>.</em></p><h3>Step2: Generate the Graphql schema and types with Codegen</h3><p>With multiple endpoints, we’ll need to generate multiple schemas which will generate the API types in separate files.</p><p>To do this we’ll need to start by writing Graphql requests of each endpoint in separate files, for example, the endpoint1 query will go under **.grapqhl.ts the file name, and endpoint2 will be in **.graphqlEndpoint2.ts<br>This way we can target each schema generation easily in codegen.ts.</p><p>Finally using useQuery and adding the context clientName can be a bit tricky and redundant to solve that we’ll use the typescript-react-apollo plugin to generate typed apollo hooks so instead of this 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSWW6QIAg0HZ0RYrWIlBfA.png" /></figure><p>You can use the generated apollo hook getCustomersQuery like this 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3bdl21IWXqK18IvN1P_elA.png" /></figure><p>To achieve this behavior we need to add some configs inside the Codegen config file 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGoh4BPlG8TedAh456_nFQ.png" /></figure><p>What made it possible to use apollo hooks with the clientName is the defaulsBaseOptions from typescript-react-apollo you can check <a href="https://github.com/dotansimha/graphql-code-generator/pull/5530">this PR</a> for more details.</p><h4>Thanks for reading 📚</h4><p><a href="https://github.com/yassir4">Github</a> | <a href="https://twitter.com/hartaniyassir/">Twitter</a> ✈️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24bba2e2f941" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a popup menu in react native]]></title>
            <link>https://hartaniyassir.medium.com/how-to-create-a-popup-menu-in-react-native-d2fc8908e932?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2fc8908e932</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Tue, 29 Mar 2022 11:49:16 GMT</pubDate>
            <atom:updated>2023-03-20T18:16:47.112Z</atom:updated>
            <content:encoded><![CDATA[<p>Popup menu has become an essential part of mobile apps UI, in this article, I will guide you through the process of building popup menu components that you can use in both Android and IOS.</p><p>There is a lot of packages that you can use, but if you are facing a limitation(UI/positioning/animation/ etc..) or just want to improve your react-native skills this article is for you.</p><p>I’ll cover the most important parts of building a popup menu:<br>- How to let the menu popup appear on top of the screen<br>- Create the menu and MenuItem component to make it reusable<br>- Calculate the meu popup positioning.</p><h3>Step1: two different approaches to display a popup menu</h3><p>The Popup menu should display on top of the element that triggered the menu in other words on top of the screen, so to avoid the inherited styles from the parent and the zIndex issue there are two different approaches to solve this CSS issue.</p><ul><li><strong>Modal: </strong>This approach is straightforward, pressing the trigger(by the trigger I mean the button that is responsible for opening the menu popup) will open a <a href="https://reactnative.dev/docs/modal">react native modal</a> with the menu inside it, the modal will have a transparent background and you can easily control where to display the menu. <br>But we have one downside, opening the modal while the keyboard is up will lead to closing the keyboard on both Platforms, which is not ideal.</li><li><strong>React Portal: </strong><a href="https://reactjs.org/docs/portals.html">Portals</a> will solve this CSS issue by breaking the menu component from its parent and rendering it at the root level of the app.<br>we’ll use this <a href="https://github.com/gorhom/react-native-portal">react-native-portal</a> package to achieve that.</li></ul><p>In our case we’ll use the React portals inside our root component like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea6fb88240c7f558287f706963786c1c/href">https://medium.com/media/ea6fb88240c7f558287f706963786c1c/href</a></iframe><h3>Step 2: Create the components and the props</h3><ul><li>Menu component that will hold the trigger and be responsible for calculating the popup position.</li><li>MenuItem component will include pop-up options and actions.</li></ul><p>If you’re confused just hold on, the picture will be more clear as we jump to the code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72d3101fd6d1ada81d9293826a18bc6a/href">https://medium.com/media/72d3101fd6d1ada81d9293826a18bc6a/href</a></iframe><p>As we are just initializing the components, the menu will display a red background color on the entire screen, while displaying the MenuItem at the top(we’ll position the items later).</p><p>Now let’s use our components:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ce015e1710e9e759ac6acf4b119495e/href">https://medium.com/media/6ce015e1710e9e759ac6acf4b119495e/href</a></iframe><p>Now we have the main functionalities, <br>1 - The user clicks on the trigger<br>2- Menu pop-up appears on top<br>3- After the user clicks on the screen or the item the menu will be closed.</p><p>check how it looks <a href="https://youtu.be/gMs1bfngo4w">https://youtu.be/gMs1bfngo4w</a></p><h3>Step3: measure the position of the menu</h3><p>For calculating the menu position we’ll need:<br>- Layout dimensions<br>- Menu dimensions<br>- Trigger dimensions<br>- Keyboard Height</p><p>Not like the layout and the keyboard, the menu and trigger dimensions are dynamic that’s why we’ll be using the Refs to measure their dimensions, so let’s do that first.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53b70ed007634d838b7b34670d3f7eb9/href">https://medium.com/media/53b70ed007634d838b7b34670d3f7eb9/href</a></iframe><p>We had already attached the refs when initializing the menu component.<br>In the above, I used `<strong><em>measureInWindow</em></strong>` in order to get the view position in the window, you can read more about it <a href="https://reactnative.dev/docs/direct-manipulation#measureinwindowcallback">here</a>.</p><p>For the keyboard height, we’ll add a custom hook to calculate it</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3546ac021c2b3f6d38a9c3b90884cbb0/href">https://medium.com/media/3546ac021c2b3f6d38a9c3b90884cbb0/href</a></iframe><p>then we can use it in our menu component like this</p><pre>const {keyboardHeight} = useKeyboardHeight()</pre><p>Just hold on we are almost there, now we will just add the calculation to position our menu.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9020239712a06963ffbc13eccac0b430/href">https://medium.com/media/9020239712a06963ffbc13eccac0b430/href</a></iframe><p>Hereafter doing the calculation inside React.useMemo (no need to go through the details) the menuPositionStyles will holds the top and left that the menu should display.</p><p>We then pass the menuPositionStyles to the View that wraps the menuItems childrens.</p><p>There is one more important trick that we need to add, now the menu will jump on the screen and that’s because the calculation takes a bit of time to complete. To fix that we need to add this in the activeSection style</p><pre>opacity: modalDimensions.width !== 0 &amp;&amp; triggerDimensions.left !== 0 ? 1 : 0,</pre><p>This way the menu will be hidden until the calculation finishes and the jump will disappear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3dciQP68LKlinq_cS4hL-Q.gif" /></figure><h3>Thanks for reading 📚</h3><p>I hope this article helps you build your custom menu popup.</p><p>Check the code on <a href="https://github.com/Yassir4/react-native-popup-menu/tree/master">Github</a>.</p><p><a href="https://github.com/yassir4">Github</a> | <a href="https://twitter.com/hartaniyassir/">Twitter</a> ✈️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2fc8908e932" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Problems that You Need to Know Before Using React Native Webview]]></title>
            <link>https://javascript.plainenglish.io/4-problems-that-you-need-to-know-before-using-react-native-webview-d1d6ef803347?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1d6ef803347</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 20:31:25 GMT</pubDate>
            <atom:updated>2021-12-31T19:14:17.854Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the last year, I’ve been working on a react native app that uses Webview to display Html emails, during the process I’ve faced some uncommon problems that took us a long time to solve.</p><p>My purpose in this article is to save you time by showing you the problems you may encounter and how to solve them.</p><h3>Problem 1: WebView Dynamic height</h3><p>React Native Webview can’t set its own height like the ‘&lt;View /&gt;’ which can scale based on its content</p><p>The only way a webview can have a height is by providing a specific one to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQ4_UUjoh4b3kf-NaUwNRQ.png" /></figure><p>Here we injected a script after the webview finishes loading using the <strong><em>injectJavascript </em></strong><em>prop</em> that will get the content height and then update the webview height.</p><h3>Problem 2: Webview may lead to crashing the app in android</h3><p>This one was tricky to find, we were having some unexpected crashes in the app while navigating from some screens, at first we did what every experienced react native developer will do, run `<em>adb logcat</em>` command and spend hours debugging what causes the crash.</p><p>Luckily we found <a href="https://github.com/react-navigation/react-navigation/issues/9061">this GitHub Issue</a> that fixes our problem and the fix was just disabling navigation animation in the screens that include a webview</p><p>There are other react-navigation and webview crashes fixes that may work for others, check out this<a href="https://lonelycpp.github.io/react-native-youtube-iframe/navigation-crash/"> react-native-youtube-iframe doc</a> for more info.</p><h3>Problem 3: Importing local HTML File in webview [Android]</h3><p>Importing local HTML files inside webview differs between expo and bare react native.</p><p>In a bare React native project it’s quite simple you just need to add the file to the android asset and import it from there.<br>check out the full workaround <a href="https://stackoverflow.com/a/61473740/7951454">here</a>.</p><p>In an expo project, as we don’t have access to the android folder, you can use this workaround.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxsbgVmLc49_BdOETSGh4g.png" /></figure><h3>Problem 4: Test the webview on older android versions</h3><p>If you find yourself adding a custom HTML file with javascript inside it, make sure to test the webview on older versions as in my case I was using some new javascript features like optional chaining that lead to breaking the webview in the android version 8.</p><h3>Thanks for reading 📚</h3><p>I hope this article can help you when facing some unexpected webview issue 💪</p><p><a href="https://github.com/yassir4">Github</a> | <a href="https://twitter.com/hartaniyassir/">Twitter</a> ✈️</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><em>free weekly newsletter</em></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><em>community Discord</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1d6ef803347" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/4-problems-that-you-need-to-know-before-using-react-native-webview-d1d6ef803347">4 Problems that You Need to Know Before Using React Native Webview</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we should Learn Writing as Developers]]></title>
            <link>https://medium.com/swlh/why-we-should-learn-writing-as-developers-338643584b33?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/338643584b33</guid>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bootcamp]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 10:34:35 GMT</pubDate>
            <atom:updated>2021-04-29T11:41:16.213Z</atom:updated>
            <content:encoded><![CDATA[<h3>How Writing Can Help Developers Succeed</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3E9zNPaw-hULhZ_0b0FNEw.jpeg" /></figure><p>Before we start I need to say that I don’t claim that I’m good at writing, actually English is my third language, the idea behind this post is to give you an idea why you and I should start improving our Writing skill 😀, after that being said let’s get started.</p><p>Recently I was listening to <a href="https://www.youtube.com/watch?v=-YG0kMpzL_A"><strong><em>Jason Fried </em></strong>in the chase Jaris podcast</a>, for you who doesn’t know Json Fried he is the chief executive officer of Basecamp, in this podcast <strong><em>Jason </em></strong>mentioned how basecamp hire and it was mind-blowing for me, the first criteria they see in a candidate is their writing skills, and when you think about it, it actually makes sense, now people tend to work remotely with different timezone, the good writer knows how to communicate, he can make difficult things easy to understand, this clear writing leads to better communication in a remote team.</p><p>So the question here is what are other benefits that a developer can learn from writing?</p><h4>1- A good writer is a good thinker</h4><p>In the <a href="https://basecamp.com/books/getting-real">Getting real book</a> there is a quote <em>“Clear Writing Leads To Clear Thinking”, </em>basically what this means is writing will help you organize your mind by arranging information and arguments in a systematic fashion that will help your reader understand the topic.</p><p>Imagine that you are working with someone in a different timezone, your communications will not be in sync, so when sending a message before your day ends it needs to be understood, a misunderstanding can have a big impact on productivity, time-wasting as he needs to wait until you are around the next day.</p><h4>2- It helps you learn more about the topic.</h4><p>If this was the only argument for why you should improve your writing it will be enough.</p><p>Generally speaking, writing will improve your learning, sometimes as a developer, you’ll find yourself writing about certain solutions or technologies, in the process of writing about the topic you’ll find yourself learning more about it.</p><h4>3- It will improve your critical thinking</h4><p>This one is from DR Jordan Peterson, when he was asked how to develop critical thinking he said:</p><blockquote>“the best way to teach people critical thinking is to teach them how to write”.</blockquote><p>With critical thinking you’ll be able to:</p><p>- understand the connection between ideas.<br>- Identify, construct and evaluate ideas.<br>- detect inconsistencies and common mistakes in reasoning<br>- solve problems systematically<br>- identify the relevance of importance of ideas</p><h4>Final thought</h4><p>As developers, we usually tend to be better at coding/programming and learning new technologies but we don’t pay attention to other skills that can improve not only our career but our lives, and writing is one of them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=338643584b33" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/why-we-should-learn-writing-as-developers-338643584b33">Why we should Learn Writing as Developers</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Infinite Scrolling With Apollo Hooks in React Native]]></title>
            <link>https://medium.com/swlh/easy-infinite-scrolling-with-apollo-hooks-in-react-native-8e1a4af46e3d?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e1a4af46e3d</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Tue, 15 Sep 2020 14:08:20 GMT</pubDate>
            <atom:updated>2020-09-16T00:31:09.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5YT-TOe8ffbZW8JlK2m2iA.jpeg" /></figure><p>Infinite scrolling is a feature that you can see in a lot of modern apps(Facebook, Tweeter, Reddit, etc…), every time the list data in your app gets bigger you will need to add this feature to optimize your list performance.</p><p>So In this article, we’ll implement the infinite scrolling using apollo hooks</p><p>Note: I expect that you already have a react-native project initialized with apollo client, also I’ll be using the GitHub Graphql API as an endpoint to display a list of repositories, please also make sure to create a personal access token <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">here</a> and attach it in the apollo header😁.</p><p>So Let’s get started.</p><h3>First, let’s build our basic list component.</h3><p>For now, we’ll add just the basics in our list component: the repositories query, a flatlist, and a useQuery from apollo hooks to fetch the data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/200d20437cbfce39f36f52db0be5d58c/href">https://medium.com/media/200d20437cbfce39f36f52db0be5d58c/href</a></iframe><p>- Here we added a query to fetch the Facebook repositories with a first variable that will allow us to specify the number of the items being fetched.</p><p>- the pageInfo in query contains two values(endcursor and hasNextPage) which we’ll use when fetching a new set of repo’s.</p><h3>Add The Infinite scroll</h3><p>To add the infinite scroll functionality we’ll use the fetchMore function from the useQuery result,</p><p>This will allow us to make a new query with and merge the new result into the original result. You can read more about this function <a href="https://www.apollographql.com/docs/react/data/pagination/#using-fetchmore">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bafac6c87fe294c3dfe6f58a22012b1d/href">https://medium.com/media/bafac6c87fe294c3dfe6f58a22012b1d/href</a></iframe><p>Now let’s add the function that will handle the fetchMore</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17630970260e8a3c5a8994480db9590a/href">https://medium.com/media/17630970260e8a3c5a8994480db9590a/href</a></iframe><p>Before we fetch more data I checked if there is more data available with `<em>hasNextPage</em>` which is a good thing to prevent unnecessary network requests (optional), then we passed the after and first variables, the after here refer to the endCursor(the last item fetched) this method is called cursor-based pagination you can read more about it <a href="https://www.apollographql.com/docs/react/data/pagination/#cursor-based">here</a>.</p><p>Now when the update will complete the onUpdate function will be fired, this function will be responsible for merging the previous data with the new one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b670ff9343a99e9d980eded2b51f2de/href">https://medium.com/media/6b670ff9343a99e9d980eded2b51f2de/href</a></iframe><p>Note that we inserted the new repo’s at the end of the list and we updated the pageInfo so we have its new values.</p><h3>Pull Refresh</h3><p>In a lot of cases, we’ll need to implement the pull refresh along with the infinite scrolling, for that we’ll use the refetch function from the useQuery result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e28eb4792b62dccaea1f0d0a12e8f987/href">https://medium.com/media/e28eb4792b62dccaea1f0d0a12e8f987/href</a></iframe><p>Here we also added the networkstatus property to identify the status of our query, and we set the notifyOnNetworkStatusChange option to true in order to trigger a rerender in our component when the refetch is called.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5c4714cdbbd0cd5fadea71124b27c1f/href">https://medium.com/media/a5c4714cdbbd0cd5fadea71124b27c1f/href</a></iframe><p>The refreshing constant will be set to true when the refetch function will be triggered, and notice how we prevented the first loading from rendering when refreshing is set to true.</p><h3>Thanks for reading 📚</h3><p>→ You can find the source code in this <a href="https://github.com/Yassir4/InfiniteScrollApolloHooks">repo</a>.</p><p>I hope you enjoyed reading this article, I would love to hear your thoughts and feedback in the comments below.</p><p><a href="https://github.com/yassir4">Github</a> | <a href="https://twitter.com/hartaniyassir/">Twitter</a> ✈️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e1a4af46e3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/easy-infinite-scrolling-with-apollo-hooks-in-react-native-8e1a4af46e3d">Easy Infinite Scrolling With Apollo Hooks in React Native</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to react-native-navigation]]></title>
            <link>https://javascript.plainenglish.io/introduction-to-react-native-navigation-e453ec30c42f?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e453ec30c42f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 22:25:36 GMT</pubDate>
            <atom:updated>2019-09-20T09:58:58.368Z</atom:updated>
            <content:encoded><![CDATA[<h3>An introduction to react-native-navigation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOzz-CeH3nhx0p4xF44ZOg.jpeg" /></figure><p>One of the most challenging things in react-native is choosing the right navigation, and that’s because Facebook use a native navigation system (a native app that has some RN views). So this will lead us to the two most popular navigation solutions <em>react-native-navigation</em> by Wix and <em>react-navigation</em> by Airbnb. and of course, as mentioned in the title we’ll be using <em>react-native-navigation.</em> To see the difference between the two solutions check out <a href="https://medium.com/hackernoon/how-to-choose-the-right-react-native-navigation-library-48679d63c9e9">choose the right native navigation</a>.</p><h4>First What is Navigation?</h4><blockquote>Before we start let’s first talk about navigation and the problem we are trying to solve. Basically navigation it’s a crucial part of the app, It’s responsible for handling the interactions that allow users to move across, into, out from different content areas within your app.</blockquote><h4>Why react-native-navigation(RNN)?</h4><p>As mentioned in the react-native <a href="https://facebook.github.io/react-native/docs/navigation#react-navigation">docs</a>, RNN provides native navigation in both Android and IOS.That’s exactly what we are looking for after all; the navigation should feel familiar to our user’s. Also the word <em>native</em> means that the library will be more efficient and have smooth transitions between screens 😃.</p><p>After that being, said let’s create an application, integrate RNN and play with the basics of the RNN (stack, setRoot, push, pop, modal, etc…)</p><h4>Getting started.</h4><p>1- Go to the command line and start a new react native project using react-native CLI. The reason we used react-native init and not expo init is that we’ll need to add some native code to our app.</p><pre>&gt; react-native init RNNIntro</pre><p>Next, we’ll install react-native-navigation package using npm or yarn.</p><pre>&gt; yarn add react-native-navigation</pre><pre># or</pre><pre>&gt; npm install --save react-native-navigation</pre><p>then we’ll need to link the native dependencies and add some native code into our project.</p><p>For IOS follow these <a href="https://wix.github.io/react-native-navigation/#/docs/Installing?id=ios">instructions</a></p><p>For Android follow these <a href="https://wix.github.io/react-native-navigation/#/docs/Installing?id=android">instructions</a></p><h4>The Basics</h4><p>After successfully adding the react-native-navigation now let’s see how to implement the navigation.</p><p><strong>First, let’s add the files and folders:</strong></p><pre>&gt; cd RNNIntro &amp;&amp; mkdir src <br>&gt; cd src &amp;&amp; mkdir Navigation screens</pre><p>Here 👆we added the src folder that will contain Navigation and screens folders</p><pre>&gt; cd Navigation &amp;&amp; touch index.js screens.js<br>&gt; cd ./screens &amp;&amp; mkdir Home &amp;&amp; cd Home &amp;&amp; touch index.js styles.js<br>&gt; cd .. &amp;&amp; mkdir PushedScreen &amp;&amp; cd PushedScreen &amp;&amp; touch index.js styles.js<br>&gt; cd .. &amp;&amp; mkdir ModalScreen &amp;&amp; cd ModalScreen &amp;&amp; touch index.js styles.js</pre><p>☝️ here we added index.js and screens.js to the Navigation folder and added the Home folder which contains index.js and styles.js files</p><p>For now, the folder structure should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*cBWuyYRYcA7KkoH13vuk7Q.png" /></figure><p>In the Navigation/screens.js we will register all our screens, after all, every screen component must be registered with a unique name</p><p><strong>2. Registering the screens</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cb7a5e206059e81275cc17b0316b71f/href">https://medium.com/media/9cb7a5e206059e81275cc17b0316b71f/href</a></iframe><p>Here 👆 we registered the Home, pushedScreen and the ModalScreen components and we gave each one of them a unique name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce237dcfb529f7d377ef461f5e1f4246/href">https://medium.com/media/ce237dcfb529f7d377ef461f5e1f4246/href</a></iframe><p>Then in the Navigation/index.js we call the registerScreens function and initialize the screens (it should be called before creating the root of our navigation). then we also initiated the app via setRoot command.</p><p><strong>3. Initialize the app</strong></p><p>Now let’s update index.js and call the start function to initialize the application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd4443e5dd8d19fb26fedaf4e22867b6/href">https://medium.com/media/dd4443e5dd8d19fb26fedaf4e22867b6/href</a></iframe><p><strong>Adding Home screen</strong></p><p>Now let’s add some basic styles to our Home screen</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af4ab46e1a57d2ec7fc837931566c7c4/href">https://medium.com/media/af4ab46e1a57d2ec7fc837931566c7c4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a817698b13a4fcc0af1390a1ab90fb81/href">https://medium.com/media/a817698b13a4fcc0af1390a1ab90fb81/href</a></iframe><p>Now the app should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*bk1Xx24oLOBO2J99WJ9FJQ.png" /></figure><h4>Pushing your first Screen</h4><p>In order to push a screen, we need to use <a href="https://wix.github.io/react-native-navigation/#/docs/screen-api?id=pushcomponentid-layout">Navigation.push</a> this method expect to receive the currently presented component id from screen props.componentId.</p><p>Now let’s use the push screen button to navigate us to the next screen</p><p>Here is how the Home/index.js will look like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bee781110957d0656d3ebe757a2da87/href">https://medium.com/media/3bee781110957d0656d3ebe757a2da87/href</a></iframe><p>let’s add some basic styles to the pushScreen component</p><p>PushedScreen/index.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/180362f14d6c815c92d9ba147c1883c8/href">https://medium.com/media/180362f14d6c815c92d9ba147c1883c8/href</a></iframe><p>PushedScreen/styles.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcadfd5283c701f2183627ec63fa6aa7/href">https://medium.com/media/fcadfd5283c701f2183627ec63fa6aa7/href</a></iframe><blockquote>Please go and test the above code first before you continue reading</blockquote><p>Welcome back 😜. As expected nothing happened after clicking the push screen button and the reason for that is we should use the stack <a href="https://wix.github.io/react-native-navigation/#/docs/layout-types?id=stack">layout type</a> in order to navigate.</p><p>update the Navigation/index.js setRoot command</p><pre>Navigation.setRoot({<br> root: {<br>    stack: {<br>         children: [{<br>              component: {<br>                 name: &#39;HomeScreen&#39;,<br>              },<br>         }],<br>    },<br> },<br>});</pre><p>Now try again and voila you pushed your first screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*lIcF-OrqkMo2GQ7OqgNBPg.gif" /></figure><p>I know I know. it looks bad but let’s keep it that way for the sake of simplicity 😛</p><p>Keep in your mind that when navigating, we can pass props to the screen that we are pushing and also we can use <a href="https://wix.github.io/react-native-navigation/#/docs/options-migration?id=common-options">options</a> to style the navigator appearance. We will explore them while opening a modal</p><p><strong>Pop the screen</strong></p><p>After pushing the current screen the user should be able to go back to the previous one, this can be done by taping the top bar’s back arrow button which is provided by default (we can always hide the top bar using options if we want) or by swiping your finger from left to right if your in IOS. Or using the Navigation.pop method</p><p>Now let’s go and attach the navigation.pop with the goBack button</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5d080705cf2db6d142950b69bca95df/href">https://medium.com/media/e5d080705cf2db6d142950b69bca95df/href</a></iframe><h4>Opening Your first Modal.</h4><p>Before we open the modal let’s talk first about the differences between the openModal and pushScreen in RNN and when to use a modal</p><p>Basically, a modal is just an alternative way to push a screen but it has some functionality and behaviors that make it unique for example:</p><ul><li>Modal has a sliding up animation by default(Android)</li><li>Modal has no default back button.</li></ul><p><strong>When to use a modal.</strong></p><p>Modals are used when the user’s immediate attention is required as it prevents them from interacting with views beneath it. Typical use cases for modals are alerts, action sheets, and short tasks and flows.</p><p>Now let’s create open the modal.</p><p><strong>First</strong>, let’s attach the navigation openModal method with our button in the home screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fefcad2ef4b305755dd68f2769e8c9bb/href">https://medium.com/media/fefcad2ef4b305755dd68f2769e8c9bb/href</a></iframe><p>Let’s breakdown the openModal method:</p><ul><li>passProps: allow me to pass props to the pushed screen, in this case, the props name is <em>text</em> and its value is <em>this is the modal screen</em></li><li>options: in the options object we specified the top bar title and added the left button</li></ul><p>Now let’s go to ModalScreen and give it some basic styles</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a88e760506462364373690772506a282/href">https://medium.com/media/a88e760506462364373690772506a282/href</a></iframe><p>As you can see here 👆we added the <em>navigationButtonPressed</em> event which will be called whenever a TopBar button is pressed by the user, then we dismiss the modal when the user has clicked on the left button (we gives the button the id of ‘leftButton’). Inside the render function, we retrieved and displayed the text prop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fb979eec216333e1c645995d51f2e77/href">https://medium.com/media/3fb979eec216333e1c645995d51f2e77/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*-Kj4ZLqQfdukZUHw-8MP2w.gif" /></figure><h3>Bonus</h3><p>As you are my favorite reader, I want to share with you a better way to structure your navigation. Instead of declaring the navigation function on each component let’s declare all of our functions in <strong>Navigation/index.js</strong>. 1- go and remove <strong>openModal</strong> and <strong>PushScreen</strong> functions from <strong>Home/index.js</strong>.</p><p>2- open <strong>Navigation/index.js</strong> and add the navigation functions</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01775f65009f80949dac9b2f9b8b60f4/href">https://medium.com/media/01775f65009f80949dac9b2f9b8b60f4/href</a></iframe><p>3- To easily import this file we’ll add <strong>package.json</strong> file to Navigation folder.</p><pre><strong>{<br>	&quot;name&quot;: &quot;Navigation&quot;<br>}</strong></pre><p>4- Now go to <strong>Home/index.js</strong> and import the functions and replace</p><pre><strong>import {Navigation} from &#39;react-native-navigation&#39;</strong></pre><p>with</p><pre><strong>import {pushScreen, openModal} from  &#39;Navigation&#39;;</strong></pre><h3>Thanks for reading 📚 !</h3><p>I hope you enjoyed this quick intro to RNN as I did, and good luck with your react-native-navigation journey. Please Check the <a href="https://github.com/Yassir4/react-native-navigation-intro">repo</a> and don’t forget to follow me on <a href="https://twitter.com/hartaniyassir"><strong><em>Twitter</em></strong></a> and <a href="https://github.com/Yassir4/"><strong><em>Github</em></strong></a></p><blockquote><strong><em>This article was originally published on the </em></strong><a href="https://www.obytes.com/blog/2019/intro-to-react-native-navigation/"><strong><em>Obytes blog</em></strong></a><strong><em>.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e453ec30c42f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/introduction-to-react-native-navigation-e453ec30c42f">Introduction to react-native-navigation</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Todo App in React Native using hooks]]></title>
            <link>https://medium.com/weekly-webtips/build-a-todo-app-in-react-native-using-hooks-9953f1066d67?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9953f1066d67</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Sun, 06 Jan 2019 14:29:07 GMT</pubDate>
            <atom:updated>2020-06-04T05:47:30.346Z</atom:updated>
            <content:encoded><![CDATA[<p>I love making todo apps when I want to learn a new concept. So in this article, I’ll show you how to build a simple todo app using react hooks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*L7ZTSJ1HOSvSnZMw_Y7djw.gif" /></figure><p>If you’re wondering what is hooks. Hooks are a new way of building stateful components without using classes to understand more watch this <a href="https://www.youtube.com/watch?v=V-QO-KO90iQ">talk</a>, sounds awesome right?. So let’s get started</p><blockquote><em>One thing to mention is that hooks are still in the alpha version of react</em></blockquote><h3>Getting Started</h3><pre> react-native init RNHooksTodo</pre><p>after initializing the project let’s add hooks. As hooks are not yet supported in react native we’ll use <a href="https://github.com/facebook/react-native/issues/21967#issuecomment-443858969">this method</a> to add it.</p><pre>$ yarn add react@16.7.0-alpha-2 react-native@&quot;npm:@brunolemos/react-native&quot;<br>$ yarn add --dev @types/react @types/react-native</pre><p>In the package.json file add</p><pre>&quot;resolutions&quot;: {<br>  &quot;scheduler&quot;: &quot;0.12.0-alpha.3&quot;<br>},</pre><p>Then run $ yarn install</p><p>Nice! Now let’s add <a href="https://github.com/oblador/react-native-vector-icons">vector icons</a> as we’ll use icons in the app</p><pre>$ yarn add react-native-vector-icons </pre><p>link the package with</p><pre>$ react-native link react-native-vector-icons</pre><p><em>Please consider that some users are having trouble using this method. Try the </em><a href="https://github.com/oblador/react-native-vector-icons#ios"><em>manual linking</em></a><em> if you are too.</em></p><h3>First</h3><p>open the project in your favorite <em>IDE </em>then open <em>App.js</em> file and change the class component to be a functional component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1z1go205NSiDuPU7euh3XQ.png" /><figcaption>App.js file</figcaption></figure><p>Now run the application in any platform you want, for me I’ll stick with IOS</p><pre>$ react-native run-ios</pre><p>if you faced any issue with<strong> (reactDevTools.connectToDevTools is not a function) </strong>add this to the package.json</p><pre>&quot;resolutions&quot;: {<br>  &quot;react-devtools-core&quot;: &quot;3.4.3&quot;<br>.<br>.<br>.<br>},</pre><p>then run $yarn installif everything goes well you should see the welcome screen</p><p>Next. let’s add the background and the text input.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc960b5df25ebc0543eb4ad5ce583813/href">https://medium.com/media/dc960b5df25ebc0543eb4ad5ce583813/href</a></iframe><p>at this point, the app should like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*-VxlBVxmj9w1sz2xPegK5Q.png" /></figure><h3>The fun part</h3><p>In this section, we’ll use hooks to add our tasks.</p><p>To add a task the normal way is by declaring a state and updating that state whenever the user clicks the plus sign button.</p><pre>// instead of using<br>this.state = {<br>     todo: [],<br>     value: &#39;&#39;<br>}<br>// with hooks you can use <br>const [todos, setTodos] = useState([])<br>const [value, setValue] = useState(&#39;&#39;)</pre><pre>// updating the state the old way <br>this.setState({<br>     todos: [...this.state.todos,{text: this.state.values, <br>             key: Date.now()}            ]<br>})</pre><pre>// with hooks<br>setTodos([...todos, { text: value, key: Date.now()}])</pre><p>In the code above the only argument passed to useState is the initial state. the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Array_destructuring">array destructuring</a> syntax lets us give a name to the state variables and the method we’ll be using to update it. So by convention, the todos are the state name we’ll be using in the render, and setTodos we’ll be responsible for updating our state. If you want to learn more check this <a href="https://reactjs.org/docs/hooks-overview.html">link</a></p><p>So let’s initialize the state in the app component</p><pre>import React, {useState} from &#39;react&#39;<br>.<br>.<br>const App () =&gt; {<br>   const [value, setValue] = useState(&#39;&#39;)<br>   const [todos, setTodos] = useState([])</pre><p>the value state we’ll be responsible for storing the user input.</p><p>Now we’ll store the user input in the value state variable. Go to the text input and add the onChangeText prop to update our state in user input.</p><pre>&lt;TextInput<br> style={styles.textInput}<br> multiline={true}<br> onChangeText={(value) =&gt; setValue(value)}<br> placeholder={&#39;Do it now!&#39;}<br> placeholderTextColor=&quot;white&quot;<br> value={value}<br>/&gt;</pre><p>Now after the user clicks the plus sign icon we should update the todos state and display the task in the screen</p><p>First, let’s update the todos state to contain the input value. We’ll create a function called handleAddtodo that we’ll take care of it</p><pre>const App = () =&gt; {<br> const [value, setValue] = useState(&#39;&#39;)<br> const [todos, setTodos] = useState([])</pre><pre><br> handleAddTodo = () =&gt; {<br>   if (value.length &gt; 0) {<br>    setTodos([...todos, { text: value, key: Date.now(), checked:                          false<br> }])<br>    setValue(&#39;&#39;)<br>    }<br> }<br>.<br>.<br>.</pre><p>Here we check the text input, if it’s not empty we’ll add the value state to the todos and generate a key in order to retrieve the todo in case we want to delete or check a todo, and checked to false</p><p>This function we’ll be called whenever the user clicks the plus icon.</p><pre>&lt;TouchableOpacity <br>onPress={() =&gt; handleAddTodo()}&gt;<br>....<br>&lt;/TouchableOpacity&gt;</pre><p>Now it’s time to render the todo. we’ll create a new file called Task.js that will be responsible for rendering the todo. it should like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65c47a33cf2d171bf31abae1e5f24129/href">https://medium.com/media/65c47a33cf2d171bf31abae1e5f24129/href</a></iframe><p>The Task component we’ll be responsible for rendering the tasks the user adds.</p><p>Now let’s go back to the App component and import the task component with</p><pre>import Task from &#39;./Task&#39;</pre><p>Then at the bottom of the render method add (<em>before the closing tag of ImageBackground</em>)</p><pre>.<br>.<br>. <br> &lt;ScrollView style={{width: &#39;100%&#39;}}&gt;<br>   {todos.map((task) =&gt; (<br>      &lt;Task<br>        text={task.text}<br>        key={task.key}<br>      /&gt;<br>     )) <br> }<br> &lt;/ScrollView&gt;<br>&lt;/ImageBackground&gt;</pre><p>Here we pass the text and the key to the Task component. Refresh the Simulator with (cmd + R) write something in the text input hit the plus icon and Voilà. we see tasks been added 🚀.</p><p>Last Steps. We need to be able to check and delete a task, for that let’s add two functions to the App component.</p><pre>const App = () =&gt; {<br>const [value, setValue] = useState(&#39;&#39;)<br>const [todos, setTodos] = useState([])</pre><pre><br>handleDeleteTodo = (id) =&gt; {<br> setTodos( todos.filter((todo) =&gt; {<br>     if (todo.key !== id) return true<br> })<br>)}</pre><pre>handleChecked = (id) =&gt; {<br>  setTodos( todos.map((todo) =&gt; {<br>     if (todo.key === id) todo.checked = !todo.checked;<br>       return todo;<br>     })<br>)}</pre><p>In the delete function, we use the filter method to remove a given task from todos state, in the second function we use the map to loop through the todos array and check the proper todo.</p><p>Now we’ll execute these function from the Task component,</p><pre>// pass the functions as props <br>&lt;Task<br> text={task.text}<br> key={task.key}<br> checked={task.checked} <em>// toggle the checked icon</em><br> setChecked={() =&gt; handleChecked(task.key)}<br> delete={() =&gt; handleDeleteTodo(task.key)}<br>/&gt;</pre><p>In the Task component, we’ll toggle the check icon, set a task to checked and delete a task. Here is the final code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b355b9a8ef5b341e63d62b1ae986407/href">https://medium.com/media/4b355b9a8ef5b341e63d62b1ae986407/href</a></iframe><p>That’s it. Now if you follow all the steps properly you’ll be able to check and delete a task 😅.</p><p>At this point, you understand the power of hooks and how they allow creating stateful components without the headache of using classes and binding functions etc…</p><h3><strong>Thanks for reading 📚</strong></h3><p>I hope you enjoyed making this todo app like I did when creating this article. Please Check the <a href="https://github.com/Yassir4/React-native-hooks-todo-list">repo</a> and don’t forget to follow me on <a href="https://twitter.com/hartaniyassir"><strong><em>Twitter</em></strong></a><strong><em> </em></strong>and <a href="https://github.com/Yassir4/"><strong><em>Github</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9953f1066d67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/build-a-todo-app-in-react-native-using-hooks-9953f1066d67">Build a Todo App in React Native using hooks</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating slug URLs in Rails without gems]]></title>
            <link>https://hartaniyassir.medium.com/creating-slug-urls-in-rails-without-gems-c693e0eeec8a?source=rss-26fa966be9a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c693e0eeec8a</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Yassir Hartani]]></dc:creator>
            <pubDate>Mon, 23 Apr 2018 08:12:59 GMT</pubDate>
            <atom:updated>2020-05-11T18:08:52.649Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will use a human readable URL instead of id’s , so instead of having an awful url like <a href="http://localhost:3000/articles/114"><em>http://localhost:3000/articles/114</em></a><em> </em>wouldn’t <a href="http://localhost:3000/articles/114-creating-slug-urls-in-rails-without-gems"><em>http://localhost:3000/articles/114-creating-slug-urls-in-rails-without-gems</em></a><em> </em>be better ? So</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*fcwLWixk10G27dEqiHOM-Q.gif" /></figure><h4>First add slug to the table</h4><pre>&gt; rails generate migration AddSlugToArticles slug:string</pre><p>run the migration</p><pre>&gt; rake db:migrate</pre><h4>Next create a method to generate the slug</h4><pre>#app/model/article.rb</pre><pre>class Article &lt; ApplicationRecord </pre><pre>private</pre><pre>def set_slug<br>self.slug = title.to_s.parameterize<br>end </pre><p>The parameterize method replace the special characters with hyphens</p><pre>&gt; &quot;Creating slug URLs in Rails without gems&quot;.to_s.parameterize<br>=&gt; &quot;creating-slug-urls-in-rails-without-gems&quot;</pre><p>Then ensure that set_slug is called in create and update by adding</p><pre>#app/model/article.rb</pre><pre>class Article &lt; ApplicationRecord<br>after_validation :set_slug, only: [:create, :update]<br> .<br> .<br> .<br>end</pre><p>If you already have created records you can run this commands</p><pre>&gt; articles = Article.all<br>&gt; articles.each do |article|<br>&gt; article.update(slug: article.title.parameterize)<br>&gt; end</pre><h4>Finally override Rails default to_param method</h4><p>To generate the slug we should force Rails to use both slug and ids instead of just the ids by overwriting the to_param method</p><pre>#app/model/article.rb</pre><pre>class Article &lt; ApplicationRecord<br>after_validation :set_slug, only: [:create, :update]</pre><pre>def to_param<br>  &quot;#{id}-#{slug}&quot;<br>end<br> .<br> .<br> .<br>end</pre><blockquote>Note : We used the id with the slug in order to have a better performance because the id column are normally unique and indexed .</blockquote><p>Now we can find the record just by id and have a beautiful url, that’s work because in rails <em>find_by_id</em> call <em>to_i</em> method and ruby only casts all numeric characters</p><pre>&gt; &quot;114-creating-slug-urls-in-rails-without-gems&quot;.to_i<br>=&gt; 114</pre><h3>Conclusion</h3><p>if you want to clean your URLs, without hitting the performance, this strategy will work for you.</p><h4>Thanks for reading!</h4><p>Feel free to leave a comment below or<a href="https://twitter.com/hartaniyassir"> reach out to me on Twitter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c693e0eeec8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>