{"id":2373,"date":"2022-04-07T10:49:10","date_gmt":"2022-04-07T17:49:10","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=2373"},"modified":"2022-04-07T10:49:10","modified_gmt":"2022-04-07T17:49:10","slug":"snackbar-dual-screen","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/snackbar-dual-screen\/","title":{"rendered":"Snackbar for dual-screens"},"content":{"rendered":"<p>Hello Android developers!<\/p>\n<p>\n  We are excited to announce the release of our latest Android component: <b>SnackbarContainer<\/b>.\n<\/p>\n<p>The new SnackbarContainer allows you to place a <a href=\"https:\/\/developer.android.com\/reference\/com\/google\/android\/material\/snackbar\/Snackbar\">Snackbar<\/a> on a specific display area on foldable devices, while keeping the original Snackbar behaviour in conventional single screen devices.\n<\/p>\n<p>\n  The SnackbarContainer will help you to show a Snackbar at the bottom of the first screen, second screen, or across the entire display area.\n<\/p>\n<p>\nThis additional flexibility allows you place the Snackbar where the user is currently focused to create a better user experience, especially on devices with more than one display area such as dual-screen and foldable devices.\n<\/p>\n<h2>How to add it to your project<\/h2>\n<p>\n  This component is available on Maven Central and to include it in your project, add the following dependencies to your app&#8217;s <b>build.gradle<\/b> file:\n<\/p>\n<pre>dependencies {\r\n   implementation \"com.microsoft.device.dualscreen:snackbar:1.0.0-alpha1\"\r\n}<\/pre>\n<h2>How it works<\/h2>\n<p>\n  Snackbar is a way to display messages which inform users about a concrete action, usually at the bottom of the screen. Unfortunately, the material design Snackbar does not know how many display areas are available and how to display that message depending on device\u2019s screen mode (e.g. single screen mode, dual-portrait, etc.). To fix this we&#8217;ve created a custom container that is dual-screen aware. The SnackbarContainer is actually a <a href=\"https:\/\/developer.android.com\/reference\/android\/widget\/FrameLayout\">FrameLayout<\/a> with a <a href=\"https:\/\/developer.android.com\/reference\/androidx\/coordinatorlayout\/widget\/CoordinatorLayout\">CoordinatorLayout<\/a> as a child. Using the information from <a href=\"https:\/\/developer.android.com\/reference\/android\/view\/WindowManager\">WindowManager<\/a>, this component knows exactly when the app is displayed in single screen or is spanned across the entire display area. Thus, the CoordinatorLayout is moved depending on a position parameter set by the developer.\n<\/p>\n<h2>How to use the SnackbarContainer<\/h2>\n<p>\n  In order to show a <code>Snackbar<\/code>, you first need to add the <code>SnackbarContainer<\/code> at the bottom of the display area:\n<\/p>\n<pre>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;com.microsoft.device.dualscreen.snackbar.SnackbarContainer\r\n        android:id=\"@+id\/snackbar_container\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        app:layout_constraintBottom_toBottomOf=\"parent\"\r\n        app:layout_constraintEnd_toEndOf=\"parent\"\r\n        app:layout_constraintStart_toStartOf=\"parent\" \/&gt;\r\n&lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;<\/pre>\n<p>\n  Once you have an instance of the <code>SnackbarContainer<\/code> inside the activity or a fragment, you can display the <code>Snackbar<\/code> like this:\n<\/p>\n<pre>Snackbar.make(snackbarContainer.coordinatorLayout, message, LENGTH_LONG)\r\n    .show(snackbarContainer, position)<\/pre>\n<p>\n  Where the <code>show<\/code> function is an extension function with two parameters: the <code>snackbarContainer<\/code> and the position of the <code>Snackbar<\/code> inside the screen.\n<\/p>\n<p>\n  The <code>position<\/code> parameter can take three values:\n<\/p>\n<ul>\n<li>\n    <code>SnackbarPosition.START<\/code> &#8211; the Snackbar will be displayed at the bottom of the first display area \n  <\/li>\n<li>\n    <code>SnackbarPosition.END<\/code> &#8211; the Snackbar will be displayed on the second display area\n  <\/li>\n<li>\n    <code>SnackbarPosition.BOTH<\/code> &#8211; the Snackbar will be displayed at the bottom of the entire display area\n  <\/li>\n<\/ul>\n<p>\n  Here is how the Snackbar will look with different SnackbarPosition values:\n<\/p>\n<h3>SnackbarPosition.START<\/h3>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-start.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-start-1024x561.png\" alt=\"Surface Duo sample showing the snackbar on left screen\" width=\"640\" height=\"351\" class=\"alignnone size-large wp-image-2384\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-start-1024x561.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-start-300x164.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-start-768x421.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-start.png 1472w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h3>SnackbarPosition.END<\/h3>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-end.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-end-1024x561.png\" alt=\"Surface Duo sample showing the snackbar on right screen\" width=\"640\" height=\"351\" class=\"alignnone size-large wp-image-2385\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-end-1024x561.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-end-300x164.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-end-768x421.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-end.png 1472w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h3>SnackbarPosition.BOTH<\/h3>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-both.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-both-1024x561.png\" alt=\"Surface Duo sample showing the snackbar on both screens\" width=\"640\" height=\"351\" class=\"alignnone size-large wp-image-2386\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-both-1024x561.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-both-300x164.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-both-768x421.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/04\/position-both.png 1472w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h2>Resources and feedback<\/h2>\n<p>\n  You can review the <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/api-reference\/dualscreen-library\/snackbar\/\">dual-screen Snackbar documentation<\/a> for more information. You can also try out our sample and check out all these scenarios.\n<\/p>\n<p>\n  The\u00a0<a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk\/tree\/main\/snackbar\">source code for the Snackbar<\/a> is available on GitHub if you\u2019re curious about the implementation or wish to contribute. Also visit the\u00a0<a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/api-reference\/dualscreen-library\/?WT.mc_id=docs-surfaceduoblog-ancirja\">documentation<\/a>\u00a0for more information on all the features in the dual-screen library for Kotlin and Java developers.\u00a0\u00a0\n<\/p>\n<p>\n  Thanks to the team \u2013\u202f<a href=\"https:\/\/www.linkedin.com\/in\/bianca-miron-ro\/\" target=\"_blank\" rel=\"noopener\">Bianca Miron<\/a>,\u202f<a href=\"https:\/\/twitter.com\/CesarValiente\" target=\"_blank\" rel=\"noopener\">Cesar Valiente<\/a>,\u202f<a href=\"https:\/\/www.linkedin.com\/in\/cristian-verdes-3b0046135\/\" target=\"_blank\" rel=\"noopener\">Cristian Verdes<\/a>, and\u202f<a href=\"https:\/\/www.linkedin.com\/in\/sorin-albu-62a76a27\/\" target=\"_blank\" rel=\"noopener\">Sorin Albu<\/a>\u202f\u2013 for their work on this release.\u202f\u202f\u00a0\n<\/p>\n<p>\n  We\u2019d love to hear from you and how you plan to incorporate this navigation component into your apps. Please reach to out using the\u202f<a href=\"http:\/\/aka.ms\/SurfaceDuoSDK-Feedback\" target=\"_blank\" rel=\"noopener\">feedback forum<\/a>\u202for message us\u202f<a href=\"https:\/\/twitter.com\/surfaceduodev\" target=\"_blank\" rel=\"noopener\">@surfaceduodev<\/a>\u202fon Twitter.\u202f\u202f\u00a0\n<\/p>\n<p>\n  Finally, please join us for our <a href=\"https:\/\/twitch.tv\/surfaceduodev\" target=\"_blank\" rel=\"noopener\">Surface Duo developer livestream<\/a> at 11am (Pacific time) each Friday \u2013 mark it in your calendar and check out the <a href=\"https:\/\/www.youtube.com\/c\/SurfaceDuoDev\/\" target=\"_blank\" rel=\"noopener\">archives on YouTube<\/a>.\u202fThis week we&#8217;ll have an additional <a href=\"https:\/\/twitch.tv\/surfaceduodev\" target=\"_blank\" rel=\"noopener\">stream at 13h00 European time<\/a> on Friday 7th April to discuss the Snackbar component!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Android developers! We are excited to announce the release of our latest Android component: SnackbarContainer. The new SnackbarContainer allows you to place a Snackbar on a specific display area on foldable devices, while keeping the original Snackbar behaviour in conventional single screen devices. The SnackbarContainer will help you to show a Snackbar at the [&hellip;]<\/p>\n","protected":false},"author":47750,"featured_media":2384,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[706,473,45],"class_list":["post-2373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-jetpack-window-manager","tag-kotlin","tag-surface-duo-sdk"],"acf":[],"blog_post_summary":"<p>Hello Android developers! We are excited to announce the release of our latest Android component: SnackbarContainer. The new SnackbarContainer allows you to place a Snackbar on a specific display area on foldable devices, while keeping the original Snackbar behaviour in conventional single screen devices. The SnackbarContainer will help you to show a Snackbar at the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/2373","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\/47750"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=2373"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/2373\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/2384"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=2373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=2373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=2373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}