@@ -5,6 +5,14 @@ import android.content.ClipboardManager
55import android.os.Build
66import android.widget.Toast
77import androidx.activity.compose.BackHandler
8+ import androidx.compose.animation.AnimatedContent
9+ import androidx.compose.animation.fadeIn
10+ import androidx.compose.animation.fadeOut
11+ import androidx.compose.animation.slideInHorizontally
12+ import androidx.compose.animation.slideOutHorizontally
13+ import androidx.compose.animation.togetherWith
14+ import androidx.compose.animation.core.FastOutSlowInEasing
15+ import androidx.compose.animation.core.tween
816import androidx.compose.foundation.BorderStroke
917import androidx.compose.foundation.background
1018import androidx.compose.foundation.clickable
@@ -107,6 +115,7 @@ enum class UdroidDestination(
107115) {
108116 HOME (" Home" , Icons .Outlined .Home , Icons .Filled .Home ),
109117 DISTROS (" Linux" , Icons .Outlined .Storage , Icons .Filled .Storage ),
118+ INSTALL (" Install" , Icons .Outlined .Storage , Icons .Filled .Storage ),
110119 SYSTEM (" System" , Icons .Outlined .Storage , Icons .Filled .Storage ),
111120 TERMINAL (" Terminal" , Icons .Outlined .Terminal , Icons .Filled .Terminal ),
112121 APPS (" Apps" , Icons .Outlined .Apps , Icons .Filled .Apps ),
@@ -115,6 +124,34 @@ enum class UdroidDestination(
115124 ABOUT (" About" , Icons .Outlined .Info , Icons .Filled .Info ),
116125}
117126
127+ internal enum class NavigationMotion {
128+ FORWARD ,
129+ BACK ,
130+ FADE ,
131+ }
132+
133+ internal fun navigationMotion (
134+ initial : UdroidDestination ,
135+ target : UdroidDestination ,
136+ ): NavigationMotion {
137+ val initialDepth = initial.navigationDepth
138+ val targetDepth = target.navigationDepth
139+ return when {
140+ targetDepth > initialDepth -> NavigationMotion .FORWARD
141+ targetDepth < initialDepth -> NavigationMotion .BACK
142+ else -> NavigationMotion .FADE
143+ }
144+ }
145+
146+ private val UdroidDestination .navigationDepth: Int
147+ get() =
148+ when (this ) {
149+ UdroidDestination .INSTALL ,
150+ UdroidDestination .SYSTEM ,
151+ -> 1
152+ else -> 0
153+ }
154+
118155@Composable
119156fun UdroidApp (
120157 destination : UdroidDestination ,
@@ -142,6 +179,7 @@ fun UdroidApp(
142179 showInstallTerminal : Boolean ,
143180 runtimeService : RuntimeSupervisorService ? ,
144181 onDestinationSelected : (UdroidDestination ) -> Unit ,
182+ onPrimaryDestinationSelected : (UdroidDestination ) -> Unit ,
145183 onStart : () -> Unit ,
146184 onStop : () -> Unit ,
147185 onRefresh : () -> Unit ,
@@ -185,6 +223,13 @@ fun UdroidApp(
185223 compactNavigation = false ,
186224 )
187225 val activeDestination = requestedJourney.destination
226+ val navigationDestination =
227+ when (activeDestination) {
228+ UdroidDestination .INSTALL ,
229+ UdroidDestination .SYSTEM ,
230+ -> UdroidDestination .DISTROS
231+ else -> activeDestination
232+ }
188233
189234 if (activeDestination == UdroidDestination .DESKTOP ) {
190235 DesktopPage (
@@ -234,9 +279,9 @@ fun UdroidApp(
234279 if (useRail) {
235280 Row (modifier = Modifier .fillMaxSize()) {
236281 WorkspaceNavigationRail (
237- selected = activeDestination ,
282+ selected = navigationDestination ,
238283 destinations = requestedJourney.destinations,
239- onSelected = onDestinationSelected ,
284+ onSelected = onPrimaryDestinationSelected ,
240285 )
241286 Divider (
242287 modifier = Modifier .fillMaxHeight().width(1 .dp),
@@ -268,6 +313,7 @@ fun UdroidApp(
268313 linuxApplicationMessage = linuxApplicationMessage,
269314 showInstallTerminal = showInstallTerminal,
270315 onDestinationSelected = onDestinationSelected,
316+ onPrimaryDestinationSelected = onPrimaryDestinationSelected,
271317 onStart = onStart,
272318 onStop = onStop,
273319 onRefresh = onRefresh,
@@ -331,6 +377,7 @@ fun UdroidApp(
331377 linuxApplicationMessage = linuxApplicationMessage,
332378 showInstallTerminal = showInstallTerminal,
333379 onDestinationSelected = onDestinationSelected,
380+ onPrimaryDestinationSelected = onPrimaryDestinationSelected,
334381 onStart = onStart,
335382 onStop = onStop,
336383 onRefresh = onRefresh,
@@ -366,15 +413,15 @@ fun UdroidApp(
366413 onOpenUpdateRelease = onOpenUpdateRelease,
367414 )
368415 WorkspaceNavigationBar (
369- selected = activeDestination ,
416+ selected = navigationDestination ,
370417 destinations =
371418 workspaceJourney(
372419 requestedDestination = activeDestination,
373420 hasInstalledLinux = hasInstalledLinux,
374421 hasInstallation = installProgress != null ,
375422 compactNavigation = true ,
376423 ).destinations,
377- onSelected = onDestinationSelected ,
424+ onSelected = onPrimaryDestinationSelected ,
378425 )
379426 }
380427 }
@@ -408,6 +455,7 @@ private fun ManagementPane(
408455 linuxApplicationMessage : String? ,
409456 showInstallTerminal : Boolean ,
410457 onDestinationSelected : (UdroidDestination ) -> Unit ,
458+ onPrimaryDestinationSelected : (UdroidDestination ) -> Unit ,
411459 onStart : () -> Unit ,
412460 onStop : () -> Unit ,
413461 onRefresh : () -> Unit ,
@@ -461,7 +509,73 @@ private fun ManagementPane(
461509 .fillMaxSize()
462510 .widthIn(max = 900 .dp),
463511 ) {
464- when (destination) {
512+ AnimatedContent (
513+ targetState = destination,
514+ transitionSpec = {
515+ when (navigationMotion(initialState, targetState)) {
516+ NavigationMotion .FORWARD ->
517+ (
518+ slideInHorizontally(
519+ animationSpec =
520+ tween(
521+ durationMillis = 190 ,
522+ easing = FastOutSlowInEasing ,
523+ ),
524+ initialOffsetX = { width -> width / 10 },
525+ ) +
526+ fadeIn(
527+ animationSpec =
528+ tween(
529+ durationMillis = 150 ,
530+ delayMillis = 25 ,
531+ ),
532+ )
533+ ).togetherWith(
534+ slideOutHorizontally(
535+ animationSpec = tween(durationMillis = 150 ),
536+ targetOffsetX = { width -> - width / 24 },
537+ ) +
538+ fadeOut(animationSpec = tween(durationMillis = 110 )),
539+ )
540+ NavigationMotion .BACK ->
541+ (
542+ slideInHorizontally(
543+ animationSpec =
544+ tween(
545+ durationMillis = 190 ,
546+ easing = FastOutSlowInEasing ,
547+ ),
548+ initialOffsetX = { width -> - width / 10 },
549+ ) +
550+ fadeIn(
551+ animationSpec =
552+ tween(
553+ durationMillis = 150 ,
554+ delayMillis = 25 ,
555+ ),
556+ )
557+ ).togetherWith(
558+ slideOutHorizontally(
559+ animationSpec = tween(durationMillis = 150 ),
560+ targetOffsetX = { width -> width / 24 },
561+ ) +
562+ fadeOut(animationSpec = tween(durationMillis = 110 )),
563+ )
564+ NavigationMotion .FADE ->
565+ fadeIn(
566+ animationSpec =
567+ tween(
568+ durationMillis = 150 ,
569+ delayMillis = 35 ,
570+ ),
571+ ).togetherWith(
572+ fadeOut(animationSpec = tween(durationMillis = 100 )),
573+ )
574+ }
575+ },
576+ label = " workspace-page" ,
577+ ) { animatedDestination ->
578+ when (animatedDestination) {
465579 UdroidDestination .HOME -> {
466580 val installedDistro =
467581 (catalogueState as ? DistroCatalogState .Ready )
@@ -479,8 +593,7 @@ private fun ManagementPane(
479593 onDestinationSelected(UdroidDestination .TERMINAL )
480594 },
481595 onOpenLinux = {
482- installedRootfsName?.let (onOpenInstalledSystem)
483- ? : onDestinationSelected(UdroidDestination .DISTROS )
596+ onPrimaryDestinationSelected(UdroidDestination .DISTROS )
484597 },
485598 onOpenDevice = {
486599 onDestinationSelected(UdroidDestination .DEVICE )
@@ -497,20 +610,7 @@ private fun ManagementPane(
497610 )
498611 }
499612 UdroidDestination .DISTROS ->
500- installProgress?.let {
501- InstallExperiencePage (
502- progress = it,
503- showTerminal = showInstallTerminal,
504- onToggleTerminal = onToggleInstallTerminal,
505- onBack = onCloseInstall,
506- onOpenTerminal = {
507- onOpenRootfsTerminal(it.installationName)
508- },
509- onStartDownload = onStartDownload,
510- onPauseDownload = onPauseDownload,
511- onRetryDownload = onRetryDownload,
512- )
513- } ? : selectedOciRepository?.let { repository ->
613+ selectedOciRepository?.let { repository ->
514614 OciTagCataloguePage (
515615 repository = repository,
516616 state = ociTagsState,
@@ -529,6 +629,21 @@ private fun ManagementPane(
529629 onSelectOciRepository = onSelectOciRepository,
530630 onOpenInstalledSystem = onOpenInstalledSystem,
531631 )
632+ UdroidDestination .INSTALL ->
633+ installProgress?.let {
634+ InstallExperiencePage (
635+ progress = it,
636+ showTerminal = showInstallTerminal,
637+ onToggleTerminal = onToggleInstallTerminal,
638+ onBack = onCloseInstall,
639+ onOpenTerminal = {
640+ onOpenRootfsTerminal(it.installationName)
641+ },
642+ onStartDownload = onStartDownload,
643+ onPauseDownload = onPauseDownload,
644+ onRetryDownload = onRetryDownload,
645+ )
646+ }
532647 UdroidDestination .SYSTEM -> {
533648 val rootfsName = selectedSystemRootfsName ? : installedRootfsName
534649 val selectedRootfs =
@@ -618,6 +733,7 @@ private fun ManagementPane(
618733 )
619734 UdroidDestination .TERMINAL -> Unit
620735 UdroidDestination .DESKTOP -> Unit
736+ }
621737 }
622738 }
623739 }
0 commit comments