<?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 Aaron Krohn on Medium]]></title>
        <description><![CDATA[Stories by Aaron Krohn on Medium]]></description>
        <link>https://medium.com/@aaronkrohn?source=rss-a6add9cc39bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dcuFcGxqFGH0_CL53n5mIA.png</url>
            <title>Stories by Aaron Krohn on Medium</title>
            <link>https://medium.com/@aaronkrohn?source=rss-a6add9cc39bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:54:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aaronkrohn/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[Stop Bundling Images No One Uses]]></title>
            <link>https://medium.com/creating-totallymoney/stop-bundling-images-no-one-uses-38e39f4666a8?source=rss-a6add9cc39bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/38e39f4666a8</guid>
            <category><![CDATA[app-optimization]]></category>
            <category><![CDATA[mobile-performance]]></category>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[bundle-size]]></category>
            <dc:creator><![CDATA[Aaron Krohn]]></dc:creator>
            <pubDate>Fri, 01 Aug 2025 10:21:41 GMT</pubDate>
            <atom:updated>2025-08-01T10:21:41.146Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>How we trimmed 12% off our React Native app size by checking user pixel density</em></h4><figure><img alt="Illustration showing a mobile app and three image assets labeled 1x, 2x, and 3x, highlighting how different resolutions are handled." src="https://cdn-images-1.medium.com/max/692/1*jDuhyhB20gYf5mL7NmlrvA.jpeg" /><figcaption>Visualising how different image resolutions are bundled in a React Native app — and why removing unused 1x assets can slim down your bundle.</figcaption></figure><p>Bundle size is one of those things that quietly creeps up over time — until users start feeling it. Slower installs. Bigger updates. Frustrated downloads over mobile data.</p><p>At <a href="https://www.totallymoney.com/">TotallyMoney</a>, we decided to shine a spotlight on our bundle size and see what we could do to shrink it down. One small change ended up making a surprisingly big impact: <strong>we stopped bundling image files that never actually got served to users.</strong></p><h3>🛠 Making Bundle Size Visible to the Team</h3><p>First, we added a simple build message to Slack showing the bundle size after each release, along with the percentage change from the last build. Something like this:</p><figure><img alt="Slack messages showing CodePush deployments with iOS and Android bundle size comparisons, giving visibility into size changes per deployment." src="https://cdn-images-1.medium.com/max/692/1*pWp8tvxvR-VVWY3z_Z3WGA.png" /><figcaption>Slack notifications providing visibility into CodePush deployments, highlighting app bundle size changes across iOS and Android for each deploy.</figcaption></figure><p>The goal wasn’t to point fingers — it was about visibility. By surfacing the data, we encouraged everyone on the team to be more aware of what impacted the bundle: unused code, third-party packages… and, as it turned out, <strong>images</strong>.</p><h3>🖼 Image Assets in React Native: A Quick Primer</h3><p>In React Native, you can (and should) supply multiple versions of an image for different screen resolutions. Typically, that looks like this:</p><ul><li>image.png (for standard 1x screens)</li><li>image@2x.png (for retina screens)</li><li>image@3x.png (for high-res screens)</li></ul><p>In code, you only need to reference the base filename:</p><pre>&lt;Image<br>  source={require(&#39;@img/image.png&#39;)}<br>  style={{ width: 44, height: 40, resizeMode: &#39;contain&#39; }}<br>/&gt;</pre><p>React Native automatically picks the correct version based on the device’s pixel density.</p><p>But that got me thinking…</p><blockquote><em>Are we actually serving those 1x images to </em>anyone<em>?</em></blockquote><h3>🔍 Monitoring Pixel Density Across Our Users</h3><p>To find out which image resolutions were actually being used, I added some logging with <a href="https://reactnative.dev/docs/pixelratio">PixelRatio.get()</a> from React Native.</p><pre>import { PixelRatio } from &#39;react-native&#39;<br><br>logEvent(&#39;accessibilityStatus&#39;, {<br>  devicePixelDensity: PixelRatio.get(),<br>  // other analytics data…<br>});</pre><p>This method returns the device’s pixel density as a number. Here’s how some common values map to actual devices:</p><pre>PixelRatio.get() === 1     // mdpi Android devices (160 dpi)<br>PixelRatio.get() === 1.5   // hdpi Android devices (240 dpi)<br>PixelRatio.get() === 2     // iPhone 4–6, xhdpi Android (320 dpi)<br>PixelRatio.get() === 3     // iPhone 6 Plus, xxhdpi Android (480 dpi)<br>PixelRatio.get() === 3.5   // Nexus 6</pre><p>After gathering a decent sample size, it turned out <strong>none</strong> of our users had a pixel density of 1. Almost everyone was between 2 and 3 — which meant the base image.png files were <strong>never</strong> being served.</p><p>And even if a low-density device did sneak in, React Native would still fall back gracefully, using the @2x image when needed.</p><h3>✂️ Time to Cut the Fat</h3><p>Armed with that info, we removed the unused 1x images from our bundle. That alone saved us a decent chunk of space.</p><p>The only catch? <strong>Jest snapshot tests</strong>. They expected image.png to exist, and now it didn’t — so tests broke.</p><p>We fixed it by mocking image files:</p><pre>// jest.config.js<br>moduleNameMapper: {<br>  &#39;\\.(png|jpg|jpeg|gif)$&#39;: &#39;&lt;rootDir&gt;/app/__mocks__/imageFileMock.js&#39;,<br>  // ...<br>}<br><br>// app/__mocks__/imageFileMock.js<br>module.exports = { testUri: &#39;image-test-file-stub&#39; };</pre><p>Problem solved ✅</p><blockquote><strong><em>One caveat:</em></strong><em> we’re no longer asserting the correct image path in tests, since every image now resolves to the same image-test-file-stub. Good enough for snapshots, but worth remembering.</em></blockquote><h3>📉 The Results</h3><p>After cleaning up unused image assets, here’s what we saw:</p><figure><img alt="Slack message showing CodePush bundle size reduction after removing @1x support: iOS down 12.82% (3.71MB → 3.24MB), Android down 9.26% (5.13MB → 4.65MB). Summary table included." src="https://cdn-images-1.medium.com/max/692/1*isiQ9wX_oE-NQB7NgHbpWw.png" /><figcaption>CodePush deployment showing significant bundle size reductions after removing support for low-density (@1x) assets — 12.82% on iOS and 9.26% on Android.</figcaption></figure><p>Not bad for a change that took less than a day’s work.</p><h3>🚀 Why This Matters</h3><p>Bundle size isn’t just a developer concern — it directly affects the user experience:</p><ul><li><strong>Faster updates.</strong> Smaller bundles mean quicker CodePush downloads, which helps us get features and fixes into users’ hands faster. (Check out <a href="https://medium.com/creating-totallymoney/codepush-in-react-native-3ad152206688">Alex Borton’s post</a> on how we optimised CodePush.)</li><li><strong>Lower data usage.</strong> Not every user is on Wi-Fi — some are using mobile data, and bloated bundles can chew through their allowance.</li><li><strong>Install size limits.</strong> Especially on Android, where exceeding the limit can affect installs or trigger warnings.</li></ul><p>What worked for us might work for you too:</p><ul><li><strong>Check real device pixel densities</strong> using PixelRatio.get() — don’t assume.</li><li><strong>Drop unused image resolutions</strong> that aren’t actually being served.</li><li><strong>Mock image files in tests</strong> to avoid brittle snapshot errors.</li><li><strong>Keep monitoring bundle size</strong> — small, consistent wins add up fast.</li></ul><p>Even modest optimisations like this can make a noticeable difference for both your users and your release process.</p><p>Thanks for reading! If you’re tackling bundle size in your own React Native app, I’d love to hear what tricks or tools have worked for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38e39f4666a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creating-totallymoney/stop-bundling-images-no-one-uses-38e39f4666a8">Stop Bundling Images No One Uses</a> was originally published in <a href="https://medium.com/creating-totallymoney">Creating TotallyMoney</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating the Path to App Accessibility: 5 Essential Steps]]></title>
            <link>https://medium.com/creating-totallymoney/navigating-the-path-to-app-accessibility-5-essential-steps-4466285c9132?source=rss-a6add9cc39bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/4466285c9132</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[mobile-accessibility]]></category>
            <dc:creator><![CDATA[Aaron Krohn]]></dc:creator>
            <pubDate>Tue, 03 Oct 2023 07:31:35 GMT</pubDate>
            <atom:updated>2023-10-03T08:08:02.112Z</atom:updated>
            <content:encoded><![CDATA[<p>Making your app accessible can be daunting, and getting started may seem challenging. Here are five essential steps to guide you on this journey.</p><ol><li><a href="#c022">Check links &amp; CTA’s convey their purpose</a></li><li><a href="#37d1">Check UI accommodates varying text sizes</a></li><li><a href="#f0d2">Check touchable elements are the recommended size</a></li><li><a href="#57bf">Check icons scale when text size is increased</a></li><li><a href="#f856">Check if motion is reduced</a></li></ol><h3><strong>1. Check links &amp; CTA’s convey their purpose</strong></h3><p>Ensuring links and Calls to Action (CTA) convey their purpose is vital for app accessibility. It benefits users, especially those relying on screen readers, as it provides clear functionality without needing visual cues. This clarity in link descriptions also enhances the user experience for everyone, making interactions more intuitive.</p><p>Try navigating your app with a screen reader and see if your app makes sense when read out. Here are the screen-reading services provided by each platform:</p><ul><li><strong>TalkBack: </strong><a href="https://support.google.com/accessibility/android/answer/6283677?hl=en-GB">Link on how to enable TalkBack on Android</a></li><li><strong>VoiceOver: </strong><a href="https://support.apple.com/en-gb/guide/iphone/iph3e2e415f/ios">Link on how to enable VoiceOver on iOS</a></li></ul><h4>Example</h4><p>Here are some examples showing how you might improve them.</p><figure><img alt="Displays link copy improvement: from ‘more info’ to ‘View our Financial Guides’ for better context." src="https://cdn-images-1.medium.com/max/692/1*_YjG4vjWUWZhSNLgo8W8gQ.png" /><figcaption>Displays link copy improvement: from ‘more info’ to ‘View our Financial Guides’ for better context.</figcaption></figure><h4><strong>Solutions</strong></h4><p><strong>Educate the team and the wider company:</strong> Engineers, designers, and copywriters might not be aware of users being able to navigate an app with a screen reader, so try to educate them about it.</p><p><strong>Prefer concise and descriptive text:</strong> In cases where conveying all necessary information within the text is challenging, consider programmatically supplying alternative text for screen readers. <em>Note that this approach may involve maintaining two pieces of copy and should be a last resort.</em></p><pre>&lt;Button<br>  accessibilityLabel={`Go to the partner&#39;s site to apply for the ${card.name}`}<br>&gt;<br>  Go to site<br>&lt;/Button&gt;</pre><p><strong>Use an accessibility toolkit:</strong> Allows designers to flag copy where they want to use alternative text for screen readers within their designs before it comes to engineers. Here’s <a href="https://www.figma.com/community/file/953682768192596304">an example of a Figma toolkit</a>. This might take time and links back to the first solution about educating the team because you’re asking designers to change their workflow.</p><h3><strong>2. Check UI accommodates varying text sizes</strong></h3><p>Your UI should be able to accommodate varying text sizes. Although this may seem straightforward, achieving consistency across an entire app can be challenging, especially when many engineers are adding features. Failure in this regard can damage your company’s reputation by rendering information unreadable due to broken UI or cropped text.</p><h4>Example</h4><p>The image below illustrates the UI when a user sets their phone to a large text size. On the left, the UI breaks and crops text in the sections under “More information.” On the right is a fixed version using minHeight for the card instead of height.</p><figure><img alt="UI Issue: Broken on one device UI Fix: On the other device" src="https://cdn-images-1.medium.com/max/692/1*9auXHgOBtZKqmXuEuE0u0A.png" /><figcaption>Showing a User Interface broken on one device and fixed on the other device</figcaption></figure><h4>Solutions</h4><p><strong>Set a larger text size on your simulator:</strong> This step is often overlooked because most developers use the default text size. Encourage your team to test with a larger text size to avoid undetected issues.</p><p><strong>Educate and Raise Awareness: </strong>Use data analysis as a strategy, focusing on user text size preferences. This revealed a significant finding: approximately 27% of our users prefer larger text sizes. This figure has been a powerful advocate for accessibility in discussions with engineers and designers. Interestingly, even a lower percentage could indicate user challenges, affecting app retention.</p><p><strong>Automate checks with visual regression testing (experimental): </strong>I’m looking into running our visual regression tests with the simulator set to a larger text size so that we can automate these checks. I wrote an <a href="https://medium.com/creating-totallymoney/add-visual-regression-testing-to-your-ci-pipeline-for-react-native-apps-bc51a031905d">article on how to add visual regression tests and inline the images</a> into your Pull Request, making it easier to check.</p><h4><strong>Useful links</strong></h4><p>How to change iOS and Android text size</p><ul><li><strong>iOS </strong>— <a href="https://support.apple.com/en-gb/102453"><em>settings &gt; Accessibility &gt; Display &amp; text Size &gt; Larger Text</em></a></li><li><strong>Android</strong> — <a href="https://support.google.com/accessibility/android/answer/11183305?hl=en-GB"><em>settings &gt; Display &amp; brightness &gt; Display size</em></a></li></ul><h3>3. Check touchable elements are the recommended size</h3><p>Ensuring touchable elements adhere to recommended sizes is paramount for app accessibility. This practice guarantees that all users, including those with mobility limitations or who can only use one hand, can effortlessly navigate and engage with your app. By doing so, you align with accessibility guidelines, mitigate user frustration, and cultivate a favourable brand image.</p><figure><img alt="Shows simulator with inspector touchables enabled" src="https://cdn-images-1.medium.com/max/692/1*_FTCwVs7Xnn8_xQ4AE3xEQ.png" /><figcaption>Shows two simulators with inspector touchables enabled.</figcaption></figure><h4>Solutions</h4><p><strong>Educate and Raise Awareness:</strong> Begin by educating your engineering team about touchable element size’s critical role in accessibility, raising awareness about the challenges faced by users with diverse needs.</p><p><strong>Enable Touchable View on the Simulator:</strong> Utilise the React Native Dev Menu to display touchable areas, aiding in visualization during development. <em>(React Native Dev Menu &gt; show Inspector &gt; Touchables &gt; hide Inspector)</em></p><p><strong>Use a Component Library:</strong> Implement a component library with predefined, accessible touchable elements, or integrate them into an existing one. This ensures adherence to best practices and size guidelines.</p><p><strong>Code Reviews and Accessibility Checks:</strong> Integrate accessibility checks into your code review process, prompting developers to verify touchable elements’ compliance with recommended sizes. Automated accessibility testing tools can be valuable for this purpose.</p><p>While attending <a href="https://appjs.co/">App.js</a> 2023 conference this year I met another engineer passionate about accessibility called <a href="https://twitter.com/ceceppa">Alessandro</a>. He’s created this amazing open-source library called <a href="https://formidable.com/open-source/react-native-ama/">React Native AMA library</a>, short for Accessible Mobile App. This library provides a range of accessibility hooks and helper functions. Notably, it can dynamically flag components that don’t meet recommended sizes during runtime, greatly aiding engineers in maintaining size compliance. I’d highly recommend it!</p><h4>Useful links</h4><p>Recommended touch sizes for each platform</p><ul><li><a href="https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/">44x44px on iOS</a></li><li><a href="https://support.google.com/accessibility/android/answer/7101858?hl=en-GB">48x48dp on Android</a></li></ul><p>Others:</p><ul><li><a href="https://formidable.com/open-source/react-native-ama/">React Native AMA library</a> — Accessible Mobile App and contains a set of accessible components and hooks to simplify the building of accessible apps.</li><li><a href="https://play.google.com/store/apps/details?id=com.google.android.apps.accessibility.auditor&amp;hl=en_GB&amp;gl=US&amp;pli=1">Accessibility Scanner app</a> — Accessibility Scanner is a tool that scans an app’s user interface to provide recommendations on how to improve the accessibility of the app. This tool flags if touchables are too small.</li></ul><h3>4. Check icons scale when text size is increased</h3><p>Icons help to clarify an action or attract attention. Therefore, maintaining a well-scaled interface improves the overall user experience. When text size is increased we should look to scale the icon accordingly, otherwise the icon’s purpose is lost.</p><figure><img alt="Comparison of two text-size screenshots: one with icon scaling, the other without." src="https://cdn-images-1.medium.com/max/692/1*aTCqx0H-Ib4ft3x1JjD8oQ.png" /><figcaption>Comparison of two text-size screenshots: one with icon scaling, the other without.</figcaption></figure><h4>Code</h4><p>To achieve this react-native provides a module called PixelRatio which has a method getFontScale() that is the multiplier to the initial text size.</p><pre>import { PixelRatio } from &#39;react-native&#39;<br><br>&lt;Icon icon=&quot;tooltip&quot; size={24 * PixelRatio.getFontScale()} /&gt;</pre><h3>5. Check if motion is reduced</h3><p>Reducing motion in your app is an often overlooked but essential step in ensuring accessibility. It’s crucial to consider users who may have motion sensitivity or disabilities that make excessive motion uncomfortable or disorienting. By minimizing unnecessary animations and providing options to reduce motion, you can create a more inclusive user experience.</p><h4>Example</h4><p>See the GIF below. On the left is reduce motion disabled and on the right it’s enabled.</p><figure><img alt="Comparison of two simulators: one with reduced motion disabled, the other with it enabled and showing loading animations." src="https://cdn-images-1.medium.com/max/1024/1*eE7jlKhOvS4eoq5AOmA0cw.gif" /><figcaption>Comparison of two simulators: one with reduced motion disabled, the other with it enabled and showing loading animations.</figcaption></figure><h4>Code</h4><p>To achieve this react-native provides a AccessibilityInfo module that has isReduceMotionEnabled() method. We subscribe to it because a user can change their setting at any time.</p><pre>import { AccessibilityInfo } from &#39;react-native&#39;<br><br>AccessibilityInfo.isReduceMotionEnabled()</pre><p>In the code below we’re subscribing to reduceMotionChangedand then dispatching setDeviceState to update it in our redux store. <a href="https://reactnative.dev/docs/0.71/accessibilityinfo#addeventlistener">Here’s a list of other events you can subscribe to that react native supports</a>.</p><pre>// AccessibilityStatusLogger.tsx<br><br>useEffect(() =&gt; {<br>  const handleReduceMotionToggled = ({ isEnabled }) =&gt; {<br>    // Update the value in our redux store<br>    dispatch(setDeviceState({ isReducedMotionEnabled: isEnabled }))<br>  }<br><br>  // Log on initial app start<br>  AccessibilityInfo.isReduceMotionEnabled().then(handleReduceMotionToggled)<br><br>  // Subscribes to the &#39;reduceMotionChange&#39; event which when fire will<br>  // execute the &quot;handleReduceMotionToggle&quot; function<br>  const subscription = AccessibilityInfo.addEventListener(<br>    &#39;reduceMotionChanged&#39;,<br>    handleReduceMotionToggled<br>  )<br><br>  return () =&gt; {<br>    subscription.remove()<br>  }<br>}, [])</pre><p>You can then use this value isReducedMotionEnabled to check if you should reduce your animation. Also, it’s generally best to reduce the intensity of animations rather than completely stopping them. Completely halting animations might make the user experience less engaging for all users.</p><p>Reducing an animation may look like this.</p><pre>import { Animated, Easing, StyleProp, ViewStyle } from &#39;react-native&#39;<br><br><br>const AnimatedLoading = () =&gt; {<br>  // Select value from redux store<br>  const { isReduceMotionEnabled } = useShallowEqualSelector(selectDevice)  <br>  const animationProgress = React.useRef(new Animated.Value(0))  <br><br>  useEffect(() =&gt; {<br>      // Its here we use &quot;isReduceMotionEnabled&quot; to change the speed intensity<br>      const timingDuration = isReduceMotionEnabled ? 100000 : 5000<br>  <br>      const timingAnimation = Animated.timing(animationProgress.current, {<br>        toValue: 1,<br>        duration: timingDuration,<br>        easing: Easing.linear,<br>        useNativeDriver: true,<br>      })<br>  <br>      const loopAnimation = Animated.loop(timingAnimation)<br>  <br>      loopAnimation.start()<br>  <br>      return () =&gt; {<br>        loopAnimation.stop()<br>      }<br>  }, [duration, isReduceMotionEnabled])<br><br>  return (&lt;AnimatedLottie ... /&gt;)<br>}</pre><h3>Summary</h3><p>In the world of app development, accessibility should never be an afterthought. By following these five vital steps, React Native developers can play a pivotal role in creating apps that cater to a diverse user base. From providing meaningful link descriptions to accommodating varying text sizes, these steps form the foundation of inclusive design. Remember, accessibility isn’t about complying with guidelines; it’s about ensuring that every user can enjoy your app, regardless of their abilities. So, as you embark on your journey to app accessibility, keep these principles in mind and make a positive impact on the lives of your users. Together, we can create a more inclusive digital landscape for all.</p><p>I’ve created a <a href="https://gist.github.com/aaronkrohn/dd8133059d41bad275b59a930b9c646e#file-react-native-checklist-md">GitHub checklist</a> to help you and your team perform these essential checks in your development process. However, it’s important to remember that true change takes time. So, if progress seems gradual, stay steadfast and continue educating and raising awareness within your team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4466285c9132" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creating-totallymoney/navigating-the-path-to-app-accessibility-5-essential-steps-4466285c9132">Navigating the Path to App Accessibility: 5 Essential Steps</a> was originally published in <a href="https://medium.com/creating-totallymoney">Creating TotallyMoney</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add visual regression testing to your CI pipeline for React Native apps.]]></title>
            <link>https://medium.com/creating-totallymoney/add-visual-regression-testing-to-your-ci-pipeline-for-react-native-apps-bc51a031905d?source=rss-a6add9cc39bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc51a031905d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[visual-regression-testing]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[wix-engineering]]></category>
            <category><![CDATA[circleci]]></category>
            <dc:creator><![CDATA[Aaron Krohn]]></dc:creator>
            <pubDate>Thu, 26 Jan 2023 10:33:46 GMT</pubDate>
            <atom:updated>2023-01-26T10:33:46.358Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a high-level overview of how you can build and integrate visual regression tests into a React Native application pipeline. It utilises the <a href="https://wix.github.io/Detox/docs/guide/taking-screenshots/#device-level-screenshots">D<strong>etox</strong></a> screenshot API and <a href="https://www.npmjs.com/package/resemblejs"><strong>resemble.js</strong></a><strong> </strong>library<strong> </strong>for image comparison.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DRVmLfS3IYGr2uuUSnKlDA.png" /><figcaption>showing the process of visual regression</figcaption></figure><h3>What is Visual regression testing?</h3><p>It’s the process of generating and comparing images to showcase differences. It is an essential part of maintaining the visual integrity of an app. We do this in the following way: Capture a set of base screenshots as a reference point for our app’s user interface (UI). Then, as we add new features, capture an updated (current) set of screenshots. Finally, we compare them to identify and highlight discrepancies.</p><h3>Why bother with it?</h3><p>There are several reasons why visual regression testing can be useful:</p><ol><li><strong>Consistency</strong>: It ensures your application remains consistent over time by flagging UI differences. This is important for maintaining a cohesive and professional image for your app. It also eases refactoring components, assuring changes haven’t introduced a visual change.</li><li><strong>User experience</strong>: Visual changes can impact user experience significantly. For example, if a button was easy to locate is now hidden, it could cause frustration for users.</li><li><strong>Brand image</strong>: The visual appearance of your app is often closely tied to the brand image. Visual regression testing helps ensure that changes to your app do not damage it.</li><li><strong>Reduce development time</strong>: With visual regression testing, you can catch visual issues fast. This can save time and effort in the long run by reducing the need for manual testing.</li></ol><p>In summary, visual regression testing can help ensure your app’s UI stays consistent. It also saves time and money by catching issues early on.</p><p>Let’s look at how this can be achieved in your continuous integration (CI) pipeline.</p><h3><strong>Which visual regression service is best?</strong></h3><p>There are a few visual regression testing services that are will-suited for react-native:</p><ol><li><a href="https://applitools.com/solutions/visual-testing-ppc/?utm_term=applitools&amp;utm_source=google&amp;utm_medium=paid-search&amp;utm_content=free-account&amp;utm_campaign=brand-primary&amp;gclid=CjwKCAiA5sieBhBnEiwAR9oh2oeoNqIJWTW-FqyCiutomtNeKsMwaW2uEz8dMujZ_srX-zoZBBu5choCDgUQAvD_BwE"><strong>Applitools</strong></a>: This is a popular choice for React Native developers. It supports automated visual testing of both web and mobile apps. It offers a range of features, including layout testing and integration with popular test frameworks like Jest and Detox.</li><li><a href="https://percy.io/"><strong>Percy</strong></a>: Integrates with React Native projects and automates visual regression testing. It uses a plugin for Jest that allows you to take screenshots of your React Native app. Using this can quickly and easily detect visual changes.</li><li><a href="https://wix.github.io/Detox/"><strong>Detox</strong> by Wix</a>: This is an end-to-end testing library for React Native apps. It supports integration with popular test runners like Jest. It also includes a built-in screenshot utility that we can use for visual regression testing.</li></ol><p>The best choice for your React Native project will depend on specific requirements and available resources. Each service has its strengths. Consider them carefully to find the one that best meets your needs.</p><h3>Our solution — Detox screenshot API</h3><p>We use <strong>Detox</strong> for our end-to-end (e2e) tests and utilise their built-in screenshot API for our visual regression testing solution. This option made sense to us because we were already using Detox and didn’t need all the features that the other services provided.</p><p>In each PR we run our e2e tests for Android and iOS taking screenshots of our app. Then use those screenshots and compare them against our base screenshots to generate diff screenshots. This worked nicely with not too much work. But, the issue was displaying the diff images to engineers. We first saved them to CircleCI’s artifacts, which meant they were visible in a tab inside CircleCI. While this surfaced the diff images, it didn’t surface them high enough and you had to click on them individually one at a time. For this reason, we used GitHub REST API and sent those images as a comment, providing a great visual overview of our apps.</p><blockquote><strong>A caveat to this solution</strong> — Since we’re taking screenshots during our e2e tests, it limits us in what we can screenshot. E2e tests should test the happy path and not every possible route a user can take along with all possible component states. Thus, we wouldn’t get 100% visual test coverage. If we did it would lead to extremely long tests.</blockquote><p>Here are the jobs we created along with others to make this happen.</p><h3>High-level view</h3><p>A high-level overview looking at all the CI jobs involved when we create a PR on GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7gp7m82VIL6PZVVKmETeA.jpeg" /><figcaption>Shows CI pipeline jobs.</figcaption></figure><h4><strong>1). Pull base screenshots 🔽</strong></h4><p>Base images are up-to-date screenshots of our app on our master branch. When we first set this up, we have to manually create them (Refer to <strong>step 2</strong> if you’re setting up for the first time). After that, we programmatically update our base images when we merge PRs.</p><p>We use an orb called <a href="https://circleci.com/developer/orbs/orb/circleci/aws-s3#commands-copy"><strong>circleci/aws-s3 orb</strong></a> to copy screenshots from our s3 bucket. Once we’ve copied them we persist them to our workspace in CircleCI. Meaning any job afterwards that attaches the workspace has access to the base images. See the CircleCI job below.</p><pre>      // Copy base images from s3 bucket to &quot;e2e/tmp/base/&quot;<br>      - aws-s3/copy:<br>          aws-access-key-id: AWS_ACCESS_KEY_ID<br>          aws-secret-access-key: AWS_SECRET_ACCESS_KEY<br>          aws-region: AWS_DEFAULT_REGION<br>          from: $AWS_S3_SCREENSHOT_BUCKET/base/<br>          to: e2e/base/<br>          arguments: |<br>            --recursive<br>      // Persist images to workspace<br>      - persist_to_workspace:<br>          root: .<br>          paths:<br>            - e2e/base/*</pre><h4>2). Run e2e Detox tests (Take screenshots) 📱</h4><p>We’re piggybacking off our e2e tests to take screenshots while running through our e2e tests. This helps to reduce our pipeline time, rather than having to run a separate job. Here’s the <a href="https://wix.github.io/Detox/docs/guide/taking-screenshots/#device-level-screenshots">API Detox offers</a> to take screenshots. After our e2e tests finish in Detox they’re stored in a <a href="https://wix.github.io/Detox/docs/config/artifacts">hidden folder called artifacts</a>. From there we can use those images in the artifacts folders to create our current screenshots that we’ll use to compare to our base screenshots.</p><h4><strong>3) Copy e2e screenshots from artifacts to the current folder 🚋</strong></h4><p>This job copies and moves the newly created screenshots to a folder e2e/tmp/current. It makes it easier for our next job.</p><h4>4) <strong>Compare screenshots (diff using </strong><a href="https://www.npmjs.com/package/resemblejs"><strong>resemble.js</strong></a><strong>)</strong></h4><p>This job compares our e2e/tmp/base and e2e/tmp/current screenshots outputting e2e/tmp/diff screenshots. We use <a href="https://www.npmjs.com/package/resemblejs"><strong>resemble.js</strong></a> for the comparison that generates images like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*gRiuvEPb4TTHgBbxKrZQSQ@2x.jpeg" /><figcaption><em>App screenshots show areas in purple where the screenshots are different compared to their base image.</em></figcaption></figure><pre>  const compareImages = require(&#39;resemblejs/compareImages&#39;)<br>  const OPTIONS = {<br>    output: {<br>      errorColor: {<br>        red: 255,<br>        green: 0,<br>        blue: 255,<br>      },<br>      errorType: &#39;movement&#39;,<br>      transparency: 0.3,<br>      largeImageThreshold: 1200,<br>      useCrossOrigin: false,<br>      outputDiff: true,<br>    },<br>    scaleToSameSize: true,<br>    ignore: &#39;antialiasing&#39;,<br>  }<br><br>  const getDiff = async (imgName) =&gt; {<br>    const data = await compareImages(<br>      await readFile(`base/${imgName}`),<br>      await readFile(`current/${imgName}`),<br>      OPTIONS<br>    )<br><br>    await writeFile(`${DIR_OUTPUT}/${imgName}`, data.getBuffer())<br>  }<br><br>  const compareAllImages = async () =&gt;<br>    Promise.all(readdirSync(DIR_CURRENT).map(getDiff))<br><br>  await compareAllImages()</pre><h4><strong>5). Push </strong>diff<strong> and </strong>current<strong> screenshots to an S3 bucket 🗃</strong></h4><p>We push the diff and current screenshots to an S3 bucket so that we can create absolute image URLs to display the diff images as a comment in GitHub. We use the current screenshots to update the base screenshots once we merge the PR (See step 7).</p><p>Note — we tried converting images into base64 but GitHub had issues displaying them.</p><h4><strong>6). Display diff screenshots as a PR comment 🗣</strong></h4><p>We use the GitHub REST API to send the screenshots to the GitHub PR. Here is the <a href="https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment">GitHub API to create an issue comment</a>.</p><pre>curl \<br>  -X POST \<br>  -H &quot;Accept: application/vnd.github+json&quot; \<br>  -H &quot;Authorization: Bearer &lt;YOUR-TOKEN&gt;&quot; \<br>  https://api.github.com/repos/&lt;OWNER&gt;/&lt;REPO&gt;/issues/&lt;PULL_NUMBER&gt;/comments \<br>  -d &quot;$STRINGIFY_BODY&quot;</pre><h4><strong>7). Promote base images and clean up on merge 🏅</strong></h4><p>We create a GitHub workflow that triggers when we merge the PR. The action promotes our current images and saves over our base images. At the same time, we delete the PR images stored on the S3 bucket.</p><p>An issue we came across was when more than one PR closes at the same time. How do we avoid promoting/copying images at the same time? Luckily <a href="https://docs.github.com/en/actions/using-jobs/using-concurrency">GitHub actions offer a <strong>concurrency</strong></a> key. This ensures that only a single job or workflow using the same concurrency group will run. So in our case, if we merge several PRs simultaneously, whichever was first will run. The others will pause until it’s finished. See below a snapshot of the GitHub action code.</p><pre>name: On Pull Request close<br>on:<br>  pull_request:<br>    types: [closed]<br><br># Ensure that only a single job or workflow using the same concurrency group will run at a time.<br># We don&#39;t want any conflicts when multiple actions are trying to promote base images<br>concurrency: promote-base-images-id<br><br>jobs:<br>  pr_closed_cleanup:<br>    runs-on: ubuntu-latest<br>    if: github.event.pull_request.merged<br>    ...</pre><h3>The result</h3><p>All our PRs receive 2 GitHub comments showing visual regression images. This is for both iOS and Android emulators providing us with extra confidence. It also helps give our engineers a high-level, visual overview of our app in an automated way. Thus, improving our confidence and quality assurance of our app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uADB9BxemGAFxNeood78YQ.jpeg" /><figcaption>Shows android closed accordion and iOS open accordion of visual regression images</figcaption></figure><h3>Note on tracking base images</h3><p>We can take 3 routes here when tracking base images.</p><ol><li><strong>Store directly in the repository</strong> — Saving base images within your project proved difficult. We still had to store the current images somewhere to display them in GitHub. The next issue was promoting/updating them on our master branch. Our master branch has protection rules enabled which make merging into it difficult. We didn’t want to create a new PR each time to update the base folder. We’d have double the PRs!</li><li><strong>Store in GitHub artifacts</strong> — You’d store the artifacts on master commits then use a script to pull down the base images. These can be pulled down whenever needed but uses your GitHub credits. This is doable but just comes down to pricing.</li><li><strong>Store in an S3 bucket </strong>— Very cheap plus we’re removing them as soon as we merge a PR. This was also simple to set up and to pull and push images because there’s an orb to help.</li></ol><p>In summary, we stored our images in an S3 bucket because it was cheap and easy to do. But, if you like the idea of it all in one place and don’t mind the credit usage then I’d go for storing them in GitHub artifacts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc51a031905d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creating-totallymoney/add-visual-regression-testing-to-your-ci-pipeline-for-react-native-apps-bc51a031905d">Add visual regression testing to your CI pipeline for React Native apps.</a> was originally published in <a href="https://medium.com/creating-totallymoney">Creating TotallyMoney</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to handle spacing at scale]]></title>
            <link>https://medium.com/creating-totallymoney/how-to-handle-spacing-at-scale-307e8e838da?source=rss-a6add9cc39bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/307e8e838da</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Aaron Krohn]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 09:32:55 GMT</pubDate>
            <atom:updated>2022-09-05T09:32:55.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*AFyhuUJKf3g1Q8rpCueG2A@2x.jpeg" /><figcaption>displaying low fidelity mobile interface</figcaption></figure><p>TL;DR<strong><br></strong>Use single margin flow to reduce choice. Move spacing responsibility to layout components that manage the space at the parent level. This makes your code consistent and reusable and allows you to programmatically apply equal space between components.</p><h3>Problem: Too much flexibility</h3><p>Positioning components is easy in isolation and there are many ways we can achieve it. Take, for example, two engineers tasked with building out the same component. They will 100% produce different code even though it will visually look the same. Why is this? In programming, we have many ways to achieve the same result, whether it’s using CSS, HTML or javascript. To be fair, this is one of the joys of programming and seeing how creative you can be.</p><p>However, at scale, this flexibility can create frustration because large codebases end up having several patterns for laying out components when engineers shouldn’t have to think about which pattern to use. So, we see no standard within the code, therefore we implement our own style, adding to the never-ending spaghetti of styles.</p><p>For instance, do you create space between components by using <strong>margin-top</strong> or <strong>margin-bottom</strong>? Should this be applied <strong>inside the component</strong> or does the <strong>parent component</strong> handle this? The same applies for horizontal layouts. These choices are repeated each time an engineer adds or updates UI.</p><h4>Example: Breaking UI</h4><p>Take this as an example. You are tasked to update the order of components that are stacked on top of each other:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxWRrGskuQN3mAnQBJY3Sw.jpeg" /><figcaption>Three dummy UI components show different spacing</figcaption></figure><pre>&lt;ComponentA /&gt;<br>&lt;ComponentB marginBottom={1} marginTop={1} /&gt;<br>&lt;ComponentC marginBottom={1} /&gt;</pre><p>In the example above, if we move ComponentB to any new position the layout will break because it’s been given the responsibility to apply space above and below. Meaning more effort to update a very simple UI change. The spacing is tightly coupled.</p><h4>Example: Breaking UI hidden space</h4><p>Keeping with the same example, we could have hidden space that catches us out. If it’s applied within a component. Any of them. For example &lt;ComponentA /&gt; doesn’t appear to be applying any margin, but it could.</p><pre>//ComponentA.js<br>&lt;Box marginTop={1}&gt;<br> …<br>&lt;/Box&gt;</pre><pre>// Parent<br>&lt;ComponentA /&gt;<br>&lt;ComponentB marginBottom={1} marginTop={1} /&gt;<br>&lt;ComponentC marginBottom={1} /&gt;</pre><p>ComponentA has spacing applied within the component hiding it, making it difficult to layout within the markup. I’ve even seen space combined, where it has been applied by the parent and then within the component.</p><p>These examples can be found all over in codebases and stem from too much flexibility. This raises 2 issues:</p><ul><li>Which space direction should you use? Margin-top or margin-bottom?</li><li>Where and who should handle the spacing?</li></ul><h3>Solution</h3><h4>Rule 1) Use Single-direction margin declarations</h4><p>This rule is about removing choice and defining all your margins in one direction. This can either be margin-up or margin-bottom and then left or right for components positioned horizontally. It’s about being consistent throughout your codebase; pushing items in the same direction. Whichever one you pick, stick with it.</p><p>By following this pattern it gives you:</p><ul><li><strong>Confidence in portability</strong> — When margins are consistent in the same direction, it gives you confidence when removing or adding new elements.</li><li><strong>Predictability —</strong> Limiting the choice brings predictability to your markup and less to think about.</li></ul><p><strong>Example: Single-direction margin in code format<br></strong>Using this rule, our example would now look something like this:</p><pre>&lt;ComponentA marginBottom={1} /&gt;<br>&lt;ComponentB marginBottom={1} /&gt;<br>&lt;ComponentC marginBottom={1} /&gt;</pre><blockquote>This rule came from an <a href="https://csswizardry.com/2012/06/single-direction-margin-declarations/">article</a>, by Harry Roberts titled, <em>‘Single-direction margin declarations’.</em></blockquote><h4>Rule 2) Decouple space</h4><p>Once the single directional margin flow is implemented, engineers still have a choice. Do you add spacing onto elements directly or the parent component? This produces varying ways to layout components, but also means spacing can be hidden (within a component) as mentioned earlier. For this reason, it’s a good idea to decouple spacing and let the parent component control the components layout.</p><blockquote>“Components shouldn’t be affecting other components around them. If a component wants space inside, you use padding but if it has margin, then it’s impacting the world around it. It’s breaking encapsulation which should be handled by its parent component.” Mark Dalgleish <a href="https://twitter.com/APKoponen/status/1363783064934100994?t=NEV2iWtN2qovHKh7jAsDhA&amp;s=09">Podcast interview</a></blockquote><p><strong>Example: Decoupling space in code format<br></strong>Moving margin responsibility to parent component</p><pre>&lt;Box marginBottom={1}&gt;<br>  &lt;ComponentA /&gt;<br>&lt;/Box&gt;<br>&lt;Box marginBottom={1}&gt;<br>  &lt;ComponentB /&gt;<br>&lt;/Box&gt;<br>&lt;Box marginBottom={1}&gt;<br>  &lt;ComponentC /&gt;<br>&lt;/div&gt;</pre><p>This rule gives you:</p><ul><li><strong>Predictability </strong>—It makes the markup explicit in what it’s doing.</li><li><strong>Layout components </strong>— Decoupling space and using the single directional flow rule surfaces repeating code that lets you think about creating highly specialised components, which we wouldn’t have seen had we not gone through these steps.</li></ul><p>As you can see from the example above, it raised the question: Can we abstract this repeating code away and make it DRY?(Don’t Repeat Yourself principle). Hence why the layout components are born.</p><blockquote>This rule is heavily inspired by the <a href="https://seek-oss.github.io/braid-design-system/">Braid design system</a> created by Mark Dalgleish.</blockquote><h3>Layout components</h3><p>Layout components are specialised components whose focus is to lay out components. They only work if they handle all the spacing.</p><ul><li><strong>Stack</strong> — Applies the <strong>single-direction margin programmatically. </strong>It<strong> </strong>loops through its children and adds the margin for you. This reduces the code and means you don’t need to think too much about the single-directional margin flow as much. Another benefit is that it makes your mark up even more declarative. This moves you to a paradigm where you can think of your components as lego pieces.</li></ul><pre>&lt;Stack space={1}&gt;<br>  &lt;ComponentA /&gt;<br>  &lt;ComponentB /&gt;<br>  &lt;ComponentC /&gt;<br>&lt;/Stack&gt;</pre><ul><li><strong>Bleed</strong> —Applies a negative margin to allow a component to breaks out of its parent component.</li></ul><pre>&lt;Stack space={1}&gt;<br> &lt;ComponentA /&gt;</pre><pre> &lt;Bleed horizontal={1}&gt;<br>  &lt;ComponentB /&gt;<br> &lt;/Bleed&gt;</pre><pre> &lt;ComponentC /&gt;<br>&lt;/Stack&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NO8iXTUBpEuAVyGXy59D3Q.jpeg" /><figcaption>displaying stack and bleed component</figcaption></figure><h3>Summary</h3><p>At TotallyMoney, we’ve been transitioning to layout components on our existing react-native codebase for a while now. It’s worked very well for us, allowing engineers to add UI much faster and combined with a library called <a href="https://styled-system.com/">styled-system</a> we could develop quickly.</p><p>A new library <a href="https://mobily.github.io/stacks/">Stacks</a> has come out for react-native that houses lots of layout components for you, which I’m keen to test out.</p><p>If you’re starting a greenfield project I would recommend looking at the design system <a href="https://seek-oss.github.io/braid-design-system/">Braid</a> as it gives you access to all these layout components and a friendly component API.</p><p><strong>Reference</strong></p><ul><li>Article Max Stoiber, <a href="https://mxstbr.com/thoughts/margin/">“Margins are harmful”</a></li><li>Mark Dalgleish <a href="https://twitter.com/APKoponen/status/1363783064934100994?t=NEV2iWtN2qovHKh7jAsDhA&amp;s=09">Podcast interview</a>. Design system <a href="https://seek-oss.github.io/braid-design-system/">Braid</a></li><li>React <a href="https://www.youtube.com/watch?v=jnV1u67_yVg">Conference </a>— Rethinking Design Practices</li><li>Layout component library <a href="https://mobily.github.io/stacks/">Stacks</a> for React Native</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=307e8e838da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creating-totallymoney/how-to-handle-spacing-at-scale-307e8e838da">How to handle spacing at scale</a> was originally published in <a href="https://medium.com/creating-totallymoney">Creating TotallyMoney</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>