JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.17k stars 1.11k forks source link

Consider adding a boolean to disable `GlobalSnapshotManager.ensureStarted()` call during scene creation #4800

Open JakeWharton opened 1 month ago

JakeWharton commented 1 month ago

I am building Compose UI for a target you do not support using your repo. Thanks for all the hard work I can easily build upon!

It's hard to build Compose UI for targets which do not have Dispatchers.Main available from coroutines due to the global snapshot manager. I have a UI thread in my app, but it doesn't exist until I create it as part of app initialization. It is not known at the time that this library (well, compose-multiplatform-core) is being compiled.

I would like to set my GlobalSnapshotManagerDispatcher actual to throw when accessed, and instead initialize code similar to the implementation of global snapshot manager myself (before creating my scene).

Would you be open to a boolean flag for scene creation that disables the call to GlobalSnapshotManager.ensureStarted() in BaseComposeScene?

Of course, I could just disable this call myself, but I would prefer to leave the common sources untouched so that my changes are solely within source sets for the new target.