fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.16k stars 122 forks source link

Ensure view function is only called on UI thread #1043

Closed TimLariviere closed 1 year ago

TimLariviere commented 1 year ago

For performance reasons, we have decided to let init, update and view run on whatever thread the message was dispatched from. This is because the MVU functions don't access the UI itself, Fabulous deals with it exclusively during reconcilation so we only synchronize back to the UI thread during diffing to avoid the perf hit of jumping threads.

But if we need to access some information related to the UI inside the view function (such as the safe area margins), it requires access to the UI thread, otherwise it could crash.

This PR ensures that the view function is called only on the UI thread to avoid those issues.