Michal Klimczak
11/01/2021, 3:31 PMMichal Klimczak
11/01/2021, 3:38 PMdata class SearchSuggestions(
override val searchPhrase: String,
val suggestions: List<String>
) : ShopScreenState(), HasSearchPhrase
data class SearchRecents(
override val searchPhrase: String,
val recentSearches: List<String>
) : ShopScreenState(), HasSearchPhrase
Now I want a nice crossfade when SearchSuggestions
changes into SearchRecents
and vice versa. But don't want the crossfade to "blink" every time e.g. SearchRecents
changes to a different SearchRecents
I don't want to get rid of data class magic, too, it's useful in other places. Its equals should not change.
What I want is to compare different states myself and only then crossfade one state to another, but still be able to use the whole state internally, e.g. like this
Crossfade(state, diff = { previousState, newState -> previousState::class != newState::class }){
when(it)... //`it` should still be ShopScreenState, so that it's smartcasted and preserved across animation
}
Michal Klimczak
11/01/2021, 3:38 PMMichal Klimczak
11/01/2021, 3:39 PMMichal Klimczak
11/01/2021, 3:39 PMDoris Liu
11/01/2021, 5:37 PMcontentKey
in AnimatedContent, where the contentKey
can be defined for each target, and is being used for diffing. You can use that for your use cases. The support in crossfade is coming, tracked here: https://issuetracker.google.com/197907070
In the meantime, I'd encourage you to try out contentKey
and let us know if you have any other feature requests. See https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary#(androidx.compose.animation[…].Function1,kotlin.Function2)Michal Klimczak
11/01/2021, 5:55 PMMichal Klimczak
11/01/2021, 5:56 PMDoris Liu
11/01/2021, 5:57 PMThomas
11/02/2021, 8:10 PMcontentKey
and it should do exactly what I want. Thanks for adding it! However, it looks like you missed a function. Is there a reason contentKey
was not added here? https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ent.kt;l=119-129;drc=4b91a7fe67a0a791829b42dbccb4e80f7beaaf74Doris Liu
11/02/2021, 8:13 PMAnimatedContent
(i.e. non-extension fun version) intentionally to keep that version simple and therefore easy to learn.