<?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 Wojciech Ogrodowczyk on Medium]]></title>
        <description><![CDATA[Stories by Wojciech Ogrodowczyk on Medium]]></description>
        <link>https://medium.com/@sharnik?source=rss-8d58addab3eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*G2YQctaoCe8Ozlbw27HaxQ.jpeg</url>
            <title>Stories by Wojciech Ogrodowczyk on Medium</title>
            <link>https://medium.com/@sharnik?source=rss-8d58addab3eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 18:40:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sharnik/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[Moving away]]></title>
            <link>https://medium.com/@sharnik/moving-away-d42aa29f60b?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d42aa29f60b</guid>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 05:55:12 GMT</pubDate>
            <atom:updated>2021-01-15T05:55:12.319Z</atom:updated>
            <content:encoded><![CDATA[<p>In case you’re wondering why it got so quiet here, I’ve moved my professional blogging to my company’s site: <a href="https://brainsandbeards.com/blog">https://brainsandbeards.com/blog</a></p><p>Feel free to add it to your RSS reader, or whatever’s the way you follow content online. Hope to see you there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d42aa29f60b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling runtime application permissions in Detox]]></title>
            <link>https://medium.com/brains-beards/handling-runtime-application-permissions-in-detox-d5759fc2ca2c?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5759fc2ca2c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Fri, 17 May 2019 11:01:01 GMT</pubDate>
            <atom:updated>2019-05-17T11:01:01.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>Problem</h3><p>One of the problems when working with <a href="https://github.com/wix/Detox/">Detox</a> as a framework for end-to-end testing in your React Native application is unclear platform support. Once you dive into the project it quickly becomes clear that most people use it with iOS and a lot of Stackoverflow questions, answers, guides, etc. don’t mention platform differences, even though that’s sometimes crucial.</p><p>A good example of when it becomes complicated is when you try to find the recommended way of handling runtime permissions in your mobile app. The docs mention to use the API that’s provided and a lot of people on Stack Overflow and GitHub repeat that, saying it all works good, but there are some confused voices that just might not be using iOS 🤷‍♂️</p><p>So, in this blog post I’d like to write in more detail how such a platform-sensitive feature can be addressed in your Detox tests. Hopefully, it will not only give a step-by-step guide to working with runtime permissions, but also show a general approach how we can handle other platform-specific features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ui9Epp2_qfEREyK8lxUlPA.jpeg" /><figcaption>Yet another detox recipe.</figcaption></figure><h3>Solutions</h3><h4>iOS</h4><p>Easy, just use <a href="https://github.com/wix/Detox/blob/master/docs/APIRef.DeviceObjectAPI.md#devicelaunchappparams">the provided API.</a> It lets us launch the app in a mode where detox will take care of accepting particular permissions as they are being asked for.</p><p>In that case, we can specify in our test whether we’re going to accept or deny permissions and handle both cases accordingly.</p><h4>Android</h4><p>However, the API described above relies on using <a href="https://github.com/wix/AppleSimulatorUtils">AppleSimUtils</a>, so it won’t work when we run our tests on the Android platform. We’ll need a different solution for that. Here enters detox’s take on mocking.</p><p>Detox doesn’t allow for per-test mocking, because the idea is that we make a single build of the app, deploy it to an emulator (or a device) and run multiple scenarios against this one build. So, if we want to have something mocked, we need to prepare an alternative file to be used. The details are of course described <a href="https://github.com/wix/Detox/blob/master/docs/Guide.Mocking.md">in the docs</a>.</p><p>But let’s dive a bit deeper into an example that will let us walk through this process.</p><h3>Detox mocking in practice</h3><p>Let’s have an app that makes sure during its onboarding process that the user gave it access to their contact list. A component that takes care of that could look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc54302a10de141698cc5440c9796b8c/href">https://medium.com/media/cc54302a10de141698cc5440c9796b8c/href</a></iframe><p>The problem with end-to-end testing of such a component is that runtime permission modals that pop up are not controlled by the app, so we can’t tell Detox to just tap <em>allow</em>. To be able to move further, we need a way to avoid displaying this modal completely.</p><p>We can start with refactoring the permission request to a separate file. Those changes could look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd845837eae8d0bf187cc4399115ff0b/href">https://medium.com/media/dd845837eae8d0bf187cc4399115ff0b/href</a></iframe><p>We’re still not finished, because although our component has been changed, it still does exactly the same thing. However, as we have extracted a permissions check to a separate file, it’s very easy to mock it out for an optimistic version that always returns true. It could look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48d8dfe91390ecaab893af0c90adcfc9/href">https://medium.com/media/48d8dfe91390ecaab893af0c90adcfc9/href</a></iframe><p>Then, whenever we run the development server with the RN_SRC_EXT argument to specify the extension of the files, those mocked files will replace the original versions. For example, in my app using TypeScript and yarn I would run: RN_SRC_EXT=e2e.ts yarn start</p><p>Of course, that will mean that the app (in this particular build) will <em>pretend</em> that it has the permissions, not actually <em>have</em> them. In that case, when we try to get the contacts from the device, we’ll have to mock it out later as well (which would be a normal testing practise, so I don’t consider that a problem).</p><h4>Dealing with 3rd party modules</h4><p>But what happens when it’s not your code that’s requesting the permissions? For example react-native-camera will ask for camera access the first time it’s used.</p><p>In such a case we can switch the whole 3rd party component for a mocked one. For example, instead of import { RNCamera } from ‘react-native-camera’ we can create a proxy <em>component provider</em> that will decide what component to use. This way for detox testing we can use a mocked version.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/610201b0dc2d3f721c9555be33fd6d32/href">https://medium.com/media/610201b0dc2d3f721c9555be33fd6d32/href</a></iframe><p>Obviously, in this case the mock doesn’t have <em>any</em> functionality, because it’s just an empty View. If we want, we can add to it some API functionality that it might need to offer for our tests to pass.</p><h3>Conclusion</h3><p>As we can see, currently it’s not that straightforward to handle Android runtime permissions in Detox. It might seem a lot of hassle to go through this process. However, let’s keep in mind that (as always in programming) it’s a <em>tradeoff </em>— by using Detox we get faster and more reliable (reproducible) tests than with any other end-to-end solution. I think overall it’s still a big win.</p><p>Finally, if you liked this article, you might want to check the rest of <a href="https://blog.brainsandbeards.com/">our blog</a>. And if you already did, then stay tuned and make sure you subscribe to this blog to get our weekly tips for creating better mobile applications faster 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5759fc2ca2c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/handling-runtime-application-permissions-in-detox-d5759fc2ca2c">Handling runtime application permissions in Detox</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Redux Patterns: Selectors]]></title>
            <link>https://medium.com/brains-beards/advanced-redux-patterns-selectors-cb9f88381d74?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb9f88381d74</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Tue, 26 Feb 2019 12:01:02 GMT</pubDate>
            <atom:updated>2019-03-07T07:46:55.183Z</atom:updated>
            <content:encoded><![CDATA[<p>In our <a href="https://blog.brainsandbeards.com/advanced-redux-patterns-normalisation-6b9a5aa46e1f">previous blog post on using Redux responsibly</a> we talked about state normalisation and its advantages. Some people have suggested that adopting a data schema like that might make it more difficult to access the data that we need, when everything is sorted by ID and stored in a separate <em>table</em>. Today, we’ll talk about best practises around accessing this data.</p><h3>Selectors</h3><p>This term is pretty descriptive — it’s something that you’d use to select the data that you want from the store. You’ve probably already seen code like this:</p><pre>const SomeConnectedComponent = connect(<br>  state =&gt; ({<br>    lang: state.i18n.locale,<br>  }),<br>  dispatch =&gt; ({})<br>)(SomeComponent);</pre><p>As you can see we use state.i18n.locale to <em>select</em> the data that we want (the user’s locale) from the global state. This works fine and on the surface it looks like everything is great.</p><p>However, it does couple the internal implementation of the component to a particular data schema used. For instance, it depends on the application state looking like that:</p><pre>{<br>  i18n: {<br>    locale: &#39;en&#39;<br>  }<br>}</pre><p>But in the future we might want to change the format to something a bit different. For example, we might want to make it a richer object, to contain some meta-data:</p><pre>{<br>  i18n: {<br>    locale: { <br>      name: &#39;English&#39;,<br>      simpleCode: &#39;en&#39;, <br>      fancyCode: &#39;en_EN&#39;<br>    }<br>  }<br>}</pre><p>This would mean we’d have to track down all the state.i18n.locale uses in the app and adjust them to the new format and this might be tricky and error-prone. How about if we had a helper function that we could use instead? 🤔</p><p>It could be something as simple as:</p><pre>getLocaleCode = (state) =&gt; state.i18n.locale;</pre><p>This would be our selector.</p><h3>Advantages of using explicit selectors</h3><p>There are a few advantages of using explicit selectors. Let’s go through them one by one.</p><h4>Clear API</h4><p>There’s no need for every component in your app to know the internal schema of our data store.</p><p>If we were writing backend code, it would be wildly considered an anti-pattern and we’d be advised to follow a <em>Single Responsibility Principle</em> and create a separate class / service to take care of extracting data from our “database”, or somebody might even mention using a <em>Query service</em> in a code review.</p><p>In the frontend world we tend to think much lighter of software architecture, which sometimes can be an advantage (when we can deploy simple projects much faster), but with the project’s growth it might turn into a nightmare (where we introduce bugs every time we try to change anything).</p><p>Creating (even simple) selectors from the beginning of the project helps us to keep a separation between the data layer (the Redux state) and the UI layer (our React components). Our code is read many times, while we write it just once. It’s silly to optimise for writes in such a read-heavy environment. (Oh look, a database pun! 🤗 )</p><h4>Easier refactoring</h4><p>As in the example above, using selector functions helps us refactor our store schema much easier. We can keep the same API (the selector functions that we use to access the state), but just change them internally to operate on a new data format.</p><p>Selectors add a new level of abstraction, separating the data from the code that accesses it. New levels of abstraction are not always beneficial, but this one is easy to understand and not leaky, so I think that’s as good as they get.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*wwOPL0h9iZIyxVtvrOIsfg.gif" /><figcaption>Thrills of refactoring when not using selectors</figcaption></figure><h4>Performance</h4><p>Finally, we can use the new level of abstraction to offer something that every engineer likes: generalised performance improvements.</p><p>In a codebase where every component queries its data directly it’s very difficult to offer performance improvements to data fetching. You’d have to think of a fix that would work everywhere and then go through each of your components one by one, implementing it. That’s definitely not a fun way to spend your day.</p><p>Instead, using selectors we have a single interface that they all use, so we can implement our performance fixes directly at this level. The obvious thing to do would be to offer data caching — if more components ask for the same thing, we can keep its value cached / memoized to serve it quicker, as long as the underlying data doesn’t change.</p><p>As the old joke says, there are only a couple hard problems in computer science, with caching being one of them, so let’s dive into this subject a bit deeper.</p><h3>Caching selector results: reselect</h3><p>Of course, we’re not the first ones with this problem, so <a href="https://www.npmjs.com/package/reselect">there’s an NPM module for that</a>. Reselect lets you easily add level of caching (also called <em>memoization</em> when we talk about caching function output) to your Redux store queries. You could try to use it to memoize your <em>locale</em> selector, but… After implementing such change we’d probably run our app again and notice that <em>nothing changed</em> 🤔</p><p>After a brief consideration you might reach a (quite reasonable) conclusion that it didn’t magically speed up your app, because getting user’s locale probably isn’t the performance bottleneck of your app. The performance bottlenecks lie in more elaborate data queries.</p><p>For example let’s take our article-writing app that we talked about in our <a href="https://blog.brainsandbeards.com/advanced-redux-patterns-normalisation-6b9a5aa46e1f">Normalisation blog post</a>. We can imagine that for such a simple app we quickly run out of reasonable features to implement and we start working on tasks that are as… let’s say <em>sophisticated</em> as “user can see the list of the last tags they used”.</p><p>How would we get such a list if we don’t keep track of when tags are used? Let’s say we choose to implement it like this:</p><ul><li>get all the articles</li><li>sort them by when they were modified last</li><li>map them into a list of tags that were used</li><li>clear up this list from duplicates</li><li>pick a few of the first ones as our “last tags used”</li></ul><p>Now, this definitely feels much more like a performance bottleneck! 🧐</p><p>In such a case we could use reselect to cache the result like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e28f536d1b0d3de35d8a109a00f9e4ff/href">https://medium.com/media/e28f536d1b0d3de35d8a109a00f9e4ff/href</a></iframe><p>The crucial line is the createSelector(…) method call. This creates a <em>cached</em> selector for us to use. This means that the result it computes is going to be saved, along with the parameters that were used to compute it. At any subsequent call it will compare whether any of the state values that we use there has changed. If they didn’t, it will return the same value that it calculated earlier, without going through the expensive process again.</p><p>So, running this code give us the following result:</p><pre>Computing recent tags…<br>[ &#39;old ones&#39;, &#39;short story&#39;, &#39;insanity&#39;, &#39;novel&#39; ]<br>[ &#39;old ones&#39;, &#39;short story&#39;, &#39;insanity&#39;, &#39;novel&#39; ]<br>[ &#39;old ones&#39;, &#39;short story&#39;, &#39;insanity&#39;, &#39;novel&#39; ]</pre><p>We can see that the calculations has been done only once, the second and third results are served from cache.</p><p>That works pretty well in case of our simple (if a little crazy) example. However, when we face more complicated real-world uses, we’ll probably find reselect’s caching mechanism to be a little bit limiting and we’d want more control over when and how do we cache the results. In such a case we’d go one step deeper (or one level of abstraction higher) and use re-reselect.</p><h3>Hand-crafting your caching with re-reselect</h3><p>Reselect seems like a great plug-and-play generalised solution for the problem of selector caching. It’s simple to use and easy to start with (which is wonderful!), but with this simplicity come some usage limitations.</p><h4>Caching more results</h4><p>One of the problems that you’ll probably hit with reselect pretty soon is connected to the fact that each selector has a cache limit of one. Instead of keeping a small store of cache results (for argument A the results was X, for argument B it was Y, etc.) we can only keep track of the last computed argument — result pair.</p><p>Let’s look at a simple feature where this might be a problem. Imaging that in our article writing app we would like to be able to see which tags have been used in a particular year. Using reselect this gets a bit complicated, because we’re basically limited to only passing one argument (the app state) into our selector (only the first argument is used to check for caching). That means that if we wanted to cache that we’d need to create multiple selectors, one for each year, like this:</p><pre>const tagsFrom1918 = createSelector(…);<br>const tagsFrom1919 = createSelector(…);<br>const tagsFrom1920 = createSelector(…);</pre><p>As you can see, that seems a bit over the top. Of course, we could create a <em>selector factory</em>:</p><pre>const makeYearlyTagSelector = year =&gt; {<br>  return createSelector(<br>   // custom selector definition for a particular year<br>  );<br>}</pre><pre>const tagsFrom1918 = makeYearlyTagSelector(1918);<br>const tagsFrom1919 = makeYearlyTagSelector(1919);<br>const tagsFrom1920 = makeYearlyTagSelector(1920);</pre><p>This is not only a bit verbose, but comes with a strong disadvantage. Because such selectors would be dynamically created in each component that uses them, they wouldn’t share the cache between themselves (because they’re different selectors that just coincidentally work the same way). This means that if we want to get the same information in two different components, we’d have to instantiate two selectors and compute it twice, not once.</p><p>With re-reselect, you can handle this problem in a better way. Let’s first take a look at the solution and we’ll break down the differences afterwards:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edaa29f1870075f36cc137610012d4db/href">https://medium.com/media/edaa29f1870075f36cc137610012d4db/href</a></iframe><p>The output of this code is the following (notice that we only compute the values twice and the last function call hits the already existing cache):</p><pre>Computing recent tags with re-reselect…<br>[ &#39;old ones&#39;, &#39;short story&#39; ]<br>Computing recent tags with re-reselect…<br>[ &#39;insanity&#39;, &#39;novel&#39; ]<br>[ &#39;old ones&#39;, &#39;short story&#39; ]</pre><p>There are two big differences worth noting here. Let’s take a look how it looks in a more general form:</p><pre>const someSelector = createCachedSelector(<br>  [selectorA, selectorB, functionThatExtractsAnArgument],<br>  (valueA, valueB, selectorArgument) =&gt; {<br>   // Selector magic goes here<br>  }<br>)((state, someArgument) =&gt; {<br> // We compute the cache key here<br>});</pre><ul><li>When we’re using the createCachedSelector function, it not only defines the selector, but also the way we determine the cache key for it. We have two specify both. See how it’s broken down into two parts above.</li><li>Take a closer look what arguments createCachedSelector takes. In reselect we had a bunch of state selectors (for narrowing down what parts of state we’re dealing with) and at the end we had a function that takes all the values that came out of those state selectors to compute the result. In re-reselect, apart from state, we also get arguments from the selector function call itself (like we are passing year for our tag computation), so we also need additional <em>input selectors</em> to extract those. They will be later passed to the final <em>computation function</em> in the same way as the values from the state selectors.</li></ul><p><strong>What’s the benefit again?</strong></p><p>Let me rehash the biggest advantage that we get. Using re-reselect we get <em>parametrised cached selectors</em> that we can reuse all over our app, but still getting the advantage of the common cache that they share.</p><p>All of this with, arguably, cleaner syntax than a selector factory that we’d have to use otherwise.</p><h4>Getting more control with custom cache keys</h4><p>With re-reselect we need to define a cache key to use when creating our cached selector. It’s no longer computed automatically (as it is when using pure reselect) and we have full control over how it’s created.</p><p>Most often, you’d use a string or a number as the cache key (as in the example above). This would be typically a parameter (or a string being a unique combination of different parameters) for the selector. However, for more elaborate cases you have also an option to use a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map object</a>.</p><p>Of course, there are also various caching strategies (around cache size and which values get expired first) available for you to use and even a possibility to create your own. It’s all controlled by the <a href="https://github.com/toomuchdesign/re-reselect/#optionscacheobject">(</a><a href="https://github.com/toomuchdesign/re-reselect/#optionscacheobject">cacheObject option)</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*2WWkuocDUL01KvZGy4olOg.png" /><figcaption>Low-level cache management possible with re-reselect</figcaption></figure><h3>Summary</h3><p>After reading this blog post you’ve read how and why to use custom selectors for your Redux store. We hope it motivated you to give a closer look at how it’s implemented in your applications and make sure you take advantage of caching to memoize any of the expensive transformations that you make 💪</p><p>If that’s a topic that you found interesting, you should probably check out also our blog post on <a href="https://blog.brainsandbeards.com/advanced-redux-patterns-normalisation-6b9a5aa46e1f">data normalisation in Redux stores</a>. As you have probably noticed, those two subjects go closely together.</p><p>Also, stay tuned and make sure you subscribe to this blog to get our weekly tips for creating better mobile applications faster 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb9f88381d74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/advanced-redux-patterns-selectors-cb9f88381d74">Advanced Redux Patterns: Selectors</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Beautiful Apps: Drops]]></title>
            <link>https://medium.com/brains-beards/building-beautiful-apps-drops-969feebd3ad5?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/969feebd3ad5</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Tue, 12 Feb 2019 00:11:00 GMT</pubDate>
            <atom:updated>2019-02-13T18:49:27.649Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve recently had a chance to talk with <a href="https://twitter.com/itchingpixels">Mark Aron Szulyovszky</a>, one of the founders and developers of <a href="https://languagedrops.com/">Drops</a> — a beautiful vocabulary learning app.</p><p>Google named Drops as one of the <a href="https://play.google.com/store/apps/topic?id=campaign_editorial_bestof2018_best_self_improvement&amp;hl=en_US">best apps of 2018</a>. What is particularly interesting for us, Drops has been written in React Native, which despite its continuously growing popularity and success, many still not consider a suitable tool for building <em>quality applications</em>. Fortunately, with examples like Drops, we can see that it’s not the framework that matters, but the team and the mindset.</p><p>We’ve decided to publish this interview here in its entirety, so that you can learn a lot of interesting insights from Mark!</p><h3>Interview</h3><h4>Application domain</h4><p><strong>Wojciech</strong>: Thank you for taking the time to talk with me. I wanted to start with getting to know more about you, what made you start Drops, and what’s your mission behind it. Could you start by talking a bit about that?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*UmxRiaQ-tURQGX375jMP4w.jpeg" /></figure><p><strong>Mark</strong>: Yeah, sure! The company started around 7 years ago. I was a designer back then, we were creating visual trivia, that was quite fun! Then I met Daniel, my co-founder and we decided to do a spin-off from the visual riddles to try to make it more useful and use it in education.</p><p>The theory was that by combining the visual riddles with educational content, in this specific case — foreign words, we would be able to do something that’s much more effective on a subconscious level. While your brain is trying to put together the puzzle, it helps form a stronger active connection with the foreign word that it’s also seeing in the screen. So, this app was called Learn Invisible and we’ve gone into an Estonian startup incubator, around six and a half, or seven years ago. That’s when we actually funded the company, so the company is Estonian, although we’re both with my co-founder originally from Budapest. Then the original app didn’t turn out as well as we thought, we weren’t as experienced and, let’s say, as thoughtful, about who we are actually building this for and what we want to achieve exactly. We were quite naive to be honest.</p><p><strong>Wojciech</strong>: So, this was mostly a learning experience?</p><p><strong>Mark</strong>: Definitely. But the company’s kept going. We got originally four co-founders, two of them have left and we are two now, which is fine. We have never raised money other than the original seed round (which is probably pre-seed in any meaningful way) from the startup incubator that got us a runway of about 3 months and then everybody was working on it in their free time from that point on.</p><p>Then based on that experience we did give the education another go, we realised a few things that were wrong with the previous app, how to make it more user-friendly, a lot more interactive and mobile-optimised. That was at the time when Tinder, Uber, and many other services were starting and these guys were taking over the mobile space. Mobile was getting a huge amount of traction, so we thought that all the others — Duolingo, Babbel, etc. are a little bit behind, as they did a rather 1:1 port of their web app to mobile. They were still successful, but we felt we could do something more — a mobile-first language learning product. So, that was Drops. We released it about four years ago and we started getting traction around two and a half years ago.</p><p><strong>Wojciech</strong>: Four years ago it clearly wasn’t React Native. Was it a native application?</p><p><strong>Mark</strong>: Yes, it was a native application. We have rewritten it from scratch at one point in React Native, but we can get into the details of that a little bit later if you want to.</p><h4>Interactions as a learning tool</h4><p><strong>Wojciech</strong>: You made Drops with a principle in mind to make it “the most interactive vocabulary learning app”. Why focus on the interactions?</p><p><strong>Mark</strong>: We though that is why we are different from the others, because we managed to do something that feels like a game. It has a <em>game</em> <em>feel</em>. I’m not sure if everyone’s familiar with this term. Gameplay designers use it to describe where you have a very basic version of the game and you add effects to it that make a huge difference. I think we were the first ones that put a lot of effort into it.</p><p>We approached it as a design problem, not necessarily as a learning problem. Our idea was to approach it as a game. The benchmark was — if I could play with this for 15 minutes as a designer who hasn’t really learned a language for a long time and I’m still not bored, but I’m enjoying it, then this is something that we that can help other people getting into this space — keeping up their motivations and giving them the initial sense of success, which is necessary to keep the routine going.</p><p><strong>Wojciech</strong>: There’s definitely something there. Myself, I went through four different vocabulary learning apps and I think definitely Drops is the one that is the most fun and the one that I stuck to the longest. Because when you think of vocabulary learning it doesn’t seem exciting by itself, so it’s obvious that the gamification that you added plays a big role.</p><p><strong>Mark</strong>: Yeah, definitely. What you said is exactly what we are all about. Learning vocabulary is by default, you know, a chore. And if we can make it something that’s a lot more interesting and much more enjoyable then we’re winning on so many fronts already. That’s why we dedicated ourselves to this domain, to the small product company that we’re sticking to for the next few years at least. There’s a lot of potential here that we still haven’t really reached.</p><p><strong>Wojciech</strong>: I saw that you’ve also released another language learning application: <a href="https://languagedrops.com/scripts/">Scripts</a> for learning alphabets. Do you have plans to cover more aspects of language learning?</p><p><strong>Mark</strong>: That’s correct, we released it a few months ago. It has been seeing some success, which is encouraging. It’s definitely something that we’re really interested in and we’ll be covering more and more of language learning. One of the interesting things you’ll be seeing from us is that we’ll attach metadata to those words, so it’ll be easier for you to remember them, to put them in context and use them in real life.</p><h4>Design process</h4><p><strong>Wojciech</strong>: Drops is definitely an eye-catching application and a delight to use. In the world where a lot of applications get build using static designs that are being handed off through a tool like <a href="http://zeplin.io/">Zeplin</a> from designers to developers, clearly Drops looks like it’s from a different world. Could you share a bit about how your design process looks like?</p><p><strong>Mark</strong>: It’ll probably be a little more casual than what you might think. We’re a small team, we’re around 15 people. We have one designer and four developers, including myself, although I don’t really code much these days.</p><p>We have Thomas who is prototyping few things in <a href="https://framer.com/">Framer</a> and some other tools and then handing them over. It’s probably the main source how we’ll be approaching creating new interactions. We’ve used Keynote in the past for prototyping, also for interactions. Our process is mostly about prototyping things, seeing what works, adding some subtle effects and checking whether it makes the whole interaction easier to understand and finally cutting out some of it in the end. It’s very, very organic.</p><p>What we’ve been having a lot of fun with is using a physics engine, which helped us provide subtlety of the interactions, the bounciness and interactiveness. That’s a great differentiator that I’d love to hold onto if we can. Although, it doesn’t really makes sense in some other cases.</p><p>Just to some it up: we have an idea, we use paper sketches, then we use Keynote, Framer or something similar, and then we have someone from the tech team to try and make it work. We’re still iterating on it while we are implementing the actual interaction. There’s a bunch of stuff we only figured out in the last minute — how to handle specific words, how to deal with some edge cases, etc.</p><p><strong>Wojciech</strong>: When you mention Framer, their new X version has some <a href="https://framer.com/features/react/">React compatibility features</a>. Did you have a chance to use them?</p><p><strong>Mark</strong>: No, not just yet. To be honest, the code we use in Framer is easy for us to re-implement. We haven’t looked at the Framer X, or React component export part, but right now it’s difficult for me to imagine how the code that we have right now could have been produced by Framer. Maybe some base form of that.</p><p><strong>Wojciech</strong>: Definitely, your components must be more complicated than the typical case. One last question on your design process: do you think the UI that the Drops has is the product of this organic process that you have, or would you like to have it more rigid. Is there something that you’d want to improve in your design process?</p><p><strong>Mark</strong>: Actually, we got to the point when we did become more rigid. For example we said that every time that we A/B test a feature when we see that it’s working well and we’d want to roll it out for everyone then we add animations to all the pages (or components) that we just added. These are usually appearance, or disappearance animations, that’s the part which we agreed will be important part of our development process. This is a huge part of the Drops visual design DNA.</p><p>All of the companies probably inherit something from their founders. Sometimes that’s bad, sometimes that’s good. I think this product has inherited quite a bit from us and our approach — I was really into UI animations. I was working as a UX prototyper for a while on creating new interactions. That’s probably why we ended up here with the <em>interactiveness</em> and then we tried to basically follow that path when we hired people. We hired our frontend developers, Fadani &amp; Anton, who do care a lot about the UI that they’re building, they raise issues, they figure out things on their own and we hired Thomas, our designer who has a great eye and who is able to express himself in various forms regarding the interactiveness of the app.</p><h4>Working with animations in React Native</h4><p><strong>Wojciech</strong>: Definitely you got something that’s working really well and I hope we can all learn from it. Could you tell us more about how you implement those interactions? Do you use Animated from React Native a lot, or what other tools and frameworks do you use?</p><p><strong>Mark</strong>: We are using a lot of Animated from the React Native library and we simply use PanResponders to move them around. What we are also using is we are storing the animated values in state and we’re trying to pass in PanResponders to multiple views if we can and we try to make sure we’re not re-rendering the whole screen and the whole Redux state every time there’s been a PanResponder change.</p><p>We had a bunch of problems, especially in the very beginning, with performance. It took us two or three months to get to the stage where we could comfortably say that the performance won’t be a problem in the mid-range Android devices and above. Basically, it’s never been a problem on iOS.</p><p><strong>Wojciech</strong>: iOS devices are usually more powerful.</p><p><strong>Mark</strong>: Yes, but it also feels like React Native has been built for iOS, which I believe is true. Android has always been a second thought.</p><p>Digging a little deeper into it, we had a few React Native views in our native iOS app, because we said at some point that any new view is going to be a React Native view, so that we can make the migration easier on our side, because we knew it was coming soon. And we’d rebuild the whole app for Android in React Native and then release this codebase for the iOS app afterwards, handling all the migrations that were needed. This made for a little bit of cross-polination of our platforms. This was a really interesting experience.</p><p>Basically we’ve built everything for Android from scratch and assumed everything will be working on iOS, which was pretty much true and I’d recommend it this way, not the other way round.</p><p><strong>Wojciech</strong>: That’s a very good way of addressing this issue. I saw that a lot of teams do it the other way round, because the developers themselves use iOS, so they start with this version. It sounds much smarter to do it the way you handled that.</p><p><strong>Mark</strong>: It has been working well for us for sure.</p><p>We’re using a lot of Animated views. Most of our really interactive components are unfortunately quite <em>stateful</em>. We’d love to try to clean it up, which probably will happen at some point. It has been quite hard to keep everything clean. We realised that there was some stuff that we need to store outside of the React state, because their change doesn’t require a re-render, as we’re using native drivers for the animated values. And every time we re-render a screen Android performance becomes miserable.</p><p>In particular, one thing that we ended up doing is passing Animated Values into a component, but not keeping it referenced in the internal state. Then in the parent component we can use setValue to change it. This way the child component doesn’t track this change (as the reference to the value does not change) and it doesn’t trigger any re-render, but because we’re using the native driver for animations, those values have a direct binding to the native side, so on the screen we can see the changes. This way we could see 60 FPS animations, at least on certain devices that are capable of doing so.</p><p>Every time that we’d be updating the internal state of a component, not even the Redux state, there’s a frame drop on Android. You can probably see that even on the high-end Android device. For example, on the screen when a word appears for the first time when we start dragging the word to a head icon at some point the head opens up. We have a frame drop there, because we need to replace the image with a different image and this will happen in the React realm, so part of the tree will be rendering. The frame drop is visible even on the super-high-end devices.</p><p><strong>Wojciech</strong>: I see that you’re using Animated and PanResponder from the standard library. Did you consider using react-native-reanimated or react-native-gesture-handler libraries?</p><p><strong>Mark</strong>: We did. And we do have a prototype somewhere with it. The react-native-gesture-handler definitely gave us better performance.</p><p>The reason why we didn’t end up using them was that there was one issue with certain iOS versions that was somewhat concerning and it didn’t seem like it is resolved. This would completely break the whole experience and we were really risk-averse at the time, as there were so many moving parts. Also, we didn’t have any performance problems on iOS. The performance problems only appeared on Android and at that point we were more considering iOS our primary platform. We didn’t really want to do something that could potentially affect badly some of the iOS versions and devices.</p><p>But there’s one more reason. We’re preparing to do something on the web and as far as I can tell the Animated values and PanResponder are mocked up and they’re the universal API that we can use with react-native-web as well and I did not find information about that for react-native-reanimated or react-native-gesture-handler.</p><p><strong>Wojciech</strong>: I think that makes sense, they seem to be more native code focused libraries.</p><p><strong>Mark</strong>: Although, the API can be really similar, or we can do something that could be wrapping both of these at the same time. We just haven’t had the time to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*kxlkJjeNoOvOnVvKgagTTA.gif" /></figure><p><strong>Wojciech</strong>: Do you use any other ways of displaying animations, like for example Lottie?</p><p><strong>Mark</strong>: Yes, we do. The drop animation (when a new word is introduced) is a Lottie animation. We use an animated value to drive the Lottie animation. For orchestrating animations we use the Animated.sequence and things like that.</p><p>We have also written our own higher level component that wraps Animate.sequence that makes sure you don’t get an error when a component gets unmounted that you’d normally be getting when the completion block is called.</p><h4>Debugging performance</h4><p><strong>Wojciech</strong>: It seems like you spent a significant amount of time debugging performance issues. Do you have a workflow to go through it? Is there something that you could share to help other people debugging performance issues related to animations?</p><p><strong>Mark</strong>: There was a time that performance around animations was our main concern. That was a bit tricky and I’m not sure whether we have a particularly good workflow for it. Let me share what we had been doing.</p><p>Obviously, the Chrome debugger doesn’t really work that well, because some of the code is running on the native side and also the JavaScript code is running in your browser, not even on your phone. However, the Chrome debugger and React Native debugger app were really useful for debugging React re-renders and Redux problems. You can do performance, CPU and memory profiling and you get a nice tree of functions that take most of the time.</p><p>We did find some issues, sometimes when we were using a lot of complex selectors, but this is not connected to animations. We did introduce some problems at random times, but later we created unit tests that made sure that the most complex selectors that we’re using are not recalculated unnecessarily.</p><p><strong>Wojciech</strong>: I was wondering whether you used reselect for solving these issues?</p><p><strong>Mark</strong>: Yes, we’re using both reselect and re-reselect, because we’re building selectors on top of other selectors and we needed more control over how the memoisation works and a few other things.</p><p>Regarding animations, we tried a few things. Native drivers are working for us very nicely. We’ve written our own wrappers and we’re basically never calling Animated.timing or spring without using a native driver. Except maybe one or two cases throughout the whole codebase where we cannot.</p><p>We never really found issues with animations in general, the issues we did find were around re-renders that we limited by using the setValue technique I described earlier. We did have one issue after a React Native upgrade when things started to be really slow. We found out that on Android when you set a borderRadius larger than what it can be then it will start rendering a huge texture that is the size of the value specified. That was really hard to debug, but once we managed to find out what the problem was, the actual solution was pretty easy.</p><h4>Creating custom navigation</h4><p><strong>Wojciech</strong>: As far as I know you also have a custom solution for the navigation. Could you explain why you decided to roll your own?</p><p><strong>Mark</strong>: It was performance. At that time, around one and a half years ago there was basically no way to get any of the navigation libraries (and we did try all of them) only to render the current, visible screen and not any of the others that are on the stack. We thought that’s because the whole system was built on the same foundations how native iOS navigation is working. You push and pop the screens off a stack and views are still retained.</p><p>What we ended up with was something of a mindset shift. We realised that we are more like a game and in games the history of where you came from in the navigation doesn’t really matter. It’s not like on Twitter where you’d be tapping on the profile, then tapping on a tweet and you’d expect to go back through the same screens. But for us this is not the case, our navigation is very simple. We have modals that are rendered on top of the other screens, but that’s the only complication. What we ended up with was somewhat similar to react-router, but a lot simpler, because we could take away the whole abstraction and fit it directly to our domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*i2vE-kt8FIsNg8w2i6pJGA.gif" /></figure><p>We have higher-level, domain-specific routers and then all the screens and props are written into the Redux state. Then we have a huge switch case to determine which component / screen to render. The huge benefit is that all our state is in Redux, so every time we want to change something, or make a snapshot, it’s going to be there.</p><p>It’s also a requirement for us for a different reason. Our interactions are somewhat probabilistic. For example, one of them determines the position of letters in a random order. That order we need to persist between re-renders, so we need to put it in Redux and make sure that it never changes. Otherwise on every re-render the order of letters would be messed up. What we ended up with is to have a props provider for all those interaction type screens, which basically is a kind of map state to props function, but it happens before everything is rendered. We’d persist the order to Redux and proceed from there.</p><h4>Using React Native for complex projects</h4><p><strong>Wojciech</strong>: There is a fame / myth / opinion going around that React Native is more suited for simpler applications that are not interaction heavy. Obviously, you went against this advise and build a really polished application, even went as far to rewrite a native application in React Native. Are you happy with the experience? Would you recommend to others to do it?</p><p><strong>Mark</strong>: We are massively happy about it. When I ask my frontend developer colleagues who I’ve done it with, they say it was a good bet. It was definitely a bet at this point in time. When we started, the React Native ecosystem definitely wasn’t as mature as it is right now. There were so many issues. Actually, we wouldn’t probably be able to release the app before November and we ended up releasing it in December, because there was so much stuff missing, so many bugs, etc.</p><p>But then it became a lot more stable around a year ago. Since then there’s been some regressions, but the ecosystem is a lot more rich, you can find bindings for anything that you want, even any obscure analytics SDK. Around December we were wondering whether we should write our own Zendesk bindings, because there were none and suddenly from one day to the other they appeared and we could just use them. That happened multiple times through the one and a half years that we have spent so far on React Native almost exclusively.</p><p>About the advise, I see no reason why you wouldn’t be able to create a complex app with React Native. I think maintainability-wise having one codebase is a huge plus. All the other cross-platform frameworks suck, except maybe for Flutter that I have never tried. I’m interested in it, but Flutter is basically React Native made by Google, as far as I can tell.</p><p>The approach that React and React Native bring is a massive benefit. If we hadn’t done this, our development team would be at least twice or three times the size that we are now and we’d be having a lot of issues with consistency between platforms. For the web we’d have to re-write the whole app from scratch, because we wouldn’t be able to reuse any of the native code.</p><p><strong>Wojciech</strong>: I wanted to touch a bit about the developer experience. In your team, every developer works on both platforms at once, they need to be familiar with both of them. Was it a problem, did you have to especially look for people who are comfortable doing that?</p><p><strong>Mark</strong>: I think it was a bit hard to use in the very beginning, but we got to the stage when you don’t really have to check. Unless you’re writing something platform specific, like getting something from the bundle of the app directly.</p><p>If you’re just creating UI and there’s something wrong, it gets caught by QA, not by us. I’m using an iOS simulator and I expect everything to work on Android by default. If you’re sticking to UI, there will be very little surprise.</p><p>Maybe when you start using react-native-svg and a few other things there could be some problems, but obviously there’s a person who checks it in the end and it’s really useful. In general, comparing to native mobile experience, it’s been a massive boost to productivity. The live reload part, the super quick recompilation time and just not opening Android Studio, or Xcode can make your day, no matter how sad that sounds.</p><p><strong>Wojciech</strong>: I know exactly the feeling and I’m sure a lot of developers share it.</p><h4>Final advice</h4><p><strong>Wojciech</strong>: That was a very interesting and motivating interview. I found a lot of inspiration in it and I hope other people will too. Is there something else that you’d like to share with other React Native, or mobile developers in general?</p><p><strong>Mark</strong>: <strong>If you’re concerned you can’t do something in React Native, a quick investigation will probably prove you wrong</strong>, or prove that it will be a lot easier to work around anything that you think is a hurdle. We have had great surprises. What we thought will take us time and what we thought would be impossible ended up being super easy to do.</p><p>You will need to have the right patterns to deal with the performance issues, but these are not JavaScript specific I believe. Rather, they’re in general the performance issues that you’d be facing also when writing native mobile code. We’ve seen the same optimisation tricks that we have used for iOS in our native code being used again in React Native for the exact same reasons.</p><p>But what you end up with is a maintainable codebase that has a universal API that is so much nicer to work with than anything you can currently have on the native side.</p><p><strong>Wojciech</strong>: Thank you, that was great!</p><h3>What’s coming next</h3><p>If you enjoyed this interview, let us know. We’re consistently talking to other developers, especially in the React Native space, and we’re wondering whether it would be beneficial to publish some of those conversations. We’re considering a podcast, more blog posts like this one, or maybe other media. <a href="https://brainsandbeards.com/#footer">Let us know</a> what you think!</p><p>We’re dedicated to help people create applications that not only work reliably, but are also a joy to use and a pleasure to look at. If that’s something that is interesting for you, make sure to watch this space!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=969feebd3ad5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/building-beautiful-apps-drops-969feebd3ad5">Building Beautiful Apps: Drops</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Redux Patterns: Normalisation]]></title>
            <link>https://medium.com/brains-beards/advanced-redux-patterns-normalisation-6b9a5aa46e1f?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b9a5aa46e1f</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Fri, 01 Feb 2019 10:46:01 GMT</pubDate>
            <atom:updated>2019-03-07T07:45:55.690Z</atom:updated>
            <content:encoded><![CDATA[<h3>Normalisation</h3><p>The term <em>normalisation</em> comes from the database world. It refers to transforming the schema of a database to remove redundant information. Also, <em>redundant information</em> means the same data that is stored in more than one place.</p><p>Why is it important? There are many possible reasons, the one that I consider the most important is about offering a <em>single point of truth</em>. It means that there’s exactly one place in the database that contains the true value of <em>something</em>.</p><h4>Single source of truth</h4><p>For example let’s say we have a site with a list of articles and every article has an author. A <em>normalised state</em> would mean that each article would contain a <em>reference</em> to its author and all the author’s data would be in a separate place, in some author store / DB table. In case of a <em>denormalised</em> (not normalised) state / store / DB we could have all the author data bundled alongside the article. Sometimes it might make sense, especially for performance reasons (that could be a form of <em>caching</em>). However, what if we have two articles, both with the same author (we know it’s the same, because the ID is the same), but in our denormalised store we have different names (one says “Joe” and the other says “Bob”) listed under different articles. This could potentially happen, when there’s been an update to the author’s name that hasn’t been propagated well across our whole store.</p><p>That’s why the <em>single source of truth</em> is important. If we had it, we’d know where to look to figure out which name is the correct one and update all the redundant (cached) copies.</p><h4>Performance</h4><p>Another reason to go for a normalised state in Redux is performance. If you have deeply nested structures, it’s difficult to traverse them. It’s much easier to find your data if you have it all filed by their ID in a dictionary / hash / map structure.</p><p>Imagine the performance of finding an article by its ID in a big array of articles (you’d have to go through the whole collection and check IDs along the way until you find it) compared to finding it in a dictionary structure where you can just fetch it directly by the ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*KCtplkwZaV5CQxVy1YPBjA.jpeg" /><figcaption>Normalisation is good, they said.</figcaption></figure><h3>Creating a normalised Redux store</h3><p>Often, the structure of the stores in our applications reflects the format of the data that we receive from the API. However, it doesn’t have to be this way.</p><p>Usually, the format of the data that you receive in your app from your REST API reflects how <em>backend</em> treats this data, which probably will be different how this data should be structured for you. For example, imagine a blogging platform where we use a mobile app to write new articles and browse what we already wrote.</p><h4>Backend</h4><p>The backend side needs to handle thousands of different users, so when one of them signs in using the mobile app and fetches their articles here’s what they do: they look for this particular user, find a collection of all of their articles and send it back to the app. Probably, as an array. Maybe something like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/315947187cef31ec43ac4305a007d4f1/href">https://medium.com/media/315947187cef31ec43ac4305a007d4f1/href</a></iframe><h4>Frontend</h4><p>What would happen in a lot of apps, they’d just store those articles in the same form as they received it — as an array. This would make it easy to store (you can just save the JSON object that you received), but (a bit more) difficult to fetch the articles afterwards.</p><p>Instead of doing that, we should think about what would be the best schema <strong>for us</strong>. Probably, we’d do a lot of accessing by the article ID, so it would be nice to store them in a dictionary that allows us direct access. Also, we might notice that there’s some data redundancy with the tags. Backend returned to us a bunch of strings that get repeated a lot. We could do better by assigning them IDs, storing them in a separate table / dictionary and just reference them in articles. For example, our store could look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5826df73663e8fcc6d059525696b2097/href">https://medium.com/media/5826df73663e8fcc6d059525696b2097/href</a></iframe><p>This store optimises what <strong>our</strong> needs are and how <strong>we</strong> want to access the data inside the mobile app that we’re running. But I can hear you saying:</p><blockquote>It’s such a <em>bore</em> to do this data massaging manually… I don’t want to code it by hand!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*xW4cQS0_Fvt1faynqmrh6Q.gif" /></figure><h3>Automating normalisation</h3><p>Of course, we should automate and speed up this process (and avoid bugs that might pop up in our custom data massaging code). We could use <a href="https://github.com/paularmstrong/normalizr">normalizr</a> for that. Here’s how that could look like.</p><h4>Normalising data using a schema</h4><p>First, we’ll need to define the schema that we want to use. In our case we have two objects (<em>entities</em>): tag and article. We’d have to describe the schema of the object that we originally receive. For the example above, our schema would be the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e30f5667d7e9b81ed1631f04b26ffc9/href">https://medium.com/media/1e30f5667d7e9b81ed1631f04b26ffc9/href</a></iframe><p>The above code defines what a tag (a {} object means that it doesn’t have any nested objects inside) and an article (something that contains an array of tags) look like. Then we try to normalize the data by passing the original object we got from the API and a schema that describes it ({ articles: [article] } tells us we’re dealing with an array of articles).</p><p>Here’s how the normalised state would look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d97894d0faf6e802059068e0fc6ac44/href">https://medium.com/media/7d97894d0faf6e802059068e0fc6ac44/href</a></iframe><p>At first glance, it looks a bit weird with the two main keys: entities and result, so let’s explain what those are:</p><ul><li><strong>Entities</strong> are all the objects that are referenced in our data. We keep them sorted first by their type (tags and articles) and then by their IDs. This lets us to look them up easily. We can think of it as a dictionary of all the objects in our world.</li><li><strong>Result</strong> is the simplified version of what we passed into the normalising function. In our case we passed a list of articles with all of their nested objects, so we get back… a list of articles, just simplified to use the dictionary / entities references. That’s why it looks so simple: { “articles”: [1, 2, 3] }. It’s up to us to use this result in a reasonable way in our app.</li></ul><h3>Normalising state for Redux</h3><p>So, the question arises — how do we use this normalised state to keep track of things <strong>in our app</strong>? We should probably separate two things:</p><h4>Keeping track of what things are</h4><p>One thing that we absolutely need to store in our Redux is the dictionary of all the objects in our world. That’s the entities part described above. Every article or tag that we want to reference in our app needs to be stored there and easily accessible by ID.</p><h4>Keeping track of everything else</h4><p>Of course, it’s an arbitrary case-by-case choice whether a particular piece of data should be stored as an <em>entity</em>, or as something else. In a lot of apps we store data that is only used to power the user experience. For example, we might need to store an ID of the article that has been edited last, or an error message that we received from a recent API call, etc.</p><p>Sometimes we can refactor it to use a local component state for such things (and it’d be better to do so), but not always. Sometimes we have a good reason to store it in the globally accessible state. In such case it might not make much sense to try to force it into a normalised form.</p><p>For example, that’s how our entire Redux state could look like for our article publishing app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa5c1a2ee5e84c09814a83ad2e4c8670/href">https://medium.com/media/aa5c1a2ee5e84c09814a83ad2e4c8670/href</a></iframe><p>We can see here the <em>entities</em> part where we describe all the tags and articles that we’re dealing with and apart from that we can see a couple of fields where we keep track of some values that help us with the application’s UI.</p><p>For example we have an errorMessage variable that we could use to provide a floating error message that follows a user around through different screens and only disappears after you acknowledge its existence. And a lastArticleWorkedOn field that helps the app to re-open the last article that the user was working on when we restart the app.</p><h3>Updating normalised state</h3><p>At the first glance, this might seem like a huge hassle — do I really have to convert all this data that comes from the backend API calls? Fortunately, the normalizr schema that we set up earlier comes to the rescue.</p><p>Whenever we get new articles fetched from the API we could use our schema, convert them to our entities, and trigger a Redux action to update the entities:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20b92be3dc1884027412c6197e44a35a/href">https://medium.com/media/20b92be3dc1884027412c6197e44a35a/href</a></iframe><p>Then, in the Redux reducer, we could handle the state update as simple as that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/001f2b7f6b9b7afdf81a1701eb6ede60/href">https://medium.com/media/001f2b7f6b9b7afdf81a1701eb6ede60/href</a></iframe><h3>Conclusion</h3><p>Using a normalised state in your Redux-powered mobile application doesn’t need to include a lot of manual (and error-prone) data massaging and can be automated. There’s no need to let the backend data format influence the way we store the application state on the frontend side and we can choose to go with formats and schemas that are better optimised for read performance and store size.</p><p>I hope you enjoyed this introduction to the topic of using a normalised state in a Redux application and you will give it a shot next time you’re deciding on your Redux store schema.</p><p>We’re working on presenting <strong>more of advanced Redux usage patterns</strong>, so watch this space to see them published soon. Of course, if you enjoyed reading this article, make sure you share it with your fellow developers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b9a5aa46e1f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/advanced-redux-patterns-normalisation-6b9a5aa46e1f">Advanced Redux Patterns: Normalisation</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Mimic]]></title>
            <link>https://medium.com/brains-beards/introducing-mimic-fd49e7f743ac?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd49e7f743ac</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 10:16:34 GMT</pubDate>
            <atom:updated>2018-12-28T10:16:34.237Z</atom:updated>
            <content:encoded><![CDATA[<h3>Merry Christmas ☃️ 🎄🍴</h3><p>Over the last few months we’ve been working on a desktop app that makes life easier for developers. Now it’s high time we showed it to you! 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXEryPgtdG9sH_iahPJ8bg.png" /><figcaption>Wojciech explaining the value of working offline.</figcaption></figure><p>If you want to see a practical example how this tool works, the fastest way is to watch the video below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8kEgb_hmICg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8kEgb_hmICg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8kEgb_hmICg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d61a88efb0567922c1a978b5fc05c47b/href">https://medium.com/media/d61a88efb0567922c1a978b5fc05c47b/href</a></iframe><h4>tl;dr</h4><p>Long story short, Mimic is a tool for mobile (and web!) developers that have the… challenge of working with APIs they don’t control. It allows them to create an easily customisable local copy of the backend server, so they can carry on working when they go offline, staging servers go down, or they just want to try out a feature that’s not implemented yet.</p><p>If that sounds like you, I’d highly recommend you subscribe to our closed group of beta-testers. We’d love to hear your feedback on what we built before we launch Mimic publicly! 📣</p><h4>Next steps</h4><p>To register for beta-testing, please go to 👉 <a href="http://brains.zone/mimic">Mimic signup page</a> and give us permission to contact you as soon as we can let you in.</p><p>If you’re not into beta-testing and prefer to wait a bit more for the rock-solid version, make sure to subscribe to our blog. We’ll be posting updates about Mimic here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd49e7f743ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/introducing-mimic-fd49e7f743ac">Introducing Mimic</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native meetup in Barcelona]]></title>
            <link>https://medium.com/brains-beards/react-native-meetup-in-barcelona-f14b7d8580da?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/f14b7d8580da</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[barcelona]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Tue, 18 Dec 2018 11:26:29 GMT</pubDate>
            <atom:updated>2018-12-18T11:28:58.364Z</atom:updated>
            <content:encoded><![CDATA[<p>We’ve recently organised a new <a href="https://www.meetup.com/React-Native-Barcelona/events/256726716/">meeting</a> of the <a href="https://www.meetup.com/React-Native-Barcelona/">React Native Barcelona group</a>. It’s been a pretty long time since the previous meetings, so it feels great that we managed to get back to it 💪</p><p>A lot has changed since that last meeting almost one-and-a-half year ago. Back then barely any of the attendees worked with React Native, vast majority where just interested in this technology, mostly web developers wondering how difficult it would be to start developing mobile apps. But now, the ratio was completely different. Half of the attendees works with React Native on a daily basis, some of them in huge organisations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LFUBgmQRYia9WD4X2vfTgQ.jpeg" /><figcaption>Wojciech kicking off the meetup</figcaption></figure><p>Thanks to the support of <a href="http://www.skyscanner.es/">Skyscanner</a>, we could use their great offices to host the meeting. Also, one of their software engineers gave a great introduction to using <a href="https://github.com/wix/detox">Detox</a> for end-to-end testing of your React Native applications.</p><p>However, the part that I particularly enjoyed came after the talks. Almost all of the attendees stayed to chat with their fellow developers, exchange ideas, problems and solutions. I believe that nurturing such local communities is really important, so it was great to see that happen.</p><p>As <a href="http://brainsandbeards.com/">Brains &amp; Beards</a>, we’re really happy that we can help bring this community together.</p><h3>Talks</h3><p>In case you couldn’t attend, here are the notes that I made during the presentations. I hope they’re useful for both the attendees that wanted to refresh their knowledge and those who unfortunately couldn’t join us.</p><h4>End-to-end testing using Detox</h4><p>As mentioned before, this talk was delivered by Samuel Parra from Skyscanner. Sam is a test engineer who turned into a software engineer and his QA background made his perspective particularly interesting. He started by stating that it’s really important to test like the real user would use the application and not only unit test our modules in separation. That’s what they use Detox for in Skyscanner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YFdlYGw6pgaRTptkiCDyQw.jpeg" /><figcaption>Samuel Parra giving a talk about Detox</figcaption></figure><p><a href="https://github.com/wix/detox/">Detox</a> is a <em>greybox</em> testing tool. It means that it has <em>some</em> knowledge about the rendering process, that allows it to be more reliable than the <em>blackbox</em> solutions (like for example <a href="https://appium.io/">Appium</a>).</p><p>After the initial introduction, Sam walked us through how setting up detox test runner for your app looks like. Then he showed us the API he likes to use for writing tests. Basically, he creates a <em>robot</em>/service that knows the nitty-gritty interaction details (for example that in order to book a hotel, it needs to click the third button of a particular component) and use this higher-level API in his tests. The goal here is to have more readable tests that are easier to maintain when the UI changes.</p><p>He also mentioned different problems you might encounter when writing your Detox tests:</p><ul><li>There’s an architectural limitation that you can only interact with particular elements, not with the screen “in general”. It means a bit of a different perspective than the user has. For example, let’s take scrolling a list of elements. From the user’s perspective, they just swipe <em>somewhere on the screen</em>, while in our tests we need to specify which <em>component</em> we’re interacting with. This might be tricky if we specify one that is not visible at the moment and the swipe won’t have any effect.</li><li>Matching elements by text can be flaky, because all the components that are in memory are searched, not just the visible ones. So we might get a match to two components with a particular text, with only one of them actually being visible on the screen. Sam suggests to always use a unique testID instead, to avoid such issues.</li><li>Detox can’t use a real keyboard, only the one from the simulator. So you need to make sure you have the <em>hardware keyboard</em> option in your emulator disabled, otherwise you won’t be able to fill in any input fields in your tests.</li></ul><p>He also shared a trick how to speed up your tests by avoiding costly setup. Normally the app would start on the initial screen and if we want to test something that’s deeper in the hierarchy, we’d have to first navigate there — click buttons, switch screens, render everything along the way, etc. However, there’s a faster way. We can use the openURL API and a deep-link to our content nested somewhere deeper in the app to go there straight away.</p><p><strong>Summing up</strong>, Detox offers as a great advantage of being able to automate the most common manual testing scenarios, saving us a lot of time. It’s also under constant development, so new features are being added and bugs are being addressed.</p><p>On the flip side, we have to remember that end-to-end tests are inherently slow (because they touch the whole stack of your application), which means we can only reasonably maintain a small number of them. This means we’re able to test the <em>happy path</em> through our application to make sure the most important operations are necessary. However, we won’t be able to test all the edge cases.</p><p>Another issue is that Detox tests (like other end-to-end testing solutions) are a bit flaky and sometimes fail for some random reasons like connection timeouts. The error outputs also leave something to be desired, because it’s a bit of an effort to figure out the root cause of the failure from the error message.</p><h4>Using Lottie in React Native</h4><p>The second talk that night was about <a href="http://airbnb.io/lottie/">Lottie</a> — a framework that lets us easily embed <a href="https://www.adobe.com/products/aftereffects.html">Adobe After Effects</a> animations in mobile applications. Lottie project is maintained by Airbnb, but the React Native wrapper for the project is <a href="https://github.com/react-community/lottie-react-native">community supported</a> and we had a treat of hearing about it from its maintainer: Emilio Rodriguez Martinez.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*recsrJJhc80TEYQDVtujpg.jpeg" /><figcaption>Emilio walking us through using Lottie in React Native</figcaption></figure><p>He shared with us the basics of working with Lottie in React Native starting with the setup in out mobile app code. Then he discussed how to prepare the animation: first in After Effects, than using <a href="https://aescripts.com/bodymovin/">Bodymovin</a> to export it as JSON and finally embedding it in our app using Lottie’s React Native wrapper. He also shared a valuable source of examples that we could play with or even use in our apps: <a href="https://www.lottiefiles.com/">LottieFiles</a>.</p><p>Finally, he touched on a few challenges we might face when working with Lottie in React Native:</p><ul><li>Not all the After Effects features are supported by Lottie. This means that occasionally we can create an animation that doesn’t render properly in our mobile application.</li><li>The build process when adding Lottie support to your app is not straightforward. In particular, there are issues when your project uses <a href="https://cocoapods.org/">CocoaPods</a>. It works, but you have to make sure you follow the instructions carefully. It’s not as easy as using other native modules in React Native.</li><li>The React Native wrapper is a community-supported project, so the maintainers don’t have much insight into the development of Lottie itself (as it’s developed internally in Airbnb). That means that wrapper development has to lag a bit behind, as it depends on the native releases to be published first and then catches up.</li></ul><h3>What’s next?</h3><p>It was a really enjoyable evening that we spent with fellow React Native users from our local community. We’re hoping to be able to meet again soon in even greater numbers. Again, thanks to <a href="http://www.skyscanner.es/">Skyscanner</a> for letting us use their Barcelona office and help with all the logistics 🙇‍♂️</p><p>If you want to join our local React Native community, you can do so by joining the <a href="https://www.meetup.com/React-Native-Barcelona/">React Native Barcelona</a> group on Meetup. Hope to see you at our future meetups! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f14b7d8580da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/react-native-meetup-in-barcelona-f14b7d8580da">React Native meetup in Barcelona</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better modals in React Native]]></title>
            <link>https://medium.com/brains-beards/better-modals-in-react-native-8ea6fb207146?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ea6fb207146</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Fri, 07 Dec 2018 06:47:49 GMT</pubDate>
            <atom:updated>2018-12-07T06:47:49.085Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working recently with modal popups in React Native (again!) and realised it’s a recurring pattern in a lot of applications that’s worth writing a bit about. So, here’s a few of my lessons learnt over implementing modal dialogs over and over again 📣</p><p>Note: For a lot of cases you might be just fine using the built-in <a href="https://facebook.github.io/react-native/docs/modal.html">Modal</a> component from React Native. If that solves your problem, all the power to you! 💪 However, in this post I’ll focus on handling situation where you’d like to have more control over the modal component and customise it completely.</p><h3>Basic version</h3><p>Let’s imagine a modal that we can see in a lot of simple applications. In such a basic case, the visibility of the modal is managed internally by some component’s local state. Maybe something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f95be186354f3f848a5252cdc4e70a3/href">https://medium.com/media/7f95be186354f3f848a5252cdc4e70a3/href</a></iframe><p>And here’s how it could look like 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*UAGZU4yXDDpiTCXcdHb4Ew.gif" /></figure><p>This is a typical modal that I’ve seen many times. Its visibility is handled by the parent component by changing its inner state. We’d get showConfirmation from local state and depending whether it’s set or not, show or hide the confirmation dialog. We’d also pass there the handleConfirm and handleCancelbuttons that would take care of the logic that should happen when user presses any of those.</p><p>The main <strong>advantages</strong> of this solution are that it’s simple, easy to read (and reason about) and easy to customise in every view.</p><p>The main <strong>disadvantages</strong> are that even though it’s simple, there’s management code that we need to write in every component that uses it and it can be customised wherever it’s used (which makes it difficult to change it globally).</p><p>So, let’s add a few improvements here 💪</p><h3>Display with a navigation transition</h3><p>One of the things that would make it easier to extract such a dialog into a global component would be to completely separate it from the screen where it’s embedded. A good step to cut any <em>local state</em> ties is to just make it a separate screen that is shown like any other — with a navigation transition.</p><p>In this example I’ll show how we can achieve this using <a href="https://reactnavigation.org/">React Navigation</a>, which I believe is the most popular navigation solution nowadays. When we read the documentation we can see <a href="https://reactnavigation.org/docs/en/modal.html">an example how to implement a fullscreen modal</a>. We can easily follow it and add our own global navigator stack that will decide whether we render the content of our application (normal screens), or our modal:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2ae5e88d28ee22c1b5ff1b4ffb45ab7/href">https://medium.com/media/a2ae5e88d28ee22c1b5ff1b4ffb45ab7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*Kq3AQj9UM2JeXLqT_Z55mA.gif" /></figure><p>After we run this code we can see that React Navigation has really cool support for modals. We can just pass a mode: modaloption to a StackNavigator and we already have some cool modal features and animations. However, the behaviour out-of-the-box leaves something to be desired for our use case, so we’ll have to tune it a bit along the way.</p><p>Now we can use normal .navigate(…) calls to display the modal and remove our local state that manages the visibility of the modal and just pop it into view with a normal navigation transition. Let’s see how that worked out 👈</p><h4>Making background transparent</h4><p>First thing we’d want to achieve is that our modal is not rendered as a completely new screen, but slides over the existing screen. We can achieve that with a mix of a custom transition animation and adding transparency.</p><p>First, for us to be able to see the previous screen underneath ours, we’ll need to make the modals transparent. By default, any screen rendered with React Navigation has a white background. However, we can pass an (experimental) option of transparentCard: true to make it… transparent. We can add it to the navigator options passed when creating AppNavigator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*ls_W40lM0-cNo7vGAZKKLQ.gif" /></figure><p>After this change we’ll see that the modal is indeed transparent, but it’s not exactly on top of our other screen. We have this weird animation that our modal slides in and then the other screen disappears (on an Android phone it would get pushed out of the way).</p><p>So, instead of the background of the previous screen, what we see below is our application’s splash screen 🤷‍♂️ To fix that, we’ll need to add a custom animation to our navigation transition.</p><h4>Customising pop-up animation</h4><p>To customise the way our modal gets pushed onto the screen, we need to add another option when creating our navigator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c66eac65dd6faacd3ea6a629d5c20bf1/href">https://medium.com/media/c66eac65dd6faacd3ea6a629d5c20bf1/href</a></iframe><p>This will pass custom configuration to drive the navigation transition. If you used Animated before, that should feel familiar. If not, why don’t you check out <a href="https://www.youtube.com/watch?v=grR9UmbjpsQ">our introduction to creating animations in React Native</a>.</p><p>This will make our modal screen slide on top of the previous screen, instead of pushing it out of the way, we’re getting one step closer to getting a nice experience:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*peDDbI1kl1QFC5Y9m0Qyng.gif" /></figure><p>One note here, because I know it confuses some people. When we create an <em>interpolation</em> we pass arrays for both input and output ranges. For a simple animation the input is usually [0, 1] and the output [someValueX, someValueY]. In that case it means that the value is <strong>interpolated</strong> between someValueX and someValueY <strong>linearly</strong>. So, in the middle of the animation (in case of a one-second-long animation, after half a second), the value will be exactly in the middle between them.</p><p>However, sometimes we don’t want a linear change, but something more drastic. In that case we can pass more values to both inputRange and outputRange (we just need to make sure their lengths are the same). For example, if we want a one-second animation that changes opacity to quickly go from 1.0 to 0.5 in the first 100 ms and then slow down and linearly go to 0.1, we can create the following interpolation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6738378713c5f72cde3bb45ddd0cdf99/href">https://medium.com/media/6738378713c5f72cde3bb45ddd0cdf99/href</a></iframe><p>In case of our animation, we have inputRange: [thisSceneIndex — 1, thisSceneIndex, thisSceneIndex + 1] and thisSceneIndex is the index of the screen that’s currently being pushed into view. So, the previous screen (which is being covered) will be thisSceneIndex — 1.</p><h4>Fading the background screen away</h4><p>Now we can see our custom dialog screen on top of the previous screen. It’s kind of what we wanted, but not quite. The screen in the back is a little bit distracting, so it would be nice to make it a little less <em>attention-grabbing</em>. For this purpose we could fade it away a little bit, by lowering its opacity. To do so, we can just extend out custom animation transition to look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adafca4e3e48c54167322b3bef5e6901/href">https://medium.com/media/adafca4e3e48c54167322b3bef5e6901/href</a></iframe><p>This should make the screen underneath fade away slightly. Trick question: as we set up its opacity to 0.5, something’s going to show underneath — what it will be?</p><p>If you think <em>any previous screen that the user visited</em>, you’d be wrong. Remember how we added our custom navigation animation, because the the previous screen disappeared? This happens by default to all transitions, so our <em>background screen</em> doesn’t have another screen underneath. Instead, what we’ll see underneath is the application’s splash screen. If your application is like most people’s and it’s just a single colour view with an application logo in the middle, you’re in luck! In that case, we can just use the above transition, because the whole screen will <em>fade</em> consistently (merging with the solid colour of the splash screen).</p><p>If not, and your splash screen is more elaborate than that — well, you’ll have to figure it out Mrs. FancyPants. Let me know if you ended up using any other strategies, I’m always curious to see what works for other people.</p><p>I’m lucky and my splash screen is dark, so we get a nice darkened effect on the previous screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*LDeSsy2I4J3X54r0Tkfstw.gif" /></figure><h4>Disabling gestures</h4><p>One last (visual) thing that I’d like to do is to disable swipe to dismiss. We want to make sure that the user reads our dialog message and chooses one of the options (or acknowledges that they’ve read it). In that case, <em>swipe to dismiss</em> doesn’t really serve us well.</p><p>Fortunately, it’s really easy in React Navigation. We can just supply another option when creating our navigator: navigationOptions: {gesturesEnabled: false}.</p><p>This will disable all the modal gestures and we’ll have to cover dismissing or navigating away from the modal ourselves.</p><h4>Code architecture</h4><p>Okay, now we have a modal that looks and behaves really nice. Time to create an equally nice API for the developers to use.</p><p>Of course, you can choose whatever code architecture you want (it’s JavaScript in the end), let me just share the API I like and find pleasant to work with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3406d66913d07b11c8a3abf69d0a24ef/href">https://medium.com/media/3406d66913d07b11c8a3abf69d0a24ef/href</a></iframe><p>When we have the above defined <em>service</em> that helps us create options for particular types of dialogs (errors, warning, confirmations, etc.), we can use it in any component with the following navigation call:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45f4b207107d4a82e9daa7a0b4977ddf/href">https://medium.com/media/45f4b207107d4a82e9daa7a0b4977ddf/href</a></iframe><p>This code snippet assumes we have a general DialogScreen that can handle any configuration: one button — to dismiss, two buttons — to confirm or cancel, etc. This can get verbose depending on how many different types of dialogs you need to handle. In my case, it’s at least four: warnings, errors, informational and asking for confirmation.</p><p>What I particularly like about this implementation is that those services are typed using TypeScript, so my IDE can easily help me with suggesting which options are required depending on the type of dialog pop-up that I use.</p><h3>What’s next?</h3><p>Next week we’ll publish more material on getting started with using GraphQL in React Native. Afterwards, who knows? 🤔 You can drop us an email if you have any suggestions what you’d like cleared up.</p><p>Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ea6fb207146" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/better-modals-in-react-native-8ea6fb207146">Better modals in React Native</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supercharging your console logs in React Native]]></title>
            <link>https://medium.com/brains-beards/supercharging-your-console-logs-in-react-native-8f1c9fce20f4?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f1c9fce20f4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 09:31:00 GMT</pubDate>
            <atom:updated>2018-11-21T09:31:00.726Z</atom:updated>
            <content:encoded><![CDATA[<p>A common piece of folk wisdom says you can divide the programmers into two groups: those that use <em>debuggers</em> and those that prefer to sprinkle <em>printf</em> (or console.log if they do JavaScript) statements over their code like magic pixie dust.</p><p>I think there’s a lot of value in both of these approaches and they both have their place. Simply outputting the value of a variable in a particular place using a console.log statement is great for confirming your suspicions when you think you know where the problem lies, while debuggers are great for those long sessions when you have no clue what’s going on.</p><p>In this post I’m not trying to tell you which one is better, nor repeat what’s already mentioned in the <a href="https://facebook.github.io/react-native/docs/debugging">official docs</a>, but rather share some techniques I use daily when working with React Native code that help me keep my debugging sessions quick and simple. I hope you’ll find something here that will help you save a couple of minutes on this most common programming task!</p><h4>Displaying complex objects</h4><p>When you’re trying to see what’s inside an object or an array, it quickly gets tiring clicking those tiny arrows to see details. Instead, you could use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Console/table">console.table</a> to have those visible straight away and with a much nicer representation!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*J4lZ8QbO81v24lH7Nf4wOw.png" /><figcaption>Source: MDN</figcaption></figure><p><strong>Tip</strong>: displaying as a table works best for simple objects — arrays or maps / dictionaries / hashes. If you have nested objects this method of presentation gets cluttered and much less readable.</p><h4>Switching Chrome for Reactotron</h4><p>Personally, I don’t use Chrome much and it pains me to run it just to be able to see the debugging logs I’m adding to my application. Instead, I use <a href="https://github.com/infinitered/reactotron">Reactotron</a> to display my logs.</p><p>If you don’t know what Reactotron is and you’d prefer to see a convincing pitch rather than play with it yourself, there’s a whole <a href="https://www.youtube.com/watch?v=UiPo9A9k7xc">conference talk about it</a>. I use it as my <em>remote debugging tool</em> of choice for almost two years now mostly because of the following features:</p><ul><li>Shared timeline that displays all the actions as they’re being dispatched, all the network connections and my debugging logs</li><li>Ability to quickly check the context of my Redux store</li></ul><p>As for the logs themselves, you can still just use basic Reactotron logging that works similar like a console.log would, but you can also go a step further and take advantage of its custom system to get even more out of it.</p><h4>Displaying custom objects</h4><p>Using Reactotron you’re not constrained to just sending console.log and console.warn (in case you didn’t know the latter one, it stands out more) equivalents, but you can fully customise the experience. For example, in my app that shows random Marvel superheroes I could get a log that looks like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hUqdJjzfEy5Ft0ip7Y7cng.png" /><figcaption>Agent Brand, for any brand emergency.</figcaption></figure><p>And the code responsible for it is really simple and customisable:</p><pre>const data = responseJson.data.results[0];<br>console.tron.display({<br>  name: “Superhero loaded”,<br>  value: data,<br>  preview: “Click for details: “ + data.name,<br>  image: data.thumbnail.path + “.” + data.thumbnail.extension<br>});</pre><h4>Easier logging from VS Code</h4><p>If you’re like most of React Native developers nowadays, you probably use Visual Studio Code as your code editor of choice. In that case, you can make your experience of adding logs really easy using the <a href="https://marketplace.visualstudio.com/items?itemName=ChakrounAnas.turbo-console-log">Turbo Console Log extension</a>. See it in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0NpFDnZ1vEdAZXAEouAgjw.gif" /></figure><p><strong>Tip</strong>: the shortcut for inserting the logs is ctrl + alt + l (letter L, like lettuce), <strong>not</strong> ctrl + alt + I (letter I, like iguana) 🤦‍♂️</p><h3>Final word</h3><p>Is that all? Of course not! It’s just a couple of tips to get more value out of the console.log that you use for debugging your app. There’s so much more to debugging than that!</p><p>Useful links to try if you want to read more:</p><ul><li><a href="https://facebook.github.io/react-native/docs/debugging">Debugging React Native documentation</a>: the official docs have more suggestion on tools that you might want to try in your development workflow.</li><li><a href="https://facebook.github.io/react-native/docs/performance">Performance in React Native</a>: the official documentation also has an extensive section on debugging performance problems.</li><li><a href="https://blog.brainsandbeards.com/logging-in-react-native-3bc4e69a4c21">Logging in React Native</a>: another article with practical tips around logging stuff in React Native.</li></ul><p>Finally, you should watch this space. We’ll publish soon another article that focuses on tips for working efficiently with a debugger in VS Code 💪</p><p>Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f1c9fce20f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/supercharging-your-console-logs-in-react-native-8f1c9fce20f4">Supercharging your console logs in React Native</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Help us help you!]]></title>
            <link>https://medium.com/brains-beards/saving-the-world-lets-talk-e0313b50d1a?source=rss-8d58addab3eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0313b50d1a</guid>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[climate-change]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[product-development]]></category>
            <dc:creator><![CDATA[Wojciech Ogrodowczyk]]></dc:creator>
            <pubDate>Mon, 22 Oct 2018 09:20:42 GMT</pubDate>
            <atom:updated>2018-10-22T09:25:06.749Z</atom:updated>
            <content:encoded><![CDATA[<h3>Help us help you</h3><p>It’s been a crazy hot summer, right? We’re a distributed team spread over five different countries, but that’s something that we all agree on. It seems that the recent heatwaves affected all of us. Let me rephrase that: climate going crazy affects all of us. And I don’t mean just the team members at Brains &amp; Beards.</p><p>However, apart from the record temperatures (as it seems to happen every year now, unfortunately…), there are a few more things that got me thinking recently:</p><ul><li>I’ve been to the <a href="http://react-native.eu/">European React Native conference</a>, where I saw a great talk. Not only was it a wonderful performance, but I also deeply resonated with the message. If you were there you probably know very well, which talk I mean. If not, you’re in luck, the videos have already been published and you can <a href="https://www.youtube.com/watch?v=mVcMAtaAwsA">watch it now</a>. Go ahead, I`ll wait.</li><li>Also quite recently, I came across an article: <a href="http://worrydream.com/ClimateChange/"><strong>What can a technologist do about climate change?</strong></a> It’s an interesting enumeration of many possible ways we programmers can help build a better future. We don’t have to drop our jobs filled with interesting technological challenges and go chain ourselves to trees in the Amazon. There’s a lot of place (and need!) for our well-honed skills in our own field. We can save the planet from the comfort of our swivel chairs and standing desks.</li><li>The last thing, probably the most important of them, was my <a href="http://haikuco.de/blog/2018/alternative-lifestyle/"><strong>recent lifestyle change</strong></a> — a couple of months ago I’ve moved into a tiny, self-built house on wheels. One of the side effects was a completely different relationship with basic resources that we usually take for granted: water and electricity. This, combined with reading maybe a bit too much of #solarpunk , gave me a hopeful outlook on what sustainability changes are possible with today’s technology.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SV1SG8Kk-dJ9EOyBhZ146Q.jpeg" /><figcaption>That’s what we are trying to save. Logarska Dolina, Slovenia.</figcaption></figure><h3>How we (all) can help</h3><p>So, what came out of all this thinking? Well, it’s pretty clear what the problem is — Earth is going straight down to hell in a hand basket. It’s also pretty clear on what I can do and (as a co-owner of a software development studio) and <strong>what resources I could leverage</strong> <strong>to help</strong> the situation. Let’s build some software!</p><p>However, being crazy about efficiency and productivity I know it’s a wasted effort to think of and start some new initiative just by ourselves. Instead, it’d be much smarter to join forces with a team that already knows what they’re doing, but needs help from <a href="https://brainsandbeards.com/">software experts</a>.</p><p>So, if you run an environmental project that’s trying to tip the scales on the side of humanity’s survival — let us know and we’ll help you. It won’t be free (there’s a lot of research on why <em>free help</em> isn’t necessarily a good idea), but we’ll offer you <strong>significantly discounted</strong> rates. You’ll get expert help for your project with an affordable budget. The main guideline is: <strong>if you’re helping save the humanity by decreasing our harmful impact on Earth’s resources — we’d probably love to help you</strong>.</p><p>However, what about if you <strong>don’t</strong> run an environmental project yourself? Well, you can still help us help the planet, just keep on reading.</p><p>As everybody, we live in a bubble. Being developers and writing a technical blog, most of our audience are probably fellow developers, not people who mount solar panels in remote Brazilian villages. That’s where <strong>we need your help</strong>.</p><p>Even though we don’t build build revolutionary solar panels, there’s plenty of ways we can help different organisations. Coming right below, there’s a list of problems we’d be particularly interested in (and well suited to!) working on. Maybe one of them rings familiar to you and you can put us in touch with somebody who could take advantage of our offer.</p><h3>What kind of projects are we talking about?</h3><h4>Clean energy</h4><p>The first challenge we’d love to help with is spreading the use of sustainable energy sources: solar and wind. Although we won’t design a more efficient solar panel, there’s still a lot of connected work that fits our area of expertise:</p><ul><li>We can help reducing installation costs by providing software that improves (or automates) workflows. We have a lot of experience working on apps leveraging low-level bluetooth communication, we could easily handle any other types of sensors.</li><li>Public demand is something that drives the adoption of alternative energy sources. We could build better apps for the end users, to help them get more value from their installations and increasing their satisfaction. Happy users mean more recommendations, which lead to more clean energy going around.</li></ul><h4>Reducing meat consumption</h4><p>Long story short, a meat dish requires a lot more of natural resources to prepare than a vegetarian one, with beef being the least environmentally responsible meal choice. Of course, it’s difficult to completely change your eating habits from one day to another, but there are initiatives that nudge people into making better choices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQh7HR2bUqHri59HGO-sXA.jpeg" /><figcaption>Those cows might look pretty in the morning light, but beware of their environmental hoofprint. Random pasture in the south of Poland.</figcaption></figure><p>I’ve lived in a few countries that traditionally are very meat-oriented. In Poland, Spain, or Germany, meat traditionally is the default base of any lunch or dinner dish (except maybe on Fridays). I know that in many cases it’s the external factors that keep us from a healthier diet (good luck being vegetarian in Hungary!). But there are many ways we can improve the situation without a big effort, my personal favourite being the <a href="https://www.ted.com/talks/graham_hill_weekday_vegetarian">Weekday Vegetarian</a> idea.</p><p>However, how can mobile apps make people go vegan? Well, we all know that mobile apps play a big role in forming (and keeping!) our habits. And for many people most of their meat consumption is just that — a habit that can be changed. It’s definitely something that the tiny computer in our pockets can help us with, whether via apps that suggest easy vegetarian lunches you can take to work, or helping keeping track of your meals.</p><h4>Transportation</h4><p>Obviously, transportation sector has a big impact on climate change and there’s a lot that can be improved there. In our case, it’d probably be easiest to focus on two aspects that we already have experience in:</p><ul><li><strong>Carsharing</strong> in big cities helps people to not buy a car at all. Between public transport for everyday stuff and just temporarily hiring a vehicle when we really need one (weekend trip out of town, moving, etc.) you don’t need the hassle of owning, maintaining, repairing and storing your own car. <br>We’ve already been helping for more than two years a company that <strong>operates in Switzerland and Luxembourg</strong> and helps people to share their cars when they’re not using them. We’d love to help in other countries as well.</li><li><strong>Logistics</strong> is another industry that we already have experience with. There’s a lot of improvements that can be made in the efficiency of current delivery systems. Business-wise it’s an easy sell, because any savings in gas emissions are also savings in terms of fuel costs. <br>We’ve worked with a big German logistics enterprise on an internal application for their drivers to help them get their job done easier. We’d love to expand on this experience helping others to cut their costs (and environmental impact) as well.</li></ul><h4>Re-using things</h4><p>In the Western world, we’re chasing a lot of <em>things</em>. We try to have the newest phone, the best <em>this</em>, the most expensive <em>that</em>, etc. What we’re often missing is the purpose of all those objects — why did we get them in the first place. Consumerism is definitely not sustainable and makes us exploit the natural resources at an alarming pace. Cutting down on amount of <em>stuff</em> that we possess is a good way of limiting our negative impact. There are a few ways that instantly come to my mind how we could do that:</p><ul><li>Simply by repairing things. <em>Back in the day</em> when something broke, you would take it to a shop to get it fixed. Nowadays, it’s cheaper to throw it out and order a new one. Unfortunately, in such case it’s the environment that pays the price. However, there are initiatives that help change that. One of my favourite ones is what Patagonia does: they not only offer repair guides for their products, so you don’t have to buy a new one. They even have a truck driving around the country fixing people’s clothes for free. Different example would be the appearance of repair labs — places that keep popping up in bigger cities where volunteers teach ordinary folks how to repair their damaged products — whether that’s a lamp that suddenly stopped working, or a TV that can’t switch channels anymore.</li><li>Another thing that can help here is <em>sharing economy</em>. And by “sharing economy” I don’t mean companies like Airbnb that have little to do with regular people sharing free bedrooms, but a lot with cashing in on provisions wherever they comes from. I mean real local communities helping each other. Just like the case I mentioned above with carsharing, we don’t need to <em>own things</em> in order to use them. You don’t need to buy a drill to put up a picture on your wall, the same way you don’t need to buy a kayak to paddle on a lake.</li></ul><p>However, all of those ideas to work need a strong local social network to work well. And what do we use nowadays for growing our personal “social networks”? Yes, mobile apps. Whether we like it, or not.</p><h3>Conclusion</h3><p>So, if you’re working on an environmental project that needs some help in the mobile department (or you know somebody who does!), let us know. We’d love to help you saving our planet.<br> <br>Let’s join forces! 💪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0313b50d1a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/saving-the-world-lets-talk-e0313b50d1a">Help us help you!</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>