Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SG-K/a004859cd0673dd4fe406eb926e85c24 to your computer and use it in GitHub Desktop.
Save SG-K/a004859cd0673dd4fe406eb926e85c24 to your computer and use it in GitHub Desktop.
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun NumberUpdateAnimationView(){
var displayNumber by remember { mutableStateOf(0) }
Row(
verticalAlignment = Alignment.CenterVertically,
) {
CircleButton(
imageVector = Icons.Default.Remove,
contentDescription = "Minus",
clickable = displayNumber != 0
){
if (displayNumber != 0){
displayNumber--
}
}
Spacer(modifier = Modifier.size(8.dp))
AnimatedContent(
targetState = displayNumber,
transitionSpec = {
if ( targetState > initialState ){
ContentTransform(
targetContentEnter = slideInVertically { height -> height } + fadeIn(),
initialContentExit = slideOutVertically { height -> -height } + fadeOut()
)
} else {
ContentTransform(
targetContentEnter = slideInVertically { height -> -height } + fadeIn(),
initialContentExit = slideOutVertically { height -> height } + fadeOut()
)
}
}
) { _displayNumber ->
Text(
text = "${_displayNumber}",
fontSize = 24.sp,
fontWeight = FontWeight(500),
color = Color.Black
)
}
Spacer(modifier = Modifier.size(8.dp))
CircleButton(
imageVector = Icons.Default.Add,
contentDescription = "Add"
){
displayNumber++
}
}
}
@Composable
fun CircleButton(
imageVector: ImageVector,
contentDescription : String = "",
clickable : Boolean = true,
click: () -> Unit
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.clip(RoundedCornerShape(20.dp))
.size(40.dp)
.background(GreenButton.copy(alpha = 0.1f))
.clickable(
enabled = clickable,
onClick = click
)
) {
Icon(
imageVector = imageVector,
contentDescription = contentDescription,
tint = GreenButton,
modifier = Modifier
.size(20.dp)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment