{"id":2254,"date":"2022-02-17T12:08:11","date_gmt":"2022-02-17T20:08:11","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=2254"},"modified":"2022-02-17T12:08:11","modified_gmt":"2022-02-17T20:08:11","slug":"foldable-navigation-component-update","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/foldable-navigation-component-update\/","title":{"rendered":"Foldable Navigation component update"},"content":{"rendered":"<p>\n  Hello Android developers!\n<\/p>\n<p>\n  We\u2019re excited to announce the release of our latest SDK component, Foldable Navigation Component, which is an extension of <a href=\"https:\/\/developer.android.com\/guide\/navigation\">Jetpack Navigation Component<\/a> and is now available for foldable devices.\n<\/p>\n<h2>How to add Foldable Navigation Component to your project<\/h2>\n<pre>dependencies {\r\n   def nav_version = \"1.0.0-alpha2\"\r\n   implementation \"com.microsoft.device.dualscreen:navigation-fragment-ktx:$nav_version\"\r\n   implementation \"com.microsoft.device.dualscreen:navigation-ui-ktx:$nav_version\"\r\n}<\/pre>\n<h2>How it works<\/h2>\n<p>\n  Jetpack Navigation Component is a set of tools, libraries, and guidance to help developers create quality apps, simplifies the navigation between fragments or activities, and provides a way to visualize the navigation flow for the entire app.\n<\/p>\n<p>\n  Instead of having only a single fragment on the display area, this navigation component splits the display into two areas (physical or not, depending on the device manufacturer) and shows two fragments at once, one for each display area. To achieve this, we are using the FoldableLayout in the background. Read the <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/api-reference\/dualscreen-library\/layouts\/surfaceduo-layout\">FoldableLayout documentation<\/a> for more information. \n<\/p>\n<h2>Single-screen navigation<\/h2>\n<p>\n  If the app is opened in the single-screen mode, then our navigation component has exactly the same behavior as the Jetpack Navigation component. The magic happens only when the app is rendered across a folding feature.\n<\/p>\n<p>\n  <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-1.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-1.gif\" alt=\"Surface Duo showing single screen navigation sample\" width=\"880\" height=\"670\" class=\"alignnone size-full wp-image-2264\" \/><\/a>\n<\/p>\n<h2>Dual-screen navigation<\/h2>\n<p>\n  When you are opening the app for the first time, only one fragment (A) will be displayed on the first side of the fold and the other side of the fold will be blank. \n<\/p>\n<p>\n  From this state, if you navigate to another fragment (B), then the new fragment will be opened on the end screen. Now, you\u2019ll have fragment A on the first display area and fragment B on the second display area.\n<\/p>\n<p>\n  If you are navigating to a third fragment (C), then fragment B will be moved to the first display area and the second display area will present the newly added fragment C.\n<\/p>\n<p>\n  You can navigate further, and open other fragments and the behavior will be the same; all fragments will be shifted from the end display area to the first one.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"945\" height=\"793\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/word-image.png\" class=\"wp-image-2256\" alt=\"Diagram showing three representations of Surface Duo devices and different views showing, marked A, B, and C\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/word-image.png 945w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/word-image-300x252.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/word-image-768x644.png 768w\" sizes=\"(max-width: 945px) 100vw, 945px\" \/>\n<\/p>\n<p>\n  You can change this behavior with the launchScreen attribute like this:\n<\/p>\n<pre>&lt;navigation xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n      xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n      xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n      android:id=\"@+id\/home\"\r\n      app:startDestination=\"@+id\/titleScreen\"&gt;\r\n      &lt;fragment\r\n          android:id=\"@+id\/titleScreen\"\r\n          android:name=\"com.microsoft.device.dualscreen.navigation.sample.homescreen.TitleFragment\"\r\n          android:label=\"@string\/title_home\"\r\n          tools:layout=\"@layout\/fragment_title\"&gt;\r\n          &lt;action\r\n              android:id=\"@+id\/action_title_to_about\"\r\n              <strong>app:launchScreen=\"end\"<\/strong>\r\n              app:destination=\"@id\/aboutScreen\"\r\n              app:enterAnim=\"@anim\/slide_in_right\"\r\n              app:exitAnim=\"@anim\/slide_out_left\"\r\n              app:popEnterAnim=\"@anim\/slide_in_right\"\r\n              app:popExitAnim=\"@anim\/slide_out_left\" \/&gt;\r\n      &lt;\/fragment&gt;\r\n  &lt;\/navigation&gt;<\/pre>\n<p>\n  Possible values for\u00a0launchScreen\u00a0are:\n<\/p>\n<ul>\n<li>\n    <b>Start<\/b>\u00a0&#8211; the fragment will be opened on the first screen\n  <\/li>\n<\/ul>\n<p>\n  <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-3.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-3.gif\" alt=\"Surface Duo showing navigation example with Start feature\" width=\"880\" height=\"670\" class=\"alignnone size-full wp-image-2266\" \/><\/a>\n<\/p>\n<ul>\n<li>\n    <b>End<\/b>\u00a0&#8211; the fragment will be opened on the second screen\n  <\/li>\n<\/ul>\n<p>\n<a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-4.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-4.gif\" alt=\"Surface Duo showing navigation example with End feature\" width=\"880\" height=\"670\" class=\"alignnone size-full wp-image-2267\" \/><\/a>\n<\/p>\n<ul>\n<li>\n    <b>Both<\/b>\u00a0&#8211; the fragment will cover the entire display area\n  <\/li>\n<\/ul>\n<p>\n<a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-5.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/02\/animation-5.gif\" alt=\"Surface Duo showing navigation example with Both feature\" width=\"880\" height=\"670\" class=\"alignnone size-full wp-image-2268\" \/><\/a>\n<\/p>\n<p>\n  You can review the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dual-screen\/android\/api-reference\/dualscreen-library\/navigation-component\/?tabs=kotlin\">documentation<\/a> for more info. You can also try out our <a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk\/tree\/main\/navigation\/navigation-sample\">sample<\/a> and check out all these navigation scenarios.\n<\/p>\n<h2>Tech Community Live<\/h2>\n<p>\nThis week the Surface Duo Developer Experience team participated in a live <a hre=\"https:\/\/techcommunity.microsoft.com\/t5\/surface-devices-events\/ama-dual-screen-experiences-developers-and-it-pros-with-surface\/ev-p\/2911194\">&#8220;Ask Me Anything (AMA)&#8221; discussion<\/a> with the Tech Community team. You can watch it online on YouTube:\n<\/br>\n<iframe width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/_uGTqwjyr08\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/p>\n<p>\nVisit the <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/surface-duo-sdk\/bd-p\/SurfaceDuoSDK\">Surface Duo developer questions<\/a> Tech Community forum to ask questions or provide feedback on our samples and SDKs. \n<\/p>\n<h2>Feedback and resources<\/h2>\n<p>\n  The\u202f<a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk\/tree\/main\/navigation\">source code for the Foldable Navigation Component<\/a> is available on GitHub if you\u2019re curious about the implementation or wish to contribute. Also visit the\u202f<a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/api-reference\/dualscreen-library\/?WT.mc_id=docs-surfaceduoblog-ancirja\" target=\"_blank\" rel=\"noopener\">documentation<\/a>\u202ffor more information on all the features in the dual-screen library for Kotlin and Java developers.\u202f\u00a0\n<\/p>\n<p>\n  Thanks to the team \u2013\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/bianca-miron-ro\/\">Bianca Miron<\/a>,\u00a0<a href=\"https:\/\/twitter.com\/CesarValiente\">Cesar Valiente<\/a>,\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/cristian-verdes-3b0046135\/\">Cristian Verdes<\/a>, and\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/sorin-albu-62a76a27\/\">Sorin Albu<\/a>\u00a0\u2013 for their work on this release.\u00a0\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\u00a0\n<\/p>\n<p>\n  Finally, please join us for our <a href=\"https:\/\/twitch.tv\/surfaceduodev\" target=\"_blank\" rel=\"noopener\">dual screen 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\/channel\/UClGu9QLtPNz8OdddBfhZXPA\" target=\"_blank\" rel=\"noopener\">archives on YouTube<\/a>.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Android developers! We\u2019re excited to announce the release of our latest SDK component, Foldable Navigation Component, which is an extension of Jetpack Navigation Component and is now available for foldable devices. How to add Foldable Navigation Component to your project dependencies { def nav_version = &#8220;1.0.0-alpha2&#8221; implementation &#8220;com.microsoft.device.dualscreen:navigation-fragment-ktx:$nav_version&#8221; implementation &#8220;com.microsoft.device.dualscreen:navigation-ui-ktx:$nav_version&#8221; } How it works [&hellip;]<\/p>\n","protected":false},"author":47750,"featured_media":2256,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,705,473,45],"class_list":["post-2254","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-dual-screen-development","tag-java","tag-kotlin","tag-surface-duo-sdk"],"acf":[],"blog_post_summary":"<p>Hello Android developers! We\u2019re excited to announce the release of our latest SDK component, Foldable Navigation Component, which is an extension of Jetpack Navigation Component and is now available for foldable devices. How to add Foldable Navigation Component to your project dependencies { def nav_version = &#8220;1.0.0-alpha2&#8221; implementation &#8220;com.microsoft.device.dualscreen:navigation-fragment-ktx:$nav_version&#8221; implementation &#8220;com.microsoft.device.dualscreen:navigation-ui-ktx:$nav_version&#8221; } How it works [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/2254","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=2254"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/2254\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/2256"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=2254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=2254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=2254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}