dimsuz
03/06/2023, 5:18 PMval transition = updateTransition(myState) { state ->
when (state) {
MyState.One -> if (previousState == MyState.Two) 1.0f else 0.0f
MyState.Two -> ...
}
Notice the previousState in if
. To implement this I'd have to put previousState
in a mutableStateOf
or something like this. Which I do not like for some reason. Am I approaching this incorrectly and my thinking needs shifting? 🙂curioustechizen
03/06/2023, 5:36 PMAnimatedContent
allows you to customise the entry and exit animations depending on both the current state and target state. Perhaps you could look at the implementation to get some inspiration.Chris Sinco [G]
03/07/2023, 5:56 AMdimsuz
03/07/2023, 11:19 AMenum Screen { Screen1, Screen2 }
@Composable
fun Screen1() { ... }
@Composable
fun Screen2() { ... }
fun Container(currentScreen: Screen) {
val offset1: IntOffset = updateTransition(currentScreen) { ... }
val offset2: IntOffset = ...
Box(modifier = Modifier.offset(offset1)) {
Screen1()
}
Box(modifier = Modifier.offset(offset2)) {
Screen2()
}
}
where "previousScreen" would be required to determine whether offsets should be animated "forward" or "backward" (push/pop). Transitioning from Screen1 -> Screen2 would mean "forward" and Screen2 -> Screen1 would mean backward.curioustechizen
03/07/2023, 11:36 AMdimsuz
03/07/2023, 11:44 AMChris Sinco [G]
03/07/2023, 3:56 PMDoris Liu
03/07/2023, 6:47 PMTransition.currentState
. Though based on your use case, it does seem like AnimatedContent
is a better fit, as folks above have pointed out. 🙂dimsuz
03/07/2023, 10:25 PMAnimatedContent
successfully! Thanks to you all!
I will investigate LookaheadLayout
a bit later too, curious to see how it works, and it would be great to have pre-measured target composables in some cases.Doris Liu
03/07/2023, 11:58 PMdimsuz
03/09/2023, 2:39 PMDoris Liu
03/10/2023, 12:12 AMModifier.animateContentSize
, but better. Knowing the future size would allow more possibilities in size animation. In addition to animating a clip bound like we do in animateContentSize
, we could also animate the constraints, so that children in the layout would resize/relayout themselves to respond to the parent size change, like this: https://developer.android.com/images/reference/androidx/compose/foundation/layout/row_arrangement_visualization.gif▾
dimsuz
03/10/2023, 5:06 PMSubcomoseLayout
+ Swipeable
and is full of subtle hacks and tricky logic, especially around size changes and measurements.
It seems I have to try to implement this with LookaheadLayout
too.Doris Liu
03/10/2023, 6:20 PMLookaheadLayout
APIs that landed in 1.5.0-alpha01. Let me know if/when you have a chance to try them out. 🙂dimsuz
03/10/2023, 6:34 PMDoris Liu
03/10/2023, 6:47 PMdimsuz
03/10/2023, 9:50 PMDoris Liu
03/10/2023, 10:03 PM