mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
feat: Add animation to ConverterKeyboard.kt
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
792dc9366b
commit
00ca88b1e6
@ -18,6 +18,10 @@
|
||||
|
||||
package app.myzel394.numberhub.feature.converter.components
|
||||
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@ -25,7 +29,11 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@ -163,8 +171,33 @@ internal fun NumberBaseKeyboard(
|
||||
basis: BasicUnit.NumberBase,
|
||||
) {
|
||||
val contentHeight: Float = if (LocalWindowSize.current.heightSizeClass < WindowHeightSizeClass.Medium) KeyboardButtonToken.CONTENT_HEIGHT_SHORT else KeyboardButtonToken.CONTENT_HEIGHT_TALL
|
||||
val amount = basis.factor.toInt()
|
||||
|
||||
var direction by remember {
|
||||
mutableStateOf(AnimatedContentTransitionScope.SlideDirection.Right)
|
||||
}
|
||||
|
||||
LaunchedEffect(basis) {
|
||||
when (direction) {
|
||||
AnimatedContentTransitionScope.SlideDirection.Left -> {
|
||||
direction = AnimatedContentTransitionScope.SlideDirection.Right
|
||||
}
|
||||
|
||||
AnimatedContentTransitionScope.SlideDirection.Right -> {
|
||||
direction = AnimatedContentTransitionScope.SlideDirection.Left
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnWithConstraints(Modifier) { constraints ->
|
||||
AnimatedContent(
|
||||
transitionSpec = {
|
||||
slideIntoContainer(animationSpec = tween(600), towards = direction).togetherWith(
|
||||
slideOutOfContainer(animationSpec = tween(600), towards = direction),
|
||||
)
|
||||
},
|
||||
targetState = basis.factor.toInt(),
|
||||
label = "ConverterKeyboard-FlowRow",
|
||||
) { amount ->
|
||||
val columns: Int = when {
|
||||
amount == 5 -> 2
|
||||
amount == 3 -> 2
|
||||
@ -184,8 +217,6 @@ internal fun NumberBaseKeyboard(
|
||||
amount == 13 -> 5
|
||||
else -> 6
|
||||
}
|
||||
|
||||
ColumnWithConstraints(Modifier) { constraints ->
|
||||
val horizontalSpacing = 8.dp
|
||||
val verticalSpacing = 12.dp
|
||||
val height: Float = (1f - (verticalSpacing * (rows - 1) / constraints.maxHeight)) / rows
|
||||
@ -329,6 +360,8 @@ internal fun NumberBaseKeyboard(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user