Last active
December 8, 2021 17:00
-
-
Save FStranieri/1509c0f0af9312767a13ad7ec83d420f to your computer and use it in GitHub Desktop.
Animation for in and out of the available text translation languages
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
@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