mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 22:29:10 +00:00
make navigation transistion animation duration follow system transition animation scale
This commit is contained in:
parent
55259b2915
commit
ba88129641
1 changed files with 13 additions and 4 deletions
|
@ -1,11 +1,16 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
package helium314.keyboard.settings
|
package helium314.keyboard.settings
|
||||||
|
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.provider.Settings.Global
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.slideInHorizontally
|
import androidx.compose.animation.slideInHorizontally
|
||||||
import androidx.compose.animation.slideOutHorizontally
|
import androidx.compose.animation.slideOutHorizontally
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
|
@ -41,6 +46,10 @@ fun SettingsNavHost(
|
||||||
val dir = if (LocalLayoutDirection.current == LayoutDirection.Ltr) 1 else -1
|
val dir = if (LocalLayoutDirection.current == LayoutDirection.Ltr) 1 else -1
|
||||||
val target = SettingsDestination.navTarget.collectAsState()
|
val target = SettingsDestination.navTarget.collectAsState()
|
||||||
|
|
||||||
|
// duration does not change when system setting changes, but that's rare enough to not care
|
||||||
|
val duration = (250 * Settings.System.getFloat(LocalContext.current.contentResolver, Global.TRANSITION_ANIMATION_SCALE, 1f)).toInt()
|
||||||
|
val animation = tween<IntOffset>(durationMillis = duration)
|
||||||
|
|
||||||
fun goBack() {
|
fun goBack() {
|
||||||
if (!navController.popBackStack()) onClickBack()
|
if (!navController.popBackStack()) onClickBack()
|
||||||
}
|
}
|
||||||
|
@ -48,10 +57,10 @@ fun SettingsNavHost(
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = startDestination ?: SettingsDestination.Settings,
|
startDestination = startDestination ?: SettingsDestination.Settings,
|
||||||
enterTransition = { slideInHorizontally(initialOffsetX = { +it * dir }) },
|
enterTransition = { slideInHorizontally(initialOffsetX = { +it * dir }, animationSpec = animation) },
|
||||||
exitTransition = { slideOutHorizontally(targetOffsetX = { -it * dir }) },
|
exitTransition = { slideOutHorizontally(targetOffsetX = { -it * dir }, animationSpec = animation) },
|
||||||
popEnterTransition = { slideInHorizontally(initialOffsetX = { -it * dir }) },
|
popEnterTransition = { slideInHorizontally(initialOffsetX = { -it * dir }, animationSpec = animation) },
|
||||||
popExitTransition = { slideOutHorizontally(targetOffsetX = { +it * dir }) }
|
popExitTransition = { slideOutHorizontally(targetOffsetX = { +it * dir }, animationSpec = animation) }
|
||||||
) {
|
) {
|
||||||
composable(SettingsDestination.Settings) {
|
composable(SettingsDestination.Settings) {
|
||||||
MainSettingsScreen(
|
MainSettingsScreen(
|
||||||
|
|
Loading…
Add table
Reference in a new issue