{"id":3028,"date":"2023-01-19T12:00:06","date_gmt":"2023-01-19T20:00:06","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=3028"},"modified":"2023-01-19T03:29:21","modified_gmt":"2023-01-19T11:29:21","slug":"jetpack-compose-relay-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/jetpack-compose-relay-2\/","title":{"rendered":"Relay Leg 2: Tips and tricks"},"content":{"rendered":"<p>\n  Hello Compose developers,\n<\/p>\n<p>\n  Last week, I gave a <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/jetpack-compose-relay-1\/\">brief introduction to Relay<\/a>, the new Figma to Compose tool developed by Google. This week, I\u2019ll dive deeper into some tips and tricks I learned when testing out Relay,\n<\/p>\n<p>\n  As a reminder, Relay is in alpha, so please go <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/tooling\/relay\">try it out<\/a> and <a href=\"https:\/\/goo.gle\/relay-feedback\">send the Relay team your feedback<\/a>!\n<\/p>\n<h2>Putting Relay to the test<\/h2>\n<p>\n  After following introductory tutorials, my next step in learning Relay was to test it out in a variety of scenarios. Since I\u2019m not a designer, I decided to try out the tool on some existing Figma designs from the <a href=\"https:\/\/github.com\/microsoft\/surface-duo-dual-screen-experience-example\">Surface Duo Dual Screen Experience Example<\/a>, the <a href=\"https:\/\/aka.ms\/SurfaceDuoDesign\">Surface Duo Design Kit<\/a>, and the <a href=\"https:\/\/www.figma.com\/community\/file\/778763161265841481\">Material 2 Design Kit<\/a>. By working with these different examples, I learned some tips and tricks about 1) when it\u2019s best to use Relay, and 2) how to map styles successfully.\n<\/p>\n<h3>Choose use cases wisely<\/h3>\n<p>\n  Going into this learning process, I think my biggest misconception about Relay was that it was going to be some magical tool that could translate any and all Figma designs! Because of this, I was skeptical that the tool would work well, especially in special cases (like building responsive UI for foldables and large screens \ud83d\ude09).\n<\/p>\n<p>\n  Essentially, I had assumed that Relay could, and should, be used to translate entire screens worth of designs. As a developer, I often build UI one screen at a time, referring to Figma designs like the \u201cOrder history list\u201d frame shown in Figure 1. After using the tool more, though, I quickly realized that Relay is not meant to be used like that at all. For one, we wouldn\u2019t want to translate elements like the status bar or device frames. On top of that, it would be very complicated for Relay to try and guess which foundational layouts you want to use, like choosing between <code>TwoPaneLayout<\/code> and <code>TwoPane<\/code>, <code>Column<\/code> and <code>LazyColumn<\/code>, etc. \n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1431\" height=\"605\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-1.png\" class=\"wp-image-3029\" alt=\"\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-1.png 1431w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-1-300x127.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-1-1024x433.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-1-768x325.png 768w\" sizes=\"(max-width: 1431px) 100vw, 1431px\" \/>\n<\/p>\n<p><em>Figure 1. As developers, we often build UI based on an entire screen of design, like the \u201cOrder history light\u201d frame. However, with Relay, it makes more sense to build individual UI packages, like the \u201clist item order preview\u201d component.<\/em>\n<\/p>\n<p>\n  Instead, I learned that the best use case for Relay is to translate smaller individual UI elements, like the \u201clist item order preview\u201d component in Figure 1. That way, you can incorporate the generated composables into any higher-level layouts or app logic as needed. In fact, I would guess that this is why Relay only allows you to create UI packages from Figma components. I wasn\u2019t very familiar with the distinction between different Figma elements prior to this learning process, but in various design files, I saw that most higher level layers were either <a href=\"https:\/\/www.figma.com\/best-practices\/groups-versus-frames\/summary\/\">frames, groups<\/a>, or <a href=\"https:\/\/help.figma.com\/hc\/en-us\/articles\/360038662654-Guide-to-Components-in-Figma\">components<\/a>, which, according to the documentation, \u201care elements you can reuse across your designs.\u201d So, something like a design mockup for an entire screen may be represented by a frame, but a UI element like a card or button would be represented by a component and thus potentially be a good use case for Relay.\n<\/p>\n<p>\n  However, it\u2019s important to note that, even if a UI element has been marked as a component by a designer, it still may not be a great use case for Relay! Trying out Relay with Material Design kits was helpful for understanding Relay\u2019s workflow, but in practice, these mappings wouldn\u2019t really be helpful for developers. This is because Relay will translate the Figma component literally, instead of just using the desired component from the Material library.\n<\/p>\n<p>\n  For instance, when I translated the navigation rail component from the Surface Duo Design Kit, Relay generated Compose code that was basically a column of vector drawables. Did it match the color and spacing of the designs? Sure, but functionality-wise, it\u2019s not going to achieve what we want, so this could be a case for using <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/tooling\/relay\/mapping-components-to-existing-code\">Relay component mapping<\/a> or, more likely, just not a case where we would use Relay at all.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1497\" height=\"788\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-text-description-automa.png\" class=\"wp-image-3030\" alt=\"\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-text-description-automa.png 1497w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-text-description-automa-300x158.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-text-description-automa-1024x539.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-text-description-automa-768x404.png 768w\" sizes=\"(max-width: 1497px) 100vw, 1497px\" \/>\n<\/p>\n<p><em>Figure 2. Even if something in a Figma file is a component, it still may not be a good candidate to use with Relay, like this navigation rail component from the Surface Duo Design Kit that is translated as image assets.<\/em>\n<\/p>\n<p>\n  So, to summarize, when trying to decide if you should use Relay, consider:\n<\/p>\n<ul>\n<li>\n    Can this UI element be treated as a reusable individual package?\n  <\/li>\n<li>\n    Do I want to translate everything in this UI element?\n  <\/li>\n<li>\n    Can this UI be represented by basic composables, like Text, Column, and Image, or do I need to rely on specific library components?\n  <\/li>\n<\/ul>\n<h3>Set up designs for style success<\/h3>\n<p>\n  Besides making sure to pick your use cases wisely, experimenting with Relay also helped me learn how to map styles correctly.\n<\/p>\n<p>\n  Again, partly due to my unfamiliarity with Figma, I had some trouble understanding how Relay style mapping worked. I tried building a component from scratch that just contained rectangles, using color fills from the existing Material 2 Design Kit style, but in the generated code, I saw that the elements were actually downloaded as image assets and did not pull from the Material Theme.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"859\" height=\"624\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-2.png\" class=\"wp-image-3031\" alt=\"\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-2.png 859w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-2-300x218.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/graphical-user-interface-application-description-2-768x558.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/>\n<\/p>\n<p><em>Figure 3. To the untrained (developer) eye, it may not be obvious what makes these two Figma components different, but if you look at the left sidebar, you can see that the top version is made from shapes, while the bottom version is made from frames.<\/em>\n<\/p>\n<p>\n  After trying style mapping with an existing component from the design kit, and seeing how the themed colors did correctly transfer, I realized the difference was due to the chosen Figma components. Shapes are treated as vector assets, whereas frames\/groups are not, so if you want colors to be mapped successfully to Material Theme colors, keep this distinction in mind! This may be more of a tip for developers than designers, since we\u2019re not really trained in Figma best practices, but it\u2019s good to remember in case any vector designs rely on themed colors that need to change based on light\/dark theme.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1157\" height=\"1033\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/text-description-automatically-generated.png\" class=\"wp-image-3032\" alt=\"\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/text-description-automatically-generated.png 1157w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/text-description-automatically-generated-300x268.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/text-description-automatically-generated-1024x914.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2023\/01\/text-description-automatically-generated-768x686.png 768w\" sizes=\"(max-width: 1157px) 100vw, 1157px\" \/>\n<\/p>\n<p><em>Figure 4. Composables generated by Relay for UI built with frames (top) vs. rectangles (bottom). Even though style mapping was set up in both cases, only the frame version pulls color from the Material Theme, whereas the rectangle version is treated as an image asset. <\/em>\n<\/p>\n<p>\n  To learn more about Relay style mapping, check out the <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/tooling\/relay\/mapping-styles-to-compose-theme\">documentation<\/a>. In addition to colors, it also supports mapping text styles. There\u2019s also a cool feature where, even if your design file doesn\u2019t follow the Material 2\/3 Design Kit naming conventions, you can set up a custom mapping file between your Figma style and Compose theme. \n<\/p>\n<h2>Even more Relay content next week<\/h2>\n<p>\n  I know I said this would be a two-part blog post, but since we have so much Relay content, there\u2019s actually one more post coming next week! We\u2019ll talk about overall impressions of the tool from the developer point of view.\n<\/p>\n<p>\n  Since this will be a <s>two<\/s> three-part Relay blog post, we won\u2019t be livestreaming this week, but stay tuned for next Friday when we\u2019ll stream about all three Relay blog posts. \n<\/p>\n<h2>Feedback and resources<\/h2>\n<p>\n  To learn more about Relay, check out the <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/tooling\">documentation<\/a>. You can also provide the Relay team with feedback in <a href=\"https:\/\/goo.gle\/relay-feedback\">Google\u2019s public issue tracker<\/a>.\n<\/p>\n<p>\n  If you have any questions, or would like to tell us about your apps, use the <a href=\"http:\/\/aka.ms\/SurfaceDuoSDK-Feedback\">feedback forum<\/a> or message us on <a href=\"https:\/\/twitter.com\/surfaceduodev\">Twitter @surfaceduodev<\/a>.\n<\/p>\n<p>\n  Finally, please join us for our <a href=\"https:\/\/www.twitch.tv\/surfaceduodev\">dual-screen developer livestream<\/a> at 11am (Pacific time) <strong>next Friday 27th January<\/strong> \u2013 mark it in your calendar and check out the <a href=\"https:\/\/youtube.com\/c\/surfaceduodev\">archives on YouTube<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Compose developers, Last week, I gave a brief introduction to Relay, the new Figma to Compose tool developed by Google. This week, I\u2019ll dive deeper into some tips and tricks I learned when testing out Relay, As a reminder, Relay is in alpha, so please go try it out and send the Relay team [&hellip;]<\/p>\n","protected":false},"author":72597,"featured_media":3030,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[710,1],"tags":[709,692],"class_list":["post-3028","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-design","category-surface-duo-sdk","tag-design","tag-jetpack-compose"],"acf":[],"blog_post_summary":"<p>Hello Compose developers, Last week, I gave a brief introduction to Relay, the new Figma to Compose tool developed by Google. This week, I\u2019ll dive deeper into some tips and tricks I learned when testing out Relay, As a reminder, Relay is in alpha, so please go try it out and send the Relay team [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/3028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/users\/72597"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=3028"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/3028\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/3030"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=3028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=3028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=3028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}