I'm using a BasicTextField with an annotated strin...
# compose
b
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
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
Oh. That's surprising considering the BasicTextField interface allows for, and properly renders, styled text.
a
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
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?
365 Views