<?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: Angelo Raso</title>
    <description>The latest articles on DEV Community by Angelo Raso (@angeloraso).</description>
    <link>https://dev.to/angeloraso</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%2F113129%2Fa5d3c066-f1df-408a-9eb1-57a771a76221.png</url>
      <title>DEV Community: Angelo Raso</title>
      <link>https://dev.to/angeloraso</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/angeloraso"/>
    <language>en</language>
    <item>
      <title>Angular Material performance problems</title>
      <dc:creator>Angelo Raso</dc:creator>
      <pubDate>Thu, 25 Feb 2021 20:25:49 +0000</pubDate>
      <link>https://dev.to/angeloraso/angular-material-performance-problems-43jn</link>
      <guid>https://dev.to/angeloraso/angular-material-performance-problems-43jn</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/angeloraso/angular-material-scrolling-with-multiple-columns-43e7"&gt;In the last article&lt;/a&gt; we created a card grid with the angular material scrolling help. Although the result was as expected, things began to get complicated. &lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Minimal knowledge of angularJs and Angular is expected, including javascript and typescript.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sponsors:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This article has been created thanks to &lt;a href="https://www.anura.com.ar/" rel="noopener noreferrer"&gt;Anura&lt;/a&gt;'s support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When Things Go Wrong
&lt;/h2&gt;

&lt;p&gt;Some of the texts that were shown inside the cards were too long, so we had to hide the excess text so as not to affect the design. Therefore, we add &lt;a href="https://material.angular.io/components/tooltip/overview" rel="noopener noreferrer"&gt;material tooltips&lt;/a&gt; to all the card internal elements to communicate the hidden content to the user. However, things went wrong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fqxb7o2fm19ornyxsl7ev.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqxb7o2fm19ornyxsl7ev.gif" alt="Alt Text" width="730" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suddenly, the scrolling experience was affected. When we analyzed the problem with the chrome dev tools (DevTools &amp;gt; More tools &amp;gt; Performance monitor), we found that we had 100% CPU usage. What happened? We had only added a few simple tooltips?! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3jr9g4e9nhrhbhfzwarh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3jr9g4e9nhrhbhfzwarh.gif" alt="Alt Text" width="638" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The reason behind this problem was that the material tooltips have a few set of animations in their behavior and as you should know, &lt;a href="https://developers.google.com/web/fundamentals/design-and-ux/animations/animations-and-performance" rel="noopener noreferrer"&gt;quoting the Google team&lt;/a&gt;: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Animating properties is not free, and some properties are cheaper to animate than others. For example, animating the width and height of an element changes its geometry and may cause other elements on the page to move or change size. This process is called layout (or reflow in Gecko-based browsers like Firefox), and can be expensive if your page has a lot of elements. Whenever layout is triggered, the page or part of it will normally need to be painted, which is typically even more expensive than the layout operation itself. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is nothing wrong with the Angular Material Tooltips. Only that Angular was not expecting us to use them on 5 to 10 elements inside card ... inside grid of cards ... inside virtual scroll. &lt;/p&gt;

&lt;p&gt;One of the possible solutions would have been to cancel all the tooltip animation styles. However, because that could cause an overload in css processing work, it was preferred to create a simple tooltip without animations. &lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/angular-material-perfonmance-problems?" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/angeloraso/angular-material-performance-problems" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;To avoid receiving complaints from your customers, whenever you add some changes, always remember to compare the performance before and after those changes. It's a small step for a dev, and a giant leap to become a great professional. &lt;/p&gt;

</description>
      <category>angular</category>
      <category>material</category>
      <category>performance</category>
    </item>
    <item>
      <title>Angular Material Scrolling with multiple columns</title>
      <dc:creator>Angelo Raso</dc:creator>
      <pubDate>Thu, 21 Jan 2021 14:46:49 +0000</pubDate>
      <link>https://dev.to/angeloraso/angular-material-scrolling-with-multiple-columns-43e7</link>
      <guid>https://dev.to/angeloraso/angular-material-scrolling-with-multiple-columns-43e7</guid>
      <description>&lt;p&gt;Pagination has helped combat performance issues for a long time. However, with the massive use of mobile screens, page up and down has become annoying and impractical.&lt;/p&gt;

&lt;p&gt;This article will try to move on from this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F21rho7xhanbz6p8r0nca.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F21rho7xhanbz6p8r0nca.gif" alt="Alt Text" width="690" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjw6j9yai68x2oihihzvx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjw6j9yai68x2oihihzvx.gif" alt="Alt Text" width="690" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/angeloraso/virtual-scroll-multiple-columns/tree/main/src/app" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Minimal knowledge of angularJs and Angular is expected, including javascript and typescript.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sponsors:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This article has been created thanks to &lt;a href="https://www.anura.com.ar/" rel="noopener noreferrer"&gt;Anura&lt;/a&gt;'s support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  From pagination to infinite scroll and beyond
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To avoid showing all existing accounts in the system, we used the &lt;a href="https://angular-ui.github.io/bootstrap/#!#pagination" rel="noopener noreferrer"&gt;ui-bootstrap&lt;/a&gt; pagination directive. However, the UX of this view was significantly worse on mobile. For this reason, it was decided to use the &lt;a href="https://material.angular.io/cdk/scrolling/overview" rel="noopener noreferrer"&gt;Angular Material's CDK&lt;/a&gt; and implement a view with infinite scroll.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6e9dgl8cvhfaq41ohi32.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6e9dgl8cvhfaq41ohi32.gif" alt="Alt Text" width="690" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Although the problem had been fixed on mobile phones, too much space was being wasted on the web version. However, implementing a grid was more difficult than expected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0xx3bgjgqmpcamxok12w.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0xx3bgjgqmpcamxok12w.gif" alt="Alt Text" width="690" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;After investigating the library, we discovered that Angular Material expects a single column in its virtual scroll. In this way, solving the problem with only CSS was not going to work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Testing various alternatives, the following solution was reached:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The set of "N" elements is obtained&lt;/li&gt;
&lt;li&gt;The set of elements is divided into groups of 4 elements, forming an Nx4 matrix&lt;/li&gt;
&lt;li&gt;A double "ngFor" is applied: the first to loop through the array, and the second to loop through each group of four elements&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fympv7mc3sfkubxpewlpp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fympv7mc3sfkubxpewlpp.gif" alt="Alt Text" width="690" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this way, it was possible to have a single column with four elements per row, show them as a grid.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Although the victory seemed consecrated, problems appeared: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Four items per row is a very small number if you have a very large screen&lt;/li&gt;
&lt;li&gt;Certain screen sizes will fit three items in a row and one below.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmmk7tcprfz0ujes3fjna.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmmk7tcprfz0ujes3fjna.gif" alt="Alt Text" width="690" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Therefore, it was necessary to choose a number of elements per row according to the size on the screen, adjusting said quantity in case the screen size changed again.&lt;/li&gt;
&lt;li&gt;For this, the following architecture was created:

&lt;ul&gt;
&lt;li&gt;A structural directive to get the infinite scroll elements&lt;/li&gt;
&lt;li&gt;A component to calculate the optimal number of elements per row&lt;/li&gt;
&lt;li&gt;The corresponding HTML that will contain the cdk-virtual-scroll-viewport"&lt;/li&gt;
&lt;li&gt;An attribute directive to apply the grid styles&lt;/li&gt;
&lt;li&gt;A module to declare the created entities&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/virtual-scroll-multiple-columns?" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/angeloraso/virtual-scroll-multiple-columns/tree/main/src/app" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perfect! After several hours, an infinite scroll with multiple columns has been obtained. In your face, Google!&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Although creating a virtual scroll with several columns was challenging and fun, it is worth clarifying that if a library has certain limits, as a professional developer you have to ask yourself if the chosen path is really the correct one. On the other hand, there are already created libraries that solve this problem (&lt;a href="https://github.com/rintoj/ngx-virtual-scroller" rel="noopener noreferrer"&gt;ngx-virtual-scroller&lt;/a&gt;). Thus, reinventing the wheel should be avoided whenever possible.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>angular</category>
      <category>material</category>
      <category>virtual</category>
      <category>scroll</category>
    </item>
  </channel>
</rss>
