Created
November 28, 2021 18:27
-
-
Save FStranieri/c9a66e6d162e82d96b23fdc564225e83 to your computer and use it in GitHub Desktop.
ML Composer - Ep.1 - Text Recognition composable
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
@androidx.compose.ui.tooling.preview.Preview | |
@Composable | |
private fun BindTextRecognitionOutput() { | |
ConstraintLayout(Modifier.fillMaxSize()) { | |
val (title, text, backToCameraButton) = createRefs() | |
val textValue by textRecognitionViewModel.getOutput().observeAsState() | |
val scrollState = rememberScrollState(0) | |
Text( | |
modifier = Modifier | |
.constrainAs(title) { | |
top.linkTo(parent.top) | |
linkTo(start = parent.start, end = parent.end) | |
width = Dimension.wrapContent | |
height = Dimension.wrapContent | |
} | |
.then(Modifier.padding(16.dp)), | |
text = "TEXT RECOGNITION RESULT", | |
style = TextStyle(fontStyle = FontStyle.Italic), | |
fontWeight = FontWeight.Bold | |
) | |
SelectionContainer(modifier = Modifier | |
.constrainAs(text) { | |
linkTo(top = title.bottom, bottom = backToCameraButton.top, 16.dp, 16.dp) | |
linkTo(start = parent.start, end = parent.end) | |
width = Dimension.fillToConstraints | |
height = Dimension.fillToConstraints | |
} | |
.then( | |
Modifier.padding(16.dp) | |
) | |
.then( | |
Modifier.border( | |
width = 4.dp, | |
color = Color.Black, | |
shape = RectangleShape | |
) | |
)) { | |
Text( | |
text = textValue ?: "", | |
modifier = Modifier | |
.verticalScroll(scrollState) | |
.then(Modifier.padding(8.dp)) | |
) | |
} | |
Button(modifier = Modifier.constrainAs(backToCameraButton) { | |
linkTo(start = parent.start, end = parent.end) | |
bottom.linkTo(parent.bottom, 16.dp) | |
width = Dimension.preferredWrapContent | |
height = Dimension.preferredWrapContent | |
}, onClick = { | |
navController.popBackStack() | |
}) | |
{ | |
Text("CAMERA") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment