Giter Site home page Giter Site logo

Comments (4)

MohamedRejeb avatar MohamedRejeb commented on June 13, 2024

Hi,
We shouldn't use non-composable functions inside the scope of a composable function. You need to make those calls inside a LaunchedEffect:

LaunchedEffect(Unit) {
    richTextState.setHtml(content)
    richTextState.selection = TextRange.Zero
}

What was happening in your case is when you use setHtml it causes a recomposition because the text is changed, and the recomposition causes the setHtml to be called again and so on... That's why normal function calls need to be outside the scope of the composable function.

from compose-rich-editor.

Shusek avatar Shusek commented on June 13, 2024

Yes, you are absolutely right. I don't know why, but I thought it worked on the binding principle.
Still, i do not get why spaces for this code is applied after few miliseconds:

private fun FxRichText( ) {
    val richTextState = rememberRichTextState()
    LaunchedEffect(Unit) {
        val newContent = "<ol> " +
            "\t<li>NLorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit. \t</li><br> " +
            "\t<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
            "\t \t\t<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. \t\t</li>" +
            "</ol>"

        richTextState.setHtml(newContent)
        richTextState.selection = TextRange.Zero
    }

    RichTextEditor(
        state = richTextState,
        readOnly = true,
        shape = AppTheme.shapes.rectangle,
        colors = richTextEditorColors(),
        textStyle = AppTheme.typography.normalLightText,
        contentPadding = PaddingValues(0.dp)
    )
}

On start:
obraz

After while:
obraz

from compose-rich-editor.

MohamedRejeb avatar MohamedRejeb commented on June 13, 2024

I will check this. Can you try again with the latest version?

from compose-rich-editor.

Shusek avatar Shusek commented on June 13, 2024

Yeap, the latest version fixes this bug.

from compose-rich-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.