<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fabio Giolito on Medium]]></title>
        <description><![CDATA[Stories by Fabio Giolito on Medium]]></description>
        <link>https://medium.com/@fabiogiolito?source=rss-e919563dd745------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sJgZCY1Au_ZCpyy0oAepmw.jpeg</url>
            <title>Stories by Fabio Giolito on Medium</title>
            <link>https://medium.com/@fabiogiolito?source=rss-e919563dd745------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:53:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fabiogiolito/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Swift Styled Elements]]></title>
            <link>https://medium.com/@fabiogiolito/swift-styled-elements-a2b484bd7faa?source=rss-e919563dd745------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2b484bd7faa</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Fabio Giolito]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 18:53:53 GMT</pubDate>
            <atom:updated>2018-12-05T19:00:54.729Z</atom:updated>
            <content:encoded><![CDATA[<h4>Bring some CSS flare to your App</h4><p>Designers think in terms of Elements &amp; Components. Code has always had the reusability approach, but some times both designers and engineers make the same mistake:</p><blockquote>“I need a button that is just like this one, but wider on the sides, and purple instead of blue, and outlined…”</blockquote><p>Designers end up with 10 different button components. As for engineers, sure you can just override what you need, but now that inset and color are not well strucured. Sure you can subclass your button, but next time you need “the same, but keep it blue”. Sure you can create an initializer to take care of the variants, but again you’re hardcoding your changes.</p><p>Nonononono what you need is to look at CSS. More specifically, how you can add on classes to an element to ever so slightly change it’s layout in structured and pre-defined ways. It gives you the design flexibility and the style management sanity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_h_dHy8vrqHcm8lAxMt4Q.png" /></figure><h4>Creating a StyledButton</h4><p>We’ll use an enum to define all our different styles, and hold the list of styles applied to our button.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3076f7316034099451b15a1b9a8ed420/href">https://medium.com/media/3076f7316034099451b15a1b9a8ed420/href</a></iframe><p>Then we’ll create a helpful little initializer to take our styles and set some base parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11f00b66f3aeda103f464b96b96fd95b/href">https://medium.com/media/11f00b66f3aeda103f464b96b96fd95b/href</a></iframe><p>Now we’re just missing our applyStyles function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/133bc8c074befac4de70ce0ea37699ff/href">https://medium.com/media/133bc8c074befac4de70ce0ea37699ff/href</a></iframe><p>So we have our StyledButtons ready! Our initializer is super helpful an lets us declare our buttons with one line.</p><p>Styles can be combined and applied over each other, just like CSS classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/747ae1bcebe8e62fe4e2a937226e41ed/href">https://medium.com/media/747ae1bcebe8e62fe4e2a937226e41ed/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*iNk7HWZ2OUXfeYNZDhHaGw.png" /></figure><p>There you have it, all the flexibility while still being structured and following the design guidelines.</p><p>A bonus of this approach is that any time you need to change your button’s look just set the new styles and call applyStyles on it again. Eg.: change styles to .disabled, or from Follow to Following going from .primary to .regular.</p><h4>Beyond Buttons</h4><p>You can apply this thinking to any element, not only buttons.</p><pre>let title = StyledLabel(&quot;My Title&quot;, styles: [.screenTitle])<br>let body = StyledLabel(&quot;Lorem ipsum…&quot;, styles: [.body])</pre><pre>let avatar = StyledImage(url: &quot;…&quot;, styles: [.circle, border])</pre><p>Happy styling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2b484bd7faa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Themes support to your App]]></title>
            <link>https://medium.com/@fabiogiolito/add-themes-support-to-your-app-54217794be40?source=rss-e919563dd745------2</link>
            <guid isPermaLink="false">https://medium.com/p/54217794be40</guid>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Fabio Giolito]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 16:34:35 GMT</pubDate>
            <atom:updated>2018-12-03T16:55:03.897Z</atom:updated>
            <content:encoded><![CDATA[<h3>Supporting multiple themes in your App</h3><h4>A swift tutorial on how to add themes to your iOS app.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWyVABMv_yUvh1NwQI_Euw.png" /></figure><p>Don’t wait for Dark mode from Apple, add support for different themes on your app today.</p><blockquote>Beyond just Theming your app, this is a best practice to keeping your colors, fonts and design consistent across all views.</blockquote><h3>Part1: Single Theme app</h3><p>We’ll create a Theme class, extending NSObject, with all the properties of our theme like colors and fonts. I’ll just add a few.</p><pre>class <strong>Theme</strong>: NSObject {</pre><pre>    let <strong>colorPrimary</strong>: UIColor<br>    let <strong>colorBackground</strong>: UIColor <br>    let <strong>colorText</strong>: UIColor</pre><pre>    let <strong>fontBody</strong>: UIFont<br>    let <strong>fontTitle</strong>: UIFont</pre><pre>}</pre><p>We’ll need to add an initialiser, that is a bit repetitive.</p><pre>class <strong>Theme</strong>: NSObject {</pre><pre>    …</pre><pre>    init(colorPrimary: UIColor, colorBackground: UIColor, colorText: UIColor, fontBody: UIFont, fontTitle: UIFont) {</pre><pre>        self.<strong>colorPrimary</strong> =    colorPrimary<br>        self.<strong>colorBackground</strong> = colorBackground<br>        self.<strong>colorText</strong> =       colorText</pre><pre>        self.<strong>fontBody</strong> =        fontBody<br>        self.<strong>fontTitle</strong> =       fontTitle<br>    }<br>}</pre><p>Then we’ll define our default theme as a static constant on our Theme class that initialises an instance of Theme. We’ll call it “light”.</p><pre>class <strong>Theme</strong>: NSObject {</pre><pre>    …</pre><pre>    static let <strong>light</strong> = Theme(<br>        <strong>colorPrimary</strong>:    .blue,<br>        <strong>colorBackground</strong>: .white,<br>        <strong>colorText</strong>:       .darkText,</pre><pre>        <strong>fontBody</strong>:        .preferredFont(forTextStyle: .body),<br>        <strong>fontTitle</strong>:       .boldSystemFont(ofSize: 32)<br>    )<br>}</pre><p>If all you need is a single Theme, you’re done. You can use Theme.light throughout your app. view.backgroundColor = Theme.light.colorBackground</p><h3>Part 2: Adding more themes</h3><p>To add more themes we’ll need a way to manage them, so we know which theme is the selected one. We’ll give each theme a title and store the title of our preferred theme in UserDefaults.</p><pre>struct <strong>ThemeManager</strong> {</pre><pre>    // Register different Themes<br>    static let <strong>themes</strong>: [(title: String, theme: Theme)] = [<br>        (&quot;Light&quot;, .light),<br>        (&quot;Dark&quot;, .dark)<br>    ]</pre><pre>    // User Defaults key to store the selected theme<br>    static let <strong>udKey</strong> = &quot;Theme&quot;</pre><pre>    // Get the selected Theme title from UserDefaults<br>    static var <strong>themeTitle</strong>: String {<br>        return <strong>UserDefaults.standard.string</strong>(forKey: <strong>udKey</strong>) ?? &quot;Light&quot;<br>    }</pre><pre>    // Get the theme with that title<br>    // Update UserDefaults if ThemeManager.theme changes<br>    static var <strong>theme</strong> = <strong>themes</strong>.first(where: { $0.title == themeTitle })?.theme ?? <strong>Theme.light</strong> {</pre><pre>        didSet {<br>            let <strong>themeName</strong> = <br>                themes.first(where: { $0.theme == theme })?.title<br>            <strong>UserDefaults.standard.set</strong>(<strong>themeName</strong>, forKey: <strong>udKey</strong>)<br>        }<br>    }<br>}</pre><p>Now you can use ThemeManager.theme.colorBackground anywhere to get the value you need from whatever theme the user has selected.</p><p>To change the current theme just update ThemeManager.theme = .dark anywhere. Your views won’t update immediately though, you need to for your views to render again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PvcRa-TC48n8pKb1GeL-A.png" /></figure><p><strong>Download and run the project:</strong></p><p><a href="https://github.com/fabiogiolito/SwiftAppTheme">fabiogiolito/SwiftAppTheme</a></p><p>This article was inspired by how <a href="https://rocket.chat/">Rocket.Chat</a> implemented themes on their app. Check out their code to see how they solved updating views in real time when the Theme changes:</p><p><a href="https://github.com/RocketChat/Rocket.Chat.iOS/tree/develop/Rocket.Chat/Theme">RocketChat/Rocket.Chat.iOS</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54217794be40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grid animation effects in Swift]]></title>
            <link>https://medium.com/@fabiogiolito/grid-animation-effects-in-swift-4d6ea4d6360d?source=rss-e919563dd745------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d6ea4d6360d</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Fabio Giolito]]></dc:creator>
            <pubDate>Fri, 16 Nov 2018 23:00:13 GMT</pubDate>
            <atom:updated>2019-01-20T17:06:44.594Z</atom:updated>
            <content:encoded><![CDATA[<h4>Load CollectionView cells with diagonal fade in effect</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*d93GVXCpFutt74VY6O67Ag.png" /></figure><p><a href="https://twitter.com/warpling/status/1062069654498279429">This mini thread</a> from <a href="https://medium.com/u/c25bf2f84d4">Ryan McLeod</a> has the best gem of delightful design I’ve come across recently. A simple tweak to your animations that make them feel more natural.</p><p>This tutorial is a deeper look into how you can code this grid animation and calculate the delays for your elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3AiccVge49M0JzsCtySBA.gif" /><figcaption>animations slowed down for clarity</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ToX-x5qw95HUIeBUT0RzRQ.png" /></figure><h3>Preparing</h3><p>To make it easy to test the animation parameters, let’s define them at the top of our class.</p><pre>let <strong>animationDuration</strong>: Double = 1.0<br>let <strong>delayBase</strong>: Double = 1.0</pre><p><em>The value of </em><em>1.0 will allow us to see the animation in detail. When you’re all finished you can test different values like</em><em>0.3 and </em><em>0.1 respectively to speed it up.</em></p><p>We have our collection view setup, we want to display each cell with a fade in effect. First of all we need to load our cells with a zero opacity, so we can then animate their alpha value to one when they appear on screen.</p><pre>func collectionView(<strong>_</strong> collectionView: UICollectionView, <strong>cellForItemAt</strong> indexPath: IndexPath) -&gt; UICollectionViewCell {</pre><pre><strong>  </strong>let <strong>cell</strong> = dequeueReusableCell(withReuseIdentifier: &quot;cell&quot;, for: indexPath)</pre><pre><strong>  cell</strong>.alpha = 0 <em>// make cell initial state transparent</em></pre><pre><strong>  </strong>return <strong>cell</strong></pre><pre>}</pre><p>Then, when the cell is going to be displayed on screen we can animate it’s alpha back to 1.</p><pre>func collectionView(<strong>_</strong> collectionView: UICollectionView, <strong>willDisplay cell</strong>: UICollectionViewCell, forItemAt indexPath: IndexPath) {</pre><pre>  UIView.<strong>animate</strong>(withDuration: <strong>animationDuration</strong>) {</pre><pre>    <strong>cell</strong>.alpha = 1</pre><pre>  }<br>}</pre><h3>Index Delay</h3><p>We want to create an effect where our views appear almost one at a time. They all load a the same time, so we need to calculate how long is the delay for each one, depending on their position and pass it to our animation.</p><pre>let <strong>delay</strong> = <strong>sqrt</strong>(Double(indexPath.<strong>row</strong>)) * <strong>delayBase</strong></pre><pre>UIView.<strong>animate</strong>(withDuration: <strong>animationDuration</strong>, delay: <strong>delay</strong>, options: .curveEaseOut, animations: {</pre><pre>  <strong>cell</strong>.alpha = 1</pre><pre>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*-CUwR0nXLlWAKeJ-sVql7w.png" /></figure><p>We’re not just simply multiplying the position and delayBase. By using the square root of the position it speeds up the animation as it reaches the end, making it much smoother.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*D-6TVzGde6NUWdTk0Ahnhw.gif" /></figure><p>On both cases the duration and delayBase are the same, the decay on the delay makes it a lot more natural and acceptable, and that’s still using our slowed down settings.</p><h3>Distance Delay</h3><p>The zigzag effect of the index delay is not very natural. Even though it gets harder to notice when you speed up the animation, it still feels choppy.</p><p>What we want is a wave that goes through the grid and lights up each cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*WiDEcLGvFWpwOKw62-CDig.png" /></figure><p>So we want our delay to be based on the distance from the top left corner of the grid, not it’s index.</p><p>But how do we calculate that distance?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FJzUaPlWYRc_LlTgSoGdjw.png" /><figcaption>Remember the <a href="https://en.wikipedia.org/wiki/Pythagorean_theorem">pythagorean theorem</a>?</figcaption></figure><p>You can find the row and column from the indexPath.row by doing some math, but for that you need to know how many views you have per row, which depends on your layout, and could vary based on the user’s device and rotation.</p><pre>// I don&#39;t recommend using this</pre><pre>let <strong>viewsPerRow</strong> = 4<br>let <strong>column</strong> = Double(indexPath.<strong>row</strong> % <strong>viewsPerRow</strong>)<br>let <strong>row</strong> = floor(Double(indexPath.<strong>row</strong> / <strong>viewsPerRow</strong>))</pre><p>I prefer calculating from the cell.frame. It is slightly less precise, because spacings and insets will make a small difference, but it works for every layout, screen size, number of elements, different views shapes.</p><pre>let <strong>column</strong> = Double(cell.frame.<strong>minX</strong> / cell.frame.<strong>width</strong>)<br>let <strong>row</strong> = Double(cell.frame.<strong>minY</strong> / cell.frame.<strong>height</strong>)</pre><p>With that we can calculate the distance, our delay, and animate our views.</p><pre>let <strong>distance</strong> = sqrt(pow(<strong>column</strong>, 2) + pow(<strong>row</strong>, 2))<br>let <strong>delay</strong> = sqrt(<strong>distance</strong>) * <strong>delayBase</strong></pre><pre>UIView.<strong>animate</strong>(withDuration: <strong>animationDuration</strong>, delay: <strong>delay</strong>, options: [], animations: {</pre><pre>  cell.<strong>alpha</strong> = 1</pre><pre>})</pre><p>And the final result, in regular speed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*PUTZZCz7zF2JREhGl7D3sQ.gif" /><figcaption>🎉</figcaption></figure><h3>BONUS: Adding more effects</h3><p>We built our cells on cellForItemAt and set their alpha to zero. You can play with other properties and animate them too.</p><pre>cell.alpha = 0<br>cell.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)</pre><p>Then on willDisplay you can reset that transform.</p><pre>cell.alpha = 1<br>cell.transform = .identity</pre><p>You can also play with the animation parameters, add a spring for a bouncy effect.</p><pre>UIView.<strong>animate</strong>(withDuration: <strong>animationDuration</strong>, delay: <strong>delay</strong>, usingSpringWithDamping: <strong>0.5</strong>, initialSpringVelocity: <strong>10</strong>, options: [], animations: {</pre><pre>  cell.<strong>alpha</strong> = 1<br>  cell.<strong>transform</strong> = .<strong>identity</strong></pre><pre>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*sRnegXVq20ubCtSrJmSosw.gif" /><figcaption>slowed down animation</figcaption></figure><p>It’s worth saying: be careful to not overdo things. Animations should be fast and subtle, and used at the right places. Don’t make users wait.</p><blockquote>Thank you for reading! Let me know you enjoyed by applauding, following me here, or <a href="https://twitter.com/fabiogiolito">on Twitter</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d6ea4d6360d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How CSS Variables have changed my code]]></title>
            <link>https://medium.com/@fabiogiolito/how-css-variables-have-changed-my-code-a7956b41cd3b?source=rss-e919563dd745------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7956b41cd3b</guid>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Fabio Giolito]]></dc:creator>
            <pubDate>Sat, 18 Aug 2018 09:56:34 GMT</pubDate>
            <atom:updated>2018-11-19T23:44:34.782Z</atom:updated>
            <content:encoded><![CDATA[<h4>What are CSS Variables</h4><p>CSS Variables are <strong>nothing like</strong> <a href="http://sass-lang.com/">SCSS</a> variables. They are dynamic values on your DOM. You can change them at any time on the client and that change is reflected automatically everywhere the variable is used.</p><p>So it’s not only about defining something once to avoid repetition, it’s about redefining it at any point and taking advantage of the cascading effect of CSS.</p><p>It’s a whole new way of thinking about CSS and has change how I code. We’re manipulating values and setting behaviors instead of overriding properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*zRcH7eJCyViX-Pm9rsTdnw.png" /></figure><h3>A practical use of CSS Variables</h3><p>To really illustrate what can be done with variables we need to compare coding with and without them.</p><p>Let’s code these buttons from basic links:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*aNdQ0Z60kKxw9wbwjduEyw.png" /></figure><h4>Basic button</h4><p>&lt;a class=&quot;btn&quot;&gt;Button&lt;/a&gt;</p><pre>.btn {<br>  text-decoration: none;<br>  display: inline-block;<br>  padding: 8px 12px;<br>  border-radius: 4px;<br>  border: 1px solid;</pre><pre>  color: white;<br>  background: cornflowerblue;<br>  border-color: cornflowerblue;<br>}<br>.btn:hover {<br>  background: royalblue;<br>  border-color: royalblue;<br>}</pre><h4>Red button</h4><p>&lt;a class=&quot;btn btn--red&quot;&gt;Button&lt;/a&gt;</p><pre>.btn--red {<br>  background: crimson;<br>  border-color: crimson;<br>}<br>.btn--red:hover {<br>  background: darkred;<br>  border-color: darkred;<br>}</pre><p>We need to override all properties that need to change at each state. So for each new button color we add 8 lines. And it only gets compounded as you add variations.</p><h4>Outlined button</h4><pre>&lt;a class=&quot;btn btn--outlined&quot;&gt;Blue Outlined Button&lt;/a&gt;<br>&lt;a class=&quot;btn btn--red btn--outlined&quot;&gt;Red Outlined </pre><pre>=====</pre><pre>.btn--outlined {<br>  color: cornflowerblue;<br>  background: white;<br>  border-color: cornflowerblue;<br>}<br>.btn--outlined:hover { … }<br>.btn--outlined.btn--red { … }<br>.btn--outlined.btn--red:hover { … }</pre><p>We’re up to 42 lines, and for each new color we need 18 more lines.</p><h3>How can CSS Variables help us</h3><p>On our main .btn class we’ll define variables for the text, background and background-hover, and set the properties to those variables.</p><pre>.btn {<br>  --text: white;<br>  --bg: cornflowerblue;<br>  --bg-hover: royalblue;</pre><pre>  color: var(--text);<br>  background: var(--bg);<br>  border-color: var(--bg);<br>}<br>.btn:hover {<br>  color: var(--text);<br>  background: var(--bg-hover);<br>  border-color: var(--bg-hover);<br>}</pre><p>Now, for any new colors, all we need to do is change the value of the variables, we don’t need to redefine the properties and we don’t need to rewrite the :hover state either.</p><pre>.btn--red {<br>  --bg: crimson;<br>  --bg-hover: darkred;<br>}</pre><p>We didn’t need redefine --text because it’s the same value as default. And we defined both shades of red on the same class, no need to rewrite the :hover state. That’s half the lines as before to define .btn--red.</p><p>Now, for the outline version we’re not changing variable values, we’re changing which variables we use for each property. So in this case we do need to override the parameters, but use the same variables.</p><pre>.btn--outlined {<br>  color: var(--bg);<br>  background: var(--text);<br>  border-color: var(--bg);<br>}<br>.btn--outlined:hover {<br>  color: var(--bg-hover);<br>  background: var(--text);<br>  border-color: var(--bg-hover);<br>}</pre><p>Now what was the text color will be the background, what was the background will be the text…</p><p>Notice we’re coding the behavior of the button, not what color the button is. This means we don’t need to code .btn--red.btn-outined anymore, this code works for any new color we add.</p><h4>Recap</h4><p>Using Variables we reduced our code significantly and made it easy to add more variations and new colors without growing the number of lines exponentially.</p><p>Think about what values you’re overriding, instead of what properties. See if using a variable makes sense.</p><blockquote>Let me know you enjoyed by applauding, following me here, or <a href="https://twitter.com/fabiogiolito">on Twitter</a>. I appreciate it!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7956b41cd3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Familiar With Sketch Scripts]]></title>
            <link>https://medium.com/@fabiogiolito/getting-familiar-with-sketch-scripts-b83be4ff523e?source=rss-e919563dd745------2</link>
            <guid isPermaLink="false">https://medium.com/p/b83be4ff523e</guid>
            <category><![CDATA[sketch]]></category>
            <category><![CDATA[plugin-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[plugins]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Fabio Giolito]]></dc:creator>
            <pubDate>Mon, 06 Aug 2018 00:04:14 GMT</pubDate>
            <atom:updated>2018-11-19T23:45:12.139Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn by making an icon library</h4><p>One of the greatest <a href="https://medium.com/u/d39f69b23aa2">Sketch</a> features is its extensibility with plugins. What not everyone knows is that Sketch has a script console where you can run javascript with that same <a href="https://developer.sketchapp.com/reference/api/">plugin API</a>.</p><blockquote>Should designers code⸮</blockquote><p>Before building your first plugin, you can start smaller, play around with the code, and maybe automate some repetitive task you’re facing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OIkblki7eYaXRRc7hN-vZg.png" /></figure><h3>Let’s automate an icon library</h3><p>We’ll look at a real world example to learn the basics of navigation the document, creating elements, renaming things, editing parameters…</p><p>Say you have a file with different icon shapes floating around with no artboards or symbols, and you want to turn them into a reusable library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*SCS4Xg0lHvT__iRPjAEWPQ.png" /><figcaption><a href="https://symbolicons.com/">Symbolicons Pro</a> is a great icon set. Feel free to fake some pages and small shapes to follow along.</figcaption></figure><p>Sketch provides a console for running code, which makes it easy to try things. Press Ctrl + Shift + K to open it.</p><p>First thing you need to do is import the API. While we’re at it we’ll get a reference to our document as well.</p><pre>const <strong>Sketch</strong> = require(&#39;sketch&#39;)<br>const <strong>document</strong> = Sketch.Document.getSelectedDocument()</pre><h3>Navigating your document</h3><p>From there you can loop through your pages with document.pages and for each page you can loop through its layers with page.layers</p><pre>// Loop pages in the document<strong><br>document</strong>.pages.forEach( (<strong>page</strong>) =&gt; {</pre><pre>  // Loop layers in this page<br>  <strong>page</strong>.layers.forEach( (<strong>layer</strong>, i) =&gt; {</pre><pre>    // Here we can do more things with each layer<br>    log(&quot;Layer name: &quot; + layer.name)<br>    log(&quot;Layer number: &quot; + i)</pre><pre>  })<br>})</pre><blockquote>The <em>log()</em> function is just for debugging, it will print the results on the console below your code when you click the <strong>Run</strong> button.</blockquote><h3>Creating the Symbols</h3><p>Symbols come in two parts, the SymbolMaster is the actual symbol artboard. And the SymbolInstance is the copy of the symbol you use in your designs.</p><p>This goes inside the layers loop:</p><pre>const <strong>symbol</strong> = new Sketch.SymbolMaster({<br>  name: <strong>page</strong>.name + &quot;/&quot; + <strong>layer</strong>.name,                   // 1 <br>  parent: <strong>page</strong>,                                         // 2<br>  layers: [<strong>layer</strong>],                                      // 3<br>  frame: { x: (i * 50), y: 0, width: 40, height: 40 }   // 4<br>})</pre><p>1: Name symbol as “category/icon” to make them easier to find later<br>2: Add symbol to the page<br>3: Add the icon layer to the symbol. This moves it from the page.<br>4: Size and position the symbol on the page. We’re moving each symbol 50px at a time with (i * 50) so they’re not overlapping each other.</p><p>There’s a problem though, layers are not centered in the symbols yet. So after crating our symbol let’s use some math to reposition the layer inside it.</p><pre><strong>layer</strong>.frame.x = (40 - <strong>layer</strong>.frame.width) / 2<br><strong>layer</strong>.frame.y = (40 - <strong>layer</strong>.frame.height) / 2</pre><h3>Make it colorful</h3><p>You probably want to use the icons in different colors. So we’ll create a color symbol then mask that symbol with the icon shape. This will let you override them later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*NTWhVesMoFg7MCporj-Tqw.png" /></figure><p>We’ll create a new page to hold that color symbol and create a placeholder color symbol. Then we’ll add that color symbol to our icon symbols and turn the icon shape into a mask.</p><p>This code goes before the page loop</p><pre>// Create new page and add to document<br>const <strong>colorsPage</strong> = new Sketch.Page({ <br>  name: &quot;Colors&quot;,<br>  parent: <strong>document</strong> <br>})</pre><pre>// Create new symbol and add to color page<br>const <strong>colorMaster</strong> = new Sketch.SymbolMaster({<br>  name: &quot;Color/placeholder&quot;,<br>  frame: { x: 0, y: 0, width: 80, height: 20},<br>  parent: <strong>colorsPage<br></strong>})</pre><pre>// Create new red rectangle and add to color symbol<br>const <strong>colorRectangle</strong> = new Sketch.Shape({<br>  name: &quot;color placeholder&quot;,<br>  frame: <strong>colorMaster</strong>.frame,<br>  parent: <strong>colorMaster</strong>,<br>  style: {<br>    fills: [{<br>      color: &quot;#ff0000cc&quot;,<br>      fillType: Sketch.Style.FillType.Color<br>    }]<br>  }<br>})</pre><blockquote>The <em>style</em> parameter holds all the shape fills, borders, shadows… We created a fill of type <em>Color</em>. Note that the color code is a <a href="https://css-tricks.com/8-digit-hex-codes/">8-digit hexadecimal</a>, the last 2 digits are optional, they define the alpha value.</blockquote><h4>We broke it</h4><p>Now we have a new page, our previous code will try to convert our color symbol in it as well, we need to prevent that. So if the page name is “Colors” we’ll skip to the next page.</p><pre><strong>document</strong>.pages.forEach( (<strong>page</strong>) =&gt; {</pre><pre>  // Ignore Colors page<br>  if (<strong>page</strong>.name == &quot;Colors&quot;) { return } // &lt;-----</pre><pre><strong>  page</strong>.layers.forEach( (<strong>layer</strong>, i) =&gt; { <br>    ... <br>  }</pre><pre>}</pre><h4>Add color instance</h4><p>We have our color symbol master, now we need to add it to our icon symbols. Before creating our symbol we’ll create a new instance of the color.</p><pre>// Create instance of colorMaster<br>const <strong>color</strong> = <strong>colorMaster</strong>.createNewInstance()</pre><pre><strong>color</strong>.name = &quot;🎨 color&quot;<br><strong>color</strong>.frame = { x: 0, y: 0, width: 40, height: 40 }</pre><p>Then edit the symbol creation to add our color as a layer of the symbol, and make the icon layer a mask</p><pre>const <strong>symbol</strong> = new Sketch.SymbolMaster({<br>  name: <strong>page</strong>.name + &quot;/&quot; + <strong>layer</strong>.name,<br>  parent: page,<br>  layers: [<strong>layer</strong>, <strong>color</strong>], // &lt;----------- this changed<br>  frame: { x: (i * 50), y: 0, width: 40, height: 40 }<br>})</pre><pre>// This added<br><strong>layer</strong>.sketchObject.hasClippingMask = true<br><strong>layer</strong>.sketchObject.clippingMaskMode = 1</pre><p>The two clipping mask options are not available directly through the javascript API, so we need to call .sketchObject first to get the reference to the native object for that layer and apply it directly.</p><h3>We’re done!</h3><p>Click the <strong>Save</strong> button on your Script console, save it as Create Icon Library in case you want to run it again in the future. It will be saved on your Plugins menu.</p><p>Then you can do File › Add as Library to make your library available on your other design files.</p><p>About the colors, on your design files create more colors symbols with the specific colors for that project. It’s a good idea to not have any other color symbols on your icon library to keep it project agnostic.</p><p><strong>Congrats on reading all the way.</strong> I hope this was helpful. Designers should code, everyone should code. If this peaked your interest, take a look at the full API Reference to learn how to handle text, other shape styles, showing alerts and prompts, lots more:</p><p><a href="http://developer.sketchapp.com/reference/api/">API Reference</a></p><blockquote>Let me know you enjoyed by applauding, following me here, or <a href="https://twitter.com/fabiogiolito">on Twitter</a>. I appreciate it!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b83be4ff523e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The ARKit Hamburger Menu]]></title>
            <link>https://medium.com/@fabiogiolito/the-arkit-hamburger-menu-3b822887dcf3?source=rss-e919563dd745------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b822887dcf3</guid>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Fabio Giolito]]></dc:creator>
            <pubDate>Thu, 05 Jul 2018 15:05:00 GMT</pubDate>
            <atom:updated>2018-07-18T08:17:25.478Z</atom:updated>
            <content:encoded><![CDATA[<p>The “<a href="https://medium.com/search?q=hamburger%20menu">Hamburger Menu</a>” became a design joke and subject of intense discussions about its efficacy. So why not make it even more convoluted by using the newest buzzwordy technology: Augmented Reality.</p><p>Here’s what I made:</p><h3>Fabio Giolito on Twitter</h3><p>Hamburger Menu. #ARKit #iOS12 https://t.co/ORj9LBY4mJ</p><p>I feel like I mislead some people, because this is just a prototype, and not actually coded. It was meant as a joke of course. But hey, there’s still value in learning how to prototype something like this!</p><h3>How to prototype an AR experience</h3><h4>Step 1: Make the burger</h4><p>Any Hamburger will do. Vegetarian is fine too.</p><h4>Step 2: Record yourself, add the tracking</h4><p>Here’s the part that may give you a laugh. I made this using Instagram Stories. Paste in a unicode square symbol, long press to pin it to the video and Voilá! No Machine Learning required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*KW0DX9SV0fLyUIrzRRiOGg.gif" /></figure><h4><strong>Step 3: Animate in Keynote</strong></h4><p>Animate the UI over the video in Keynote, make each step of the animation triggered by a click, then record your screen in presentation mode. Hit that spacebar when the square moves in or out of view to trigger the next animation step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrS1xFy9hkGvm7Y4xyxFXw.png" /></figure><h4>Lessons learned</h4><p>Sometimes the simplest way to mock up something is the best. I could do the tracking in some advanced video software, but Instagram worked. Or time the animation just right, but pressing the spacebar on the fly worked… If you reach obstacles, take a step back and find an alternative path.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b822887dcf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>