Archie
09/06/2020, 4:41 PMComposable
s getting "disposed".
When changing state in compose it is usually done this way:
Surface(color = selectorExpandedColor, elevation = 3.dp) {
when (currentSelector) {
InputSelector.EMOJI -> EmojiSelector(onTextAdded, focusRequester)
<http://InputSelector.DM|InputSelector.DM> -> NotAvailablePopup(onCloseRequested)
InputSelector.PICTURE -> FunctionalityNotAvailablePanel()
InputSelector.MAP -> FunctionalityNotAvailablePanel()
InputSelector.PHONE -> FunctionalityNotAvailablePanel()
else -> { throw NotImplementedError() }
}
}
(Note: Code above is taken from JetChat
)
But doing so, creates a jarring experience where contents just pops-out and pops-in in an instant. Is it possible to trigger/create transition or animation when changing states (animate composable out and then animate composable coming in)?
Is there any guide for this out there?jaqxues
09/06/2020, 4:42 PMCrossfade(current = currentTab) {
when (it) {
Fragments.HOME_FRAG -> HomeScreen()
Fragments.ABOUT_US_FRAG -> AboutUsScreen()
}
}
Adam Powell
09/06/2020, 4:48 PMArchie
09/06/2020, 4:57 PMAdam Powell
09/06/2020, 5:26 PMSergey Y.
09/06/2020, 6:49 PMx-axis
in range from X
to X1
. In general, I achieved the desired result but I think the implementation was far from ideal.
I wanted to see more examples of animation API usage.
I am having difficulty with understanding the analogy of View.animate().translateX(...)
in Compose. Also, I was wondering how to use the AnimatedFloat
or transitionDefinition
with dynamic values for states, etc.
Thanks.Adam Powell
09/06/2020, 7:13 PManimate
should return a State<T>
- that's what it's using internally anyway and you shouldn't need to bounce it into another MutableState<T>
via composition.
2. Modifier.offset
should accept a lambda block that returns the offset when needed, so you can freely use State<T>
in expressions and have the observation pushed to layout-positioning time rather than moving back into composition, or forcing the value into an additional State<T>
holder.Sergey Y.
09/06/2020, 7:46 PManimate
should return a State<T>
:thinking_face: