<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kadi Kraman</title>
    <description>The latest articles on DEV Community by Kadi Kraman (@kadikraman).</description>
    <link>https://dev.to/kadikraman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F244747%2Fd6454d24-94d8-4089-ba44-e7f2d734e9ca.jpeg</url>
      <title>DEV Community: Kadi Kraman</title>
      <link>https://dev.to/kadikraman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kadikraman"/>
    <language>en</language>
    <item>
      <title>10 Tips for Structuring a React Native Project</title>
      <dc:creator>Kadi Kraman</dc:creator>
      <pubDate>Sun, 29 Nov 2020 12:25:03 +0000</pubDate>
      <link>https://dev.to/kadikraman/10-tips-for-structuring-a-react-native-project-k19</link>
      <guid>https://dev.to/kadikraman/10-tips-for-structuring-a-react-native-project-k19</guid>
      <description>&lt;p&gt;When starting a new project, there are plenty of choices to be made around code style, language, folder layout, and more. Consistency is the key for creating clean, maintainable codebases. Therefore once decided, you'd usually need to stick with these choices for a while.&lt;/p&gt;

&lt;p&gt;Time and experience will teach you what works and what doesn't. But what if you don't have time? You can always use someone else's experience.&lt;/p&gt;

&lt;p&gt;Here are my top 10 tips for structuring a React Native project:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Use TypeScript
&lt;/h2&gt;

&lt;p&gt;Yes, there is a bit of a learning curve if you're used to plain JavaScript.&lt;/p&gt;

&lt;p&gt;Yes, it's worth it.&lt;/p&gt;

&lt;p&gt;Typed JavaScript makes refactoring a whole lot easier, and when done right, gives you a lot more confidence in your code. Use the guide in the &lt;a href="https://reactnative.dev/docs/typescript"&gt;docs&lt;/a&gt; for setup instructions. Make sure to enable strict mode (&lt;code&gt;"strict": true&lt;/code&gt; in the &lt;code&gt;compilerOptions&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;You can also add type checking in your CI with &lt;code&gt;tsc --noEmit&lt;/code&gt;, so you can be confident in your types!&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Set up a module alias to &lt;code&gt;/src&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Set up a single module alias to &lt;code&gt;/src&lt;/code&gt; (and a separate one for &lt;code&gt;/assets&lt;/code&gt; if needed), so instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CustomButton&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../../../components/CustomButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CustomButton&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@src/components/CustomButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I always use a &lt;code&gt;@&lt;/code&gt; or a &lt;code&gt;~&lt;/code&gt; in front of &lt;code&gt;src&lt;/code&gt; to highlight it's an alias.&lt;/p&gt;

&lt;p&gt;I've seen implementations where folks set up multiple type aliases - one for &lt;code&gt;@components&lt;/code&gt;, one for &lt;code&gt;@screens&lt;/code&gt;, one for &lt;code&gt;@util&lt;/code&gt; etc, but I've found a single top level alias to be the clearest.&lt;/p&gt;

&lt;p&gt;There's a handy guide for setting this up with TypeScript in the &lt;a href="https://reactnative.dev/docs/typescript#using-custom-path-aliases-with-typescript"&gt;React Native docs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Use Inline Styles
&lt;/h2&gt;

&lt;p&gt;You have an option for using the built in inline styles, or &lt;a href="https://styled-components.com/docs/basics#react-native"&gt;Styled Components&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I started off with Styled Components, then switched to inline styles, because there used to be a performance implication, though that's &lt;a href="https://medium.com/@jm90mm/a-quick-performance-comparison-of-styled-components-vs-inline-styles-in-react-native-21d8f6a561d7"&gt;negligible&lt;/a&gt;, so now it's just a preference.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. One Style File Per Component
&lt;/h2&gt;

&lt;p&gt;Each component should have their own style file with a &lt;code&gt;styles.ts&lt;/code&gt; extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FirstComponent.tsx
FirstComponent.styles.ts
SecondComponent.tsx
SecondComponent.styles.tsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note, the &lt;code&gt;.styles.ts&lt;/code&gt; in the filename is just a convention I use to indicate that the styles belong to the component, the TypeScript compiler will treat these as regular &lt;code&gt;.ts&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;Each style file exports a single style object for the component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// FirstComponent.styles.ts&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;StyleSheet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;container&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each component only imports only its own styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// FirstComponent.tsx&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./FirstComponent.styles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Use Global Styles
&lt;/h2&gt;

&lt;p&gt;Create a &lt;code&gt;globalStyles.ts&lt;/code&gt; file at the top level of the &lt;code&gt;/src&lt;/code&gt; directory, and import it to the &lt;code&gt;.styles.ts&lt;/code&gt; as needed.&lt;/p&gt;

&lt;p&gt;Always use constants for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;colours&lt;/li&gt;
&lt;li&gt;fonts&lt;/li&gt;
&lt;li&gt;font sizes&lt;/li&gt;
&lt;li&gt;spacing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It may seem tedious at first, but handy in the long term. And if you find you're ending up creating constant for every single space, it's something to gently bring up with the Design team, as design guides would generally not want that.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Flatten Style Constants
&lt;/h2&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;globalStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#235789&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;red&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#C1292E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#F1D302&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;globalStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;colorBlue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#235789&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;colorRed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#C1292E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;colorYellow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#F1D302&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can be tempting to group these, but I've found that keeping them flat can be more handy, e.g. if you wanted to replace all instances of &lt;code&gt;colorRed&lt;/code&gt; in your codebase, you could do a find and replace, whereas with &lt;code&gt;colors.red&lt;/code&gt; it'd be harder, since the colour could have been destructured. &lt;/p&gt;

&lt;h2&gt;
  
  
  7. Use Numbers in Style Constants
&lt;/h2&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;globalStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;extraSmall&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;small&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;medium&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;large&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;extraLarge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;globalStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;fontSize8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fontSize12&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fontSize16&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fontSize18&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fontSize24&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first option may look nicer when writing it down, but during development, you don't tend to care about "medium" and "large", and just care about the number. And it will avoid the awkward naming when the designers inevitably add a font size 14 and you have to start calling your variables things like &lt;code&gt;mediumSmall&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. One Component Per File
&lt;/h2&gt;

&lt;p&gt;Here's the template for a new component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.styles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some things to note here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;function components over class components: I'd always use function components and manage any state and side-effects using hooks&lt;/li&gt;
&lt;li&gt;I use constant functions, but both &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;function&lt;/code&gt; are equally good here. In fact &lt;code&gt;function&lt;/code&gt; might be better in the long term&lt;/li&gt;
&lt;li&gt;default export: I always use a default export, though there is an argument to be made that named exports are better since they'll be clearer to refactor, and I agree - that might be the next step&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Separate Components and Screens
&lt;/h2&gt;

&lt;p&gt;Here's a typical folder structure I end up with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/assets
  /images
    image.png
    anotherImage.png
  /icons
    icon.svg
    anotherIcon.svg
/src
  /components
    Component1.tsx
    Component1.styles.ts
    Component1.test.ts
    Component2.tsx
    Component2.styles.ts
    Component2.test.ts
  /screens
    Screen.tsx
    Screen.styles.ts
    Modal.tsx
    Modal.styles.ts
  App.tsx
  globalStyles.ts
  types.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I always separate components in the &lt;code&gt;/components&lt;/code&gt; directory and the screens and modals in the &lt;code&gt;/screens&lt;/code&gt; directory. When using &lt;code&gt;react-navigation&lt;/code&gt;, there is no structural difference between screens and modals, but I prefer to also differentiate the intent by naming the file &lt;code&gt;SomethingModal.tsx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another thing to note is the file names - rather than creating a folder with the file name, and naming each file &lt;code&gt;index.tsx&lt;/code&gt;, the filename should reflect the component name. That is mostly for convenience - in most editors, it'll get tedious to track down which file you're editing when they're all called &lt;code&gt;index.tsx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I've also seen implementations where all components are imported to a single &lt;code&gt;index.ts&lt;/code&gt; file and exported from there. I personally am not a fan of that solution and see it as an unnecessary extra step.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Lint Your Code
&lt;/h2&gt;

&lt;p&gt;It's worth it. Trust me!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;a href="https://eslint.org/"&gt;eslint&lt;/a&gt; and &lt;a href="https://prettier.io/"&gt;prettier&lt;/a&gt; - they actually come pre-installed when you initialise a new project&lt;/li&gt;
&lt;li&gt;Set up a pre-commit hook - I usually set up a pre-commit hook for linting and pre-push hook for tests. There's a great guide &lt;a href="https://prettier.io/docs/en/precommit.html"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Check lint, test and TypeScript errors on CI! This is so important - the only way to ensure a consistent code style across the project lifecycle. Setting up CI is one of the first things I do when starting a new project.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope this helps! Got any tips of your own that I did't list here? Let me know in the comments! 👀&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>typescript</category>
    </item>
    <item>
      <title>An Open Source Maintainer's Guide to Publishing npm Packages</title>
      <dc:creator>Kadi Kraman</dc:creator>
      <pubDate>Sat, 23 May 2020 16:34:49 +0000</pubDate>
      <link>https://dev.to/kadikraman/an-open-source-maintainer-s-guide-to-publishing-npm-packages-1218</link>
      <guid>https://dev.to/kadikraman/an-open-source-maintainer-s-guide-to-publishing-npm-packages-1218</guid>
      <description>&lt;p&gt;The JavaScript community is built on Open Source and being able to give back to the community feels most gratifying. However, publishing a package for the first time might feel rather daunting, and publishing a release candidate may be a bit scary even for experienced authors. I hope to give some insight and helpful tips, especially for new authors.&lt;/p&gt;

&lt;p&gt;I have owned two open source libraries: a tiny utility library for DraftJS called &lt;a href="https://github.com/kadikraman/draftjs-md-converter"&gt;draftjs-md-converter&lt;/a&gt; and a React Native security library called &lt;a href="https://github.com/FormidableLabs/react-native-app-auth"&gt;react-native-app-auth&lt;/a&gt;. I am certainly not as heavily involved in Open Source as some, but I have had the sole responsibility of publishing new versions of these libraries for several years so I think I have enough experience to justify this blog post! I remember how scary it was to publish a library for the first time, and I still remember how apprehensive I felt publishing a release candidate. The purpose of this writeup is to produce a guide on how to publish packages: both a comprehensive guide for new authors, and a sanity check for future me.&lt;/p&gt;

&lt;p&gt;I will cover the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting up your repo for publishing&lt;/li&gt;
&lt;li&gt;Publishing a package (initial release)&lt;/li&gt;
&lt;li&gt;Versioning&lt;/li&gt;
&lt;li&gt;Publishing a package (subsequent releases)&lt;/li&gt;
&lt;li&gt;Publishing alpha / beta / release candidate versions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use npm or yarn, it's completely up to you. The publish commands are identical. I will be using npm throughout.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up your repo for publishing
&lt;/h2&gt;

&lt;p&gt;Before you're ready to run the &lt;code&gt;publish&lt;/code&gt; command, you should check that your package is in a good state to be published. Here are a few things you might want to consider:&lt;/p&gt;

&lt;h3&gt;
  
  
  Check the package name
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://docs.npmjs.com/files/package.json#name"&gt;&lt;code&gt;name&lt;/code&gt;&lt;/a&gt; field in your &lt;code&gt;package.json&lt;/code&gt; will be the name of your published package. So for instance if you name your package &lt;code&gt;package-name&lt;/code&gt;, users will import it with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;package-name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The name needs to be unique, so make sure you check the name is available on &lt;a href="https://www.npmjs.com/"&gt;https://www.npmjs.com/&lt;/a&gt; or your publish command will fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set the initial version
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;version&lt;/code&gt; attribute in your &lt;code&gt;package.json&lt;/code&gt; will determine the version of the package when published. For your initial release you might use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;NPM packages use &lt;a href="https://semver.org/"&gt;semver&lt;/a&gt; for versioning, which means the version consists of 3 numbers: the major, minor and patch version. We will talk more about versioning in the "Versioning" section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Make sure your repository is not private
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;package.json&lt;/code&gt; you may have an attribute &lt;code&gt;"private": true&lt;/code&gt;. It is a &lt;a href="https://docs.npmjs.com/files/package.json#private"&gt;built in protection&lt;/a&gt; so you wouldn't accidentally publish something that's meant to be private. It is generally a good practice to use this if you're building something that is not meant to be open source, like a personal or a client project. However if you're about to publish the repo as a package, this line should be removed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add a license
&lt;/h3&gt;

&lt;p&gt;Ensure you have set the &lt;a href="https://docs.npmjs.com/files/package.json#license"&gt;license&lt;/a&gt; in your &lt;code&gt;package.json&lt;/code&gt;. This is to let people know how you are permitting them to use your package. The most common licenses are "MIT" and "Apache-2.0". They are both permissive, allowing users to distribute, modify, or otherwise use the software for any purpose. You can read more about the differences &lt;a href="https://snyk.io/blog/mit-apache-bsd-fairest-of-them-all/"&gt;here&lt;/a&gt;. I have always used the "MIT" license.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check the entry point
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://docs.npmjs.com/files/package.json#main"&gt;&lt;code&gt;main&lt;/code&gt;&lt;/a&gt; field in your &lt;code&gt;package.json&lt;/code&gt; defined the main entry file for the package. This is the file the users will access then importing your package. It'll usually be something like &lt;code&gt;./index.js&lt;/code&gt; or &lt;code&gt;./src/index.js&lt;/code&gt; depending on the location of your entry file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Restrict the files you want to publish
&lt;/h3&gt;

&lt;p&gt;Be default, publishing a package will publish everything in the directory. Sometimes you might not want to do that, e.g. if your repository includes an example folder or if you have a build step and only want to publish the built bundle. For that purpose, there is a &lt;a href="https://docs.npmjs.com/files/package.json#files"&gt;files&lt;/a&gt; field in the &lt;code&gt;package.json&lt;/code&gt;. If omitted, the field defaults to &lt;code&gt;["*"]&lt;/code&gt;, but when set, it includes only the files and directories listed in the array. Note that certain files are always included, even if not listed: &lt;code&gt;package.json&lt;/code&gt;, &lt;code&gt;README&lt;/code&gt;, &lt;code&gt;CHANGES / CHANGELOG / HISTORY&lt;/code&gt;, &lt;code&gt;LICENSE / LICENCE&lt;/code&gt;, &lt;code&gt;NOTICE&lt;/code&gt;, and the file in the "main" field.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add a build step
&lt;/h3&gt;

&lt;p&gt;Sometimes, you may need a build step. For example if you've written your package using Flow, TypeScript or cutting edge JavaScript features that aren't implemented in all browsers, and want to compile/transpile your package to vanilla JavaScript that anyone could use. For this you can use a &lt;code&gt;prepublish&lt;/code&gt; script like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prepublish"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run your-build-script"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will be run automatically when you run the publish command. For example in &lt;a href="https://github.com/kadikraman/draftjs-md-converter/blob/master/package.json"&gt;this package&lt;/a&gt; I use the &lt;code&gt;prepublish&lt;/code&gt; script to rebuild the app in the &lt;code&gt;dist&lt;/code&gt; directory. Notice also that the &lt;code&gt;main&lt;/code&gt; field in this &lt;code&gt;package.json&lt;/code&gt; is set to &lt;code&gt;"main": "dist/index.js"&lt;/code&gt; since I want the users to access the built file.&lt;/p&gt;

&lt;p&gt;There are more built in scripts for various occasions, but this is the only one I've had to use when publishing packages. You can read more about other available scripts &lt;a href="https://docs.npmjs.com/misc/scripts"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing a package (initial release)
&lt;/h2&gt;

&lt;p&gt;Clone your repo, and make sure you're on the latest &lt;code&gt;master&lt;/code&gt; branch (or whatever your main branch is) with no uncommitted changes.&lt;/p&gt;

&lt;p&gt;Create an account on &lt;a href="https://www.npmjs.com/"&gt;https://www.npmjs.com/&lt;/a&gt; if you don't have one already, and use these credentials to log in on your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm login
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, in your project repo, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm publish
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you've set up two factor authentication, you'll get a prompt for it in your terminal before the publish is completed. Once the command has finished successfully, you should be able to instantly see your package at &lt;a href="https://www.npmjs.com/package/package-name"&gt;https://www.npmjs.com/package/package-name&lt;/a&gt; where &lt;code&gt;package-name&lt;/code&gt; is the name of your package set in the &lt;code&gt;package.json&lt;/code&gt;, and people will be able to install your package with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;package-name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Versioning
&lt;/h2&gt;

&lt;p&gt;Publishing subsequent versions of the package involves more thought, because now we need to consider versioning. As mentioned above, npm packages are versioned using semver. This means that there are 3 types of releases: major, minor and patch, and you should use these to communicate the types of changes in your library.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Major&lt;/strong&gt; changes include anything that is incompatible with the previous versions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minor&lt;/strong&gt; changes are usually new features and bigger bug fixes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Patch&lt;/strong&gt; changes are tiny bug fixes or additive changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing to note is that the semver naming is a bit misleading, specifically in "major" - a major release doesn't necessarily mean that a lot has changed. It means that when going from the previous to current version, there is a breaking change, and that the users of your library might need to change something in their code in order to accommodate the latest version. For instance, changing an exported function name or parameter order would be considered major changes. A lot of maintainers tend to collect breaking changes and release them all together to minimise how often the major version is incremented.&lt;/p&gt;

&lt;p&gt;The reason you should only do breaking changes in major releases is because the users of your library may opt in to all future patch and minor versions silently, so the next time they run &lt;code&gt;npm install&lt;/code&gt; you might end up breaking their build.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;package.json&lt;/code&gt;, this is communicated with ~ and ^ where ~ opts in for all future patch releases and ^ opts in for all future patch and minor releases:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;~1.2.3&lt;/code&gt; will match all &lt;code&gt;1.2.x&lt;/code&gt; versions but will miss &lt;code&gt;1.3.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;^1.2.3&lt;/code&gt; will match any &lt;code&gt;1.x.x&lt;/code&gt; release including &lt;code&gt;1.3.0&lt;/code&gt;, but will hold off on &lt;code&gt;2.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Side note: when the major version is &lt;code&gt;0&lt;/code&gt;, the package is considered unstable and so the ^ acts the same as ~ and for all releases before major 1 you may publish breaking changes in &lt;code&gt;minor&lt;/code&gt; releases.&lt;/p&gt;

&lt;p&gt;There is no option to opt in for all future major releases, because they are expected to be breaking and thus should be manual upgrades. &lt;a href="https://medium.com/@Hardy2151/caret-and-tilde-in-package-json-57f1cbbe347b"&gt;Source.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing a package (subsequent releases)
&lt;/h2&gt;

&lt;p&gt;This is how you do releases after the initial one. As before, you should ensure you're on the master branch with no uncommitted changes. Consider what type of release this is: major, minor or patch. Now run the command to increment the version in your working directory, using &lt;code&gt;major&lt;/code&gt;, &lt;code&gt;minor&lt;/code&gt; or &lt;code&gt;patch&lt;/code&gt; depending on the type of the change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm version minor
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is a convenience method that does a couple of things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;increments the version in your &lt;code&gt;package.json&lt;/code&gt; based on the type of the change&lt;/li&gt;
&lt;li&gt;commits this version bump&lt;/li&gt;
&lt;li&gt;creates a tag for the current release in your &lt;code&gt;.git&lt;/code&gt; repo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now all that's left to do is to run the publish command as before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm publish
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is important to make sure you do the version bump before the publish. If you try to publish the same version of the library twice, the command will fail.&lt;/p&gt;

&lt;p&gt;Finally, you'll want to push the version bump commit and the tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push
git push --tags
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice that you'll have to push the tags separately using the &lt;code&gt;--tags&lt;/code&gt; flag.&lt;/p&gt;

&lt;p&gt;If you're using GitHub to host your repository, the tags will show up under the Releases tab on your repository, e.g. &lt;a href="https://github.com/kadikraman/draftjs-md-converter/releases"&gt;https://github.com/kadikraman/draftjs-md-converter/releases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is good practice to write some release notes against the tag. I usually also use this space to thank any contributors!&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing an alpha / beta / release candidate
&lt;/h2&gt;

&lt;p&gt;An alpha / beta / release candidate is usually an early access version of a major release. When you're about to do a major change, you might want to give your users a chance to try out the new release first on an opt-in basis but with the expectation that it may be unstable.&lt;/p&gt;

&lt;p&gt;Basically what we want to achieve is to publish a new version "silently" that would allow only interested users to opt in for.&lt;/p&gt;

&lt;p&gt;Let's look at how you might create a release candidate. Suppose you are currently on &lt;code&gt;v3.4.5&lt;/code&gt; and you want to do a release candidate for &lt;code&gt;v4&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First, we increment the version. The &lt;code&gt;npm version&lt;/code&gt; command allows you to provide your own version number. In this case we're going to say it's the first release candidate for v4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm version 4.0.0-rc1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As before, this does the version bump, commits the change, and creates the tag. Now to publish the package. This is the most important step, since you want to ensure none of your users get this release candidate version by default.&lt;/p&gt;

&lt;p&gt;The publish command has a &lt;code&gt;--tag&lt;/code&gt; argument, which defaults to "latest". This means that whenever someone &lt;code&gt;npm install&lt;/code&gt;s your library, they get the last publish that has the "latest" tag. So all we need to do is provide a different tag. This can be anything really, I have usually used "next".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm publish --tag next
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will publish your package under the next tag, so the users who do &lt;code&gt;npm install package-name&lt;/code&gt; will still get &lt;code&gt;v3.4.5&lt;/code&gt;, but users who install &lt;code&gt;npm install package-name@next&lt;/code&gt; or &lt;code&gt;npm install package-name@4.0.0-rc1&lt;/code&gt; will get your release candidate. Note that if you publish another release candidate with the "next" tag, anyone installing &lt;code&gt;npm install package-name@next&lt;/code&gt; will get the latest version.&lt;/p&gt;

&lt;p&gt;When you're ready to do the next major release, you can run &lt;code&gt;npm version major&lt;/code&gt; (this will bump the version to &lt;code&gt;4.0.0&lt;/code&gt;) and &lt;code&gt;npm publish&lt;/code&gt; as normal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's pretty much it! Publishing packages can be a bit scary the first few times, but like anything it gets easier the more you do it.&lt;/p&gt;

&lt;p&gt;Thank you for contributing to Open Source!&lt;/p&gt;

</description>
      <category>npm</category>
      <category>publishing</category>
      <category>opensource</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Building an Animated Drawer in React Native</title>
      <dc:creator>Kadi Kraman</dc:creator>
      <pubDate>Fri, 01 May 2020 21:17:26 +0000</pubDate>
      <link>https://dev.to/kadikraman/building-an-animated-drawer-in-react-native-2f97</link>
      <guid>https://dev.to/kadikraman/building-an-animated-drawer-in-react-native-2f97</guid>
      <description>&lt;p&gt;&lt;a href="https://i.giphy.com/media/UWzu4ncONA24vcFHDf/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/UWzu4ncONA24vcFHDf/giphy.gif" alt="Animated drawer example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Animations are a sure way to improve user experience and delight in your app. However, they are often not that straightforward to implement, and so end up as a "nice to have" at the very bottom of the backlog.&lt;/p&gt;

&lt;p&gt;React Native actually comes with some rather handy features that make adding certain types of animations a lot more straightforward than you might imagine!&lt;/p&gt;

&lt;p&gt;In this tutorial, I will show you how to create an animated drawer component in React Native - without using the Animated API!&lt;/p&gt;

&lt;h2&gt;
  
  
  LayoutAnimation
&lt;/h2&gt;

&lt;p&gt;The key to building this is &lt;a href="https://reactnative.dev/docs/layoutanimation"&gt;LayoutAnimation&lt;/a&gt;. It is a built in feature that automagically animates views to the new position when a layout change happens.&lt;/p&gt;

&lt;p&gt;Let's demonstrate how this works by animating a box to grow and shrink onPress.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/VzH9JzrSk2RXNtV4Rx/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/VzH9JzrSk2RXNtV4Rx/giphy.gif" alt="Box growing and shrinking on an iPhone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First let's create a box:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SafeAreaView&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;StyleSheet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SafeAreaView&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;safeArea&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;SafeAreaView&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;safeArea&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;container&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;justifyContent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;alignItems&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;box&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's update out code so that the box toggles from being 50x50 to 200x200 in size when you tap on it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use the &lt;code&gt;useState&lt;/code&gt; hook to hold the state for whether the box is expanded&lt;/li&gt;
&lt;li&gt;update the box style so that it is 200x200 when &lt;code&gt;isExpanded&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;add a Touchable around the box and toggle expanded state onPress
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;-import React from "react";
&lt;/span&gt;&lt;span class="gi"&gt;+import React, { useState, useCallback } from "react";
&lt;/span&gt;&lt;span class="gd"&gt;-import { View, SafeAreaView, StyleSheet } from "react-native";
&lt;/span&gt;&lt;span class="gi"&gt;+import { View, SafeAreaView, StyleSheet, TouchableOpacity } from "react-native";
&lt;/span&gt;
const App = () =&amp;gt; {
&lt;span class="gi"&gt;+  const [isExpanded, setIsExpanded] = useState(false);
+  const handlePress = useCallback(() =&amp;gt; {
+    setIsExpanded(val =&amp;gt; !val);
+  }, []);
&lt;/span&gt;  return (
    &amp;lt;SafeAreaView style={styles.safeArea}&amp;gt;
      &amp;lt;View style={styles.container}&amp;gt;
&lt;span class="gi"&gt;+        &amp;lt;TouchableOpacity onPress={handlePress}&amp;gt;
&lt;/span&gt;&lt;span class="gd"&gt;-          &amp;lt;View style={styles.box} /&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+          &amp;lt;View style={[styles.box, isExpanded ? styles.expanded : undefined]} /&amp;gt;
+        &amp;lt;/TouchableOpacity&amp;gt;
&lt;/span&gt;      &amp;lt;/View&amp;gt;
    &amp;lt;/SafeAreaView&amp;gt;
  );
&lt;span class="err"&gt;};&lt;/span&gt;

&lt;span class="p"&gt;const styles = StyleSheet.create({
&lt;/span&gt;  safeArea: {
    flex: 1
  },
  container: {
    justifyContent: "center",
    alignItems: "center",
    flex: 1
  },
  box: {
    backgroundColor: "pink",
    height: 50,
    width: 50
&lt;span class="gd"&gt;-  }
&lt;/span&gt;&lt;span class="gi"&gt;+  },
+  expanded: {
+    height: 200,
+    width: 200
+  }
&lt;/span&gt;&lt;span class="err"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;export default App;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the box toggles from being 50x50 to 200x200, but there's no animation. This is where LayoutAnimation comes to play. We want to tell the layout that the next time there is a UI change, instead of snapping to it, animate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;import React, { useState, useCallback } from "react";
&lt;/span&gt;&lt;span class="gd"&gt;-import { View, SafeAreaView, StyleSheet, TouchableOpacity } from "react-native";
&lt;/span&gt;&lt;span class="gi"&gt;+import { View, SafeAreaView, StyleSheet, TouchableOpacity, LayoutAnimation } from "react-native";
&lt;/span&gt;
const App = () =&amp;gt; {
  const [isExpanded, setIsExpanded] = useState(false);
  const handlePress = useCallback(() =&amp;gt; {
    setIsExpanded(val =&amp;gt; !val);
&lt;span class="gi"&gt;+    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
&lt;/span&gt;  }, []);
  return (
    &amp;lt;SafeAreaView style={styles.safeArea}&amp;gt;
      &amp;lt;View style={styles.container}&amp;gt;
        &amp;lt;TouchableOpacity onPress={handlePress}&amp;gt;
          &amp;lt;View style={[styles.box, isExpanded ? styles.expanded : undefined]} /&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
      &amp;lt;/View&amp;gt;
    &amp;lt;/SafeAreaView&amp;gt;
  );
&lt;span class="err"&gt;};&lt;/span&gt;

&lt;span class="p"&gt;const styles = StyleSheet.create({
&lt;/span&gt;  safeArea: {
    flex: 1
  },
  container: {
    justifyContent: "center",
    alignItems: "center",
    flex: 1
  },
  box: {
    backgroundColor: "pink",
    height: 50,
    width: 50
  },
  expanded: {
    height: 200,
    width: 200
  }
&lt;span class="err"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;export default App;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that if you need this to work on Android as well, you'll need to place this extra it of code just under your import statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;UIManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Platform&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Platform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OS&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;android&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UIManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setLayoutAnimationEnabledExperimental&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;UIManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setLayoutAnimationEnabledExperimental&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's literally it! Sure, there are limits to what you can achieve with this, but there is quite a bit you can use LayoutAnimation for with very little additional developer effort.&lt;/p&gt;

&lt;p&gt;Check out the source code for the animated box &lt;a href="https://snack.expo.io/@kadikraman/layoutanimation-demo"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building an animated drawer
&lt;/h2&gt;

&lt;p&gt;Now that you have the power of LayoutAnimation in your back pocket, you can use this to build a drawer.&lt;/p&gt;

&lt;p&gt;Let's see how to build a single drawer. The core concept is this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create a touchable area which is the always visible title&lt;/li&gt;
&lt;li&gt;add a list of elements underneath it that should be displayed when the drawer is open&lt;/li&gt;
&lt;li&gt;wrap the list of element in a view and give it a conditional style that sets the view height to 0 when the list is "closed"&lt;/li&gt;
&lt;li&gt;call &lt;code&gt;LayoutAnimation.configureNext&lt;/code&gt; immediately after triggering the state change to open or close the drawer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The code for a single section should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;FlatList&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;LayoutAnimation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;TouchableOpacity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;UIManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Platform&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Platform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OS&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;android&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UIManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setLayoutAnimationEnabledExperimental&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;UIManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setLayoutAnimationEnabledExperimental&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Section&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsOpen&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toggleOpen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setIsOpen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;LayoutAnimation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;configureNext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LayoutAnimation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Presets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;easeInEaseOut&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TouchableOpacity&lt;/span&gt; &lt;span class="na"&gt;onPress=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggleOpen&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Section header&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;TouchableOpacity&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;FlatList&lt;/span&gt;
          &lt;span class="na"&gt;data=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="na"&gt;keyExtractor=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="na"&gt;renderItem=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Section&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now all that's left to do is add some styling and a couple more sections and you're all done! Check out the source code for the animated drawer &lt;a href="https://snack.expo.io/@kadikraman/animated-drawer-example"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would also recommend &lt;a href="https://reactnative.dev/docs/layoutanimation"&gt;reading up on LayoutAnimation&lt;/a&gt; to learn more about ways you can customise it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layout Animation in the Wild
&lt;/h2&gt;

&lt;p&gt;Here is an example of a feature in a production app that I built using LayoutAnimation. The drawer here is built using exactly the method described in this article!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/VGnjrpz0hGuGVJMgJQ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/VGnjrpz0hGuGVJMgJQ/giphy.gif" alt="Alt mode select example using LayoutAnimation"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>animation</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
