https://kotlinlang.org logo
#compose
Title
# compose
b

Brendan Campbell-hartzell

07/11/2022, 8:50 PM
I'm using a BasicTextField with an annotated string to make a rudimentary rich text editor. However, the styles keep getting removed whenever the value is updated via the onValueChange callback. Am I missing something about the functionality of the BasicTextField? Code in thread.
Copy code
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            
            var value by remember {
                mutableStateOf(TextFieldValue(
                    annotatedString = buildAnnotatedString {
                        withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
                            append("Bolded")
                        }
                        append(" should not be removed")
                    },
                    selection = TextRange(28)
                ))
            }

            BasicTextField(value = value, onValueChange = { value = it })

        }
    }
}
a

Anastasia [G]

07/12/2022, 2:32 PM
Compose doesn't support rich text editing yet. We use this ticket to track this work https://issuetracker.google.com/issues/139320381 Feel free to vote or drop a comment with your use case
b

Brendan Campbell-hartzell

07/12/2022, 5:06 PM
Oh. That's surprising considering the BasicTextField interface allows for, and properly renders, styled text.
a

Anastasia [G]

07/13/2022, 5:31 PM
We haven't done the implementation but we made sure that we have API in place. Found a better ticket to track the status of this FR https://issuetracker.google.com/issues/135556699
b

Brendan Campbell-hartzell

07/13/2022, 7:18 PM
Thank you for sharing these @Anastasia [G]! I know building support for that is definitely going to be an undertaking. I have a working prototype on desktop using a swing-based component wrapped inside compose and I can put the mobile version on hold for now. Is building this functionality something that's considered a high priority? Or is it a bit too use-case specific to warrant attention?
95 Views