Skip to content

Commit dc7cc85

Browse files
vineetfrozeninfernoGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Remove CarouselItem and CarouselScope" into androidx-main
2 parents d001b5a + 53ddc55 commit dc7cc85

File tree

10 files changed

+120
-475
lines changed

10 files changed

+120
-475
lines changed

tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/FeaturedCarousel.kt

+29-24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
package androidx.tv.integration.playground
1818

19+
import androidx.compose.animation.ExperimentalAnimationApi
20+
import androidx.compose.animation.core.tween
21+
import androidx.compose.animation.fadeIn
22+
import androidx.compose.animation.fadeOut
23+
import androidx.compose.animation.slideInVertically
24+
import androidx.compose.animation.slideOutHorizontally
25+
import androidx.compose.animation.togetherWith
1926
import androidx.compose.foundation.background
2027
import androidx.compose.foundation.border
2128
import androidx.compose.foundation.focusable
@@ -88,7 +95,7 @@ fun FeaturedCarouselContent() {
8895
}
8996
}
9097

91-
@OptIn(ExperimentalTvMaterial3Api::class)
98+
@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
9299
@Composable
93100
internal fun FeaturedCarousel(modifier: Modifier = Modifier) {
94101
val backgrounds = listOf(
@@ -117,33 +124,31 @@ internal fun FeaturedCarousel(modifier: Modifier = Modifier) {
117124
.align(Alignment.BottomEnd)
118125
.padding(16.dp),
119126
)
120-
}
127+
},
128+
contentTransformStartToEnd =
129+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000))),
130+
contentTransformEndToStart =
131+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000)))
121132
) { itemIndex ->
122-
CarouselItem(
123-
modifier = Modifier.semantics {
124-
contentDescription = "Featured Content"
125-
},
126-
background = {
127-
Box(
128-
modifier = Modifier
129-
.background(backgrounds[itemIndex])
130-
.fillMaxSize()
131-
)
132-
},
133+
Box(
134+
modifier = Modifier
135+
.background(backgrounds[itemIndex])
136+
.fillMaxSize()
137+
.semantics { contentDescription = "Featured Content" }
133138
) {
134-
Box(
139+
Column(
135140
modifier = Modifier
136-
.fillMaxSize()
137-
.padding(20.dp),
138-
contentAlignment = Alignment.BottomStart
141+
.padding(start = 50.dp, top = 100.dp)
142+
.animateEnterExit(
143+
enter = slideInVertically(animationSpec = tween(1000)),
144+
exit = slideOutHorizontally(animationSpec = tween(1000))
145+
)
139146
) {
140-
Column {
141-
Text(text = "This is sample text content.", color = Color.Yellow)
142-
Text(text = "Sample description.", color = Color.Yellow)
143-
Row {
144-
OverlayButton(text = "Play")
145-
OverlayButton(text = "Add to Watchlist")
146-
}
147+
Text(text = "This is sample text content.", color = Color.Yellow)
148+
Text(text = "Sample description of slide ${itemIndex + 1}.", color = Color.Yellow)
149+
Row {
150+
OverlayButton(text = "Play")
151+
OverlayButton(text = "Add to Watchlist")
147152
}
148153
}
149154
}

tv/integration-tests/presentation/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
## Setup
44

55
* Uncomment the `coil` and `gson` libraries dependency additions from the `build.gradle` file.
6+
* Uncomment the function content and imports from
7+
`presentation/src/main/java/androidx/tv/integration/presentation/ExternalLibs.kt` file
68
* Create the `data.json` file in `presentation/src/main/assets` directory and add the content from
79
this link: go/compose-tv-presentation-app-data
810

911
> If you are not a Googler and want to use this app for
1012
> testing, you will have to create the `data.json` file by following the schema mentioned in the
1113
`Data.kt` file
12-
13-
* Uncomment the function content and imports from
14-
`presentation/src/main/java/androidx/tv/integration/presentation/ExternalLibs.kt` file

tv/integration-tests/presentation/src/main/java/androidx/tv/integration/presentation/FeaturedCarousel.kt

+24-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616

1717
package androidx.tv.integration.presentation
1818

19+
import androidx.compose.animation.AnimatedContentScope
20+
import androidx.compose.animation.ExperimentalAnimationApi
21+
import androidx.compose.animation.core.tween
22+
import androidx.compose.animation.fadeIn
23+
import androidx.compose.animation.fadeOut
24+
import androidx.compose.animation.slideInHorizontally
25+
import androidx.compose.animation.slideOutHorizontally
26+
import androidx.compose.animation.togetherWith
27+
import androidx.compose.foundation.layout.Box
1928
import androidx.compose.foundation.layout.Column
2029
import androidx.compose.foundation.layout.fillMaxWidth
2130
import androidx.compose.foundation.layout.height
@@ -32,7 +41,6 @@ import androidx.compose.ui.unit.dp
3241
import androidx.compose.ui.unit.sp
3342
import androidx.tv.material3.Carousel
3443
import androidx.tv.material3.CarouselDefaults
35-
import androidx.tv.material3.CarouselScope
3644
import androidx.tv.material3.CarouselState
3745
import androidx.tv.material3.ExperimentalTvMaterial3Api
3846
import androidx.tv.material3.Text
@@ -60,7 +68,11 @@ fun FeaturedCarousel(
6068
.align(Alignment.BottomEnd)
6169
.padding(end = 58.dp, bottom = 16.dp),
6270
)
63-
}
71+
},
72+
contentTransformEndToStart =
73+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000))),
74+
contentTransformStartToEnd =
75+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000)))
6476
) { itemIndex ->
6577
val movie = movies[itemIndex]
6678

@@ -80,22 +92,23 @@ fun FeaturedCarousel(
8092
}
8193
}
8294

83-
@OptIn(ExperimentalTvMaterial3Api::class)
95+
@OptIn(ExperimentalAnimationApi::class)
8496
@Composable
85-
private fun CarouselScope.CarouselSlide(
97+
private fun AnimatedContentScope.CarouselSlide(
8698
title: String,
8799
description: String,
88100
background: @Composable () -> Unit,
89101
actions: @Composable () -> Unit
90102
) {
91-
CarouselItem(
92-
background = {
93-
background()
94-
},
95-
modifier = Modifier
96-
) {
103+
Box {
104+
background()
97105
Column(
98-
modifier = Modifier.padding(start = 58.dp, top = 150.dp)
106+
modifier = Modifier
107+
.padding(start = 58.dp, top = 150.dp)
108+
.animateEnterExit(
109+
enter = slideInHorizontally(animationSpec = tween(1000)) { it / 2 },
110+
exit = slideOutHorizontally(animationSpec = tween(1000))
111+
)
99112
) {
100113
Text(
101114
text = title,

tv/samples/src/main/java/androidx/tv/samples/CarouselSamples.kt

+42-22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
package androidx.tv.samples
1818

1919
import androidx.annotation.Sampled
20+
import androidx.compose.animation.ExperimentalAnimationApi
21+
import androidx.compose.animation.core.tween
22+
import androidx.compose.animation.fadeIn
23+
import androidx.compose.animation.fadeOut
24+
import androidx.compose.animation.slideInHorizontally
25+
import androidx.compose.animation.slideOutHorizontally
26+
import androidx.compose.animation.togetherWith
2027
import androidx.compose.foundation.background
2128
import androidx.compose.foundation.border
2229
import androidx.compose.foundation.layout.Box
@@ -44,7 +51,7 @@ import androidx.tv.material3.CarouselDefaults
4451
import androidx.tv.material3.CarouselState
4552
import androidx.tv.material3.ExperimentalTvMaterial3Api
4653

47-
@OptIn(ExperimentalTvMaterial3Api::class)
54+
@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
4855
@Sampled
4956
@Composable
5057
fun SimpleCarousel() {
@@ -59,16 +66,16 @@ fun SimpleCarousel() {
5966
modifier = Modifier
6067
.height(300.dp)
6168
.fillMaxWidth(),
69+
contentTransformEndToStart =
70+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000))),
71+
contentTransformStartToEnd =
72+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000)))
6273
) { itemIndex ->
63-
CarouselItem(
64-
background = {
65-
Box(
66-
modifier = Modifier
67-
.background(backgrounds[itemIndex])
68-
.border(2.dp, Color.White.copy(alpha = 0.5f))
69-
.fillMaxSize()
70-
)
71-
}
74+
Box(
75+
modifier = Modifier
76+
.background(backgrounds[itemIndex])
77+
.border(2.dp, Color.White.copy(alpha = 0.5f))
78+
.fillMaxSize()
7279
) {
7380
var isFocused by remember { mutableStateOf(false) }
7481

@@ -82,6 +89,13 @@ fun SimpleCarousel() {
8289
color = if (isFocused) Color.Red else Color.Transparent,
8390
shape = RoundedCornerShape(50)
8491
)
92+
// Duration of animation here should be less than or equal to carousel's
93+
// contentTransform duration to ensure the item below does not disappear
94+
// abruptly.
95+
.animateEnterExit(
96+
enter = slideInHorizontally(animationSpec = tween(1000)) { it / 2 },
97+
exit = slideOutHorizontally(animationSpec = tween(1000))
98+
)
8599
.padding(vertical = 2.dp, horizontal = 5.dp)
86100
) {
87101
Text(text = "Play")
@@ -90,7 +104,7 @@ fun SimpleCarousel() {
90104
}
91105
}
92106

93-
@OptIn(ExperimentalTvMaterial3Api::class)
107+
@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
94108
@Sampled
95109
@Composable
96110
fun CarouselIndicatorWithRectangleShape() {
@@ -127,24 +141,30 @@ fun CarouselIndicatorWithRectangleShape() {
127141
)
128142
}
129143
)
130-
}
144+
},
145+
contentTransformEndToStart =
146+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000))),
147+
contentTransformStartToEnd =
148+
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000)))
131149
) { itemIndex ->
132-
CarouselItem(
133-
background = {
134-
Box(
135-
modifier = Modifier
136-
.background(backgrounds[itemIndex])
137-
.border(2.dp, Color.White.copy(alpha = 0.5f))
138-
.fillMaxSize()
139-
)
140-
}
150+
Box(
151+
modifier = Modifier
152+
.background(backgrounds[itemIndex])
153+
.border(2.dp, Color.White.copy(alpha = 0.5f))
154+
.fillMaxSize()
141155
) {
142156
var isFocused by remember { mutableStateOf(false) }
143-
144157
Button(
145158
onClick = { },
146159
modifier = Modifier
147160
.onFocusChanged { isFocused = it.isFocused }
161+
// Duration of animation here should be less than or equal to carousel's
162+
// contentTransform duration to ensure the item below does not disappear
163+
// abruptly.
164+
.animateEnterExit(
165+
enter = slideInHorizontally(animationSpec = tween(1000)) { it / 2 },
166+
exit = slideOutHorizontally(animationSpec = tween(1000))
167+
)
148168
.padding(40.dp)
149169
.border(
150170
width = 2.dp,

tv/tv-material/api/public_plus_experimental_current.txt

+1-17
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,8 @@ package androidx.tv.material3 {
114114
field public static final long TimeToDisplayItemMillis = 5000L; // 0x1388L
115115
}
116116

117-
@androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselItemDefaults {
118-
method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformEndToStart();
119-
method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformLeftToRight();
120-
method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformRightToLeft();
121-
method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformStartToEnd();
122-
property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformEndToStart;
123-
property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformLeftToRight;
124-
property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformRightToLeft;
125-
property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformStartToEnd;
126-
field public static final androidx.tv.material3.CarouselItemDefaults INSTANCE;
127-
}
128-
129117
public final class CarouselKt {
130-
method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public static void Carousel(int itemCount, optional androidx.compose.ui.Modifier modifier, optional androidx.tv.material3.CarouselState carouselState, optional long autoScrollDurationMillis, optional androidx.compose.animation.ContentTransform contentTransformStartToEnd, optional androidx.compose.animation.ContentTransform contentTransformEndToStart, optional kotlin.jvm.functions.Function1<? super androidx.compose.foundation.layout.BoxScope,kotlin.Unit> carouselIndicator, kotlin.jvm.functions.Function2<? super androidx.tv.material3.CarouselScope,? super java.lang.Integer,kotlin.Unit> content);
131-
}
132-
133-
@androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselScope {
134-
method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public void CarouselItem(optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function0<kotlin.Unit> background, optional androidx.compose.animation.ContentTransform contentTransformStartToEnd, optional androidx.compose.animation.ContentTransform contentTransformEndToStart, kotlin.jvm.functions.Function0<kotlin.Unit> content);
118+
method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public static void Carousel(int itemCount, optional androidx.compose.ui.Modifier modifier, optional androidx.tv.material3.CarouselState carouselState, optional long autoScrollDurationMillis, optional androidx.compose.animation.ContentTransform contentTransformStartToEnd, optional androidx.compose.animation.ContentTransform contentTransformEndToStart, optional kotlin.jvm.functions.Function1<? super androidx.compose.foundation.layout.BoxScope,kotlin.Unit> carouselIndicator, kotlin.jvm.functions.Function2<? super androidx.compose.animation.AnimatedContentScope,? super java.lang.Integer,kotlin.Unit> content);
135119
}
136120

137121
@androidx.compose.runtime.Stable @androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselState {

0 commit comments

Comments
 (0)