jeziellago / compose-markdown

Markdown Text for Android Jetpack Compose 📋.
MIT License
508 stars 42 forks source link

Invalid compose usage #9

Closed jbruchanov closed 2 years ago

jbruchanov commented 2 years ago

Actual version is creating new textview every state change, if I'm not mistaken. the code should be using something like this

val markwon = ...
val text = ...

AndroidView(modifier = modifier,
      factory = { context -> TextView(context)},
      update = { textView -> markwon.setMarkdown(textView, text) }
  )
jeziellago commented 2 years ago

Hi @jbruchanov Could you put any evidence describing the problem?

jbruchanov commented 2 years ago

HI @jeziellago

I think it's misuse of the AndroidView API in compose here https://github.com/jeziellago/compose-markdown/blob/main/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/MarkdownText.kt#L57-L76

the factory is a lambda to create a view, the implementation ^^ is creating textview each state change and lambda is just passing a reference to new textview and it doesn't behave as a factory....

you would have to wrap it inside a remember or something like that...

jeziellago commented 2 years ago

Hi @jbruchanov Thanks for reporting! I fixed it in v0.2.4.