Address API council feedback on AnimatedContent
Fixes: 275365354
Fixes: 273287756
Test: Existing tests all pass
Relnote: "
Rename infix fun with to togetherWith for combining
enter and exit transitions.
New AnimatedContentScope as receiver for the content lambda.
"
Change-Id: Ic39aee09d77a905e538a101264dc352e1fecbfc0
diff --git a/compose/animation/animation/api/current.txt b/compose/animation/animation/api/current.txt
index e836634..6a4cd96 100644
--- a/compose/animation/animation/api/current.txt
+++ b/compose/animation/animation/api/current.txt
@@ -6,10 +6,13 @@
}
public final class AnimatedContentKt {
- method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(S? targetState, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional String label, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedVisibilityScope,? super S,kotlin.Unit> content);
- method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(androidx.compose.animation.core.Transition<S>, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional kotlin.jvm.functions.Function1<? super S,?> contentKey, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedVisibilityScope,? super S,kotlin.Unit> content);
+ method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(S? targetState, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional String label, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super S,kotlin.Unit> content);
+ method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(androidx.compose.animation.core.Transition<S>, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional kotlin.jvm.functions.Function1<? super S,?> contentKey, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super S,kotlin.Unit> content);
method public static androidx.compose.animation.SizeTransform SizeTransform(optional boolean clip, optional kotlin.jvm.functions.Function2<? super androidx.compose.ui.unit.IntSize,? super androidx.compose.ui.unit.IntSize,? extends androidx.compose.animation.core.FiniteAnimationSpec<androidx.compose.ui.unit.IntSize>> sizeAnimationSpec);
- method public static infix androidx.compose.animation.ContentTransform with(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ method public static infix androidx.compose.animation.ContentTransform togetherWith(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ }
+
+ public sealed interface AnimatedContentScope extends androidx.compose.animation.AnimatedVisibilityScope {
}
public sealed interface AnimatedContentTransitionScope<S> extends androidx.compose.animation.core.Transition.Segment<S> {
diff --git a/compose/animation/animation/api/public_plus_experimental_current.txt b/compose/animation/animation/api/public_plus_experimental_current.txt
index b192211..ef9503c 100644
--- a/compose/animation/animation/api/public_plus_experimental_current.txt
+++ b/compose/animation/animation/api/public_plus_experimental_current.txt
@@ -6,10 +6,14 @@
}
public final class AnimatedContentKt {
- method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(S? targetState, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional String label, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedVisibilityScope,? super S,kotlin.Unit> content);
- method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(androidx.compose.animation.core.Transition<S>, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional kotlin.jvm.functions.Function1<? super S,?> contentKey, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedVisibilityScope,? super S,kotlin.Unit> content);
+ method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(S? targetState, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional String label, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super S,kotlin.Unit> content);
+ method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(androidx.compose.animation.core.Transition<S>, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional kotlin.jvm.functions.Function1<? super S,?> contentKey, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super S,kotlin.Unit> content);
method public static androidx.compose.animation.SizeTransform SizeTransform(optional boolean clip, optional kotlin.jvm.functions.Function2<? super androidx.compose.ui.unit.IntSize,? super androidx.compose.ui.unit.IntSize,? extends androidx.compose.animation.core.FiniteAnimationSpec<androidx.compose.ui.unit.IntSize>> sizeAnimationSpec);
- method public static infix androidx.compose.animation.ContentTransform with(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ method public static infix androidx.compose.animation.ContentTransform togetherWith(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ method @Deprecated @androidx.compose.animation.ExperimentalAnimationApi public static infix androidx.compose.animation.ContentTransform with(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ }
+
+ public sealed interface AnimatedContentScope extends androidx.compose.animation.AnimatedVisibilityScope {
}
public sealed interface AnimatedContentTransitionScope<S> extends androidx.compose.animation.core.Transition.Segment<S> {
diff --git a/compose/animation/animation/api/restricted_current.txt b/compose/animation/animation/api/restricted_current.txt
index e836634..6a4cd96 100644
--- a/compose/animation/animation/api/restricted_current.txt
+++ b/compose/animation/animation/api/restricted_current.txt
@@ -6,10 +6,13 @@
}
public final class AnimatedContentKt {
- method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(S? targetState, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional String label, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedVisibilityScope,? super S,kotlin.Unit> content);
- method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(androidx.compose.animation.core.Transition<S>, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional kotlin.jvm.functions.Function1<? super S,?> contentKey, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedVisibilityScope,? super S,kotlin.Unit> content);
+ method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(S? targetState, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional String label, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super S,kotlin.Unit> content);
+ method @androidx.compose.runtime.Composable public static <S> void AnimatedContent(androidx.compose.animation.core.Transition<S>, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function1<? super androidx.compose.animation.AnimatedContentTransitionScope<S>,androidx.compose.animation.ContentTransform> transitionSpec, optional androidx.compose.ui.Alignment contentAlignment, optional kotlin.jvm.functions.Function1<? super S,?> contentKey, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super S,kotlin.Unit> content);
method public static androidx.compose.animation.SizeTransform SizeTransform(optional boolean clip, optional kotlin.jvm.functions.Function2<? super androidx.compose.ui.unit.IntSize,? super androidx.compose.ui.unit.IntSize,? extends androidx.compose.animation.core.FiniteAnimationSpec<androidx.compose.ui.unit.IntSize>> sizeAnimationSpec);
- method public static infix androidx.compose.animation.ContentTransform with(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ method public static infix androidx.compose.animation.ContentTransform togetherWith(androidx.compose.animation.EnterTransition, androidx.compose.animation.ExitTransition exit);
+ }
+
+ public sealed interface AnimatedContentScope extends androidx.compose.animation.AnimatedVisibilityScope {
}
public sealed interface AnimatedContentTransitionScope<S> extends androidx.compose.animation.core.Transition.Segment<S> {
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/NestedMenuDemo.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/NestedMenuDemo.kt
index 8317633..cd45d8b 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/NestedMenuDemo.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/NestedMenuDemo.kt
@@ -19,7 +19,7 @@
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedContentTransitionScope.SlideDirection
import androidx.compose.animation.ExperimentalAnimationApi
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
@@ -73,7 +73,7 @@
transitionSpec = {
if (initialState < targetState) {
// Going from parent menu to child menu, slide towards left
- slideIntoContainer(towards = SlideDirection.Left) with
+ slideIntoContainer(towards = SlideDirection.Left) togetherWith
slideOutOfContainer(
towards = SlideDirection.Left,
targetOffset = { offsetForFullSlide -> offsetForFullSlide / 2 }
@@ -83,7 +83,7 @@
slideIntoContainer(
towards = SlideDirection.Right,
initialOffset = { offsetForFullSlide -> offsetForFullSlide / 2 }
- ) with
+ ) togetherWith
slideOutOfContainer(towards = SlideDirection.Right)
}.apply {
targetContentZIndex = when (targetState) {
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ScreenTransitionDemo.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ScreenTransitionDemo.kt
index 0454eb6..e798134 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ScreenTransitionDemo.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ScreenTransitionDemo.kt
@@ -25,7 +25,7 @@
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.shrinkVertically
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -88,22 +88,22 @@
if (TestScreens.Screen1 isTransitioningTo TestScreens.Screen2 ||
TestScreens.Screen2 isTransitioningTo TestScreens.Screen1
) {
- (expandHorizontally(animationSpec = tween(500)) + fadeIn()).with(
+ (expandHorizontally(animationSpec = tween(500)) + fadeIn()).togetherWith(
shrinkVertically(animationSpec = tween(500)) +
fadeOut(animationSpec = tween(500))
)
} else if (TestScreens.Screen2 isTransitioningTo TestScreens.Screen3) {
- slideIntoContainer(towards = SlideDirection.Left) with
+ slideIntoContainer(towards = SlideDirection.Left) togetherWith
slideOutOfContainer(towards = SlideDirection.Left)
} else if (TestScreens.Screen3 isTransitioningTo TestScreens.Screen2) {
- slideIntoContainer(towards = SlideDirection.Right) with
+ slideIntoContainer(towards = SlideDirection.Right) togetherWith
slideOutOfContainer(towards = SlideDirection.Right)
} else {
// Material fade through
fadeIn(animationSpec = tween(220, delayMillis = 90)) +
scaleIn(
initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90)
- ) with fadeOut(animationSpec = tween(90))
+ ) togetherWith fadeOut(animationSpec = tween(90))
}
}
) {
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ShrineCartDemo.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ShrineCartDemo.kt
index b938cba..4b5c059 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ShrineCartDemo.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/layoutanimation/ShrineCartDemo.kt
@@ -25,7 +25,7 @@
import androidx.compose.animation.core.updateTransition
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
@@ -88,7 +88,7 @@
cartOpenTransition.AnimatedContent(
transitionSpec = {
fadeIn(animationSpec = tween(150, delayMillis = 150))
- .with(fadeOut(animationSpec = tween(150)))
+ .togetherWith(fadeOut(animationSpec = tween(150)))
.using(
SizeTransform { initialSize, targetSize ->
if (CartState.Collapsed isTransitioningTo CartState.Expanded) {
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/AnimatedContentWithInterruptions.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/AnimatedContentWithInterruptions.kt
index fb79e9f..4e58285 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/AnimatedContentWithInterruptions.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/AnimatedContentWithInterruptions.kt
@@ -22,7 +22,7 @@
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
@@ -50,10 +50,10 @@
var count by remember { mutableStateOf(0) }
AnimatedContent(targetState = count, transitionSpec = {
if (targetState == 0) {
- (slideInVertically { it } with fadeOut(targetAlpha = 0.88f))
+ (slideInVertically { it } togetherWith fadeOut(targetAlpha = 0.88f))
.apply { targetContentZIndex = 1f }
} else {
- (fadeIn(initialAlpha = 0.88f) with slideOutVertically { it } +
+ (fadeIn(initialAlpha = 0.88f) togetherWith slideOutVertically { it } +
fadeOut(targetAlpha = 0.88f))
.apply { targetContentZIndex = -1f }
}
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/SlideInContentVariedSizes.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/SlideInContentVariedSizes.kt
index e947060..134949f 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/SlideInContentVariedSizes.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/visualinspection/SlideInContentVariedSizes.kt
@@ -23,7 +23,7 @@
import androidx.compose.animation.AnimatedContentTransitionScope.SlideDirection.Companion.Up
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.SizeTransform
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
@@ -85,21 +85,21 @@
transitionSpec = {
if (targetState < initialState) {
if (horizontal) {
- slideIntoContainer(towards = Right) with slideOutOfContainer(
+ slideIntoContainer(towards = Right) togetherWith slideOutOfContainer(
towards = Right
)
} else {
- slideIntoContainer(towards = Down) with slideOutOfContainer(
+ slideIntoContainer(towards = Down) togetherWith slideOutOfContainer(
towards = Down
)
}
} else {
if (horizontal) {
- slideIntoContainer(towards = Left).with(
+ slideIntoContainer(towards = Left).togetherWith(
slideOutOfContainer(towards = Left)
)
} else {
- slideIntoContainer(towards = Up).with(
+ slideIntoContainer(towards = Up).togetherWith(
slideOutOfContainer(towards = Up)
)
}
diff --git a/compose/animation/animation/samples/src/main/java/androidx/compose/animation/samples/AnimatedContentSamples.kt b/compose/animation/animation/samples/src/main/java/androidx/compose/animation/samples/AnimatedContentSamples.kt
index 2947e60..915c79c 100644
--- a/compose/animation/animation/samples/src/main/java/androidx/compose/animation/samples/AnimatedContentSamples.kt
+++ b/compose/animation/animation/samples/src/main/java/androidx/compose/animation/samples/AnimatedContentSamples.kt
@@ -30,7 +30,7 @@
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -75,11 +75,13 @@
if (targetState > initialState) {
// If the incoming number is larger, new number slides up and fades in while
// the previous (smaller) number slides up to make room and fades out.
- slideInVertically { it } + fadeIn() with slideOutVertically { -it } + fadeOut()
+ slideInVertically { it } + fadeIn() togetherWith
+ slideOutVertically { -it } + fadeOut()
} else {
// If the incoming number is smaller, new number slides down and fades in while
// the previous number slides down and fades out.
- slideInVertically { -it } + fadeIn() with slideOutVertically { it } + fadeOut()
+ slideInVertically { -it } + fadeIn() togetherWith
+ slideOutVertically { it } + fadeOut()
// Disable clipping since the faded slide-out is desired out of bounds, but
// the size transform is still needed from number getting longer
}.using(SizeTransform(clip = false)) // Using default spring for the size change.
@@ -110,17 +112,26 @@
// enum class ContentState { Foo, Bar, Baz }
@Composable
fun Foo() {
- Box(Modifier.size(200.dp).background(Color(0xffffdb00)))
+ Box(
+ Modifier
+ .size(200.dp)
+ .background(Color(0xffffdb00)))
}
@Composable
fun Bar() {
- Box(Modifier.size(40.dp).background(Color(0xffff8100)))
+ Box(
+ Modifier
+ .size(40.dp)
+ .background(Color(0xffff8100)))
}
@Composable
fun Baz() {
- Box(Modifier.size(80.dp, 20.dp).background(Color(0xffff4400)))
+ Box(
+ Modifier
+ .size(80.dp, 20.dp)
+ .background(Color(0xffff4400)))
}
var contentState: ContentState by remember { mutableStateOf(ContentState.Foo) }
@@ -144,7 +155,7 @@
{
// Fade in with a delay so that it starts after fade out
fadeIn(animationSpec = tween(150, delayMillis = 150))
- .with(fadeOut(animationSpec = tween(150)))
+ .togetherWith(fadeOut(animationSpec = tween(150)))
.using(
SizeTransform { initialSize, targetSize ->
// Using different SizeTransform for different state change
@@ -192,6 +203,7 @@
when {
CartState.Expanded isTransitioningTo CartState.Collapsed ->
tween(durationMillis = 433, delayMillis = 67)
+
else ->
tween(durationMillis = 150)
}
@@ -199,7 +211,8 @@
) { if (it == CartState.Expanded) 0.dp else 24.dp }
Surface(
- Modifier.shadow(8.dp, CutCornerShape(topStart = cornerSize))
+ Modifier
+ .shadow(8.dp, CutCornerShape(topStart = cornerSize))
.clip(CutCornerShape(topStart = cornerSize)),
color = Color(0xfffff0ea),
) {
@@ -210,7 +223,7 @@
cartOpenTransition.AnimatedContent(
transitionSpec = {
fadeIn(animationSpec = tween(150, delayMillis = 150))
- .with(fadeOut(animationSpec = tween(150)))
+ .togetherWith(fadeOut(animationSpec = tween(150)))
.using(
SizeTransform { initialSize, targetSize ->
// Using different SizeTransform for different state change
@@ -269,7 +282,7 @@
val transitionSpec: AnimatedContentTransitionScope<NestedMenuState>.() -> ContentTransform = {
if (initialState < targetState) {
// Going from parent menu to child menu, slide towards left
- slideIntoContainer(towards = SlideDirection.Left) with
+ slideIntoContainer(towards = SlideDirection.Left) togetherWith
// Slide the parent out by 1/2 the amount required to be completely
// out of the bounds. This creates a sense of child menu catching up. Since
// the child menu has a higher z-order, it will cover the parent meu as it
@@ -283,7 +296,7 @@
// parallax visual effect.
slideIntoContainer(towards = SlideDirection.Right) { offsetForFullSlide ->
offsetForFullSlide / 2
- } with slideOutOfContainer(towards = SlideDirection.Right)
+ } togetherWith slideOutOfContainer(towards = SlideDirection.Right)
}.apply {
// Here we can specify the zIndex for the target (i.e. incoming) content.
targetContentZIndex = when (targetState) {
diff --git a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedContentTest.kt b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedContentTest.kt
index 9fb6011..97e515e 100644
--- a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedContentTest.kt
+++ b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedContentTest.kt
@@ -88,16 +88,17 @@
testModifier,
transitionSpec = {
if (true isTransitioningTo false) {
- fadeIn() with fadeOut() using SizeTransform { initialSize, targetSize ->
- keyframes {
- durationMillis = 320
- IntSize(targetSize.width, initialSize.height) at 160 with
- LinearEasing
- targetSize at 320 with LinearEasing
+ fadeIn() togetherWith fadeOut() using
+ SizeTransform { initialSize, targetSize ->
+ keyframes {
+ durationMillis = 320
+ IntSize(targetSize.width, initialSize.height) at 160 with
+ LinearEasing
+ targetSize at 320 with LinearEasing
+ }
}
- }
} else {
- fadeIn() with fadeOut() using SizeTransform { _, _ ->
+ fadeIn() togetherWith fadeOut() using SizeTransform { _, _ ->
tween(durationMillis = 80, easing = LinearEasing)
}
}
@@ -166,9 +167,10 @@
transition.AnimatedContent(
testModifier,
transitionSpec = {
- EnterTransition.None with ExitTransition.None using SizeTransform { _, _ ->
- tween(durationMillis = 160, easing = LinearEasing)
- }
+ EnterTransition.None togetherWith ExitTransition.None using
+ SizeTransform { _, _ ->
+ tween(durationMillis = 160, easing = LinearEasing)
+ }
}
) {
if (it) {
@@ -235,7 +237,7 @@
testModifier,
contentAlignment = contentAlignment,
transitionSpec = {
- fadeIn(animationSpec = tween(durationMillis = 80)) with fadeOut(
+ fadeIn(animationSpec = tween(durationMillis = 80)) togetherWith fadeOut(
animationSpec = tween(durationMillis = 80)
) using SizeTransform { _, _ ->
tween(durationMillis = 80, easing = LinearEasing)
@@ -359,14 +361,14 @@
if (true isTransitioningTo false) {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Start, animSpec
- ) with
+ ) togetherWith
slideOutOfContainer(
AnimatedContentTransitionScope.SlideDirection.Start, animSpec
)
} else {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.End, animSpec
- ) with
+ ) togetherWith
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.End,
animSpec
@@ -494,7 +496,7 @@
modifier = Modifier.onGloballyPositioned { rootCoords = it },
transitionSpec = {
if (targetState) {
- fadeIn(tween(2000)) with slideOut(
+ fadeIn(tween(2000)) togetherWith slideOut(
tween(2000)
) { fullSize ->
IntOffset(0, fullSize.height / 2)
@@ -502,7 +504,7 @@
tween(2000)
)
} else {
- fadeIn(tween(2000)) with fadeOut(tween(2000))
+ fadeIn(tween(2000)) togetherWith fadeOut(tween(2000))
}
}) { state ->
if (state) {
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedContent.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedContent.kt
index 9a51fc4..69e9bbe 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedContent.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedContent.kt
@@ -85,7 +85,7 @@
* outgoing content will be disposed.
*
* By default, the [ContentTransform] will be a delayed [fadeIn] of the target content and a delayed
- * [scaleIn] [with] a [fadeOut] of the initial content, using a [SizeTransform] to
+ * [scaleIn] [togetherWith] a [fadeOut] of the initial content, using a [SizeTransform] to
* animate any size change of the content. This behavior can be customized using [transitionSpec].
* If desired, different [ContentTransform]s can be defined for different pairs of initial content
* and target content.
@@ -100,8 +100,8 @@
* on top of all the other content unless zIndex is specified.
*
* Different content in [AnimatedContent] will have access to their own
- * [AnimatedVisibilityScope]. This allows content to define more local enter/exit transitions
- * via [AnimatedVisibilityScope.animateEnterExit] and [AnimatedVisibilityScope.transition]. These
+ * [AnimatedContentScope]. This allows content to define more local enter/exit transitions
+ * via [AnimatedContentScope.animateEnterExit] and [AnimatedContentScope.transition]. These
* custom enter/exit animations will be triggered as the content enters/leaves the container.
*
* [label] is an optional parameter to differentiate from other animations in Android Studio.
@@ -114,20 +114,20 @@
* @sample androidx.compose.animation.samples.AnimateIncrementDecrementSample
*
* @see ContentTransform
- * @see AnimatedVisibilityScope
+ * @see AnimatedContentScope
*/
@Composable
fun <S> AnimatedContent(
targetState: S,
modifier: Modifier = Modifier,
transitionSpec: AnimatedContentTransitionScope<S>.() -> ContentTransform = {
- fadeIn(animationSpec = tween(220, delayMillis = 90)) +
- scaleIn(initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90)) with
- fadeOut(animationSpec = tween(90))
+ (fadeIn(animationSpec = tween(220, delayMillis = 90)) +
+ scaleIn(initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90)))
+ .togetherWith(fadeOut(animationSpec = tween(90)))
},
contentAlignment: Alignment = Alignment.TopStart,
label: String = "AnimatedContent",
- content: @Composable() AnimatedVisibilityScope.(targetState: S) -> Unit
+ content: @Composable() AnimatedContentScope.(targetState: S) -> Unit
) {
val transition = updateTransition(targetState = targetState, label = label)
transition.AnimatedContent(
@@ -138,14 +138,6 @@
)
}
-// TODO: Remove this before M7 stable. This is only intended for helping devs quick fix the
-// name change.
-@Deprecated(
- "AnimatedContentScope has been renamed to AnimatedContentTransitionScope",
- replaceWith = ReplaceWith("AnimatedContentTransitionScope<S>")
-)
-typealias AnimatedContentScope<S> = AnimatedContentTransitionScope<S>
-
/**
* [ContentTransform] defines how the target content (i.e. content associated with target state)
* enters [AnimatedContent] and how the initial content disappears.
@@ -263,6 +255,13 @@
*
* @sample androidx.compose.animation.samples.AnimatedContentTransitionSpecSample
*/
+infix fun EnterTransition.togetherWith(exit: ExitTransition) = ContentTransform(this, exit)
+
+@ExperimentalAnimationApi
+@Deprecated(
+ "Infix fun EnterTransition.with(ExitTransition) has been renamed to" +
+ " togetherWith", ReplaceWith("togetherWith(exit)")
+)
infix fun EnterTransition.with(exit: ExitTransition) = ContentTransform(this, exit)
/**
@@ -604,6 +603,17 @@
}
/**
+ * Receiver scope for content lambda for AnimatedContent. In this scope,
+ * [transition][AnimatedVisibilityScope.transition] can be used to observe the state of the
+ * transition, or to add more enter/exit transition for the content.
+ */
+sealed interface AnimatedContentScope : AnimatedVisibilityScope
+
+private class AnimatedContentScopeImpl internal constructor(
+ animatedVisibilityScope: AnimatedVisibilityScope
+) : AnimatedContentScope, AnimatedVisibilityScope by animatedVisibilityScope
+
+/**
* [AnimatedContent] is a container that automatically animates its content when
* [Transition.targetState] changes. Its [content] for different target states is defined in a
* mapping between a target state and a composable function.
@@ -621,7 +631,7 @@
* outgoing content will be disposed.
*
* By default, the [ContentTransform] will be a delayed [fadeIn] of the target content and a delayed
- * [scaleIn] [with] a [fadeOut] of the initial content, using a [SizeTransform] to
+ * [scaleIn] [togetherWith] a [fadeOut] of the initial content, using a [SizeTransform] to
* animate any size change of the content. This behavior can be customized using [transitionSpec].
* If desired, different [ContentTransform]s can be defined for different pairs of initial content
* and target content.
@@ -636,8 +646,8 @@
* on top of all the other content unless zIndex is specified.
*
* Different content in [AnimatedContent] will have access to their own
- * [AnimatedVisibilityScope]. This allows content to define more local enter/exit transitions
- * via [AnimatedVisibilityScope.animateEnterExit] and [AnimatedVisibilityScope.transition]. These
+ * [AnimatedContentScope]. This allows content to define more local enter/exit transitions
+ * via [AnimatedContentScope.animateEnterExit] and [AnimatedContentScope.transition]. These
* custom enter/exit animations will be triggered as the content enters/leaves the container.
*
* [contentKey] can be used to specify a key for each targetState. There will be no animation
@@ -649,20 +659,20 @@
* @sample androidx.compose.animation.samples.TransitionExtensionAnimatedContentSample
*
* @see ContentTransform
- * @see AnimatedVisibilityScope
+ * @see AnimatedContentScope
*/
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun <S> Transition<S>.AnimatedContent(
modifier: Modifier = Modifier,
transitionSpec: AnimatedContentTransitionScope<S>.() -> ContentTransform = {
- fadeIn(animationSpec = tween(220, delayMillis = 90)) +
- scaleIn(initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90)) with
- fadeOut(animationSpec = tween(90))
+ (fadeIn(animationSpec = tween(220, delayMillis = 90)) +
+ scaleIn(initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90)))
+ .togetherWith(fadeOut(animationSpec = tween(90)))
},
contentAlignment: Alignment = Alignment.TopStart,
contentKey: (targetState: S) -> Any? = { it },
- content: @Composable() AnimatedVisibilityScope.(targetState: S) -> Unit
+ content: @Composable() AnimatedContentScope.(targetState: S) -> Unit
) {
val layoutDirection = LocalLayoutDirection.current
val rootScope = remember(this) {
@@ -750,7 +760,9 @@
}
rootScope.targetSizeMap[stateForContent] =
(this as AnimatedVisibilityScopeImpl).targetSize
- content(stateForContent)
+ with(remember { AnimatedContentScopeImpl(this) }) {
+ content(stateForContent)
+ }
}
}
}
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt b/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt
index 8f5661b..50602d5 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt
@@ -26,7 +26,7 @@
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement
@@ -412,7 +412,7 @@
val contentTransform: ContentTransform
@Composable get() =
fadeIn(animationSpec = tween(100))
- .with(fadeOut(animationSpec = tween(100)))
+ .togetherWith(fadeOut(animationSpec = tween(100)))
/**
* An indicator showing the position of the current active item among the items of the
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt b/tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt
index 14650f7..2996e8d 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt
@@ -21,7 +21,7 @@
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
@@ -120,7 +120,7 @@
val contentTransformRightToLeft: ContentTransform
@Composable get() =
slideInHorizontally { it * 4 }
- .with(slideOutHorizontally { it * 4 })
+ .togetherWith(slideOutHorizontally { it * 4 })
/**
* Transform the content from left to right
@@ -129,7 +129,7 @@
val contentTransformLeftToRight: ContentTransform
@Composable get() =
slideInHorizontally()
- .with(slideOutHorizontally())
+ .togetherWith(slideOutHorizontally())
/**
* Content transform applied when moving forward taking isLTR into account
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/ImmersiveList.kt b/tv/tv-material/src/main/java/androidx/tv/material3/ImmersiveList.kt
index 9f934d8..f55c49d 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/ImmersiveList.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/ImmersiveList.kt
@@ -24,7 +24,7 @@
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
-import androidx.compose.animation.with
+import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
@@ -162,7 +162,7 @@
targetState: Int,
modifier: Modifier = Modifier,
transitionSpec: AnimatedContentTransitionScope<Int>.() -> ContentTransform = {
- ImmersiveListDefaults.EnterTransition.with(ImmersiveListDefaults.ExitTransition)
+ ImmersiveListDefaults.EnterTransition.togetherWith(ImmersiveListDefaults.ExitTransition)
},
contentAlignment: Alignment = Alignment.TopStart,
content: @Composable AnimatedVisibilityScope.(targetState: Int) -> Unit