https://kotlinlang.org logo
i

Ian Warwick

01/15/2020, 9:15 AM
Hey folks, got this issue where I compose some UI based on a model which shows either
TextInput
or
Text
when I double click on the text it turns the
Text
into a
TextInput
in the compose tree
Copy code
@Composable
private fun Text(
    element: TextElement,
    inEdit: Boolean = false
) {
    val textStyle = TextStyle(
        background = Color.Transparent,
        fontWeight = element.fontWeight,
        fontSize = TextUnit.Em(element.fontSize),
        color = element.color
    )

    val spacing =
        Spacing(element.spacingLeft.dp, element.spacingTop.dp, element.spacingRight.dp, element.spacingBottom.dp)

    if (inEdit) {
        TextField(modifier = spacing, value = element.text, textStyle = textStyle, onValueChange = {
            element.text = it
        })
    } else {
        Text(modifier = spacing, text = element.text, style = textStyle)
    }
}
It seems that even though
Text
is being displayed Compose is still receiving text input via the missing
TextInput
(see video) possibly.. I would expect that if a recompose occurs then it would not exist in this part of the compose graph anymore 🤔 any ideas?
m

matvei

01/15/2020, 11:24 AM
I think it might be worth to file a bug here
i

Ian Warwick

01/15/2020, 12:04 PM
Cool will file it, tough to explain hopefully i have covered it 🙂
Thanks @matvei filed one https://issuetracker.google.com/issues/147690622 added a cut down version of the issue as an attachement
m

matvei

01/15/2020, 12:33 PM
Thanks!
👍 1
5 Views