Refactor(Navigation): Optimize navigation bar switching transition animation
This commit is contained in:
@@ -10,7 +10,8 @@ fun OxygenNavHost(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
appState: OxygenAppState,
|
appState: OxygenAppState,
|
||||||
onShowSnackbar: suspend (message: String, action: String?) -> Boolean,
|
onShowSnackbar: suspend (message: String, action: String?) -> Boolean,
|
||||||
startDestination: String
|
startDestination: String,
|
||||||
|
isVertical: Boolean
|
||||||
) {
|
) {
|
||||||
val navController = appState.navController
|
val navController = appState.navController
|
||||||
NavHost(
|
NavHost(
|
||||||
@@ -29,9 +30,11 @@ fun OxygenNavHost(
|
|||||||
onBackClick = navController::popBackStack
|
onBackClick = navController::popBackStack
|
||||||
)
|
)
|
||||||
toolStoreScreen(
|
toolStoreScreen(
|
||||||
|
isVertical = isVertical,
|
||||||
onNavigateToToolView = navController::navigateToToolView
|
onNavigateToToolView = navController::navigateToToolView
|
||||||
)
|
)
|
||||||
toolsScreen(
|
toolsScreen(
|
||||||
|
isVertical = isVertical,
|
||||||
onShowSnackbar = onShowSnackbar,
|
onShowSnackbar = onShowSnackbar,
|
||||||
onNavigateToToolView = navController::navigateToToolView,
|
onNavigateToToolView = navController::navigateToToolView,
|
||||||
onNavigateToToolStore = { appState.navigateToTopLevelDestination(TopLevelDestination.ToolStore) }
|
onNavigateToToolStore = { appState.navigateToTopLevelDestination(TopLevelDestination.ToolStore) }
|
||||||
@@ -40,7 +43,7 @@ fun OxygenNavHost(
|
|||||||
onBackClick = navController::popBackStack
|
onBackClick = navController::popBackStack
|
||||||
)
|
)
|
||||||
starScreen(
|
starScreen(
|
||||||
|
isVertical = isVertical
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package top.fatweb.oxygen.toolbox.navigation
|
package top.fatweb.oxygen.toolbox.navigation
|
||||||
|
|
||||||
|
import androidx.compose.animation.slideInHorizontally
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
|
import androidx.compose.animation.slideOutHorizontally
|
||||||
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavOptions
|
import androidx.navigation.NavOptions
|
||||||
@@ -10,9 +14,29 @@ const val STAR_ROUTE = "star_route"
|
|||||||
|
|
||||||
fun NavController.navigateToStar(navOptions: NavOptions) = navigate(STAR_ROUTE, navOptions)
|
fun NavController.navigateToStar(navOptions: NavOptions) = navigate(STAR_ROUTE, navOptions)
|
||||||
|
|
||||||
fun NavGraphBuilder.starScreen() {
|
fun NavGraphBuilder.starScreen(
|
||||||
|
isVertical: Boolean
|
||||||
|
) {
|
||||||
composable(
|
composable(
|
||||||
route = STAR_ROUTE
|
route = STAR_ROUTE,
|
||||||
|
enterTransition = {
|
||||||
|
when (initialState.destination.route) {
|
||||||
|
TOOL_STORE_ROUTE, TOOLS_ROUTE ->
|
||||||
|
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth })
|
||||||
|
else slideInVertically(initialOffsetY = { fullHeight -> fullHeight })
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exitTransition = {
|
||||||
|
when (targetState.destination.route) {
|
||||||
|
TOOL_STORE_ROUTE, TOOLS_ROUTE ->
|
||||||
|
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth })
|
||||||
|
else slideOutVertically(targetOffsetY = { fullHeight -> fullHeight })
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
StarRoute()
|
StarRoute()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package top.fatweb.oxygen.toolbox.navigation
|
package top.fatweb.oxygen.toolbox.navigation
|
||||||
|
|
||||||
|
import androidx.compose.animation.slideInHorizontally
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
|
import androidx.compose.animation.slideOutHorizontally
|
||||||
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavOptions
|
import androidx.navigation.NavOptions
|
||||||
@@ -8,13 +12,33 @@ import top.fatweb.oxygen.toolbox.ui.tool.ToolStoreRoute
|
|||||||
|
|
||||||
const val TOOL_STORE_ROUTE = "tool_store_route"
|
const val TOOL_STORE_ROUTE = "tool_store_route"
|
||||||
|
|
||||||
fun NavController.navigateToToolStore(navOptions: NavOptions? = null) = navigate(TOOL_STORE_ROUTE, navOptions)
|
fun NavController.navigateToToolStore(navOptions: NavOptions? = null) =
|
||||||
|
navigate(TOOL_STORE_ROUTE, navOptions)
|
||||||
|
|
||||||
fun NavGraphBuilder.toolStoreScreen(
|
fun NavGraphBuilder.toolStoreScreen(
|
||||||
|
isVertical: Boolean,
|
||||||
onNavigateToToolView: (username: String, toolId: String, preview: Boolean) -> Unit
|
onNavigateToToolView: (username: String, toolId: String, preview: Boolean) -> Unit
|
||||||
) {
|
) {
|
||||||
composable(
|
composable(
|
||||||
route = TOOL_STORE_ROUTE
|
route = TOOL_STORE_ROUTE,
|
||||||
|
enterTransition = {
|
||||||
|
when (initialState.destination.route) {
|
||||||
|
TOOLS_ROUTE, STAR_ROUTE ->
|
||||||
|
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> -fullWidth })
|
||||||
|
else slideInVertically(initialOffsetY = { fullHeight -> -fullHeight })
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exitTransition = {
|
||||||
|
when (targetState.destination.route) {
|
||||||
|
TOOLS_ROUTE, STAR_ROUTE ->
|
||||||
|
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> -fullWidth })
|
||||||
|
else slideOutVertically(targetOffsetY = { fullHeight -> -fullHeight })
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
ToolStoreRoute(
|
ToolStoreRoute(
|
||||||
onNavigateToToolView = onNavigateToToolView
|
onNavigateToToolView = onNavigateToToolView
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package top.fatweb.oxygen.toolbox.navigation
|
package top.fatweb.oxygen.toolbox.navigation
|
||||||
|
|
||||||
|
import androidx.compose.animation.slideInHorizontally
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
|
import androidx.compose.animation.slideOutHorizontally
|
||||||
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavOptions
|
import androidx.navigation.NavOptions
|
||||||
@@ -11,12 +15,39 @@ const val TOOLS_ROUTE = "tools_route"
|
|||||||
fun NavController.navigateToTools(navOptions: NavOptions) = navigate(TOOLS_ROUTE, navOptions)
|
fun NavController.navigateToTools(navOptions: NavOptions) = navigate(TOOLS_ROUTE, navOptions)
|
||||||
|
|
||||||
fun NavGraphBuilder.toolsScreen(
|
fun NavGraphBuilder.toolsScreen(
|
||||||
|
isVertical: Boolean,
|
||||||
onShowSnackbar: suspend (message: String, action: String?) -> Boolean,
|
onShowSnackbar: suspend (message: String, action: String?) -> Boolean,
|
||||||
onNavigateToToolView: (username: String, toolId: String, preview: Boolean) -> Unit,
|
onNavigateToToolView: (username: String, toolId: String, preview: Boolean) -> Unit,
|
||||||
onNavigateToToolStore: () -> Unit
|
onNavigateToToolStore: () -> Unit
|
||||||
) {
|
) {
|
||||||
composable(
|
composable(
|
||||||
route = TOOLS_ROUTE
|
route = TOOLS_ROUTE,
|
||||||
|
enterTransition = {
|
||||||
|
when (initialState.destination.route) {
|
||||||
|
TOOL_STORE_ROUTE ->
|
||||||
|
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth })
|
||||||
|
else slideInVertically(initialOffsetY = { fullHeight -> fullHeight })
|
||||||
|
|
||||||
|
STAR_ROUTE ->
|
||||||
|
if (isVertical) slideInHorizontally(initialOffsetX = { fullWidth -> -fullWidth })
|
||||||
|
else slideInVertically(initialOffsetY = { fullHeight -> -fullHeight })
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exitTransition = {
|
||||||
|
when (targetState.destination.route) {
|
||||||
|
TOOL_STORE_ROUTE ->
|
||||||
|
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth })
|
||||||
|
else slideOutVertically(targetOffsetY = { fullHeight -> fullHeight })
|
||||||
|
|
||||||
|
STAR_ROUTE ->
|
||||||
|
if (isVertical) slideOutHorizontally(targetOffsetX = { fullWidth -> -fullWidth })
|
||||||
|
else slideOutVertically(targetOffsetY = { fullHeight -> -fullHeight })
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
ToolsRoute(
|
ToolsRoute(
|
||||||
onShowSnackbar = onShowSnackbar,
|
onShowSnackbar = onShowSnackbar,
|
||||||
|
|||||||
@@ -173,7 +173,8 @@ fun OxygenApp(appState: OxygenAppState) {
|
|||||||
startDestination = when (appState.launchPageConfig) {
|
startDestination = when (appState.launchPageConfig) {
|
||||||
LaunchPageConfig.Tools -> TOOLS_ROUTE
|
LaunchPageConfig.Tools -> TOOLS_ROUTE
|
||||||
LaunchPageConfig.Star -> STAR_ROUTE
|
LaunchPageConfig.Star -> STAR_ROUTE
|
||||||
}
|
},
|
||||||
|
isVertical = appState.shouldShowBottomBar
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user