fix(tv): stabilize navigation drawer animation

This commit is contained in:
2026-04-29 20:09:00 +02:00
parent 8a7577d5bb
commit 84a95b0af6

View File

@@ -1,11 +1,9 @@
package hu.bbara.purefin.ui.screen.home.components package hu.bbara.purefin.ui.screen.home.components
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
@@ -13,7 +11,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.selection.selectableGroup import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -38,9 +35,6 @@ import androidx.tv.material3.MaterialTheme as TvMaterialTheme
internal const val TvDrawerItemTagPrefix = "tv-drawer-item-" internal const val TvDrawerItemTagPrefix = "tv-drawer-item-"
internal const val TvDrawerTitleTag = "tv-drawer-title" internal const val TvDrawerTitleTag = "tv-drawer-title"
private val TvDrawerCollapsedWidth = 92.dp
private val TvDrawerExpandedWidth = 280.dp
@Composable @Composable
fun TvNavigationDrawer( fun TvNavigationDrawer(
destinations: List<TvDrawerDestinationItem>, destinations: List<TvDrawerDestinationItem>,
@@ -52,9 +46,9 @@ fun TvNavigationDrawer(
ProvideTvDrawerTheme { ProvideTvDrawerTheme {
NavigationDrawer( NavigationDrawer(
modifier = modifier.fillMaxSize(), modifier = modifier.fillMaxSize(),
drawerContent = { drawerContent = { drawerValue ->
TvNavigationDrawerRail( TvNavigationDrawerRail(
drawerValue = if (hasFocus) DrawerValue.Open else DrawerValue.Closed, drawerValue = drawerValue,
destinations = destinations, destinations = destinations,
selectedDestination = selectedDestination, selectedDestination = selectedDestination,
onDestinationSelected = onDestinationSelected onDestinationSelected = onDestinationSelected
@@ -137,22 +131,13 @@ private fun androidx.tv.material3.NavigationDrawerScope.TvNavigationDrawerRail(
onDestinationSelected: (Route) -> Unit, onDestinationSelected: (Route) -> Unit,
) { ) {
val expanded = drawerValue == DrawerValue.Open val expanded = drawerValue == DrawerValue.Open
val drawerWidth = animateDpAsState(
targetValue = if (expanded) TvDrawerExpandedWidth else TvDrawerCollapsedWidth,
label = "tv-drawer-width"
)
val scheme = MaterialTheme.colorScheme val scheme = MaterialTheme.colorScheme
Box(
modifier = Modifier
.width(drawerWidth.value)
.fillMaxHeight()
.background(scheme.surface.copy(alpha = 0.96f))
) {
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxHeight()
.padding(horizontal = 16.dp, vertical = 24.dp) .background(scheme.surface.copy(alpha = 0.96f))
.padding(horizontal = 12.dp, vertical = 24.dp)
.selectableGroup(), .selectableGroup(),
verticalArrangement = Arrangement.spacedBy(12.dp) verticalArrangement = Arrangement.spacedBy(12.dp)
) { ) {
@@ -175,7 +160,6 @@ private fun androidx.tv.material3.NavigationDrawerScope.TvNavigationDrawerRail(
) )
} }
) { ) {
if (expanded) {
Text( Text(
text = destination.label, text = destination.label,
maxLines = 1, maxLines = 1,
@@ -183,8 +167,6 @@ private fun androidx.tv.material3.NavigationDrawerScope.TvNavigationDrawerRail(
) )
} }
} }
}
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
} }
} }
}