<?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 Tanner West on Medium]]></title>
        <description><![CDATA[Stories by Tanner West on Medium]]></description>
        <link>https://medium.com/@tanner.west?source=rss-a45eba3be296------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*D7I0nLJm-jOkxwzJUljlxw.jpeg</url>
            <title>Stories by Tanner West on Medium</title>
            <link>https://medium.com/@tanner.west?source=rss-a45eba3be296------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:27:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanner.west/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[Optimizing your React Native JS Bundle Size]]></title>
            <link>https://medium.com/react-native-rocket/optimizing-your-react-native-js-bundle-size-c6b95c16c075?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6b95c16c075</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 12:57:16 GMT</pubDate>
            <atom:updated>2024-06-11T20:31:11.222Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVzsQTwvY7kdxtergGDLJw.png" /></figure><p>As an engineer working in React Native, you’re well aware that most of your application’s business logic, and all of its third-party JavaScript libraries are bundled together into one JS file and shipped alongside your app’s native code to the app stores. You also know that the larger that bundle, then the larger the app that the end user has to download, and the slower the app will start up, since it has to load that JS into memory before it can become interactive. If you’re looking for ways to make that JavaScript bundle smaller, this article is for you!</p><h3>Inspect your bundle’s contents with `react-native-bundle-visualizer`</h3><p>The first step to making your bundle smaller is to see how big it is in the first place and what’s in it. react-native-bundle-visualizer is the go-to tool for this. Check out <a href="https://github.com/IjzerenHein/react-native-bundle-visualizer">the project on GitHub</a> to learn how to install and run it (I prefer to use the npx command) . The result will be a super cool graph like this one that shows all your app’s JS modules and how they contribute to the overall size of the bundle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrUO7BZKsHF_giuUtolSZA.png" /></figure><p>As you can see, the app I’ve used for this example doesn’t depend on a ton of third party libraries. The bundle is just over 2 MB and only includes a few of the most common RN libraries: React Navigation, Reanimated, a few expo libraries, etc. But notice the blocks I’ve outlined in red. This project also includes two very popular JavaScript utility libraries: date-fns and lodash. Most engineers wouldn’t think twice about bringing these libraries into their project, but notice how in our project, they contribute almost 300 kb to the bundle size. That’s over 10% of the bundle.</p><p>Before we go any further, you may already be wondering if Metro (which is responsible for producing the final JS bundle), performs some tree-shaking step like Webpack and Rollup do. The answer is <a href="https://github.com/facebook/metro/issues/227#issuecomment-583358386">no, it doesn’t</a>, but we’ll talk about alternatives to Metro in a bit. For now, let’s explore how to reduce the footprint of the two libraries we highlighted above.</p><h3>“Cherry-pick” library imports when possible</h3><p>In the app you see visualized above, I only imported a single module from Lodash and date-fns each:</p><pre>import {chunk} from &#39;lodash&#39;<br>import {format} from &#39;date-fns&#39;;</pre><p>Metro saw that I was using the each library and bundled the whole kit and caboodle for each. Fortunately, each of these libraries are written in a way that will let me “cherry-pick” the functionality I want to prevent Metro from bundling the whole library. Replace what we did above with this:</p><pre>import chunk from &#39;lodash/chunk&#39;<br>import format from &#39;date-fns/format&#39;;</pre><p>And rerun react-native-bundle-visualizer to see the new bundle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6a0jPkpl-pLU_LMAS5jNg.png" /></figure><p>As you can see, this change reduced the footprint of date-fns from 198 kb to 30 kb (an 85% reduction), and lodash from 85 kb to 16 kb (an 81% reduction). Not bad for such a simple change!</p><p>Unfortunately, this approach only works for libraries that export modules individually, which is always likely going to be utility libraries like date-fns and lodash, and not React Native UI libraries, for example. There are a few more steps you can take to optimize your JS bundle, though.</p><h3>Enable Hermes on both platforms</h3><p>Hermes is a JavaScript engine developed by Meta specifically for running JS in React Native. Hermes has been enabled by default for both platforms in new React Native projects since 0.70, replacing the JavaScriptCore engine that was used previously.</p><p>Hermes brings many advantages such as faster startup times, improved memory consumption, and most importanly for us here, smaller bundle size. Hermes achieves these advantages by precompiling JavaScript into bytecode at build time, so it loads an runs faster at runtime. If your project doesn’t already ship with Hermes on both platforms, <a href="https://reactnative.dev/docs/hermes">enabling it</a> can be an easy win when it comes to optimizing your JS bundle.</p><h3>Consider using an alternative bundler</h3><p>The most heavy handed approach to optimizing your JS bundle is by using an alternative bundler instead of Metro. These tools each take a different approach to bundling an app’s JS assets, and some are built on popular bundling tools built for the web. I do not personally have experience with these tools, but here is a quick synopsis of the most popular ones to jump start your research if you’re interested. Note that just using an alternative bundler won’t guarantee a smaller bundle, but their advanced features can give you more control over what ultimately ends up getting bundled.</p><ul><li><a href="https://github.com/callstack/repack">Callstack’s Re.Pack</a> is the most popular tool in this category. It builds on top of Webpack to bring that tool’s rich ecosystem to React Native. It’s best for cases where you need advanced features like symlinks and code splitting</li><li>Microsoft’s rnx-kit includes <a href="https://microsoft.github.io/rnx-kit/docs/tools/metro-serializer">@rnx-kit/metro-serializer</a> that builds on top of Metro to include custom plugins, as well as <a href="https://microsoft.github.io/rnx-kit/docs/tools/metro-serializer-esbuild">metro-serializer-esbuild</a> which uses the esbuild bundler to process the JS bundle</li><li><a href="https://github.com/oblador/react-native-esbuild">react-native-esbuild</a> claims to be “a drop-in replacement for Metro” and builds upon esbuild for speed and to enable tree shaking</li></ul><h3>Conclusion</h3><p>As we’ve seen, there are a number of things you can do to optimize your React Native JavaScript bundle, and there is no one-size-fits all solution. And we didn’t even mention reducing the overall app size with native platforms optimizations, which merits its own series of articles I hope to write soon.</p><p>So what did I miss? What other JS bundle optimization techniques have you used? Let me know in the comments here or on <a href="http://x.com/useRNPatterns">X @useRNPatterns</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6b95c16c075" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/optimizing-your-react-native-js-bundle-size-c6b95c16c075">Optimizing your React Native JS Bundle Size</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t Give Up on Redux Just Yet]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@tanner.west/dont-give-up-on-redux-just-yet-e23065449be2?source=rss-a45eba3be296------2"><img src="https://cdn-images-1.medium.com/max/2600/1*iqE2o-WhtWXqNKASiOnWKw.jpeg" width="5743"></a></p><p class="medium-feed-snippet">If you&#x2019;ve worked with React and TypeScript for a while, then I&#x2019;m sure this looks familiar.</p><p class="medium-feed-link"><a href="https://medium.com/@tanner.west/dont-give-up-on-redux-just-yet-e23065449be2?source=rss-a45eba3be296------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@tanner.west/dont-give-up-on-redux-just-yet-e23065449be2?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/e23065449be2</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 02:43:54 GMT</pubDate>
            <atom:updated>2023-02-15T02:43:54.367Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Replacing Redux with Recoil in React Native Apps]]></title>
            <link>https://medium.com/react-native-rocket/replacing-redux-with-recoil-in-react-native-apps-9ce631f93ecf?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ce631f93ecf</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Sun, 15 Jan 2023 16:25:33 GMT</pubDate>
            <atom:updated>2023-01-15T16:25:33.029Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAgaz-1ZDNcZahvaWbQyRw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@tljamesa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">James Allen</a> on <a href="https://unsplash.com/s/photos/coil?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A lot of people are looking for alternatives to Redux for their React Native apps these days. Newer state management solutions like Jotai and Zustand have been getting a lot of attention lately, but one I’ve heard less about is <a href="https://github.com/facebookexperimental/Recoil">Recoil </a>— an experimental state management library from the folks at Facebook.</p><p>Instead of teaching you the basics of Recoil here (<a href="https://recoiljs.org/">the official docs</a> and J<a href="https://learnrecoil.com/">acque Blom’s free Learn Recoil Course</a> already do a great job of that), I’m going to show you a side-by-side comparison of a very common data fetching pattern implemented in both Redux and Recoil, so you can get a high-level understanding of the differences in the two frameworks’ approaches.</p><p>First, let’s look at a very basic app implemented with Redux. This “Request/Success/Failure” action pattern should look familiar to anyone who’s worked in classic Redux.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cab41b54ddcb47c033166a1e70c17af6/href">https://medium.com/media/cab41b54ddcb47c033166a1e70c17af6/href</a></iframe><p>Our post data here is fetched in a Thunk, which dispatches a success or failure action depending on the result of the API call. A Posts component maps and displays the available post data or an error.</p><p>Next, let’s look at how we’d implement this same functionality with Recoil, without a major refactor to our presentation component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c573dd4014b92d6b929eab5ee63601f1/href">https://medium.com/media/c573dd4014b92d6b929eab5ee63601f1/href</a></iframe><p>The first thing that might stand out here is how much shorter the Recoil example is. We saved over 30 lines of code. That’s due to the fact that much of the functionality we have to create manually with Redux (defining the “loading” and “error” state, for example), is essentially built in to Recoil’s concept of <a href="https://recoiljs.org/docs/api-reference/core/Loadable">Loadable</a> values. These values have a state property, which tells you if the value is &#39;hasValue&#39;, &#39;hasError&#39;, or &#39;loading&#39; . You can get the actual value (whether it’s the fetched data or an error) with the contents property.</p><p>Also notice that we make our data fetching call directly in our Recoil selector. It can handle asynchronous logic out of the box, without the need for any third-party libraries (like redux-thunk or redux-saga).</p><p>By default, Recoil values are memoized and our fetch logic will not rerun each time we need to access the state it returns. If we do want to explicitly refetch that data, then we can use the useRecoilRefresher_UNSTABLE() hook, as we did on line 39 above.</p><p>I hope this post has helped you get a feel for how to approach data fetching in Recoil. Keep in mind that Recoil is still considered an experimental library, so there’s no guarantee that it will continue to be maintained. If you’re looking to replace Redux in your app because you hate all the boilerplate code it requires, I would strongly recommend you check out <a href="https://redux-toolkit.js.org/">Redux Toolkit</a>, if you haven’t already. In my opinion, it takes a lot of the pain out of dealing with Redux apps, and can be adopted incrementally so you don’t have to replace your state library all at once.</p><p>If you enjoyed this post, please follow me here on Medium and on Twitter <a href="https://twitter.com/useRNRocket">@useRNrocket</a> for more React Native content like this!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ce631f93ecf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/replacing-redux-with-recoil-in-react-native-apps-9ce631f93ecf">Replacing Redux with Recoil in React Native Apps</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Only Thing You Need to Know About JavaScript Dates]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@tanner.west/the-only-thing-you-need-to-know-about-javascript-dates-44e4cb1d541c?source=rss-a45eba3be296------2"><img src="https://cdn-images-1.medium.com/max/2600/1*evja96FVbsmFNIrPFl6ukw.jpeg" width="6000"></a></p><p class="medium-feed-snippet">If you find JavaScript dates confusing, you&#x2019;re not alone. Luckily, there&#x2019;s one key insight that might clear up most of your confusion!</p><p class="medium-feed-link"><a href="https://medium.com/@tanner.west/the-only-thing-you-need-to-know-about-javascript-dates-44e4cb1d541c?source=rss-a45eba3be296------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@tanner.west/the-only-thing-you-need-to-know-about-javascript-dates-44e4cb1d541c?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/44e4cb1d541c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 01:32:56 GMT</pubDate>
            <atom:updated>2022-11-29T13:01:34.005Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building a Hand Drawing App with React Native Skia and Gesture Handler]]></title>
            <link>https://medium.com/react-native-rocket/building-a-hand-drawing-app-with-react-native-skia-and-gesture-handler-9797f5f7b9b4?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/9797f5f7b9b4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Fri, 26 Aug 2022 02:33:23 GMT</pubDate>
            <atom:updated>2022-08-26T02:38:09.879Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvUAgAKP2tr3UgwAtlSpbQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@introspectivedsgn?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Erik Mclean</a> on <a href="https://unsplash.com/s/photos/finger-paint?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Now that the Skia 2D graphics library is available in React Native, we have so many opportunities to create graphics intensive applications that weren’t possible before. A personal goal of mine for a while was to explore React Native Gesture Handler, then Skia crossed my radar and I wanted to get some experience with it as well. The idea struck me to build a proof-of-concept hand drawing app that captures user input via Gesture Handler and paints it to a canvas component using RN Skia. This article covers the basics of getting that app up and running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*i326_pZRKgiip4ygJLOxvQ.gif" /></figure><h3>Getting Started with React Native Gesture Handler</h3><p>The first step in this project is understanding RN Gesture Handler’s API. You can read about it more in depth in <a href="https://docs.swmansion.com/react-native-gesture-handler/docs/">Software Mansion’s documentation</a>, but it’s pretty straightforward. Here’s what a basic component looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14be88e74c96a74ff4496368425ed035/href">https://medium.com/media/14be88e74c96a74ff4496368425ed035/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*tJylWGDPGhGlqkRDlGxvNA.gif" /></figure><p>We wrap the component we want to capture gestures from in a &lt;GestureDetector&gt; and pass a gesture prop for the type of gesture we want to react to. This prop takes the form of a Gesture object that we configure with the code we want to run when certain events occur (when the gesture starts, updates, and ends). If you want to react to multiple types of gestures, just wrap you component in an additional&lt;GestureDetector&gt; for each type of gesture.</p><p>In the above recording, notice how onTouchesMove gets called before onStart and onUpdate. It gets called any time the input moves, regardless of whether a gesture has been recognized. Gesture Handler only fires onStart and onUpdate once the movement has been recognized as a gesture. This distinction will be relevant to our drawing app!</p><h3>Understanding the Basics of Canvas in RN Skia</h3><p>If you’ve worked with 2D graphics like SVGs in the past, these concepts should be familiar. Either way, they’re easy to pick up. A canvas implements a XY coordinate system that we use to draw our graphics. By default, the coordinates 0, 0 are at the upper left corner of the canvas. The X axis moves from left to right and the Y axis is up and down.</p><p>React Native Skia gives us many convenient way to draw on our canvas. For example, if you want to use the Path component to draw a line, you can use the classic SVG path notation and pass the value to your component as a string. Alternatively, you can use Skia’s Path object to build a path point by point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6caed11dd12aaf754ac1553fdb23f5be/href">https://medium.com/media/6caed11dd12aaf754ac1553fdb23f5be/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SiqKmAqJV8YTpHOJVgbMzQ.png" /></figure><p>Understanding how the SVG notation in the previous example works is critical to understand the app we’ll build. You should definitely read <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths">MDN’s article on the topic</a>, but be sure you understand at least these two things:</p><ul><li>Instructions with the syntax M {xCoordinate} {yCoordinate} tell the canvas to “move to” the provided coordinates; this instruction on its own doesn’t draw anything, but it provides the starting coordinates for the next operation.</li><li>Instructions with the syntax L {xCoordinate} {yCoordinate} tell the canvas to draw a line from its current position to the coordinates provided.</li></ul><p>We can also very easily draw shapes on our canvas. Here’s how we draw circles, for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be3a2333c745ac3762bbc56193e00606/href">https://medium.com/media/be3a2333c745ac3762bbc56193e00606/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0d486tDy19du-vp97wMyw.png" /></figure><p>Finally, using the ImageSvg component from React Native Skia, we can draw any arbitrary SVG to our canvas, including those we import from external sources.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c96946a2de9ef24cbd358a9c2e834ac/href">https://medium.com/media/7c96946a2de9ef24cbd358a9c2e834ac/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66OiMSMzCcYhfEBJRv3igw.png" /></figure><h3>Drawing with Gesture Handler and Skia</h3><p>Now that we understand the basics of Gesture Handler and Skia, we’re ready to bring the two concepts together and start drawing!</p><p>We’ll create a freehand drawing feature that captures user pan gestures data and uses it to draw paths on the Skia Canvas. This is actually much easier that it might sound at first, if you keep in mind these concepts:</p><ul><li>Gesture Handler’s Gesture.Pan.onUpdate() will run our callback function when the user moves their finger, providing us with new coordinates of the user’s finger each time</li><li>Skia Paths can be defined using SVG notation, which can include a series of L {xCoord} {yCoord} statements to draw lines</li></ul><p>With those principles in mind, check out this component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5ef58343bdbbfc0466ab40c03419ad6/href">https://medium.com/media/f5ef58343bdbbfc0466ab40c03419ad6/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*2Z2nZBk3NaF_cxKPAZuaMQ.gif" /></figure><p>The most important parts of this component to understand are lines 25 and 32.</p><ul><li>On 25, when Gesture Handler detects the beginning of a gesture, we push a new path object into our paths array. This object has an array called segments that will contain a list of SVG notation instructions to draw that path. Initially, we create a “move” command to begin our path at the starting coordinates of our gesture.</li><li>Each time the gesture updates, we push a new path segment into our array (line 32). These segments contain a command in SVG notation to draw a line to the updated coordinates.</li></ul><p>Then, we simply map over the values in paths inside our canvas to draw them. The path prop for each Path component is created by joining each segment string to form valid SVG notation.</p><p>There you have it! With fewer than 60 lines of code, we created a basic hand drawing component with React Native Gesture Handler and Skia.The power and potential of these two libraries combined really impress me. I hope you feel the same way!</p><p>Check out my <a href="https://github.com/tanner-west/rn-skia-draw">RN Skia Draw repo on GitHub</a> for a ready to install Expo app that demonstrates these principles and also shows how to “stamp” the SVG star images shown above to the Canvas using a Tap gesture!</p><p>As always, follow me here on Medium and <a href="https://twitter.com/useRNRocket">on Twitter @useRNRocket </a>for more React Native content! Tweet me with any comments, questions, or corrections.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9797f5f7b9b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/building-a-hand-drawing-app-with-react-native-skia-and-gesture-handler-9797f5f7b9b4">Building a Hand Drawing App with React Native Skia and Gesture Handler</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animating Content Placeholders in React Native with Moti]]></title>
            <link>https://medium.com/react-native-rocket/animating-content-placeholders-in-react-native-with-moti-3eeff767d397?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eeff767d397</guid>
            <category><![CDATA[moti]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Tue, 02 Aug 2022 02:09:38 GMT</pubDate>
            <atom:updated>2022-08-02T02:09:38.444Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*az6g5uSSFGL71bGr-yggGA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/es/@kellysikkema?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kelly Sikkema</a> on <a href="https://unsplash.com/s/photos/placeholder?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Content placeholders, sometimes called “skeletons” are ubiquitous in mobile apps and on the web today. They give your user something to see other than a blank screen or a generic spinner icon while they wait for your app’s content to load, and they prevent the transition from loading to loaded from being too jarring.</p><p>This type of component is fairly easy to create no matter which platform you’re using. The most time consuming part is creating the animation. Lucky for us React Native developers, Moti makes this step a breeze! The approach is slightly different depending on which style you want to create.</p><h3>The “Sweeping Gradient” Style</h3><p>We animate this type of content placeholder by translating the position of a gradient across our placeholder element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*aOSqrT2WE1k_tHy5uawTlw.gif" /></figure><p>This effect is very easy to achieve with Moti. We simply nest an SVG gradient in a MotiView component and create a looped timing animation to translate its position across the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edff716254808bdfad00ca3722596298/href">https://medium.com/media/edff716254808bdfad00ca3722596298/href</a></iframe><p>Here’s the full code for this screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d8aa8d2576f8b29072c76885b20bb04/href">https://medium.com/media/6d8aa8d2576f8b29072c76885b20bb04/href</a></iframe><p>You’re probably curious about how I came up with the gradient stops in this example. They’re generated by a bezier easing curve function to create a smooth gradient. You can read more about that process in my article <a href="https://medium.com/react-native-rocket/exploring-easing-gradients-in-react-native-3872dd2c4a5e">Exploring Easing Gradients in React Native</a>.</p><h3>The “Color Pulse” style</h3><p>Another popular animation style for content placeholders is what I call the “color pulse” style, where the elements animate in a loop from one color to another. Again, Moti makes this very simple to implement in React Native. It’s actually simpler than the gradient style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*O09psm7X_CS40E_Hv7tEJg.gif" /></figure><p>Here, we can use an animated MotiView for our placeholder component itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99afe7110353d9b7e91922aef9c75040/href">https://medium.com/media/99afe7110353d9b7e91922aef9c75040/href</a></iframe><p>And here’s the full code for this screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3b914c1732b24f55a5c3cf218022d2f/href">https://medium.com/media/f3b914c1732b24f55a5c3cf218022d2f/href</a></iframe><p>I hope this post has inspired you to create your own React Native content placeholders with Moti. As always, questions and comments are welcome on Twitter <a href="https://twitter.com/useRNRocket">@useRNRocke</a>t. Follow me there and here on Medium for more React Native and Moti content!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eeff767d397" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/animating-content-placeholders-in-react-native-with-moti-3eeff767d397">Animating Content Placeholders in React Native with Moti</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Being a React Native Developer is About More than Just Writing Good Code]]></title>
            <link>https://medium.com/react-native-rocket/being-a-react-native-developer-is-about-more-than-just-writing-good-code-bdaec89f868f?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdaec89f868f</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 21:44:22 GMT</pubDate>
            <atom:updated>2022-07-30T21:44:22.721Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qcq1sSrwhfVcb73PowpWFA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@barnimages?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Barn Images</a> on <a href="https://unsplash.com/s/photos/toolbox?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A lot of us get into software because we enjoy it. I certainly do. I spend a lot of my free time on React Native projects. I consider myself extremely lucky to have found a career doing work I enjoy. Even though I do get paid to write code, that’s not all my work as a software engineer entails. Whether you’re looking to land your first job as a React Native engineer, or you just want to brush up on your skillset for your next job or promotion, these are a few areas you should be proficient in to consider yourself a well-rounded React Native developer.</p><h3>App Deployment</h3><p>Maybe you disagree, but deploying apps to the app stores is one of the least enjoyable parts of mobile app development. I’m lucky enough now to work at a company where the mobile engineers don’t have to get too involved in the process, but other companies handle things differently. No matter how your company divides the responsibilities, you’ll definitely want to familiarize yourself with the process of deploying your React Native app to the Apple App Store and Google Play Store, especially if you hope to publish a side project one day.</p><p>As usual, the best way to learn how to deploy an app is just to try it yourself! You’ll find plenty of resources online explaining how to publish your React Native app, whether you use Expo or not. Just take it one step and a time and don’t worry if it doesn’t make sense the first time through (especially when it comes to app signing and provisioning profiles 😱).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FzPbnEgxsPJOJSD3qfr%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FzPbnEgxsPJOJSD3qfr%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FzPbnEgxsPJOJSD3qfr%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/b675392906d18d978cd4e3d40770f770/href">https://medium.com/media/b675392906d18d978cd4e3d40770f770/href</a></iframe><p>Once you get familiar with the process of submitting an app to the app stores, you’ll realize what a pain much of it can be, and you’ll be very glad to learn about Fastlane, if you’re not already familiar with it.</p><p><a href="https://fastlane.tools/">Fastlane</a> is an open source tool that automates some of the most tedious and difficult parts of mobile app deployment, from uploading your app to the app stores to managing your signing certificates. Once you learn to use it, it will become of the most valuable tools in your React Native toolkit.</p><h3>CI/CD</h3><p>Virtually all companies have adopted some version of a CI/CD (continuous integration/continuous deployment) pipeline by now. Every company will have its own unique pipeline tailored to its needs, but most have these things in common:</p><ol><li>Developers frequently check their code into a shared repo to avoid merge conflicts</li><li>App builds are automated and usually initiated by repo pull requests</li><li>Tests are automatically ran against builds</li><li>New app builds are automatically deployed to the app stores for beta testing</li><li>Software follows a predictable testing and release cadence</li></ol><p>There are many tools available to build CI/CD pipelines, from classic self-hosted Jenkins instances to managed platforms like CircleCI. Building a full CI/CD pipeline for your weekend side project might be overkill, but taking the time to learn the basics can give you skills that will likely come in handy at some point in your career.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3ohzdD4RjmkD5xpBRK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3ohzdD4RjmkD5xpBRK%2Fgiphy-downsized-large.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3ohzdD4RjmkD5xpBRK%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbcf41ddda3f88b2f8665c478f5c3117/href">https://medium.com/media/cbcf41ddda3f88b2f8665c478f5c3117/href</a></iframe><p>If you’re looking to get your feet wet with CI/CD, I’d recommended exploring <a href="https://github.com/features/actions">GitHub Actions</a>. Even if you can just learn to automate building and running tests on your code when you open PR’s to your repo, you’ll have a solid foundation in place that you can build on when the time comes to go deeper into CI/CD.</p><h3>Backend</h3><p>The concept of “frontend developer” is starting to become obsolete at more and more companies, especially in companies that use TypeScript across their stack. It’s becoming more common for the same team of developers to maintain a React Native app and some or all of the backend APIs that power it. Even if your current role doesn’t it require it, learning the basics of building backend APIs can help open up new opportunities and take your side projects to the next level.</p><p><a href="https://nodejs.org/en/">Node.js</a> can be a great place for React Native developers to get started learning backend. With the Express HTTP framework, you can spin up a local server on your computer in just a few minutes and start learning how to build APIs with JavaScript. Once you’re ready to put your app online, you can easily do so with a service like Heroku or AWS Lambda, which let you deploy your code without worrying about maintaining a traditional server.</p><p>Once you’ve learned the basics of HTTP APIs and you’re ready to start exploring things like databases, file storage, and user authentication, check out managed services like Amazon’s AWS Amplify and Firebase. These services dramatically reduce the complexity of provisioning backend infrastructure for React Native Apps.</p><h3>Testing</h3><p>It’s notoriously easy to neglect testing even on professional software teams, not to mention in side projects, but well-written tests are a hallmark of reliable software. There are many flavors of software testing, from unit and integration tests to automated, end-to-end tests. Different companies have different needs, but as a developer, it pays to be familiar with all types of tests.</p><p>The simplest and easiest-to-write are <strong>unit tests</strong>. They’re designed to test a single piece or “unit” of your code. What’s considered a unit is often as small as a utility function, but unit tests can often encompass individual React components too.</p><p>Moving up the <a href="https://martinfowler.com/articles/practical-test-pyramid.html">testing pyramid</a> (or <a href="https://twitter.com/kentcdodds/status/960723172591992832">testing trophy</a>) and increasing in terms of complexity and time required to write them are <strong>integration tests</strong>. These tests check to see whether multiple units or your software work in combination. Integration tests more closely resemble how your end users will interact with your app, but they can still be ran against your source code rather than the app itself.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FY4v7P4m3RbMDBDSXa9%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FY4v7P4m3RbMDBDSXa9%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FY4v7P4m3RbMDBDSXa9%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/5aa95ad62a944dd42cf6852fffba1c6e/href">https://medium.com/media/5aa95ad62a944dd42cf6852fffba1c6e/href</a></iframe><p>In React Native, both unit tests and integration tests can be written with React Native Testing Library. Check out <a href="https://medium.com/@tanner.west/react-native-tests-that-would-hopefully-make-kent-c-dodds-proud-a544a617c2eb">my article about React Native Testing Library</a> to learn how to get started.</p><p>For end-to-end tests, the two main solutions for React Native are Detox and Appium. Both of these solutions interact with your app the way an actual user would, by providing input like touch events, swipes, and typing. These tests can be difficult to set up and slow to run, but when used correctly, can give you a great deal of confidence that your app will work as expected in the hands of your end users.</p><h3>Conclusion</h3><p>Writing React Native apps is fun. There’s nothing quite as satisfying as watching a feature you build come to life on a simulator or physical device. Just make sure you’re taking the time to learn the other skills that go into being a well-rounded engineer. A future job offer or promotion may depend on it!</p><p>As always, I welcome comments and questions on Twitter <a href="https://twitter.com/useRNRocket">@useRNRocket</a>. Follow me there and here on Medium for more React Native content!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdaec89f868f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/being-a-react-native-developer-is-about-more-than-just-writing-good-code-bdaec89f868f">Being a React Native Developer is About More than Just Writing Good Code</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Easing Gradients in React Native]]></title>
            <link>https://medium.com/react-native-rocket/exploring-easing-gradients-in-react-native-3872dd2c4a5e?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/3872dd2c4a5e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 11:40:23 GMT</pubDate>
            <atom:updated>2022-07-26T11:40:23.862Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3LWj6x9EMx_YELTeYLUi9w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@sickle?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sergey Pesterev</a> on <a href="https://unsplash.com/s/photos/sunset?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A few weeks ago, I was <a href="https://twitter.com/useRNRocket/status/1547734054908268544">experimenting</a> with using gradients to animate skeleton placeholders with Moti, and I noticed that many of the basic gradients I tried had discernible edges that kept them from blending well with their background component. I started doing a little research on how to create smooth gradients and I came across Andreas Larsen’s article <a href="https://css-tricks.com/easing-linear-gradients/">Easing Linear Gradients</a>.</p><p>In the article, Larsen explains how you can take the principle of easing, which you are likely familiar with if you’ve ever worked with animations, and apply it to creating gradients. The same way we use easing curves to make animations appear more “natural,” we can apply them to our gradients to create smooth transitions between colors.</p><p>To help web engineers create eased gradients, Larsen wrote a PostCSS plugin that lets you pass in cubic bezier coordinates to generate a gradient based on that curve. I really wanted to see eased gradients in action in React Native, and since we can’t use PostCSS in RN, I dug in to the source code for Larsen’s plugin to see if I could port at least part of its functionality to a React Native project.</p><h3>Understanding the Basics</h3><p>At the heart of his plugin is another one of Larsen’s libraries, <a href="https://github.com/larsenwork/easing-coordinates">Easing Coordinates</a>. It contains the math functions that translate cubic bezier coordinates to sets of XY coordinates. It becomes much easier to understand what these functions do if you can visualize it, so check out this Codepen that uses some of Larsen’s code to generate coordinates, then shows them as an SVG curve with the help of D3.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ftanner-west%2Fembed%2Fpreview%2FvYRmWoB%3Fdefault-tabs%3Djs%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DvYRmWoB&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Ftanner-west%2Fpen%2FvYRmWoB&amp;image=https%3A%2F%2Fshots.codepen.io%2Ftanner-west%2Fpen%2FvYRmWoB-512.jpg%3Fversion%3D1658522254&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fbc45b9adc87991bbb6a63777eeadfb/href">https://medium.com/media/4fbc45b9adc87991bbb6a63777eeadfb/href</a></iframe><p>If you’re familiar with easing curves, you’ll recognize this as a basic ease-in curve. If you explore the JavaScript for this example, you’ll see that the first four functions are taken directly from Larsen’s library. cubicCoordinates takes five arguments: the four points of our cubic bezier curve and an optional polySteps . The latter defines how many pairs of coordinates the function will generate.</p><p>The data that’s actually generated by this function looks like this. The curve you see is simply a graph of these coordinates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57a537b2b0854fe2e24387d75a71495e/href">https://medium.com/media/57a537b2b0854fe2e24387d75a71495e/href</a></iframe><p>The above example shows that Larsen’s code gives us accurate easing curve coordinates for a given sets of bezier points, but how do we actually use these coordinates to generate gradients? That’s what we’ll cover in the next section.</p><h3>From graph coordinates to gradients</h3><p>If you’ve worked with SVG gradients before, this next example should be very familiar. We provide a number of &lt;Stop&gt; elements to define where our gradient’s colors will start and end.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ftanner-west%2Fembed%2Fpreview%2FWNzjOwb%3Fdefault-tabs%3Dhtml%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DWNzjOwb&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Ftanner-west%2Fpen%2FWNzjOwb&amp;image=https%3A%2F%2Fshots.codepen.io%2Ftanner-west%2Fpen%2FWNzjOwb-512.jpg%3Fversion%3D1658525240&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a9b1f8ddd6f3f2077c18efd06e07063/href">https://medium.com/media/4a9b1f8ddd6f3f2077c18efd06e07063/href</a></iframe><p>Typically, as in the example above, we write this manually because we just need our gradient to have two or three stops, but now we can use our bezier coordinate data to define these programmatically.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ftanner-west%2Fembed%2Fpreview%2FWNzOXMb%3Fdefault-tabs%3Djs%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DWNzOXMb&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Ftanner-west%2Fpen%2FWNzOXMb&amp;image=https%3A%2F%2Fshots.codepen.io%2Ftanner-west%2Fpen%2FWNzOXMb-512.jpg%3Fversion%3D1658540720&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6526e28b515f145ab01ffef17feef2bf/href">https://medium.com/media/6526e28b515f145ab01ffef17feef2bf/href</a></iframe><p>Since we used D3 in our last example, we use it again here to append our stops to our SVG linear gradient. We use a forEach loop that appends a new Stop for each of our coordinate pairs. The x coordinates will determine the stop offset, while we’ll use the y coordinates to set our color value.</p><p>We can get much more fancy with colors when we start using React Native, but for now we’ll map our y value to a number between 0 and 255, and use that number for all three parameters of an RGB value. This will result in an increasingly lighter gray color for each stop. This all might seem confusing at first, so here’s what the markup for the resulting gradient will look like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/662492d8647b30e4546e6414d1708341/href">https://medium.com/media/662492d8647b30e4546e6414d1708341/href</a></iframe><h3>Bringing it all to React Native</h3><p>Now that we understand the fundamentals behind our eased gradient technique, we can bring what we’ve learned to React Native. I’ve built a <a href="https://github.com/tanner-west/easing-gradient-react-native">playground app</a> for exploring what different cubic bezier easings look like. The easing curve data for this app is taken directly from <a href="https://easings.net/">easings.net</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*xmTS5LRm8yuMMyGRMUUrwQ.gif" /></figure><p>The app uses essentially the same techniques as the examples above. The coordinate data is generated by code from Larsen’s library. We map over the coordinates to generate our SVG stops, using x for our offset and y for our color values.</p><p>If you were able to follow along with the examples from above, this app should pretty self explanatory. The only concept we haven’t covered yet is the interpolation of colors. I’ve provided two text inputs where you can enter stop colors. Using the interpolation function from Reanimated, the app will map those colors to the y value of the selected bezier curve. The result is a smooth transition between those two colors across the stops!</p><h3>Conclusion</h3><p>It’s very satisfying to have eased gradients as another tool in my app building toolbox. Familiarizing myself with the idea has also helped me better understand concepts like SVG gradients and bezier curves, and I hope it’s helped you in a similar way!</p><p>As always, questions, comments, and corrections are welcome on Twitter <a href="https://twitter.com/useRNRocket">@useRNRocket</a>. Follow me here on Medium and on Twitter for more React Native content!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3872dd2c4a5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/exploring-easing-gradients-in-react-native-3872dd2c4a5e">Exploring Easing Gradients in React Native</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Easy React Native Transition Animations with Moti]]></title>
            <link>https://medium.com/react-native-rocket/3-easy-react-native-transition-animations-with-moti-4c46c75dbaec?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c46c75dbaec</guid>
            <category><![CDATA[moti]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Fri, 08 Jul 2022 01:54:08 GMT</pubDate>
            <atom:updated>2022-07-08T01:54:08.169Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z4L6yk0EssSoSEPGF0lmKw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jontyson?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jon Tyson</a> on <a href="https://unsplash.com/s/photos/film?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://moti.fyi/">Moti</a> is a fairly new React Native package from Fernando Rojo for creating “animations and transitions that work well on both websites &amp; native apps,” in the author’s own words. It provides a super simple API around Reanimated 2.</p><p>I started playing with Moti a few weeks ago, and so far my favorite thing to do with the library is to create content transitions. Making these transitions is an absolute breeze with the MotiView component.</p><p>Here are three examples of simple, beautiful transitions you can add to your app with just a few lines of code.</p><p><em>Note: the GIF format of the previews here don’t do justice to how smooth these animations are on an actual device. Visit the GitHub Gist links for each code example and scroll down to the comments for an actual screen recording of each.</em></p><h3>Example 1: Staggered Reveal Image Gallery</h3><figure><img alt="An image slide show where images stagger in gradually." src="https://cdn-images-1.medium.com/max/320/1*_HcEGTMbSKBbf0O1mgj0Iw.gif" /></figure><p>This first effect works well when you have a list of images or similar visual content, and you want them to reveal them gradually in a sequence. Each image animates from an opacity of 0 to 1 from a Y translation of 10 to 0. We use a timing transition so each image loads 300 ms after the previous one, and each animation takes 300 ms to complete.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/490da26e02ed422f0eeda8ddb15bd39f/href">https://medium.com/media/490da26e02ed422f0eeda8ddb15bd39f/href</a></iframe><h3>Example 3: Subtle Spring Text Intro</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*8vc65CAFBT18Zr3LRip75g.gif" /></figure><p>This next example uses an effect very similar to the previous one. The main difference is that this one uses a spring transition rather than a timing transition. A spring transition gives us a nice subtle “settling in” effect after each element is revealed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/184f4a3166bd29ea99f35021dc28b7f3/href">https://medium.com/media/184f4a3166bd29ea99f35021dc28b7f3/href</a></iframe><h3>Example 3: Drop-in and Slide-in UI Elements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*9D2xcAi4j1nsJHbOpASsag.gif" /></figure><p>My inspiration for this example came from how iOS home screen elements transition in after the lock screen is dismissed. This could be used for all types of content, but I think it’s a great way to present interactive UI elements rather than have them appear all at once.</p><p>There are actually two separate transitions here. The top elements’ container animates from a scale of 1.5 to 1, giving it a “drop in” effect, while the bottom element’s Y position translates from 500 to 0, making it “slide in” from the bottom of the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12d289257700f26df6e24792fab80505/href">https://medium.com/media/12d289257700f26df6e24792fab80505/href</a></iframe><h3>Conclusion</h3><p>I hope these examples have given you a taste of the powerful simplicity of the Moti library, and I hope they’ve inspired you to create your own unique animations. I’d love to see what you come up with. Tag me on your creations on Twitter <a href="https://twitter.com/useRNRocket">@useRNRocket</a>. Be sure to follow me there and here on Medium for more React Native content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c46c75dbaec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/3-easy-react-native-transition-animations-with-moti-4c46c75dbaec">3 Easy React Native Transition Animations with Moti</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animating Progress Rings with React Native Reanimated 2]]></title>
            <link>https://medium.com/react-native-rocket/animating-progress-rings-with-react-native-reanimated-2-9c19ad2115b?source=rss-a45eba3be296------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c19ad2115b</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[reanimated]]></category>
            <dc:creator><![CDATA[Tanner West]]></dc:creator>
            <pubDate>Tue, 05 Jul 2022 15:56:15 GMT</pubDate>
            <atom:updated>2022-07-05T15:57:55.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Three progress rings: 5%, 40%, and 90%" src="https://cdn-images-1.medium.com/max/1024/1*07sxC87i8y8dozsgNV9W0g.png" /></figure><p>Reanimated 2 and React Native SVG can be combined to make some powerful and impressive animations. One of the most practical shapes to animate is circles because they can be animated to create all types of useful UI components like progress rings. Once you understand a couple of SVG fundamentals, it’s a breeze to create any animated progress ring you can dream up.</p><figure><img alt="An animated progress ring that goes from 0 to 100 percent and changes color from red to yellow to green" src="https://cdn-images-1.medium.com/max/320/1*o08cUOZtO43i_7NT7b1Jiw.gif" /></figure><h3>The fundamentals: strokeDasharray and strokeDashoffset</h3><p>The technique we’ll use to animate our circles depends on a neat hack using two common SVG properties: strokeDasharray and strokeDashoffset Here’s what they do.</p><p>strokeDasharray lets us create a dashed stroke around the outside of our circle, rather than a solid stoke. If we provide just one number, we’ll get a dashed stroke with dashes and gaps that are the same size.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba70650ffb74e596dfd14ddb8c7597e4/href">https://medium.com/media/ba70650ffb74e596dfd14ddb8c7597e4/href</a></iframe><figure><img alt="A circle with a dashed outline" src="https://cdn-images-1.medium.com/max/585/1*ixP7-x9h4VWIq3fsqzE-Rg.png" /></figure><p>Alternatively, we can pass two numbers — the first will define the length of the dash, and the second will define the length of the gap between dashes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2fabcd67d8ad6181adea93bb319c210/href">https://medium.com/media/a2fabcd67d8ad6181adea93bb319c210/href</a></iframe><figure><img alt="A circle with a dashed outline" src="https://cdn-images-1.medium.com/max/585/1*jwFRxW-9Q_6S_md1nBvRIA.png" /></figure><p>strokeDashoffset lets us offset the position of our stroke by a given number.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e771c0a3e177fd804a344b2421df5da/href">https://medium.com/media/7e771c0a3e177fd804a344b2421df5da/href</a></iframe><figure><img alt="A circle with a dashed outline" src="https://cdn-images-1.medium.com/max/585/1*OJcQBtM1njILoJkhiQNJ4w.png" /></figure><p>How do these two properties help us animate a circle? This is where it’s time to get creative. Let’s see what happens when we set our stroke dash size to be the entire circumference of our circle (using radius * PI * 2). We end up with what looks like a solid stroke. Technically our stroke is still dashed, but our dash covers the entire circumference of the circle, so we don’t see a gap.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ee7b5efd99dd2be1f7ef0849fe58a4d/href">https://medium.com/media/8ee7b5efd99dd2be1f7ef0849fe58a4d/href</a></iframe><figure><img alt="A circle with a solid outline" src="https://cdn-images-1.medium.com/max/585/1*kWr8R7tsJ0gUnaNIxt7qPg.png" /></figure><p>Now, let’s add an offset that’s also the size of the circumference. It looks like our stroke is gone, but what’s actually happened is that our stroke gap covers the entire circumference of the circle, since our stroke gap is also the full circumference of the circle. This makes it so we don’t see any stroke.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b10ec5f0a03d4d66c4b1a2b822333a8f/href">https://medium.com/media/b10ec5f0a03d4d66c4b1a2b822333a8f/href</a></iframe><figure><img alt="A circle with no outline" src="https://cdn-images-1.medium.com/max/585/1*YIKpZB6_adzAq5o5GCiKSg.png" /></figure><p>We can subtract any arbitrary amount from our offset to “reveal” that much of our stroke. We’ll subtract 40 and see what happens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fb59e6fa7ef3da1d1541e9e8b3e25ad/href">https://medium.com/media/7fb59e6fa7ef3da1d1541e9e8b3e25ad/href</a></iframe><figure><img alt="A circle with a partial solid outline" src="https://cdn-images-1.medium.com/max/585/1*wjV79LelDUwwTTaY-UzvhQ.png" /></figure><p>Do you see where this is going? 😏</p><h3>Time to Animate!</h3><p>To get the progress ring effect we’re after, we just need to animate strokeDashoffset from the circle’s full circumference to zero. This is pretty straightforward with Reanimated 2.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8380346498169672ee1eaa811327b67/href">https://medium.com/media/d8380346498169672ee1eaa811327b67/href</a></iframe><figure><img alt="A circle with an animated outline" src="https://cdn-images-1.medium.com/max/320/1*wHNj3TToqdEtwytF5UQxBw.gif" /></figure><p>There are a few things to understand here.</p><ul><li>We create a new component called AnimatedCircle by passing React Native SVG’s Circle through Reanimated’s createAnimatedComponent . This will allow us to animate the component’s props using Reanimated</li><li>We create a shared value for stroke offset, initially set to the circumference of the circle so our stroke isn’t visible</li><li>With useAnimatedProps , we define a withTiming animation to handle changes in the strokeDashoffset value</li><li>With the useEffect hook, we update our shared value of zero, thus kicking off our progress ring animation</li></ul><p>It’s that simple to create beautiful progress ring animations with Reanimated and React Native. Of course, progress rings are usually accompanied by a numeric indicator, often expressed as a percentage. We can animate that, too!</p><h3>Animating percentage text</h3><p>We can apply many of the same principles we used to animate our circle and use them to animate our percentage text.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82348b28abc532cc65daf2874c74a71b/href">https://medium.com/media/82348b28abc532cc65daf2874c74a71b/href</a></iframe><figure><img alt="An animated progress ring that goes from 0 to 100 percent" src="https://cdn-images-1.medium.com/max/320/1*ExEKKl0ZjkY6RWVuxzOiIQ.gif" /></figure><p>Here’s what we’ve added:</p><ul><li>We create a new component called AnimatedText by passing React Native’s TextInput through Reanimated’s createAnimatedComponent . This will allow us to animate the component’s props with Reanimated</li><li>We create a shared value called percentage that converts the stroke offset value to a number between 0 and 100, to track the animation’s progress</li><li>With useAnimatedProps , we create an animated text prop that we can pass to our AnimatedText component</li></ul><p>Now you have a silky smooth progress ring with animated percentage text!</p><p>What’s that you say? You want to animate the color of the progress ring from red to yellow to green as it moves from 0 to 100% percent? OK, we can do that easily with Reanimated.</p><h3>Animating the progress ring color</h3><p>We can add the color animation we want with just a few more lines of code, thanks to Reanimated’s interpolateColor</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6edec0ff9b5c1233bd67bf7f714b2c53/href">https://medium.com/media/6edec0ff9b5c1233bd67bf7f714b2c53/href</a></iframe><figure><img alt="An animated progress ring that goes from 0 to 100 percent and changes color from red to yellow to green" src="https://cdn-images-1.medium.com/max/320/1*o08cUOZtO43i_7NT7b1Jiw.gif" /></figure><p>Here we create a new strokeColor value with useDerivedValue . To get it, we use interpolateColor to map our percentage value to the colors we want to animate. After that, we add our stroke color value to our animatedCircleProps and that’s it!</p><h3>Conclusion</h3><p>I hope this post has given you the knowledge to start creating your own progress rings and other animated circle components with Reanimated. I’d love to see what you build; tag me on twitter <a href="https://twitter.com/useRNRocket">@useRNRocket</a>! As always, comments and corrections are welcome! Follow me here and on Twitter for more React Native and Reanimated content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c19ad2115b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/react-native-rocket/animating-progress-rings-with-react-native-reanimated-2-9c19ad2115b">Animating Progress Rings with React Native Reanimated 2</a> was originally published in <a href="https://medium.com/react-native-rocket">React Native Patterns</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>