Refactor(Animation): Optimize animation

This commit is contained in:
2024-08-21 10:54:54 +08:00
parent 18c03c194b
commit 310214fc20
6 changed files with 29 additions and 26 deletions

View File

@@ -20,11 +20,11 @@ fun NavGraphBuilder.aboutScreen(
composable( composable(
route = ABOUT_ROUTE, route = ABOUT_ROUTE,
enterTransition = { enterTransition = {
slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth }) slideInHorizontally { it }
}, },
popEnterTransition = null, popEnterTransition = null,
popExitTransition = { popExitTransition = {
slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth }) slideOutHorizontally { it }
} }
) { ) {
AboutRoute( AboutRoute(

View File

@@ -19,11 +19,11 @@ fun NavGraphBuilder.librariesScreen(
composable( composable(
route = LIBRARIES_ROUTE, route = LIBRARIES_ROUTE,
enterTransition = { enterTransition = {
slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth }) slideInHorizontally { it }
}, },
popEnterTransition = null, popEnterTransition = null,
popExitTransition = { popExitTransition = {
slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth }) slideOutHorizontally { it }
} }
) { ) {
LibrariesRoute(onBackClick = onBackClick) LibrariesRoute(onBackClick = onBackClick)

View File

@@ -25,8 +25,8 @@ fun NavGraphBuilder.starScreen(
enterTransition = { enterTransition = {
when (initialState.destination.route) { when (initialState.destination.route) {
TOOL_STORE_ROUTE, TOOLS_ROUTE -> TOOL_STORE_ROUTE, TOOLS_ROUTE ->
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth }) if (isVertical) slideInHorizontally { it }
else slideInVertically(initialOffsetY = { fullHeight -> fullHeight }) else slideInVertically { it }
else -> null else -> null
} }
@@ -34,8 +34,8 @@ fun NavGraphBuilder.starScreen(
exitTransition = { exitTransition = {
when (targetState.destination.route) { when (targetState.destination.route) {
TOOL_STORE_ROUTE, TOOLS_ROUTE -> TOOL_STORE_ROUTE, TOOLS_ROUTE ->
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth }) if (isVertical) slideOutHorizontally { it }
else slideOutVertically(targetOffsetY = { fullHeight -> fullHeight }) else slideOutVertically { it }
else -> null else -> null
} }

View File

@@ -26,8 +26,8 @@ fun NavGraphBuilder.toolStoreScreen(
enterTransition = { enterTransition = {
when (initialState.destination.route) { when (initialState.destination.route) {
TOOLS_ROUTE, STAR_ROUTE -> TOOLS_ROUTE, STAR_ROUTE ->
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> -fullWidth }) if (isVertical) slideInHorizontally { -it }
else slideInVertically(initialOffsetY = { fullHeight -> -fullHeight }) else slideInVertically { -it }
else -> null else -> null
} }
@@ -35,8 +35,8 @@ fun NavGraphBuilder.toolStoreScreen(
exitTransition = { exitTransition = {
when (targetState.destination.route) { when (targetState.destination.route) {
TOOLS_ROUTE, STAR_ROUTE -> TOOLS_ROUTE, STAR_ROUTE ->
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> -fullWidth }) if (isVertical) slideOutHorizontally { -it }
else slideOutVertically(targetOffsetY = { fullHeight -> -fullHeight }) else slideOutVertically { -it }
else -> null else -> null
} }

View File

@@ -27,12 +27,12 @@ fun NavGraphBuilder.toolsScreen(
enterTransition = { enterTransition = {
when (initialState.destination.route) { when (initialState.destination.route) {
TOOL_STORE_ROUTE -> TOOL_STORE_ROUTE ->
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth }) if (isVertical) slideInHorizontally { it }
else slideInVertically(initialOffsetY = { fullHeight -> fullHeight }) else slideInVertically { it }
STAR_ROUTE -> STAR_ROUTE ->
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> -fullWidth }) if (isVertical) slideInHorizontally { -it }
else slideInVertically(initialOffsetY = { fullHeight -> -fullHeight }) else slideInVertically { -it }
else -> null else -> null
} }
@@ -40,12 +40,12 @@ fun NavGraphBuilder.toolsScreen(
exitTransition = { exitTransition = {
when (targetState.destination.route) { when (targetState.destination.route) {
TOOL_STORE_ROUTE -> TOOL_STORE_ROUTE ->
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth }) if (isVertical) slideOutHorizontally { it }
else slideOutVertically(targetOffsetY = { fullHeight -> fullHeight }) else slideOutVertically { it }
STAR_ROUTE -> STAR_ROUTE ->
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> -fullWidth }) if (isVertical) slideOutHorizontally { -it }
else slideOutVertically(targetOffsetY = { fullHeight -> -fullHeight }) else slideOutVertically { -it }
else -> null else -> null
} }

View File

@@ -1,7 +1,6 @@
package top.fatweb.oxygen.toolbox.ui package top.fatweb.oxygen.toolbox.ui
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInVertically
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.WindowInsets import androidx.compose.foundation.layout.WindowInsets
@@ -128,8 +127,8 @@ fun OxygenApp(appState: OxygenAppState) {
snackbarHost = { SnackbarHost(hostState = snackbarHostState) }, snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
bottomBar = { bottomBar = {
AnimatedVisibility( AnimatedVisibility(
visible = appState.shouldShowBottomBar && destination != null, visible = appState.shouldShowBottomBar && destination != null
enter = slideInVertically { it }) { ) {
BottomAppBar( BottomAppBar(
windowInsets = WindowInsets(0) windowInsets = WindowInsets(0)
) { ) {
@@ -153,7 +152,9 @@ fun OxygenApp(appState: OxygenAppState) {
) )
) )
) { ) {
AnimatedVisibility(visible = appState.shouldShowNavRail && destination != null) { AnimatedVisibility(
visible = appState.shouldShowNavRail && destination != null
) {
OxygenNavRail( OxygenNavRail(
modifier = Modifier.safeDrawingPadding(), modifier = Modifier.safeDrawingPadding(),
destinations = appState.topLevelDestinations, destinations = appState.topLevelDestinations,
@@ -165,11 +166,13 @@ fun OxygenApp(appState: OxygenAppState) {
Column( Column(
Modifier.fillMaxSize() Modifier.fillMaxSize()
) { ) {
if (destination != null) { AnimatedVisibility(
visible = destination != null
) {
OxygenTopAppBar( OxygenTopAppBar(
scrollBehavior = topAppBarScrollBehavior, scrollBehavior = topAppBarScrollBehavior,
title = { title = {
Text(text = stringResource(destination.titleTextId)) destination?.let { Text(text = stringResource(destination.titleTextId)) }
}, },
navigationIcon = OxygenIcons.Search, navigationIcon = OxygenIcons.Search,
navigationIconContentDescription = stringResource(R.string.feature_settings_top_app_bar_navigation_icon_description), navigationIconContentDescription = stringResource(R.string.feature_settings_top_app_bar_navigation_icon_description),