Vsevolod Ganin
12/05/2020, 1:37 AMCrossfade
and I want it not animate anything on initial compositionremember
@Composable
private fun isInitialComposition(): Boolean {
var isInitialComposition by remember { mutableStateOf(true) }
return isInitialComposition.also { isInitialComposition = false }
}
But maybe there is a conventional way to do this?Sean McQuillan [G]
12/05/2020, 1:52 AMZach Klippenstein (he/him) [MOD]
12/05/2020, 3:58 AMcurrentComposer.isInserting
- true means it’s the first composition.
But for this case, that feels like a hack. A lot of the animation tools already won’t animate when their target is the same as their starting value.Adam Powell
12/05/2020, 4:00 AMDoris Liu
12/05/2020, 4:24 AMCrossFade
, you could initialize its internal state to null (
var state : CrossfadeState<T>? by remember { mutableStateOf(null) }
), and update it after your first-run logic.Leland Richardson [G]
12/05/2020, 4:57 AMcurrentComposer.inserting
is the most correct and efficient way to do this but I'd be curious to see exactly how you're using itVsevolod Ganin
12/05/2020, 1:21 PMcurrentComposer.inserting
in a moment and share my code with you guysZach Klippenstein (he/him) [MOD]
12/05/2020, 8:40 PMinserting
with it, there’s probably a better way to write your animation logic, or the apis are missing a feature.Adam Powell
12/05/2020, 9:23 PMinserting
is likely to be acting as a proxy for some other animation state that you probably want to hoist explicitly and construct into a particular initial state to determine this behaviorinserting
seems like the most correct and efficient way to answer what is likely to be the wrong question 🙂Doris Liu
12/05/2020, 10:23 PMTransitionAnimation
) using the same logic as how you determine target state here. That way when you call toState()
in the first composition, you'll get an no-op, as the target state is the same as the initial state.Vsevolod Ganin
12/06/2020, 2:18 PMinserting
by setting appropriate initial state in remember
closure. If you are interested, here is what changed: https://gist.github.com/vganin/4e846beb8913c70b4886693102ac4b47/revisions#diff-79f7b006e814e81e4584b239fd3c45426def70b13bf091e5a6b1c0911bedd108