Hi, I have a doSomeHeavyStuffs() function triggere...
# compose-desktop
n
Hi, I have a doSomeHeavyStuffs() function triggered via onClick of a button, which I want to display a progress bar while it is running. I added of mutable isLoading state, and then write something like:
Copy code
if (isLoading)
   CircularProgressIndicator()
Then I set isLoading before and after doSomeHeavyStuffs(). But it doesn't work because I suppose the doSomeHeavyStuffs() function is running in the UI thread. Am I supposed to run it in a separate thread? How do I do it in Jetpack Compose?
a
This has nothing to do with Compose. You can Google how to start background threads or how to do background jobs in coroutines.
o
https://developer.android.com/kotlin/coroutines/coroutines-adv use Default coroutine dispatcher and update state on completion
n
@olonho Thank you! I did it. I use rememberCoroutineScope() to get the scope then call launch() with the dispatcher. I didn't know that compose can automatically reschedule the composition when isLoading is set in another thread. I thought I need some more callback magic or something.