gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.25k stars 268 forks source link

Fixed #78: Changed ObservedObject by StateObject #79

Closed heltena closed 2 years ago

heltena commented 2 years ago

It looks like the Markdown.store.state changes to "notRendered" at some point.

arnaud512 commented 2 years ago

This PR fixes the disappearing markdown view in my project with the currently released version! Thanks @heltena! @gonzalezreal can you please have a look and merge it if it's ok for you?

gonzalezreal commented 2 years ago

Hi, Thanks for having a look at this. I am trying to find the root cause for the bug, that is, why the state changes to notRendered. Changing ObservedObject to StateObject is not fixing the bug, only hiding it.

heltena commented 2 years ago

The problem I saw was that, using ObservedObject, init is called when the view is rendered, setting the state to "notRendered". Using StateObject, the view controls the object life properly, avoiding the init call.

gonzalezreal commented 2 years ago

Hey @heltena, I have fixed the issue with a different approach (#83), considering other uses cases of the library (see the Dingus example, for instance). Notice that the fix is in the release-1.0 branch, together with other breaking changes I am making for the 1.0 release, which is still a work in progress.