Fabio Berta
01/17/2023, 9:28 AMmutableStateOf
variable changes. I see two ways of achieving this, either have a LaunchedEffect(Unit)
and inside subscribe to changes in the state with snapshotFlow
or have a LaunchedEffect(stateVariable)
which then executes whenever the variable changes. Now I don't actually need a coroutine scope for my effect so the second option seems weird to me because I'm not using the provided scope. The first option looks a bit fishy because of the Unit
as the key for the effect. What's the correct way to do this? Or maybe I'm doing something wrong from the get go? Thanks!K Merle
01/17/2023, 10:32 AMFabio Berta
01/17/2023, 10:49 AMK Merle
01/17/2023, 10:54 AMderivedStateOf
, as remember
also takes a key and reacts to change.Stylianos Gakis
01/17/2023, 10:57 AMderivedStateOf
to trigger side-effects is a good idea. the lambda passed into it as far as I understand may be triggered more than you think, it’s just that the returning `State`’s value is not changes as often, leading to the performance benefits of it.
Unless I am misunderstanding what you mean by side effects here Fabio. It may be useful to tell us what you want to do with that change.Fabio Berta
01/17/2023, 11:01 AM.play()
and .pause()
on depending on some statederivedStateOf
is not the right callBen Trengrove [G]
01/17/2023, 9:59 PMste
01/18/2023, 1:39 PMsnapshotFlow
doesn't seem cheap.
However, when it comes to invoke Animatable.snapTo
, the samples/demos always wrap that in coroutineScope.launch
(so it ends up launching a lot of times when something like a drag gesture occurs)...Stylianos Gakis
01/18/2023, 2:19 PMZach Klippenstein (he/him) [MOD]
01/18/2023, 4:33 PMFabio Berta
01/20/2023, 1:01 PMK Merle
01/20/2023, 1:03 PMZach Klippenstein (he/him) [MOD]
01/20/2023, 10:21 PMFabio Berta
01/20/2023, 10:39 PMZach Klippenstein (he/him) [MOD]
01/21/2023, 1:56 AMsnapshotFlow
is way more lightweight.