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
|
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.Arrangement
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.Row
|
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.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.runtime.Composable
|
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.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@ -163,34 +171,57 @@ internal fun NumberBaseKeyboard(
|
|||||||
basis: BasicUnit.NumberBase,
|
basis: BasicUnit.NumberBase,
|
||||||
) {
|
) {
|
||||||
val contentHeight: Float = if (LocalWindowSize.current.heightSizeClass < WindowHeightSizeClass.Medium) KeyboardButtonToken.CONTENT_HEIGHT_SHORT else KeyboardButtonToken.CONTENT_HEIGHT_TALL
|
val contentHeight: Float = if (LocalWindowSize.current.heightSizeClass < WindowHeightSizeClass.Medium) KeyboardButtonToken.CONTENT_HEIGHT_SHORT else KeyboardButtonToken.CONTENT_HEIGHT_TALL
|
||||||
val amount = basis.factor.toInt()
|
|
||||||
|
|
||||||
val columns: Int = when {
|
var direction by remember {
|
||||||
amount == 5 -> 2
|
mutableStateOf(AnimatedContentTransitionScope.SlideDirection.Right)
|
||||||
amount == 3 -> 2
|
|
||||||
amount == 7 -> 2
|
|
||||||
amount == 10 -> 3
|
|
||||||
amount < 10 -> if (amount.and(1) == 0) 2 else if (amount % 3 == 0) 3 else amount % 3
|
|
||||||
else -> 3
|
|
||||||
}
|
}
|
||||||
val rows = when {
|
|
||||||
amount == 5 -> 3
|
LaunchedEffect(basis) {
|
||||||
amount == 3 -> 2
|
when (direction) {
|
||||||
amount == 7 -> 4
|
AnimatedContentTransitionScope.SlideDirection.Left -> {
|
||||||
amount == 10 -> 4
|
direction = AnimatedContentTransitionScope.SlideDirection.Right
|
||||||
amount < 10 -> ceil(amount.toDouble() / columns.toDouble()).toInt() + 1
|
}
|
||||||
amount == 11 -> 5
|
|
||||||
amount == 12 -> 5
|
AnimatedContentTransitionScope.SlideDirection.Right -> {
|
||||||
amount == 13 -> 5
|
direction = AnimatedContentTransitionScope.SlideDirection.Left
|
||||||
else -> 6
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnWithConstraints(Modifier) { constraints ->
|
ColumnWithConstraints(Modifier) { constraints ->
|
||||||
val horizontalSpacing = 8.dp
|
AnimatedContent(
|
||||||
val verticalSpacing = 12.dp
|
transitionSpec = {
|
||||||
val height: Float = (1f - (verticalSpacing * (rows - 1) / constraints.maxHeight)) / rows
|
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
|
||||||
|
amount == 7 -> 2
|
||||||
|
amount == 10 -> 3
|
||||||
|
amount < 10 -> if (amount.and(1) == 0) 2 else if (amount % 3 == 0) 3 else amount % 3
|
||||||
|
else -> 3
|
||||||
|
}
|
||||||
|
val rows = when {
|
||||||
|
amount == 5 -> 3
|
||||||
|
amount == 3 -> 2
|
||||||
|
amount == 7 -> 4
|
||||||
|
amount == 10 -> 4
|
||||||
|
amount < 10 -> ceil(amount.toDouble() / columns.toDouble()).toInt() + 1
|
||||||
|
amount == 11 -> 5
|
||||||
|
amount == 12 -> 5
|
||||||
|
amount == 13 -> 5
|
||||||
|
else -> 6
|
||||||
|
}
|
||||||
|
val horizontalSpacing = 8.dp
|
||||||
|
val verticalSpacing = 12.dp
|
||||||
|
val height: Float = (1f - (verticalSpacing * (rows - 1) / constraints.maxHeight)) / rows
|
||||||
|
|
||||||
FlowRow(
|
FlowRow(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
maxItemsInEachRow = columns,
|
maxItemsInEachRow = columns,
|
||||||
horizontalArrangement = Arrangement.spacedBy(horizontalSpacing),
|
horizontalArrangement = Arrangement.spacedBy(horizontalSpacing),
|
||||||
@ -329,6 +360,8 @@ internal fun NumberBaseKeyboard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user