<?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: Joseph Jazdzewski</title>
    <description>The latest articles on DEV Community by Joseph Jazdzewski (@joejazdzewski).</description>
    <link>https://dev.to/joejazdzewski</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%2F309165%2F507aac64-3ddc-433a-babc-c0338d996f77.png</url>
      <title>DEV Community: Joseph Jazdzewski</title>
      <link>https://dev.to/joejazdzewski</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joejazdzewski"/>
    <language>en</language>
    <item>
      <title>Handling state dependent content in Jetpack Compose</title>
      <dc:creator>Joseph Jazdzewski</dc:creator>
      <pubDate>Sat, 25 Jan 2020 05:01:32 +0000</pubDate>
      <link>https://dev.to/joejazdzewski/handling-state-dependent-content-in-jetpack-compose-18cb</link>
      <guid>https://dev.to/joejazdzewski/handling-state-dependent-content-in-jetpack-compose-18cb</guid>
      <description>&lt;p&gt;For almost all projects there will be state dependent content, this could be anything from error messages to whole pages. Different component based frameworks handle this issue differently. We will look at React and Angular's approaches and then look at the way Jetpack Compose handles it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Angular
&lt;/h2&gt;

&lt;p&gt;For example Angular's most common example is &lt;code&gt;*ngIf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;element *ngIf="someState"&amp;gt;&amp;lt;/element&amp;gt;&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;The display logic is handled in the template file rather than the typescript file, this approach separates template logic and state logic. The template logic is very straight forward and readable for any new developer to understand.&lt;/p&gt;

&lt;h2&gt;
  
  
  React
&lt;/h2&gt;

&lt;p&gt;React handles state dependent content in a not as straight forward way.&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;&amp;gt;
    {
        this.state.someState &amp;amp;&amp;amp; &amp;lt;p&amp;gt;some text&amp;lt;/p&amp;gt;
    }
&amp;lt;/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you are not familiar with this syntax, it functions the same as an "if statement". In the code above, if "this.state.someState" is defined and is not false, [], {}, "", or 0 then &lt;code&gt;&amp;lt;p&amp;gt;some text&amp;lt;/p&amp;gt;&lt;/code&gt; will appear. This syntax is not completely straight forward to all developers.&lt;/p&gt;
&lt;h2&gt;
  
  
  JetPack Compose
&lt;/h2&gt;

&lt;p&gt;Jetpack Compose combines these two approaches to produce a very straight forward and readable way to have state dependent content. If we are creating a carousel for our app, that changes the view  when the next button is clicked. &lt;/p&gt;


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



&lt;p&gt;In the code above, you can see that the render part of the code has a few "if statements" in it, which combines the previous two approaches when rendering state dependent content. Where there is no distinction between template and state logic and keeps the "if statement" more readable&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
    </item>
    <item>
      <title>Creating a Counter App using Android Jetpack Compose</title>
      <dc:creator>Joseph Jazdzewski</dc:creator>
      <pubDate>Wed, 08 Jan 2020 20:43:03 +0000</pubDate>
      <link>https://dev.to/joejazdzewski/creating-a-counter-app-using-android-jetpack-compose-2j6h</link>
      <guid>https://dev.to/joejazdzewski/creating-a-counter-app-using-android-jetpack-compose-2j6h</guid>
      <description>&lt;p&gt;&lt;strong&gt;The JetPack Compose syntax changed so the code samples are not up to date&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;Before we create the app, I must first introduce you to Jetpack Compose. Google's new UI component Framework for Android development. Jetpack Compose uses the same UI rendering as Flutter, where it doesn't use the native Android UI elements but draw's it own UI elements on the screen. The way you create UI components is also very similar to React with Hooks.    &lt;/p&gt;

&lt;p&gt;With any new component based library or framework, the first thing we MUST (At this point I think that it is required) do is build a counter app. In this app I will go over some basic functionality (including &lt;code&gt;+state&lt;/code&gt;) and overview of Jetpack Compose. At the moment I couldn't find any documentation on how to use &lt;code&gt;+state&lt;/code&gt; so I thought I would write up a tutorial for anyone looking to learn more about JetPack Compose. &lt;/p&gt;

&lt;h1&gt;
  
  
  Setup
&lt;/h1&gt;

&lt;p&gt;As of today (1/8/20), in order to use Jetpack Compose you will need to install the Canary build of Android Studio. In order to set up your project you will have to follow the &lt;a href="https://developer.android.com/jetpack/compose/setup"&gt;steps provided by the Android Team&lt;/a&gt; (this link is pointed to the compose setup page).&lt;/p&gt;

&lt;h1&gt;
  
  
  Code
&lt;/h1&gt;

&lt;h4&gt;
  
  
  Counter
&lt;/h4&gt;


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


&lt;p&gt;As you can see that &lt;code&gt;fun Counter&lt;/code&gt; is a function just like React Hooks function components but in this case our function has the &lt;code&gt;@Composable&lt;/code&gt; decorator. &lt;code&gt;val count = +state{0}&lt;/code&gt; is similar to the react hooks' useState &lt;code&gt;const [count, setCount] = useState(0)&lt;/code&gt; except there is no &lt;code&gt;setCount&lt;/code&gt; that is being produced from &lt;code&gt;+state&lt;/code&gt;. The state manipulation is simple with &lt;code&gt;count.value++&lt;/code&gt; and &lt;code&gt;count.value--&lt;/code&gt;. Once either button is clicked we will be changing the value of the count and the UI will update. &lt;/p&gt;

&lt;h4&gt;
  
  
  MainActivity
&lt;/h4&gt;


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


&lt;p&gt;The MainActivity is really simple, we set the content of MainActivity to our &lt;code&gt;App&lt;/code&gt; component which  calls our &lt;code&gt;Counter&lt;/code&gt; component and that is it. Short simple and straight to the point. There is more to JetPack Compose but I thought that this would be a good start for basic functionality&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/jetpack/compose"&gt;For more information on JetPack Compose&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
    </item>
  </channel>
</rss>
