Fix: ActionButton animation

This commit is contained in:
machiav3lli 2022-06-03 10:42:11 +02:00
parent ed0ad62dc0
commit b3d1440f6a
2 changed files with 36 additions and 18 deletions

View File

@ -2,6 +2,12 @@ package com.looker.droidify.ui.compose.components
import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.with
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
@ -11,6 +17,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedButton import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -19,36 +26,49 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.looker.droidify.entity.ActionState import com.looker.droidify.entity.ActionState
import com.looker.droidify.entity.ComponentState import com.looker.droidify.entity.ComponentState
import com.looker.droidify.entity.DownloadState
@OptIn(ExperimentalAnimationApi::class) @OptIn(ExperimentalAnimationApi::class)
@Composable @Composable
fun MainActionButton( fun MainActionButton(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
actionState: ActionState, actionState: ActionState,
downloadState: DownloadState?, onClick: () -> Unit
onClick: (ComponentState) -> Unit
) { ) {
ElevatedButton( ElevatedButton(
modifier = modifier, modifier = modifier,
onClick = { onClick(actionState) } onClick = {
onClick()
},
colors = ButtonDefaults.elevatedButtonColors(
containerColor = when (actionState) {
is ActionState.Cancel -> MaterialTheme.colorScheme.secondaryContainer
is ActionState.NoAction -> MaterialTheme.colorScheme.inverseSurface
else -> MaterialTheme.colorScheme.surface
},
contentColor = when (actionState) {
is ActionState.Cancel -> MaterialTheme.colorScheme.secondary
is ActionState.NoAction -> MaterialTheme.colorScheme.inverseOnSurface
else -> MaterialTheme.colorScheme.primary
},
)
) { ) {
val content = @Composable {
}
AnimatedContent( AnimatedContent(
targetState = packageState, targetState = actionState,
// TODO Fix redrawing changing state transitionSpec = {
/*transitionSpec = {
when (targetState) { when (targetState) {
is Cancelable -> { is ActionState.Cancel ->
slideInVertically { height -> height } + fadeIn() with (slideInVertically { height -> height } + fadeIn() with
slideOutVertically { height -> -height } + fadeOut() slideOutVertically { height -> -height } + fadeOut())
} else ->
is ButtonWork -> {
(slideInVertically { height -> -height } + fadeIn() with (slideInVertically { height -> -height } + fadeIn() with
slideOutVertically { height -> height } + fadeOut()) slideOutVertically { height -> height } + fadeOut())
}
} }
.using(SizeTransform(clip = false)) .using(SizeTransform(clip = false))
}*/ }
) { ) {
Row( Row(
Modifier Modifier

View File

@ -40,8 +40,7 @@ fun AppInfoHeader(
versionCode: String, versionCode: String,
appSize: String, appSize: String,
appDev: String, appDev: String,
mainAction: ActionState? = ActionState.Install, mainAction: ActionState?,
downloadState: DownloadState?,
secondaryAction: ComponentState? = null, secondaryAction: ComponentState? = null,
onSource: () -> Unit = { }, onSource: () -> Unit = { },
onSourceLong: () -> Unit = { }, onSourceLong: () -> Unit = { },
@ -73,8 +72,7 @@ fun AppInfoHeader(
}) })
MainActionButton( MainActionButton(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
actionState = mainAction ?: ActionState.Install, actionState = mainAction ?: ActionState.NoAction,
downloadState = downloadState,
onClick = { onClick = {
onAction() onAction()
} }