Skip to content

Instantly share code, notes, and snippets.

@FStranieri
Last active December 8, 2021 17:00
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 FStranieri/1509c0f0af9312767a13ad7ec83d420f to your computer and use it in GitHub Desktop.
Save FStranieri/1509c0f0af9312767a13ad7ec83d420f to your computer and use it in GitHub Desktop.
Animation for in and out of the available text translation languages
@Composable
fun BindTextRecognitionOutput(
textRecognitionViewModel: TextRecognitionViewModel,
textTranslationViewModel: TextTranslationViewModel,
listener: TextRecognitionComposableInterface
) {
//animation based on this value
val showTranslationLanguages = remember { textTranslationViewModel.showLanguagesState }
ConstraintLayout(Modifier.fillMaxSize()) {
val (title,
text,
backToCameraButton,
transButton,
progress,
transLangBox) = createRefs()
//several UI components
...
//
Button(modifier = Modifier.constrainAs(transButton) {
bottom.linkTo(text.top, margin = (-20).dp)
end.linkTo(parent.end, margin = 18.dp)
width = Dimension.preferredWrapContent
height = Dimension.preferredWrapContent
}, onClick = {
textTranslationViewModel.loadSupportedLanguages()
})
{
Text(
text = stringResource(R.string.translate_button)
)
}
...
AnimatedVisibility(
visible = showTranslationLanguages.value,
enter = scaleIn(
initialScale = 0.0f,
transformOrigin = TransformOrigin.Center,
animationSpec = tween(durationMillis = 1000)
),
exit = scaleOut(
targetScale = 0.0f,
transformOrigin = TransformOrigin.Center,
animationSpec = tween(durationMillis = 1000)
),
modifier = Modifier
.constrainAs(transLangBox) {
linkTo(top = parent.top, bottom = parent.bottom, 8.dp, 8.dp)
linkTo(start = parent.start, end = parent.end, 8.dp, 8.dp)
width = Dimension.fillToConstraints
height = Dimension.fillToConstraints
}
) {
//UI COMPONENTS TO SHOW AFTER THE ANIMATION
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment