<?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>Forem: Saad</title>
    <description>The latest articles on Forem by Saad (@saadbashar).</description>
    <link>https://forem.com/saadbashar</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%2F54687%2Fb6610c8b-c704-4a39-b096-2bd0c99ca689.jpeg</url>
      <title>Forem: Saad</title>
      <link>https://forem.com/saadbashar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/saadbashar"/>
    <language>en</language>
    <item>
      <title>I wish there was an intensive course where we only focus on working with objects, arrays, and solving real-life problems.</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Wed, 03 Mar 2021 11:25:51 +0000</pubDate>
      <link>https://forem.com/saadbashar/i-wish-there-was-an-intensive-course-where-we-only-focus-on-working-with-objects-arrays-and-solving-real-life-problems-19da</link>
      <guid>https://forem.com/saadbashar/i-wish-there-was-an-intensive-course-where-we-only-focus-on-working-with-objects-arrays-and-solving-real-life-problems-19da</guid>
      <description>&lt;p&gt;I may have not expressed myself properly from the title. But most of the time as front-end devs, we need to work with objects and arrays. I wish there was a course/tutorial only focusing on solving real-life problems with objects and arrays. Writing clean functions to extract, filter, combine objects/arrays to come to the real solution. &lt;/p&gt;

&lt;p&gt;I hope I could made my points clear. &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Remove Item with animation in a Horizontal FlatList in React Native</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Sat, 27 Feb 2021 15:08:14 +0000</pubDate>
      <link>https://forem.com/saadbashar/remove-item-with-animation-in-a-horizontal-flatlist-in-react-native-o26</link>
      <guid>https://forem.com/saadbashar/remove-item-with-animation-in-a-horizontal-flatlist-in-react-native-o26</guid>
      <description>&lt;p&gt;I have been working on a horizontal FlatList in React Native. The idea is, a user can remove the item by clicking on the item. So once the item is removed, I need to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove the item from the list with a nice opacity animation&lt;/li&gt;
&lt;li&gt;At the same time, I need to fill up space with the next items sliding in to fill it up properly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At first, I was trying it out with react native Animated library but it was getting messier and I could not achieve the effects that I wanted. However, with LayoutAnimation from react-native, this can be done easily. Let’s start then. First, we will put the initial set up for our horizontal FlatList.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const { height, width } = Dimensions.get("window");
const dummyData = [
  {
    id: 1,
    name: "orange card",
    color: "orange",
  },
  {
    id: 2,
    name: "red card",
    color: "red",
  },
  {
    id: 3,
    name: "green card",
    color: "green",
  },
  {
    id: 4,
    name: "blue card",
    color: "blue",
  },
  {
    id: 5,
    name: "cyan card",
    color: "cyan",
  },
];
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    paddingTop: 120,
    backgroundColor: "#ecf0f1",
    padding: 8,
  },
  flatList: {
    paddingHorizontal: 16,
    paddingVertical: 16,
  },
  cardContainer: {
    height: 100,
    width: width * 0.5,
    marginRight: 8,
  },
  card: {
    height: 100,
    width: width * 0.5,
    borderRadius: 12,
    padding: 10,
  },
  text: { color: "white", fontWeight: 'bold' }
});

export default function App() {
  const [data, setData] = React.useState(dummyData);
  return (
    &amp;lt;View style={styles.container}&amp;gt;
      &amp;lt;FlatList
        showsHorizontalScrollIndicator={false}
        contentContainerStyle={styles.flatList}
        horizontal={true}
        data={data}
        keyExtractor={(item) =&amp;gt; item.id.toString()}
        renderItem={({ item }) =&amp;gt; {
          return (
            &amp;lt;TouchableOpacity
              style={styles.cardContainer}
              onPress={() =&amp;gt; removeItem(item.id)}
            &amp;gt;
              &amp;lt;Card style={[styles.card, {backgroundColor: item.color}]}&amp;gt;
                &amp;lt;Text style={styles.text}&amp;gt;{item.name}&amp;lt;/Text&amp;gt;
              &amp;lt;/Card&amp;gt;
            &amp;lt;/TouchableOpacity&amp;gt;
          );
        }}
      /&amp;gt;
    &amp;lt;/View&amp;gt;
  );
}


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

&lt;/div&gt;

&lt;p&gt;With this, we get the following output. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2Finit.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2Finit.gif" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it is time for removing the item from the FlatList, we can just pass the id of the item to our FlatList and remove the items that match the id. Like so:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const removeItem = (id) =&amp;gt; {
    let arr = data.filter(function(item) {
      return item.id !== id
    })
    setData(arr);
  };


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

&lt;/div&gt;

&lt;p&gt;if we click our item, the items will be removed from the FlatList but without any animation. This will like odd. The output will be like the following - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2Fremove.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2Fremove.gif" alt="remove-item"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, now let's start the animation. With LayoutAnimation we can easily create a layout config that will have the effect. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const layoutAnimConfig = {
  duration: 300,
  update: {
    type: LayoutAnimation.Types.easeInEaseOut, 
  },
  delete: {
    duration: 100,
    type: LayoutAnimation.Types.easeInEaseOut,
    property: LayoutAnimation.Properties.opacity,
  },
};

const removeItem = (id) =&amp;gt; {
   let arr = data.filter(function(item) {
     return item.id !== id
   })
   setData(arr);
   // after removing the item, we start animation
   LayoutAnimation.configureNext(layoutAnimConfig) 
};


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

&lt;/div&gt;

&lt;p&gt;If we check the config, we can see the animation that we are doing while deleting the item from the list. The type is easeInEaseOut and the property is opacity. So let us see the final result with the LayoutAnimation effect. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2Fremove-animation.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2Fremove-animation.gif" alt="remove-animation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One last important thing to note that, ensure your key extractor returns a unique key for each item. Do not return index.toString() in your keyExtractor function of the FlatList. Otherwise, the animation will not work. I was stuck with this for quite a long time. :D&lt;/p&gt;

&lt;p&gt;You can check out the full demo &lt;a href="https://snack.expo.io/@saad-bashar/remove-item-flatlist" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>animation</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Dynamic Height, Width, and Aspect Ratio in React Native</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Fri, 05 Feb 2021 04:28:42 +0000</pubDate>
      <link>https://forem.com/saadbashar/dynamic-height-width-and-aspect-ratio-in-react-native-515c</link>
      <guid>https://forem.com/saadbashar/dynamic-height-width-and-aspect-ratio-in-react-native-515c</guid>
      <description>&lt;p&gt;Let's say you are given this design to build a simple horizontal FlatList. How can you dynamically find the width and height of the items in the flat list? We can do it in different ways but recently in my code read journey I have learned a cool trick from my colleague. First of all, let's find the width of the item, shall we?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2FScreenshot-2021-02-04-at-10.55.11-PM-1024x798.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsaadbashar.com%2Fwp-content%2Fuploads%2F2021%2F02%2FScreenshot-2021-02-04-at-10.55.11-PM-1024x798.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see from the above image, the whole screen width is 376 and if we inspect our item width in Figma (which is not shown in the above image), the item width is 240. So if we take this as our general measurement we can find out the item width according to screen width.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;itemWidth = screenWidth * 376/240 OR screenWidth * 0.64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meaning that our items in the flat list are taking up 64% of the total width. So how do we define the height now? We can get the dynamic height from the width and aspect ratio.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// In Figma, our item width is 240 and height is 198
// so first we get the aspect ratio
const CARD_ASPECT_RATIO = 240 / 198; // aspectRatio = width / height
const CARD_WIDTH = Metrics.screenWidth * 0.64; // this we already found out
const CARD_HEIGHT = CARD_WIDTH / CARD_ASPECT_RATIO;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following the same method we can find out the inner content height and width. In our case, we have a top section with empty background and bottom section with text inside it. So in order to get the top section height and width dynamically, we can use the same formula.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const IMAGE_CONTAINER_ASPECT_RATIO = 240 / 140;
const IMAGE_CONTAINER_WIDTH = CARD_WIDTH;
const IMAGE_CONTAINER_HEIGHT = IMAGE_CONTAINER_WIDTH / IMAGE_CONTAINER_ASPECT_RATIO;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, if we put it all together it will look like this in the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from 'react';
import { Text, View, StyleSheet, FlatList, Dimensions } from 'react-native';
import { Card } from 'react-native-paper';

const { width, height } = Dimensions.get('window');

const Metrics = {
  section: 16,
  halfSection: 8,
};

const CARD_WIDTH = width * 0.64;
const CARD_ASPECT_RATIO = 240 / 198;
const CARD_HEIGHT = CARD_WIDTH / CARD_ASPECT_RATIO;
const IMAGE_CONTAINER_ASPECT_RATIO = 240 / 140;
const IMAGE_CONTAINER_WIDTH = CARD_WIDTH;
const IMAGE_CONTAINER_HEIGHT =
  IMAGE_CONTAINER_WIDTH / IMAGE_CONTAINER_ASPECT_RATIO;

const styles = StyleSheet.create({
  topCars: {
    height: CARD_HEIGHT,
    width: CARD_WIDTH,
    borderRadius: 12,
    marginRight: Metrics.halfSection,
  },

  topCarsImage: {
    width: IMAGE_CONTAINER_WIDTH,
    height: IMAGE_CONTAINER_HEIGHT,
    borderRadius: 12,
    borderBottomLeftRadius: 0,
    borderBottomRightRadius: 0,
  },
});

export default function App() {
  return (
    &amp;lt;View style={{ flex: 1, paddingTop: 48 }}&amp;gt;
      &amp;lt;FlatList
        showsHorizontalScrollIndicator={false}
        contentContainerStyle={{
          paddingHorizontal: Metrics.section,
          paddingBottom: Metrics.section,
        }}
        horizontal={true}
        data={[
          {
            name: 'KFC',
            location: 'Bukit Bintang, Kuala Lumpur',
            bg: 'cyan',
          },
          {
            name: 'MacDonalds',
            location: 'Damansara, Kuala Lumpur',
            bg: 'orange',
          },
          {
            name: 'Pizza Hut',
            location: 'Damansara Jaya, Kuala Lumpur',
            bg: 'yellow',
          },
          {
            name: 'Pak Punjab',
            location: 'Bukit Heights, Kuala Lumpur',
            bg: 'grey',
          },
        ]}
        keyExtractor={(item, index) =&amp;gt; index.toString()}
        renderItem={({ item, index }) =&amp;gt; {
          return (
            &amp;lt;Card style={styles.topCars}&amp;gt;
              &amp;lt;View
                style={[styles.topCarsImage, { backgroundColor: item.bg }]}
              /&amp;gt;
              &amp;lt;View style={{ padding: 12 }}&amp;gt;
                &amp;lt;Text&amp;gt;{item.name}&amp;lt;/Text&amp;gt;
                &amp;lt;Text&amp;gt;{item.location}&amp;lt;/Text&amp;gt;
              &amp;lt;/View&amp;gt;
            &amp;lt;/Card&amp;gt;
          );
        }}
      /&amp;gt;
    &amp;lt;/View&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also if you would like to see it in action, please check out the snack link.&lt;br&gt;
&lt;a href="https://snack.expo.io/@saad-bashar/dynamic-height-and-width" rel="noopener noreferrer"&gt;https://snack.expo.io/@saad-bashar/dynamic-height-and-width&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>responsivedesign</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Create your own multi-selected input in React-Native</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Thu, 17 Dec 2020 15:59:20 +0000</pubDate>
      <link>https://forem.com/saadbashar/create-your-own-multi-selected-input-in-react-native-i48</link>
      <guid>https://forem.com/saadbashar/create-your-own-multi-selected-input-in-react-native-i48</guid>
      <description>&lt;p&gt;We can create our multi-selected input in react-native very easily. Let’s say in our demo user can select his favorite brands from a list of options. The user can check/uncheck the inputs.&lt;/p&gt;

&lt;p&gt;First, we need to show all the inputs to the user. We can use FlatList to render the items. Like so –&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Then we need to keep track of the items that the user is selecting. We can keep track of them using an array. We have two conditions – When an item is already selected and when the item is not selected. So every time the user clicks on an item we need to check if it has been already selected, if it is already selected then we need to remove the item from the selected items, if not then we need to add the item to the selected items list.&lt;/p&gt;

&lt;p&gt;We can also change the color of the button and text according to the condition. This is how our &lt;em&gt;renderBrands&lt;/em&gt; function looks like after the proper change.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The complete code can be seen in the following snack. &lt;a href="https://snack.expo.io/@saad-bashar/68cb24"&gt;https://snack.expo.io/@saad-bashar/68cb24&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating a reusable “Token Manager” class in react-native.</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Wed, 16 Dec 2020 14:54:20 +0000</pubDate>
      <link>https://forem.com/saadbashar/creating-a-reusable-token-manager-class-in-react-native-36am</link>
      <guid>https://forem.com/saadbashar/creating-a-reusable-token-manager-class-in-react-native-36am</guid>
      <description>&lt;p&gt;In any app, especially an app that has user accounts, it is a very common task to check for existing user token and redirects the user either to AuthStack or AppStack according to the token found. So for this common task, we can create our own token manager class which handles the common functionalities related to user token. In today’s code read I will try to document that.&lt;/p&gt;

&lt;p&gt;Usually, we store tokens locally in our AsyncStorage, so we have 2 functions in our class. One is to set and the other one is to clear the token.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now the next one is the most important function, anywhere in our app where we want to get the valid token for the user we need to check a few things. They are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, we check if there is any saved token in our local storage. We check for the tokenObj, that object should have the necessary information about the token. Like token value, expires-at, etc.&lt;/li&gt;
&lt;li&gt;If there is not an existing token, we return null.&lt;/li&gt;
&lt;li&gt;If there is an existing token, we need to check if the token is still valid, meaning if it is still not expired. This information should be passed from API when the user logged in or signed up in the app before.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So with all these steps, our function should look like following&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, we have our new token function where if the token is expired we request for refresh token from the API.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Once we have this class set up, we just need to import this class and create an object to get a valid token from anywhere in our app like the following.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The full code for the tokenizer class is given below for reference.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Create your own radio button component in react native easily</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Thu, 11 Apr 2019 07:07:02 +0000</pubDate>
      <link>https://forem.com/saadbashar/create-your-own-radio-button-component-in-react-native-easily-59il</link>
      <guid>https://forem.com/saadbashar/create-your-own-radio-button-component-in-react-native-easily-59il</guid>
      <description>&lt;p&gt;You can easily create your own radio button components in react native very easily. First you need to create an array of options for your radio buttons and pass it to your radio button component like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const options = [
    {
        key: 'pay',
        text: 'Most High Pay',
    },
    {
        key: 'performance',
        text: 'Most Perfomance',
    },
    {
        key: 'aToZ',
        text: 'A - Z',
    },
    {
        key: 'zToA',
        text: 'Z - A',
    },
];

{...}
&amp;lt;RadioButtons options={options} /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after this in your radio button component you can map all these options in your render method and create radio button views&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{options.map(item =&amp;gt; {
    return (
        &amp;lt;View key={item.key} style={styles.buttonContainer}&amp;gt;
            &amp;lt;Text&amp;gt;{item.text}&amp;lt;/Text&amp;gt;
            &amp;lt;TouchableOpacity style={styles.circle} /&amp;gt;
        &amp;lt;/View&amp;gt;
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will create default radio buttons which looks like this -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyk06sg8fa80zuf9a1atb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyk06sg8fa80zuf9a1atb.png" alt="default"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Right now it is time to set the state when clicked on the radio button. First we declare our state&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;state = { value: null }&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 then inside out  tag we define our checked button when clicked on any particular button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;TouchableOpacity
    style={styles.circle}
    onPress={() =&amp;gt; this.setState({ value: key })} // we set our value state to key
&amp;gt;
    { value === item.key &amp;amp;&amp;amp; (&amp;lt;View style={styles.checkedCircle} /&amp;gt;) } // when value is equal to key
&amp;lt;/TouchableOpacity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So right now when clicked it looks like this - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftk9m7nxg7xq6q9d94vnp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftk9m7nxg7xq6q9d94vnp.png" alt="checked"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;finally the styles -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;buttonContainer: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
    marginBottom: 30,
},
circle: {
    height: 20,
    width: 20,
    borderRadius: 10,
    borderWidth: 1,
    borderColor: '#ACACAC',
    alignItems: 'center',
    justifyContent: 'center',
},
checkedCircle: {
    width: 14,
    height: 14,
    borderRadius: 7,
    backgroundColor: '#794F9B',
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the snack link - &lt;a href="https://snack.expo.io/@saad-bashar/radio-buttons" rel="noopener noreferrer"&gt;https://snack.expo.io/@saad-bashar/radio-buttons&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>customcomponents</category>
    </item>
    <item>
      <title>React Native Animated Inputs</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Sat, 23 Feb 2019 12:43:47 +0000</pubDate>
      <link>https://forem.com/saadbashar/react-native-animated-inputs-2o6e</link>
      <guid>https://forem.com/saadbashar/react-native-animated-inputs-2o6e</guid>
      <description>&lt;p&gt;This is a very straight forward exploration of how I did animated inputs in my react native form. The demo is given below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdedze5hbqyu57fil4gqa.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdedze5hbqyu57fil4gqa.gif" alt="Demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I have basically three text inputs which I need to animate one after another. I used react native animated modules to do this kind of animation.&lt;/p&gt;

&lt;p&gt;In animated modules there is a method called &lt;strong&gt;stagger&lt;/strong&gt; which helps to animate components one after another with &lt;strong&gt;successive delays&lt;/strong&gt;. I just needed to pass my array inputs to this method to implement this animation. The whole code is given below:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
      <category>reactnative</category>
      <category>animations</category>
    </item>
    <item>
      <title>React Native Animated Inputs</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Wed, 23 Jan 2019 11:26:23 +0000</pubDate>
      <link>https://forem.com/saadbashar/react-native-animated-inputs-4cfn</link>
      <guid>https://forem.com/saadbashar/react-native-animated-inputs-4cfn</guid>
      <description>

&lt;p&gt;This is a very straight forward exploration of how I did animated inputs in my react native form. The demo is given below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://imgflip.com/gif/2rtnqt"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_aWAACF5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.imgflip.com/2rtnqt.gif" title="made at imgflip.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I have basically three text inputs which I need to animate one after another. I used react native animated modules to do this kind of animation. &lt;/p&gt;

&lt;p&gt;In animated modules there is a method called &lt;strong&gt;stagger&lt;/strong&gt; which helps to animate components one after another with &lt;strong&gt;successive delays&lt;/strong&gt;. I just needed to pass my array inputs to this method to implement this animation. The whole code is given below:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Creating arrays to hold the animation arrays
const arr = [];
for (var i = 0; i &amp;lt; 3; i++) {
  arr.push(i)
};

// Inputs configs
const inputs = [
  {
    placeholder: 'Full Name',
  },
  {
    placeholder: 'Email Address',
  },
  {
    placeholder: 'Password',
  }
];

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.animatedInputValue = [];
    arr.forEach((value) =&amp;gt; {
      this.animatedInputValue[value] = new Animated.Value(0)
    });
  }

  componentDidMount() {
    // creating array animations 
    const inputAnimations = arr.map((item) =&amp;gt; {
      return Animated.timing(
        this.animatedInputValue[item],
        {
          toValue: 1,
          duration: 1500,
        }
      );
    });
    // Animate each element after 1000 miliseconds
    Animated.stagger(1000, inputAnimations).start();
  }

  render() {
    const animatedInputs = inputs.map((a, i) =&amp;gt; {
      return (
        &amp;lt;Animated.View 
          key={i} 
          style={{
            opacity: this.animatedInputValue[i], // attaching animations to the input opacity
          }} 
        &amp;gt;
          &amp;lt;TextInput
            style={[{ borderColor: '#fff', borderBottomWidth: 1, padding: 5, marginBottom: 30 }]}
            selectionColor="#fff"
            placeholder={a.placeholder}
            placeholderTextColor="#fff"
          /&amp;gt;
        &amp;lt;/Animated.View&amp;gt;  
      );
    });

    return (
      &amp;lt;LinearGradient
        colors={['#642B73', '#C6426E']}
        style={{
          position: 'absolute',
          width: '100%',
          height: '100%',
          justifyContent: 'center',
          alignItems: 'center'
        }}
      &amp;gt;
        &amp;lt;View style={{ width: '100%', paddingHorizontal: 25  }}&amp;gt;
          {animatedInputs}
        &amp;lt;/View&amp;gt;
      &amp;lt;/LinearGradient&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




</description>
      <category>reactnative</category>
      <category>animation</category>
    </item>
    <item>
      <title>Splash Screen, Tutorial Screens, Authentication Screens Flow in React-Native </title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Mon, 15 Oct 2018 01:16:04 +0000</pubDate>
      <link>https://forem.com/saadbashar/splash-screen-tutorial-screens-authentication-screens-flow-in-react-native--1364</link>
      <guid>https://forem.com/saadbashar/splash-screen-tutorial-screens-authentication-screens-flow-in-react-native--1364</guid>
      <description>

&lt;p&gt;Recently I had to start up a project from scratch and I had to make a general flow of splash screens, tutorial screens and authentication screens. Today I am going to share how did I create the flow and what difficulties that I faced during the process. The flow is a very common scenario. It goes like this&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First the user sees the splash screen for few seconds&lt;/li&gt;
&lt;li&gt;If the user opens the app for the first time then the user will go through some tutorial screens.&lt;/li&gt;
&lt;li&gt;If not the first time, the user will be redirected to the authentication screen. If not the first we can not show the tutorial screens again to the users.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Splash Screen&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In react native splash screen can be added natively and also using react-native-splash-screen package but I just did it in a very simple way by creating a splash screen component in my react-native side. I had to use set timeout to show the splash screen for few seconds and then redirect back to another screen. The splash screen component is given below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YJymIzxa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1nkt6iw0saft24ofzrtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YJymIzxa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1nkt6iw0saft24ofzrtc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that I had to use resetActions to make the stack empty again while redirecting so that the user can not go back again to splash screen using hardware back button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Starting Screen&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the screen where I do not render anything but put my logic to redirect the user to the proper places. The component is given below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--267dpuob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uqztztg3mxzo9ur9ma4d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--267dpuob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uqztztg3mxzo9ur9ma4d.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am using async storage to store the value if the app is already launched or not. In the componentDidMount function I am checking first if the alreadyDidLaunch value from async storage is null or not, if null then I am showing a loader in the render and also changing the value of alreadyLaunched at the same time. So after changing the value I am redirecting the user to the tutorial screens.&lt;/p&gt;

&lt;p&gt;Next time when the user opens the app again, the alradyDidLaunched value is set to true and the user will be redirected to authentication screens.&lt;/p&gt;

&lt;p&gt;Note that the asyncStorage is asynchronous by nature so it takes some time to get the value. While getting the value I am showing a loader in the meantime.&lt;/p&gt;

&lt;p&gt;So that’s how I did it. Kindly let me know the better way that I could do this flow than this. Thanks for reading!&lt;/p&gt;


</description>
      <category>reactnative</category>
      <category>splashscreen</category>
      <category>flow</category>
    </item>
    <item>
      <title>Showcasing your work/Promoting yourself</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Thu, 22 Feb 2018 04:34:14 +0000</pubDate>
      <link>https://forem.com/saadbashar/showcasing-your-workpromoting-yourself--kle</link>
      <guid>https://forem.com/saadbashar/showcasing-your-workpromoting-yourself--kle</guid>
      <description>&lt;p&gt;As a software developer who is just starting, how should one promote himself. What are the important things/tasks that he needs to do consistently to build a good portfolio of their work or theirselves? &lt;/p&gt;

</description>
      <category>discuss</category>
      <category>suggestions</category>
    </item>
    <item>
      <title>Finding Video Duration React Native</title>
      <dc:creator>Saad</dc:creator>
      <pubDate>Mon, 22 Jan 2018 10:44:09 +0000</pubDate>
      <link>https://forem.com/saadbashar/finding-video-duration-react-native-456f</link>
      <guid>https://forem.com/saadbashar/finding-video-duration-react-native-456f</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmbcktjpesewg9idzu2s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmbcktjpesewg9idzu2s.jpg" alt="React Native Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my recent project I was stuck when the client asked me to set the timelimit of a video. I thought it would be easy, I would just call a built-in function and boom! It would work! But unfortunately I could not find such a function to call. &lt;/p&gt;

&lt;p&gt;First of all, to take a video I was using a package called &lt;a href="https://github.com/react-community/react-native-image-picker" rel="noopener noreferrer"&gt;react-native-image-picker&lt;/a&gt;, that package has the built in option to set the duration limit of a video while recording a video which is great. But unfortunately it does not have any such option to set the timelimit while a user is selecting and uploading a video from the device gallery. That's where I was stuck.&lt;/p&gt;

&lt;p&gt;Then I found out another great package for react-native which gives the meta-data of any media file. The package is called &lt;a href="https://github.com/mybigday/react-native-media-meta" rel="noopener noreferrer"&gt;react-native-media-meta&lt;/a&gt;. I just have to give the filepath to the package and it would return me meta-data of that particular media file. So everything becomes simple for me now. I tried to do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the file path of the media from react-native-image-picker option.&lt;/li&gt;
&lt;li&gt;Sending the path to the meta-data package.&lt;/li&gt;
&lt;li&gt;Getting back the meta-data which also includes video duration.&lt;/li&gt;
&lt;li&gt;Finally using condition to do whatever I want to do.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But then again I was stuck! react-native-image-picker gives back the file path only for the android but not for the ios. So it was only working for android. Eventually I found out the I have to modify the uri substring to get the actual path for ios. Luckily react-native-image-picker supports uri for both ios and android. Then finally I was able to find out the video length using react-native-image picker. &lt;/p&gt;

&lt;h1&gt;
  
  
  The working sample of code is given below:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// react-native-image-picker options
const options = {
  title: '', // specify null or empty string to remove the title
  cancelButtonTitle: 'Cancel',
  takePhotoButtonTitle: 'Record Video', // specify null or empty string to remove this button
  chooseFromLibraryButtonTitle: 'Upload Video', // specify null or empty string to remove this button
  cameraType: 'back', // 'front' or 'back'
  thumbnail: true,
  durationLimit: 300, // 5 mins - Works only when you are recording
  allowsEditing: true,
  mediaType: 'video', // 'photo' or 'video'
  videoQuality: 'high', // 'low', 'medium', or 'high'
  storageOptions: { // if this key is provided, the image will get saved in the documents/pictures directory (rather than a temporary directory)
    skipBackup: true, // image will NOT be backed up to icloud
    path: 'images' // will save image at /Documents/images rather than the root
  }
};

// after you take the video...
ImagePicker.showImagePicker(options, (video) =&amp;gt; {
      const path = video.path; // for android
      const path = video.uri.substring(7) // for ios
      const maxTime = 300000; // 5 min
      MediaMeta.get(path)
        .then((metadata) =&amp;gt; {
          if (metadata.duration &amp;gt; maxTime ) {
            Alert.alert(
              'Sorry',
              'Video duration must be less then 5 minutes',
              [
                { text: 'OK', onPress: () =&amp;gt; console.log('OK Pressed') }
              ],
              { cancelable: false }
            );
          } else {
            // Upload or do something else
          }
        }).catch(err =&amp;gt; console.error(err));
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is any better option to do this, please let me know :)&lt;/p&gt;

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