Created
July 23, 2022 06:18
-
-
Save SG-K/a004859cd0673dd4fe406eb926e85c24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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