<?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: Shivam Vijaywargiya</title>
    <description>The latest articles on DEV Community by Shivam Vijaywargiya (@vijaywargiya).</description>
    <link>https://dev.to/vijaywargiya</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%2F171731%2F032b88ed-e9f3-4507-9e0b-79deee9a21b3.png</url>
      <title>DEV Community: Shivam Vijaywargiya</title>
      <link>https://dev.to/vijaywargiya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vijaywargiya"/>
    <language>en</language>
    <item>
      <title>3D Cube Loading Animation Using SwiftUI</title>
      <dc:creator>Shivam Vijaywargiya</dc:creator>
      <pubDate>Mon, 20 Jul 2020 15:39:47 +0000</pubDate>
      <link>https://dev.to/vijaywargiya/3d-cube-loading-animation-using-swiftui-f2g</link>
      <guid>https://dev.to/vijaywargiya/3d-cube-loading-animation-using-swiftui-f2g</guid>
      <description>&lt;p&gt;I recently came across &lt;a href="https://codemyui.com/lego-style-loading-animation/"&gt;this&lt;/a&gt; lego loading animation and wanted to see if this can be created using SwiftUI. Let’s get started. &lt;/p&gt;

&lt;h2&gt;
  
  
  Breakdown
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;We have 5 3D cubes of different colours.&lt;/li&gt;
&lt;li&gt;They are arranged to form a cuboid with space for one cube being empty. &lt;/li&gt;
&lt;li&gt;One by one the cube behind the empty space moves forward.&lt;/li&gt;
&lt;li&gt;There are two scenarios in which two cubes move forward at once.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Build
&lt;/h2&gt;

&lt;p&gt;Let’s start with creating a simple 3d cube. For this, I downloaded a png image of cube and masked it over a colour. Below is the origin image and how it looks after the mask.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rQn23wCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kdfoq7q7ptxynapqiogx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rQn23wCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kdfoq7q7ptxynapqiogx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty cool. Now we can create a cube of any colour by just changing the colour of the base view. And if you took about the code it’s only about 10 lines. That’s why you got to love SwiftUI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sSBa2Nro--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6qul9prvzjxfz5atn8fc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sSBa2Nro--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6qul9prvzjxfz5atn8fc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s0S9MgNx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Fd70affab-024b-4bde-93c4-72e50cb237bc_1170x356.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s0S9MgNx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Fd70affab-024b-4bde-93c4-72e50cb237bc_1170x356.png" alt="Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we need to arrange them to form a cuboid. This is where we use the elementary maths that we all learnt (although we don’t remember most of it 😅). After some trial and error we have the co-ordinates for the 6 positions that our cubes should be in. &lt;/p&gt;

&lt;p&gt;(-80,40)&lt;/p&gt;

&lt;p&gt;(-40,20)&lt;/p&gt;

&lt;p&gt;(0,0)&lt;/p&gt;

&lt;p&gt;(40,20)&lt;/p&gt;

&lt;p&gt;(0,40)&lt;/p&gt;

&lt;p&gt;(-40,60)&lt;/p&gt;

&lt;p&gt;Once we have our co-ordinates, we can simply assign them to the cubes using .offset modifier. We use .offset because we only are about relative position between the cubes and it also does not get affected by the actual position of the cubes on the screen.&lt;/p&gt;

&lt;p&gt;We also need decide the zindex of the cubes corresponding to each of these co-ordinates. After some elementary maths, we have the final values - &lt;/p&gt;

&lt;p&gt;(-80,40) - 5&lt;/p&gt;

&lt;p&gt;(-40,20) - 3&lt;/p&gt;

&lt;p&gt;(0,0) - 1&lt;/p&gt;

&lt;p&gt;(40,20) - 2&lt;/p&gt;

&lt;p&gt;(0,40) - 4&lt;/p&gt;

&lt;p&gt;(-40,60) - 6&lt;/p&gt;

&lt;p&gt;With the zIndex in place, our cubes finally sit nicely together. Look at that!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--txGMhNcv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F6fe4322d-d3aa-4322-8e7e-31ac91e58895_530x378.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--txGMhNcv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F6fe4322d-d3aa-4322-8e7e-31ac91e58895_530x378.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IsJb107i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Fd31fd3a2-64d9-4101-a0da-b9519881ee75_1110x1928.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IsJb107i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Fd31fd3a2-64d9-4101-a0da-b9519881ee75_1110x1928.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above code section, you get a look into how the code is arranged. We have a enum with 6 elements. Each of these elements define their view. LegoView with a unique colour for 5 elements and a EmptyView for the 6th element.&lt;/p&gt;

&lt;p&gt;We create a @State variable to store the co-ordinates and indices we earlier defined. We will talk about the 4th boolean parameter later. We also have a variable called currentIndex which denotes the index of the cube which will move next. The empty space will always be at the position currentIndex+1. &lt;/p&gt;

&lt;h2&gt;
  
  
  Animation
&lt;/h2&gt;

&lt;p&gt;Now to the part you have been waiting for.  How do we animate these cubes. The offset of a cube is derived from the allIndices array. So if we change the allIndices array, the offset of our cube will get changed. So, all we need to do is swap the position of empty space with the position of cube next to empty space. The empty space is indexed 5 (as it’s the last element in the enum). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HxN-sZ-U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F6d7eacb7-ae03-4de8-ac5a-4e2e808780f1_674x358.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HxN-sZ-U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F6d7eacb7-ae03-4de8-ac5a-4e2e808780f1_674x358.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By swapping the offset, we make sure that the cubes move to their new position. TO animate this movement we simply need to perform the swap inside a withAnimation block. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h91LFkpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Fa7ee3f53-5e8a-47a9-b3fe-ee5c52c2e19a_320x114.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h91LFkpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Fa7ee3f53-5e8a-47a9-b3fe-ee5c52c2e19a_320x114.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make sure that this animation continues forever, we call this function recursively. But since, we want some delay between each movement we use DispatchQueue.main.asyncAfter. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O8L8IUqo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F0248e1c1-2b64-4d1f-8e01-f06745b97d1e_878x184.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O8L8IUqo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F0248e1c1-2b64-4d1f-8e01-f06745b97d1e_878x184.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are almost there. According to the 4th point of our breakdown, there are 2 conditions in which 2 cubes move forward at once. These two scenarios are represented by the 4th Bool parameter in allIndices&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MqRsEoEV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F5642d979-456b-42c5-bac1-b1a056d708d2_530x390.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MqRsEoEV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F5642d979-456b-42c5-bac1-b1a056d708d2_530x390.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that’s a wrap. Look at the cubes go! View the code on Github - &lt;a href="https://github.com/vijaywargiya/LegoLoadingAnimation-SwiftUI"&gt;https://github.com/vijaywargiya/LegoLoadingAnimation-SwiftUI&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
    <item>
      <title>Recreate the Translate App [ Part 2 ]</title>
      <dc:creator>Shivam Vijaywargiya</dc:creator>
      <pubDate>Sun, 19 Jul 2020 11:20:37 +0000</pubDate>
      <link>https://dev.to/vijaywargiya/recreate-the-translate-app-part-2-3e09</link>
      <guid>https://dev.to/vijaywargiya/recreate-the-translate-app-part-2-3e09</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/vijaywargiya/recreate-the-ios14-translate-app-part-1-e4l"&gt;Part 1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Welcome Back. In this post we will talk about the listening animation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ndavJNnu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kq777yxiaiofbshskefo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ndavJNnu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kq777yxiaiofbshskefo.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we take a closer look, this animation consists of several blocks with changing heights arranged horizontally. The main thing to focus here is that the min and max height of each of the block is different. Let’s start coding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bar
&lt;/h2&gt;

&lt;p&gt;Let’s start with a single bar. Each bar will have two heights. One will be set as the initial height and the other post animation. In the init method of the bar, we select two random integers between 1 &amp;amp; 50. One of these numbers will be set as the initial height and the other will be set post animation. The bar for which max height is selected initially will shrink in the first round of animation whereas the other set of bars will expand. This will give a nice mix and match affect.&lt;/p&gt;

&lt;p&gt;We define a @State variable height. The bar’s height will be dependent on this variable. In the init method, we initialise the state variable with a random integer. We have another variable which stores another randomly selected integer and will be allocated to the state variable post animation. To make sure that we enough difference between the two heights and that the animation is visible, we check if the two heights have a difference of 10 or not. If they don’t then we increase the heightPostAnimation by 10.&lt;/p&gt;

&lt;p&gt;In the below code section, we also see how this bar can be called from parent.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xnEysdrD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F8f8eba23-4dc8-47c1-a7f8-5e6ab683f9ad_1446x1116.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xnEysdrD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F8f8eba23-4dc8-47c1-a7f8-5e6ab683f9ad_1446x1116.png" alt="Bar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Row of Bars
&lt;/h2&gt;

&lt;p&gt;Once we have the bar ready, all we need to do is create a HStack of multiple Bar views. To do this, we will use a ForEach loop with a range. Make sure that the range is enough to cover the device.&lt;/p&gt;

&lt;p&gt;We also wrap the HStack in a VStack with a bottom padding to position the row correctly on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VXxgiIT2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F506047bf-a3e0-45a7-bece-6732c4a29b3e_1226x460.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VXxgiIT2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252F506047bf-a3e0-45a7-bece-6732c4a29b3e_1226x460.png" alt="Row of Bars"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UJKvW3Cq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Ff4a19816-f885-4b4f-8b12-c1206390500f_552x330.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UJKvW3Cq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.substack.com/image/fetch/c_limit%2Cf_auto%2Cq_auto:good%2Cfl_progressive:steep/https%253A%252F%252Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%252Fpublic%252Fimages%252Ff4a19816-f885-4b4f-8b12-c1206390500f_552x330.png" alt="Static"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There we go! Hope you found this post helpful. In the next post we will cover the editor &amp;amp; the bottom sheet animation.&lt;/p&gt;

&lt;p&gt;You can browse the code here - &lt;a href="https://github.com/vijaywargiya/Translate-SwiftUI"&gt;https://github.com/vijaywargiya/Translate-SwiftUI&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
    <item>
      <title>Recreate the IOS14 Translate App [ Part 1 ]</title>
      <dc:creator>Shivam Vijaywargiya</dc:creator>
      <pubDate>Sat, 18 Jul 2020 17:46:53 +0000</pubDate>
      <link>https://dev.to/vijaywargiya/recreate-the-ios14-translate-app-part-1-e4l</link>
      <guid>https://dev.to/vijaywargiya/recreate-the-ios14-translate-app-part-1-e4l</guid>
      <description>&lt;p&gt;Hey there, &lt;/p&gt;

&lt;p&gt;With the recent launch of IOS 14, one of the things that caught my eye is the new translation app. I love how minimal it is. The animations are relaxing and soothing. I recreated the app and have captured the details below. Hope you can learn something from this post. If you have any ideas, feel free to drop a comment.&lt;/p&gt;

&lt;h1&gt;
  
  
  Breakdown
&lt;/h1&gt;

&lt;p&gt;Let’s start with a breakdown of the official translate app. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;There are 2 tabs, one named translate and the other favourites. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Translate tab is divided into 4 sections.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At the top we see two buttons which are used to select the from and to languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The centre container displays the raw &amp;amp; translated text along with their respective languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The bottom section contains a text field with a placeholder “Enter text”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A mic button is overlaid on the bottom section. When clicked, this opens a listening view which has a static text at the top and a beautiful animation at the bottom.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Favourites tab displays recent and starred translations&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Language Buttons
&lt;/h1&gt;

&lt;p&gt;Let’s start from the top. These are simple buttons which displays a sheet when clicked.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We use a state variable isPresented to show / hide the sheet.&lt;/li&gt;
&lt;li&gt;We wrap the two buttons with HStack in order to display them on the same row.&lt;/li&gt;
&lt;li&gt;.frame(minWidth: 0, maxWidth: .infinity) allows our buttons to take up all the available space.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XyDhfuU_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ebrfvs6n7pl26tn8di6c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XyDhfuU_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ebrfvs6n7pl26tn8di6c.png" alt="Buttons"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Translation View
&lt;/h1&gt;

&lt;p&gt;Let's start with the raw text first. These are two Text elements wrapped in a VStack. Since the text is aligned to the leading, we set the alignment property of VStack as .leading. The translated text is also created in the same way. SystemTeal is applied as a foreground colour to the translated text.&lt;/p&gt;

&lt;p&gt;The two VStacks are wrapped in a VStack with spacing property set to 20. We also add a divider between the two inner VStacks. This creates a separation between the two sections.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eSB5nrgu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kcszg3lpj6kw5iu06z9s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eSB5nrgu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kcszg3lpj6kw5iu06z9s.png" alt="Translation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Mic
&lt;/h1&gt;

&lt;p&gt;We use a state variable which we will use to show / hide the listening view. This button activates the listening view on click.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I5LTYgn3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h9mtsvxzlcz1fnj7m33m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I5LTYgn3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h9mtsvxzlcz1fnj7m33m.png" alt="Mic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That wraps up part 1. In the next post we will talk about the editor, sheet expand animation and the listening animation.&lt;/p&gt;

&lt;p&gt;You can browse the code here - &lt;a href="https://github.com/vijaywargiya/Translate-SwiftUI"&gt;https://github.com/vijaywargiya/Translate-SwiftUI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you enjoyed reading this post 😊&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
