mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
Fix transition animation
This commit is contained in:
parent
abd0b714bb
commit
29c2f2f26e
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto
|
package com.sadellie.unitto
|
||||||
|
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@ -43,7 +45,9 @@ internal fun UnittoNavigation(
|
|||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = startDestination,
|
startDestination = startDestination,
|
||||||
modifier = Modifier.background(MaterialTheme.colorScheme.background)
|
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
||||||
|
enterTransition = { fadeIn() },
|
||||||
|
exitTransition = { fadeOut() }
|
||||||
) {
|
) {
|
||||||
converterGraph(
|
converterGraph(
|
||||||
openDrawer = openDrawer,
|
openDrawer = openDrawer,
|
||||||
|
@ -41,5 +41,7 @@ dependencies {
|
|||||||
testImplementation(libs.androidx.compose.ui.test.junit4)
|
testImplementation(libs.androidx.compose.ui.test.junit4)
|
||||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||||
|
|
||||||
|
implementation(libs.androidx.navigation)
|
||||||
|
|
||||||
implementation(project(mapOf("path" to ":core:base")))
|
implementation(project(mapOf("path" to ":core:base")))
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Unitto is a unit converter for Android
|
||||||
|
* Copyright (c) 2023 Elshan Agaev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sadellie.unitto.core.ui
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedContentScope
|
||||||
|
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||||
|
import androidx.compose.animation.EnterTransition
|
||||||
|
import androidx.compose.animation.ExitTransition
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.navigation.NamedNavArgument
|
||||||
|
import androidx.navigation.NavBackStackEntry
|
||||||
|
import androidx.navigation.NavDeepLink
|
||||||
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.compose.navigation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NavGraphBuilder.composable
|
||||||
|
*/
|
||||||
|
fun NavGraphBuilder.unittoComposable(
|
||||||
|
route: String,
|
||||||
|
arguments: List<NamedNavArgument> = emptyList(),
|
||||||
|
deepLinks: List<NavDeepLink> = emptyList(),
|
||||||
|
enterTransition: (@JvmSuppressWildcards
|
||||||
|
AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)? = { fadeIn() },
|
||||||
|
exitTransition: (@JvmSuppressWildcards
|
||||||
|
AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition?)? = { fadeOut() },
|
||||||
|
popEnterTransition: (@JvmSuppressWildcards
|
||||||
|
AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)? =
|
||||||
|
enterTransition,
|
||||||
|
popExitTransition: (@JvmSuppressWildcards
|
||||||
|
AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition?)? =
|
||||||
|
exitTransition,
|
||||||
|
content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit
|
||||||
|
): Unit = composable(
|
||||||
|
route = route,
|
||||||
|
arguments = arguments,
|
||||||
|
deepLinks = deepLinks,
|
||||||
|
enterTransition = enterTransition,
|
||||||
|
exitTransition = exitTransition,
|
||||||
|
popEnterTransition = popEnterTransition,
|
||||||
|
popExitTransition = popExitTransition,
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NavGraphBuilder.navigation
|
||||||
|
*/
|
||||||
|
fun NavGraphBuilder.unittoNavigation(
|
||||||
|
startDestination: String,
|
||||||
|
route: String,
|
||||||
|
arguments: List<NamedNavArgument> = emptyList(),
|
||||||
|
deepLinks: List<NavDeepLink> = emptyList(),
|
||||||
|
enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)? =
|
||||||
|
null,
|
||||||
|
exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition?)? =
|
||||||
|
null,
|
||||||
|
popEnterTransition: (
|
||||||
|
AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?
|
||||||
|
)? = enterTransition,
|
||||||
|
popExitTransition: (
|
||||||
|
AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition?
|
||||||
|
)? = exitTransition,
|
||||||
|
builder: NavGraphBuilder.() -> Unit
|
||||||
|
): Unit = navigation(
|
||||||
|
startDestination = startDestination,
|
||||||
|
route = route,
|
||||||
|
arguments = arguments,
|
||||||
|
deepLinks = deepLinks,
|
||||||
|
enterTransition = enterTransition,
|
||||||
|
exitTransition = exitTransition,
|
||||||
|
popEnterTransition = popEnterTransition,
|
||||||
|
popExitTransition = popExitTransition,
|
||||||
|
builder = builder
|
||||||
|
)
|
@ -19,10 +19,10 @@
|
|||||||
package com.sadellie.unitto.feature.calculator.navigation
|
package com.sadellie.unitto.feature.calculator.navigation
|
||||||
|
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.core.base.TopLevelDestinations
|
import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||||
|
import com.sadellie.unitto.core.ui.unittoComposable
|
||||||
|
import com.sadellie.unitto.core.ui.unittoNavigation
|
||||||
import com.sadellie.unitto.feature.calculator.CalculatorRoute
|
import com.sadellie.unitto.feature.calculator.CalculatorRoute
|
||||||
|
|
||||||
private val graph = TopLevelDestinations.Calculator.graph
|
private val graph = TopLevelDestinations.Calculator.graph
|
||||||
@ -32,14 +32,14 @@ fun NavGraphBuilder.calculatorGraph(
|
|||||||
navigateToMenu: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
navigateToSettings: () -> Unit
|
navigateToSettings: () -> Unit
|
||||||
) {
|
) {
|
||||||
navigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
route = graph,
|
route = graph,
|
||||||
deepLinks = listOf(
|
deepLinks = listOf(
|
||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
composable(start) {
|
unittoComposable(start) {
|
||||||
CalculatorRoute(
|
CalculatorRoute(
|
||||||
navigateToMenu = navigateToMenu,
|
navigateToMenu = navigateToMenu,
|
||||||
navigateToSettings = navigateToSettings
|
navigateToSettings = navigateToSettings
|
||||||
|
@ -22,10 +22,10 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.core.base.TopLevelDestinations
|
import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||||
|
import com.sadellie.unitto.core.ui.unittoComposable
|
||||||
|
import com.sadellie.unitto.core.ui.unittoNavigation
|
||||||
import com.sadellie.unitto.feature.converter.ConverterRoute
|
import com.sadellie.unitto.feature.converter.ConverterRoute
|
||||||
import com.sadellie.unitto.feature.converter.ConverterViewModel
|
import com.sadellie.unitto.feature.converter.ConverterViewModel
|
||||||
import com.sadellie.unitto.feature.converter.LeftSideRoute
|
import com.sadellie.unitto.feature.converter.LeftSideRoute
|
||||||
@ -42,19 +42,19 @@ fun NavGraphBuilder.converterGraph(
|
|||||||
navigateToSettings: () -> Unit,
|
navigateToSettings: () -> Unit,
|
||||||
navigateToUnitGroups: () -> Unit,
|
navigateToUnitGroups: () -> Unit,
|
||||||
) {
|
) {
|
||||||
navigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
route = graph,
|
route = graph,
|
||||||
deepLinks = listOf(
|
deepLinks = listOf(
|
||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
composable(start) { backStackEntry ->
|
unittoComposable(start) { backStackEntry ->
|
||||||
val parentEntry = remember(backStackEntry) {
|
val parentEntry = remember(backStackEntry) {
|
||||||
navController.getBackStackEntry(graph)
|
navController.getBackStackEntry(graph)
|
||||||
}
|
}
|
||||||
|
|
||||||
val parentViewModel = hiltViewModel<ConverterViewModel>(parentEntry)
|
val parentViewModel = hiltViewModel<ConverterViewModel>(parentEntry)
|
||||||
|
|
||||||
ConverterRoute(
|
ConverterRoute(
|
||||||
viewModel = parentViewModel,
|
viewModel = parentViewModel,
|
||||||
@ -65,7 +65,7 @@ fun NavGraphBuilder.converterGraph(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(LEFT) { backStackEntry ->
|
unittoComposable(LEFT) { backStackEntry ->
|
||||||
val parentEntry = remember(backStackEntry) {
|
val parentEntry = remember(backStackEntry) {
|
||||||
navController.getBackStackEntry(graph)
|
navController.getBackStackEntry(graph)
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ fun NavGraphBuilder.converterGraph(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(RIGHT) { backStackEntry ->
|
unittoComposable(RIGHT) { backStackEntry ->
|
||||||
val parentEntry = remember(backStackEntry) {
|
val parentEntry = remember(backStackEntry) {
|
||||||
navController.getBackStackEntry(graph)
|
navController.getBackStackEntry(graph)
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
package com.sadellie.unitto.feature.datecalculator.navigation
|
package com.sadellie.unitto.feature.datecalculator.navigation
|
||||||
|
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.core.base.TopLevelDestinations
|
import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||||
|
import com.sadellie.unitto.core.ui.unittoComposable
|
||||||
|
import com.sadellie.unitto.core.ui.unittoNavigation
|
||||||
import com.sadellie.unitto.feature.datecalculator.DateCalculatorRoute
|
import com.sadellie.unitto.feature.datecalculator.DateCalculatorRoute
|
||||||
|
|
||||||
private val graph = TopLevelDestinations.DateCalculator.graph
|
private val graph = TopLevelDestinations.DateCalculator.graph
|
||||||
@ -32,14 +32,14 @@ fun NavGraphBuilder.dateCalculatorGraph(
|
|||||||
navigateToMenu: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
navigateToSettings: () -> Unit
|
navigateToSettings: () -> Unit
|
||||||
) {
|
) {
|
||||||
navigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
route = graph,
|
route = graph,
|
||||||
deepLinks = listOf(
|
deepLinks = listOf(
|
||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
composable(start) {
|
unittoComposable(start) {
|
||||||
DateCalculatorRoute(
|
DateCalculatorRoute(
|
||||||
navigateToMenu = navigateToMenu,
|
navigateToMenu = navigateToMenu,
|
||||||
navigateToSettings = navigateToSettings
|
navigateToSettings = navigateToSettings
|
||||||
|
@ -21,10 +21,10 @@ package com.sadellie.unitto.feature.settings.navigation
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.core.base.TopLevelDestinations
|
import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||||
|
import com.sadellie.unitto.core.ui.unittoComposable
|
||||||
|
import com.sadellie.unitto.core.ui.unittoNavigation
|
||||||
import com.sadellie.unitto.feature.settings.SettingsRoute
|
import com.sadellie.unitto.feature.settings.SettingsRoute
|
||||||
import com.sadellie.unitto.feature.settings.about.AboutScreen
|
import com.sadellie.unitto.feature.settings.about.AboutScreen
|
||||||
import com.sadellie.unitto.feature.settings.calculator.CalculatorSettingsScreen
|
import com.sadellie.unitto.feature.settings.calculator.CalculatorSettingsScreen
|
||||||
@ -57,60 +57,60 @@ fun NavGraphBuilder.settingGraph(
|
|||||||
themmoController: ThemmoController,
|
themmoController: ThemmoController,
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
) {
|
) {
|
||||||
navigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
route = graph,
|
route = graph,
|
||||||
deepLinks = listOf(
|
deepLinks = listOf(
|
||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
composable(start) {
|
unittoComposable(start) {
|
||||||
SettingsRoute(
|
SettingsRoute(
|
||||||
menuButtonClick = navController::navigateUp,
|
menuButtonClick = navController::navigateUp,
|
||||||
navControllerAction = navController::navigate
|
navControllerAction = navController::navigate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(themesRoute) {
|
unittoComposable(themesRoute) {
|
||||||
ThemesRoute(
|
ThemesRoute(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
themmoController = themmoController,
|
themmoController = themmoController,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(formattingRoute) {
|
unittoComposable(formattingRoute) {
|
||||||
FormattingRoute(
|
FormattingRoute(
|
||||||
navigateUpAction = navController::navigateUp
|
navigateUpAction = navController::navigateUp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(calculatorSettingsRoute) {
|
unittoComposable(calculatorSettingsRoute) {
|
||||||
CalculatorSettingsScreen(
|
CalculatorSettingsScreen(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(converterSettingsRoute) {
|
unittoComposable(converterSettingsRoute) {
|
||||||
ConverterSettingsScreen(
|
ConverterSettingsScreen(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
navigateToUnitsGroup = { navController.navigate(unitsGroupRoute) }
|
navigateToUnitsGroup = { navController.navigate(unitsGroupRoute) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(unitsGroupRoute) {
|
unittoComposable(unitsGroupRoute) {
|
||||||
UnitGroupsScreen(
|
UnitGroupsScreen(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(aboutRoute) {
|
unittoComposable(aboutRoute) {
|
||||||
AboutScreen(
|
AboutScreen(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
navigateToThirdParty = { navController.navigate(thirdPartyRoute) }
|
navigateToThirdParty = { navController.navigate(thirdPartyRoute) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(thirdPartyRoute) {
|
unittoComposable(thirdPartyRoute) {
|
||||||
ThirdPartyLicensesScreen(
|
ThirdPartyLicensesScreen(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
)
|
)
|
||||||
|
@ -22,11 +22,11 @@ import androidx.navigation.NavController
|
|||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.NavType
|
import androidx.navigation.NavType
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.navArgument
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.core.base.TopLevelDestinations
|
import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||||
|
import com.sadellie.unitto.core.ui.unittoComposable
|
||||||
|
import com.sadellie.unitto.core.ui.unittoNavigation
|
||||||
import com.sadellie.unitto.timezone.AddTimeZoneRoute
|
import com.sadellie.unitto.timezone.AddTimeZoneRoute
|
||||||
import com.sadellie.unitto.timezone.TimeZoneRoute
|
import com.sadellie.unitto.timezone.TimeZoneRoute
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
@ -52,14 +52,14 @@ fun NavGraphBuilder.timeZoneGraph(
|
|||||||
navigateToSettings: () -> Unit,
|
navigateToSettings: () -> Unit,
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
) {
|
) {
|
||||||
navigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
route = graph,
|
route = graph,
|
||||||
deepLinks = listOf(
|
deepLinks = listOf(
|
||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$graph" }
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
composable(start) {
|
unittoComposable(start) {
|
||||||
TimeZoneRoute(
|
TimeZoneRoute(
|
||||||
navigateToMenu = navigateToMenu,
|
navigateToMenu = navigateToMenu,
|
||||||
navigateToSettings = navigateToSettings,
|
navigateToSettings = navigateToSettings,
|
||||||
@ -67,7 +67,7 @@ fun NavGraphBuilder.timeZoneGraph(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(
|
unittoComposable(
|
||||||
route = "$ADD_TIME_ZONE_ROUTE/{$USER_TIME_ARG}",
|
route = "$ADD_TIME_ZONE_ROUTE/{$USER_TIME_ARG}",
|
||||||
arguments = listOf(
|
arguments = listOf(
|
||||||
navArgument(USER_TIME_ARG) {
|
navArgument(USER_TIME_ARG) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user