Nana Vong
06/06/2021, 12:35 PMSurface {
darkMode.value = !darkMode.value
}
this way not recompose:
Surface {
thread {
darkMode.value = !darkMode.value
}
}
Adam Powell
06/06/2021, 1:10 PMAdam Powell
06/06/2021, 1:12 PMdarkMode.value
in the right hand side of the expression in a composable function body in snippet 1, you've told compose that the correct answer for that code depends on darkMode.value
as an input. You then immediately write darkMode.value
.Adam Powell
06/06/2021, 1:15 PMAdam Powell
06/06/2021, 1:16 PMAdam Powell
06/06/2021, 1:17 PMAdam Powell
06/06/2021, 1:19 PMNana Vong
06/06/2021, 1:32 PMSurface {
lifecycleScope.launch {
delay(1000)
darkMode.value = !darkMode.value
}
}
if add delay
function it will not recompose ,or will always recompose 😂 , always recompose I understand, but after suspend and not recompose I need take some time to understand☹️Adam Powell
06/06/2021, 1:36 PMlifecycleScope
is coming from a LifecycleOwner
then you've encountered the reason I dislike immediate coroutine dispatchers 🙂Adam Powell
06/06/2021, 1:37 PMlifecycleScope
was changed to use Dispatchers.Main.immediate
which will run that code to first suspension undispatched, which means compose will track the read.Adam Powell
06/06/2021, 1:38 PMcoroutineScope.launch {}
from a composable function body either, you should use the declarative LaunchedEffect
instead.Adam Powell
06/06/2021, 1:39 PMDominaezzz
06/06/2021, 4:52 PMAdam Powell
06/06/2021, 9:23 PMgildor
06/07/2021, 2:38 AMthe reason I dislike immediate coroutine dispatchersSame here, I was surprised when immediate dispatcher was used by default on lifecycleScope, it caused some bugs on our side after update and in general immediate dispatcher behaviour is much more tricky and doesn’t worth this optimization imo
Nana Vong
06/07/2021, 7:17 AMAdam Powell
06/07/2021, 1:36 PMCoroutineStart.UNDISPATCHED
graduated to stable recently since that almost always addresses whatever lifecycle+timing issue people tend to reach for an immediate dispatcher to solve, but without the unexpected reentrance pitfalls.Adam Powell
06/07/2021, 1:38 PMNana Vong
06/07/2021, 1:43 PMthread
and delay
case , whether Composer has check call stack frame to choose recompose ?Adam Powell
06/07/2021, 2:16 PMAdam Powell
06/07/2021, 2:17 PMAdam Powell
06/07/2021, 2:19 PMAdam Powell
06/07/2021, 2:20 PMAdam Powell
06/07/2021, 2:21 PMNana Vong
06/08/2021, 2:51 AM