refactor: rename CarouselSlide and slideCount to CarouselItem and itemCount. Updated contentTransform names
Test: Updated tests
Relnote: Rename CarouselSlide and slideCount to CarouselItem and itemCount. Rename forward and backward contentTransform to StartToEnd and EndToStart
Change-Id: Ie554cbf0d7e082e6c64c0f334d47b5bd69228372
diff --git a/tv/integration-tests/demos/src/main/java/androidx/tv/integration/demos/FeaturedCarousel.kt b/tv/integration-tests/demos/src/main/java/androidx/tv/integration/demos/FeaturedCarousel.kt
index deeafa0..6a5007f 100644
--- a/tv/integration-tests/demos/src/main/java/androidx/tv/integration/demos/FeaturedCarousel.kt
+++ b/tv/integration-tests/demos/src/main/java/androidx/tv/integration/demos/FeaturedCarousel.kt
@@ -112,22 +112,22 @@
val carouselState = remember { CarouselState() }
Carousel(
- slideCount = backgrounds.size,
+ itemCount = backgrounds.size,
carouselState = carouselState,
modifier = modifier
.height(300.dp)
.fillMaxWidth(),
carouselIndicator = {
CarouselDefaults.IndicatorRow(
- slideCount = backgrounds.size,
- activeSlideIndex = carouselState.activeSlideIndex,
+ itemCount = backgrounds.size,
+ activeItemIndex = carouselState.activeItemIndex,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
)
}
) { itemIndex ->
- CarouselSlide(
+ CarouselItem(
background = {
Box(
modifier = Modifier
diff --git a/tv/samples/src/main/java/androidx/tv/samples/CarouselSamples.kt b/tv/samples/src/main/java/androidx/tv/samples/CarouselSamples.kt
index ab964bd..aba7109 100644
--- a/tv/samples/src/main/java/androidx/tv/samples/CarouselSamples.kt
+++ b/tv/samples/src/main/java/androidx/tv/samples/CarouselSamples.kt
@@ -17,7 +17,6 @@
package androidx.tv.samples
import androidx.annotation.Sampled
-import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
@@ -45,7 +44,7 @@
import androidx.tv.material3.CarouselState
import androidx.tv.material3.ExperimentalTvMaterial3Api
-@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
+@OptIn(ExperimentalTvMaterial3Api::class)
@Sampled
@Composable
fun SimpleCarousel() {
@@ -56,12 +55,12 @@
)
Carousel(
- slideCount = backgrounds.size,
+ itemCount = backgrounds.size,
modifier = Modifier
.height(300.dp)
.fillMaxWidth(),
) { itemIndex ->
- CarouselSlide(
+ CarouselItem(
background = {
Box(
modifier = Modifier
@@ -91,7 +90,7 @@
}
}
-@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
+@OptIn(ExperimentalTvMaterial3Api::class)
@Sampled
@Composable
fun CarouselIndicatorWithRectangleShape() {
@@ -103,15 +102,15 @@
val carouselState = remember { CarouselState() }
Carousel(
- slideCount = backgrounds.size,
+ itemCount = backgrounds.size,
modifier = Modifier
.height(300.dp)
.fillMaxWidth(),
carouselState = carouselState,
carouselIndicator = {
CarouselDefaults.IndicatorRow(
- slideCount = backgrounds.size,
- activeSlideIndex = carouselState.activeSlideIndex,
+ itemCount = backgrounds.size,
+ activeItemIndex = carouselState.activeItemIndex,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
@@ -130,7 +129,7 @@
)
}
) { itemIndex ->
- CarouselSlide(
+ CarouselItem(
background = {
Box(
modifier = Modifier
diff --git a/tv/tv-material/api/public_plus_experimental_current.txt b/tv/tv-material/api/public_plus_experimental_current.txt
index 38f62bb..b0fe368 100644
--- a/tv/tv-material/api/public_plus_experimental_current.txt
+++ b/tv/tv-material/api/public_plus_experimental_current.txt
@@ -25,38 +25,38 @@
}
@androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselDefaults {
- method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public void IndicatorRow(int slideCount, int activeSlideIndex, optional androidx.compose.ui.Modifier modifier, optional float spacing, optional kotlin.jvm.functions.Function1<? super java.lang.Boolean,kotlin.Unit> indicator);
+ method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public void IndicatorRow(int itemCount, int activeItemIndex, optional androidx.compose.ui.Modifier modifier, optional float spacing, optional kotlin.jvm.functions.Function1<? super java.lang.Boolean,kotlin.Unit> indicator);
method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransform();
property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransform;
field public static final androidx.tv.material3.CarouselDefaults INSTANCE;
- field public static final long TimeToDisplaySlideMillis = 5000L; // 0x1388L
+ field public static final long TimeToDisplayItemMillis = 5000L; // 0x1388L
+ }
+
+ @androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselItemDefaults {
+ method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformEndToStart();
+ method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformLeftToRight();
+ method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformRightToLeft();
+ method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformStartToEnd();
+ property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformEndToStart;
+ property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformLeftToRight;
+ property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformRightToLeft;
+ property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformStartToEnd;
+ field public static final androidx.tv.material3.CarouselItemDefaults INSTANCE;
}
public final class CarouselKt {
- method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public static void Carousel(int slideCount, optional androidx.compose.ui.Modifier modifier, optional androidx.tv.material3.CarouselState carouselState, optional long autoScrollDurationMillis, optional androidx.compose.animation.ContentTransform contentTransformForward, optional androidx.compose.animation.ContentTransform contentTransformBackward, 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);
+ 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);
}
@androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselScope {
- method @androidx.compose.runtime.Composable @androidx.tv.material3.ExperimentalTvMaterial3Api public void CarouselSlide(optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function0<kotlin.Unit> background, optional androidx.compose.animation.ContentTransform contentTransformForward, optional androidx.compose.animation.ContentTransform contentTransformBackward, kotlin.jvm.functions.Function0<kotlin.Unit> content);
- }
-
- @androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselSlideDefaults {
- method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformBackward();
- method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformForward();
- method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformLeftToRight();
- method @androidx.compose.runtime.Composable public androidx.compose.animation.ContentTransform getContentTransformRightToLeft();
- property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformBackward;
- property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformForward;
- property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformLeftToRight;
- property @androidx.compose.runtime.Composable public final androidx.compose.animation.ContentTransform contentTransformRightToLeft;
- field public static final androidx.tv.material3.CarouselSlideDefaults INSTANCE;
+ 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);
}
@androidx.compose.runtime.Stable @androidx.tv.material3.ExperimentalTvMaterial3Api public final class CarouselState {
- ctor public CarouselState(optional int initialActiveSlideIndex);
- method public int getActiveSlideIndex();
- method public androidx.tv.material3.ScrollPauseHandle pauseAutoScroll(int slideIndex);
- property public final int activeSlideIndex;
+ ctor public CarouselState(optional int initialActiveItemIndex);
+ method public int getActiveItemIndex();
+ method public androidx.tv.material3.ScrollPauseHandle pauseAutoScroll(int itemIndex);
+ property public final int activeItemIndex;
}
@androidx.compose.runtime.Immutable @androidx.tv.material3.ExperimentalTvMaterial3Api public final class ClickableSurfaceBorder {
diff --git a/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselScopeTest.kt b/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselScopeTest.kt
index 6fdeaa9..10080e0 100644
--- a/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselScopeTest.kt
+++ b/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselScopeTest.kt
@@ -52,9 +52,9 @@
@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
@Test
- fun carouselSlide_parentContainerGainsFocused_onBackPress() {
+ fun carouselItem_parentContainerGainsFocused_onBackPress() {
val containerBoxTag = "container-box"
- val carouselSlideTag = "carousel-slide"
+ val carouselItemTag = "carousel-item"
rule.setContent {
val carouselState = remember { CarouselState() }
@@ -68,8 +68,8 @@
.focusable()
) {
CarouselScope(carouselState = carouselState)
- .CarouselSlide(
- modifier = Modifier.testTag(carouselSlideTag),
+ .CarouselItem(
+ modifier = Modifier.testTag(carouselItemTag),
background = {
Box(
modifier = Modifier
@@ -82,7 +82,7 @@
}
// Request focus for Carousel Item on start
- rule.onNodeWithTag(carouselSlideTag)
+ rule.onNodeWithTag(carouselItemTag)
.performSemanticsAction(SemanticsActions.RequestFocus)
rule.waitForIdle()
diff --git a/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt b/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt
index d9c5a2f..7582b2c 100644
--- a/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt
+++ b/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt
@@ -71,7 +71,7 @@
import org.junit.Rule
import org.junit.Test
-private const val delayBetweenSlides = 2500L
+private const val delayBetweenItems = 2500L
private const val animationTime = 900L
@OptIn(ExperimentalTvMaterial3Api::class)
@@ -89,10 +89,10 @@
rule.onNodeWithText("Text 1").assertIsDisplayed()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
rule.onNodeWithText("Text 2").assertIsDisplayed()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
rule.onNodeWithText("Text 3").assertIsDisplayed()
}
@@ -111,7 +111,7 @@
.onParent()
.performSemanticsAction(SemanticsActions.RequestFocus)
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
rule.onNodeWithText("Text 2").assertDoesNotExist()
rule.onNodeWithText("Text 1").onParent().assertIsFocused()
@@ -130,7 +130,7 @@
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.onNodeWithText("Text 1").onParent().assertIsNotFocused()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
rule.onNodeWithText("Text 2").assertDoesNotExist()
rule.onNodeWithText("Text 1").assertIsDisplayed()
@@ -154,17 +154,17 @@
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.onNodeWithText("Text 1").onParent().assertIsNotFocused()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// pause handle has not been resumed, so Text 1 should still be on the screen.
rule.onNodeWithText("Text 2").assertDoesNotExist()
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.runOnIdle { pauseHandle?.resumeAutoScroll() }
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// pause handle has been resumed, so Text 2 should be on the screen after
- // delayBetweenSlides + animationTime
+ // delayBetweenItems + animationTime
rule.onNodeWithText("Text 1").assertDoesNotExist()
rule.onNodeWithText("Text 2").assertIsDisplayed()
}
@@ -192,23 +192,23 @@
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.onNodeWithText("Text 1").onParent().assertIsNotFocused()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// pause handles have not been resumed, so Text 1 should still be on the screen.
rule.onNodeWithText("Text 2").assertDoesNotExist()
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.runOnIdle { pauseHandle1?.resumeAutoScroll() }
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// Second pause handle has not been resumed, so Text 1 should still be on the screen.
rule.onNodeWithText("Text 2").assertDoesNotExist()
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.runOnIdle { pauseHandle2?.resumeAutoScroll() }
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// All pause handles have been resumed, so Text 2 should be on the screen after
- // delayBetweenSlides + animationTime
+ // delayBetweenItems + animationTime
rule.onNodeWithText("Text 1").assertDoesNotExist()
rule.onNodeWithText("Text 2").assertIsDisplayed()
}
@@ -236,7 +236,7 @@
rule.onNodeWithText("Text 1").assertIsDisplayed()
rule.onNodeWithText("Text 1").onParent().assertIsNotFocused()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// pause handles have not been resumed, so Text 1 should still be on the screen.
rule.onNodeWithText("Text 2").assertDoesNotExist()
@@ -245,7 +245,7 @@
rule.runOnIdle { pauseHandle1?.resumeAutoScroll() }
// subsequent call to resume should be ignored
rule.runOnIdle { pauseHandle1?.resumeAutoScroll() }
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
// Second pause handle has not been resumed, so Text 1 should still be on the screen.
rule.onNodeWithText("Text 2").assertDoesNotExist()
@@ -270,7 +270,7 @@
rule.onNodeWithText("Card").performSemanticsAction(SemanticsActions.RequestFocus)
rule.onNodeWithText("Card").assertIsFocused()
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
rule.onNodeWithText("Text 1").assertDoesNotExist()
rule.onNodeWithText("Text 2").assertIsDisplayed()
}
@@ -280,7 +280,7 @@
fun carousel_pagerIndicatorDisplayed() {
rule.setContent {
SampleCarousel {
- SampleCarouselSlide(index = it)
+ SampleCarouselItem(index = it)
}
}
@@ -292,7 +292,7 @@
fun carousel_withAnimatedContent_successfulTransition() {
rule.setContent {
SampleCarousel {
- SampleCarouselSlide(index = it) {
+ SampleCarouselItem(index = it) {
Column {
BasicText(text = "Text ${it + 1}")
BasicText(text = "PLAY")
@@ -313,7 +313,7 @@
fun carousel_withAnimatedContent_successfulFocusIn() {
rule.setContent {
SampleCarousel {
- SampleCarouselSlide(index = it)
+ SampleCarouselItem(index = it)
}
}
@@ -321,7 +321,7 @@
rule.onNodeWithTag("pager")
.performSemanticsAction(SemanticsActions.RequestFocus)
- // current slide overlay render delay
+ // current item overlay render delay
rule.mainClock.advanceTimeBy(animationTime, false)
rule.mainClock.advanceTimeBy(animationTime, false)
rule.mainClock.advanceTimeByFrame()
@@ -367,14 +367,14 @@
@OptIn(ExperimentalAnimationApi::class)
@Test
- fun carousel_withCarouselSlide_parentContainerGainsFocus_onBackPress() {
+ fun carousel_withCarouselItem_parentContainerGainsFocus_onBackPress() {
rule.setContent {
Box(modifier = Modifier
.testTag("box-container")
.fillMaxSize()
.focusable()) {
SampleCarousel {
- SampleCarouselSlide(index = it)
+ SampleCarouselItem(index = it)
}
}
}
@@ -432,10 +432,10 @@
.testTag("featured-carousel")
.border(2.dp, Color.Black),
carouselState = remember { CarouselState() },
- slideCount = 3,
- autoScrollDurationMillis = delayBetweenSlides
+ itemCount = 3,
+ autoScrollDurationMillis = delayBetweenItems
) {
- SampleCarouselSlide(index = it) {
+ SampleCarouselItem(index = it) {
Box {
Column(modifier = Modifier.align(Alignment.BottomStart)) {
BasicText(text = "carousel-frame")
@@ -493,10 +493,10 @@
@OptIn(ExperimentalAnimationApi::class)
@Test
- fun carousel_zeroSlideCount_shouldNotCrash() {
+ fun carousel_zeroItemCount_shouldNotCrash() {
val testTag = "emptyCarousel"
rule.setContent {
- Carousel(slideCount = 0, modifier = Modifier.testTag(testTag)) {}
+ Carousel(itemCount = 0, modifier = Modifier.testTag(testTag)) {}
}
rule.onNodeWithTag(testTag).assertExists()
@@ -504,10 +504,10 @@
@OptIn(ExperimentalAnimationApi::class)
@Test
- fun carousel_oneSlideCount_shouldNotCrash() {
+ fun carousel_oneItemCount_shouldNotCrash() {
val testTag = "emptyCarousel"
rule.setContent {
- Carousel(slideCount = 1, modifier = Modifier.testTag(testTag)) {}
+ Carousel(itemCount = 1, modifier = Modifier.testTag(testTag)) {}
}
rule.onNodeWithTag(testTag).assertExists()
@@ -536,20 +536,20 @@
rule.mainClock.advanceTimeByFrame()
rule.waitForIdle()
- // Check that slide 1 is in view and button 1 has focus
+ // Check that item 1 is in view and button 1 has focus
rule.onNodeWithText("Button-1").assertIsDisplayed()
rule.onNodeWithText("Button-1").assertIsFocused()
- // press dpad right to scroll to next slide
+ // press dpad right to scroll to next item
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_RIGHT)
- // Wait for slide to load
+ // Wait for item to load
rule.mainClock.advanceTimeByFrame()
rule.waitForIdle()
rule.mainClock.advanceTimeBy(animationTime, false)
rule.waitForIdle()
- // Check that slide 2 is in view and button 2 has focus
+ // Check that item 2 is in view and button 2 has focus
rule.onNodeWithText("Button-2").assertIsDisplayed()
// TODO: Fix button 2 isn't gaining focus
// rule.onNodeWithText("Button-2").assertIsFocused()
@@ -557,16 +557,16 @@
// Check if the first focusable element in parent has focus
rule.onNodeWithText("Row-button-1").assertIsNotFocused()
- // press dpad left to scroll to previous slide
+ // press dpad left to scroll to previous item
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_LEFT)
- // Wait for slide to load
+ // Wait for item to load
rule.mainClock.advanceTimeByFrame()
rule.waitForIdle()
rule.mainClock.advanceTimeBy(animationTime, false)
rule.waitForIdle()
- // Check that slide 1 is in view and button 1 has focus
+ // Check that item 1 is in view and button 1 has focus
rule.onNodeWithText("Button-1").assertIsDisplayed()
rule.onNodeWithText("Button-1").assertIsFocused()
}
@@ -592,8 +592,8 @@
}
}
- SampleCarousel(carouselState = carouselState, slideCount = 20) {
- SampleCarouselSlide(modifier = Modifier.testTag("slide-$it"), index = it)
+ SampleCarousel(carouselState = carouselState, itemCount = 20) {
+ SampleCarouselItem(modifier = Modifier.testTag("item-$it"), index = it)
}
}
}
@@ -602,9 +602,9 @@
rule.onNodeWithTag("pager").performSemanticsAction(SemanticsActions.RequestFocus)
rule.waitForIdle()
- val slideProgression = listOf(6, 3, -4, 3, -6, 5, 3)
+ val itemProgression = listOf(6, 3, -4, 3, -6, 5, 3)
- slideProgression.forEach {
+ itemProgression.forEach {
if (it < 0) {
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_LEFT, it * -1)
} else {
@@ -614,20 +614,20 @@
rule.mainClock.advanceTimeBy(animationTime)
- val finalSlide = slideProgression.sum()
- rule.onNodeWithText("Play $finalSlide").assertIsFocused()
+ val finalItem = itemProgression.sum()
+ rule.onNodeWithText("Play $finalItem").assertIsFocused()
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_RIGHT, 3)
rule.mainClock.advanceTimeBy((animationTime) * 3)
- rule.onNodeWithText("Play ${finalSlide + 3}").assertIsFocused()
+ rule.onNodeWithText("Play ${finalItem + 3}").assertIsFocused()
}
@Test
fun carousel_manualScrolling_onDpadLongPress() {
rule.setContent {
- SampleCarousel(slideCount = 6) { index ->
+ SampleCarousel(itemCount = 6) { index ->
SampleButton("Button ${index + 1}")
}
}
@@ -641,31 +641,31 @@
rule.mainClock.advanceTimeByFrame()
rule.waitForIdle()
- // Assert that Button 1 from first slide is focused
+ // Assert that Button 1 from first item is focused
rule.onNodeWithText("Button 1").assertIsFocused()
// Trigger dpad right key long press
performLongKeyPress(rule, NativeKeyEvent.KEYCODE_DPAD_RIGHT)
- // Advance time and trigger recomposition to switch to next slide
+ // Advance time and trigger recomposition to switch to next item
rule.mainClock.advanceTimeByFrame()
rule.waitForIdle()
- rule.mainClock.advanceTimeBy(delayBetweenSlides, false)
+ rule.mainClock.advanceTimeBy(delayBetweenItems, false)
rule.waitForIdle()
- // Assert that Button 2 from second slide is focused
+ // Assert that Button 2 from second item is focused
rule.onNodeWithText("Button 2").assertIsFocused()
// Trigger dpad left key long press
performLongKeyPress(rule, NativeKeyEvent.KEYCODE_DPAD_LEFT)
- // Advance time and trigger recomposition to switch to previous slide
- rule.mainClock.advanceTimeBy(delayBetweenSlides, false)
+ // Advance time and trigger recomposition to switch to previous item
+ rule.mainClock.advanceTimeBy(delayBetweenItems, false)
rule.waitForIdle()
rule.mainClock.advanceTimeByFrame()
rule.waitForIdle()
- // Assert that Button 1 from first slide is focused
+ // Assert that Button 1 from first item is focused
rule.onNodeWithText("Button 1").assertIsFocused()
}
@@ -681,37 +681,37 @@
rule.onNodeWithTag("pager")
.performSemanticsAction(SemanticsActions.RequestFocus)
- // current slide overlay render delay
+ // current item overlay render delay
rule.mainClock.advanceTimeBy(animationTime, false)
rule.mainClock.advanceTimeBy(animationTime, false)
rule.mainClock.advanceTimeByFrame()
- // Assert that slide 1 is in view
+ // Assert that item 1 is in view
rule.onNodeWithText("Button 1").assertIsDisplayed()
// advance time
- rule.mainClock.advanceTimeBy(delayBetweenSlides + animationTime, false)
+ rule.mainClock.advanceTimeBy(delayBetweenItems + animationTime, false)
rule.mainClock.advanceTimeByFrame()
// go right once
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_RIGHT)
- // Wait for slide to load
+ // Wait for item to load
rule.mainClock.advanceTimeBy(animationTime)
rule.mainClock.advanceTimeByFrame()
- // Assert that slide 2 is in view
+ // Assert that item 2 is in view
rule.onNodeWithText("Button 2").assertIsDisplayed()
// go left once
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_LEFT)
- // Wait for slide to load
- rule.mainClock.advanceTimeBy(delayBetweenSlides)
+ // Wait for item to load
+ rule.mainClock.advanceTimeBy(delayBetweenItems)
rule.mainClock.advanceTimeBy(animationTime)
rule.mainClock.advanceTimeByFrame()
- // Assert that slide 1 is in view
+ // Assert that item 1 is in view
rule.onNodeWithText("Button 1").assertIsDisplayed()
}
@@ -731,70 +731,70 @@
rule.onNodeWithTag("pager")
.performSemanticsAction(SemanticsActions.RequestFocus)
- // current slide overlay render delay
+ // current item overlay render delay
rule.mainClock.advanceTimeBy(animationTime, false)
rule.mainClock.advanceTimeBy(animationTime, false)
rule.mainClock.advanceTimeByFrame()
- // Assert that slide 1 is in view
+ // Assert that item 1 is in view
rule.onNodeWithText("Button 1").assertIsDisplayed()
// advance time
- rule.mainClock.advanceTimeBy(delayBetweenSlides + animationTime, false)
+ rule.mainClock.advanceTimeBy(delayBetweenItems + animationTime, false)
rule.mainClock.advanceTimeByFrame()
// go right once
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_LEFT)
- // Wait for slide to load
+ // Wait for item to load
rule.mainClock.advanceTimeBy(animationTime)
rule.mainClock.advanceTimeByFrame()
- // Assert that slide 2 is in view
+ // Assert that item 2 is in view
rule.onNodeWithText("Button 2").assertIsDisplayed()
// go left once
performKeyPress(NativeKeyEvent.KEYCODE_DPAD_RIGHT)
- // Wait for slide to load
- rule.mainClock.advanceTimeBy(delayBetweenSlides + animationTime, false)
+ // Wait for item to load
+ rule.mainClock.advanceTimeBy(delayBetweenItems + animationTime, false)
rule.mainClock.advanceTimeByFrame()
- // Assert that slide 1 is in view
+ // Assert that item 1 is in view
rule.onNodeWithText("Button 1").assertIsDisplayed()
}
@Test
- fun carousel_slideCountChangesDuringAnimation_shouldNotCrash() {
- val slideDisplayDurationMs: Long = 100
- var slideChanges = 0
- // number of slides will fall from 4 to 2, but 4 slide transitions should happen without a
+ fun carousel_itemCountChangesDuringAnimation_shouldNotCrash() {
+ val itemDisplayDurationMs: Long = 100
+ var itemChanges = 0
+ // number of items will fall from 4 to 2, but 4 item transitions should happen without a
// crash
- val minSuccessfulSlideChanges = 4
+ val minSuccessfulItemChanges = 4
rule.setContent {
- var slideCount by remember { mutableStateOf(4) }
+ var itemCount by remember { mutableStateOf(4) }
LaunchedEffect(Unit) {
- while (slideCount >= 2) {
- delay(slideDisplayDurationMs)
- slideCount--
+ while (itemCount >= 2) {
+ delay(itemDisplayDurationMs)
+ itemCount--
}
}
SampleCarousel(
- slideCount = slideCount,
- timeToDisplaySlideMillis = slideDisplayDurationMs
+ itemCount = itemCount,
+ timeToDisplayItemMillis = itemDisplayDurationMs
) { index ->
- if (index >= slideCount) {
- // slideIndex requested should not be greater than slideCount. User could be
+ if (index >= itemCount) {
+ // itemIndex requested should not be greater than itemCount. User could be
// using a data-structure that could throw an IndexOutOfBoundsException.
- // This can happen when the slideCount changes during the transition between
- // slides.
- throw Exception("Index is larger, index=$index, slideCount=$slideCount")
+ // This can happen when the itemCount changes during the transition between
+ // items.
+ throw Exception("Index is larger, index=$index, itemCount=$itemCount")
}
- slideChanges++
+ itemChanges++
}
}
- rule.waitUntil(timeoutMillis = 5000) { slideChanges > minSuccessfulSlideChanges }
+ rule.waitUntil(timeoutMillis = 5000) { itemChanges > minSuccessfulItemChanges }
}
}
@@ -802,8 +802,8 @@
@Composable
private fun SampleCarousel(
carouselState: CarouselState = remember { CarouselState() },
- slideCount: Int = 3,
- timeToDisplaySlideMillis: Long = delayBetweenSlides,
+ itemCount: Int = 3,
+ timeToDisplayItemMillis: Long = delayBetweenItems,
content: @Composable CarouselScope.(index: Int) -> Unit
) {
Carousel(
@@ -813,16 +813,16 @@
.height(200.dp)
.testTag("pager"),
carouselState = carouselState,
- slideCount = slideCount,
- autoScrollDurationMillis = timeToDisplaySlideMillis,
+ itemCount = itemCount,
+ autoScrollDurationMillis = timeToDisplayItemMillis,
carouselIndicator = {
CarouselDefaults.IndicatorRow(
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp)
.testTag("indicator"),
- activeSlideIndex = carouselState.activeSlideIndex,
- slideCount = slideCount
+ activeItemIndex = carouselState.activeItemIndex,
+ itemCount = itemCount
)
},
content = { content(it) },
@@ -831,16 +831,16 @@
@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
@Composable
-private fun CarouselScope.SampleCarouselSlide(
+private fun CarouselScope.SampleCarouselItem(
index: Int,
modifier: Modifier = Modifier,
- contentTransformForward: ContentTransform =
- CarouselSlideDefaults.contentTransformForward,
+ contentTransformStartToEnd: ContentTransform =
+ CarouselItemDefaults.contentTransformStartToEnd,
content: (@Composable () -> Unit) = { SampleButton("Play $index") },
) {
- CarouselSlide(
+ CarouselItem(
modifier = modifier,
- contentTransformForward = contentTransformForward,
+ contentTransformStartToEnd = contentTransformStartToEnd,
background = {
Box(
modifier = Modifier
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 442c810..8f5661b 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
@@ -78,34 +78,33 @@
* @sample androidx.tv.samples.CarouselIndicatorWithRectangleShape
*
* @param modifier Modifier applied to the Carousel.
- * @param slideCount total number of slides present in the carousel.
+ * @param itemCount total number of items present in the carousel.
* @param carouselState state associated with this carousel.
- * @param autoScrollDurationMillis duration for which slide should be visible before moving to
- * the next slide.
- * @param contentTransformForward animation transform applied when we are moving forward in the
- * carousel while scrolling
- * @param contentTransformBackward animation transform applied when we are moving backward in the
- * carousel while scrolling
- * in the next slide
- * @param carouselIndicator indicator showing the position of the current slide among all slides.
- * @param content defines the slides for a given index.
+ * @param autoScrollDurationMillis duration for which item should be visible before moving to
+ * the next item.
+ * @param contentTransformStartToEnd animation transform applied when we are moving from start to
+ * end in the carousel while scrolling to the next item
+ * @param contentTransformEndToStart animation transform applied when we are moving from end to
+ * start in the carousel while scrolling to the next item
+ * @param carouselIndicator indicator showing the position of the current item among all items.
+ * @param content defines the items for a given index.
*/
@Suppress("IllegalExperimentalApiUsage")
-@OptIn(ExperimentalComposeUiApi::class, ExperimentalAnimationApi::class)
+@OptIn(ExperimentalComposeUiApi::class)
@ExperimentalTvMaterial3Api
@Composable
fun Carousel(
- slideCount: Int,
+ itemCount: Int,
modifier: Modifier = Modifier,
carouselState: CarouselState = remember { CarouselState() },
- autoScrollDurationMillis: Long = CarouselDefaults.TimeToDisplaySlideMillis,
- contentTransformForward: ContentTransform = CarouselDefaults.contentTransform,
- contentTransformBackward: ContentTransform = CarouselDefaults.contentTransform,
+ autoScrollDurationMillis: Long = CarouselDefaults.TimeToDisplayItemMillis,
+ contentTransformStartToEnd: ContentTransform = CarouselDefaults.contentTransform,
+ contentTransformEndToStart: ContentTransform = CarouselDefaults.contentTransform,
carouselIndicator:
@Composable BoxScope.() -> Unit = {
CarouselDefaults.IndicatorRow(
- slideCount = slideCount,
- activeSlideIndex = carouselState.activeSlideIndex,
+ itemCount = itemCount,
+ activeItemIndex = carouselState.activeItemIndex,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
@@ -113,7 +112,7 @@
},
content: @Composable CarouselScope.(index: Int) -> Unit
) {
- CarouselStateUpdater(carouselState, slideCount)
+ CarouselStateUpdater(carouselState, itemCount)
var focusState: FocusState? by remember { mutableStateOf(null) }
val focusManager = LocalFocusManager.current
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
@@ -122,7 +121,7 @@
AutoScrollSideEffect(
autoScrollDurationMillis = autoScrollDurationMillis,
- slideCount = slideCount,
+ itemCount = itemCount,
carouselState = carouselState,
doAutoScroll = shouldPerformAutoScroll(focusState),
onAutoScrollChange = { isAutoScrollActive = it })
@@ -142,21 +141,21 @@
carouselState = carouselState,
outerBoxFocusRequester = carouselOuterBoxFocusRequester,
focusManager = focusManager,
- slideCount = slideCount,
+ itemCount = itemCount,
isLtr = isLtr,
)
.focusable()
) {
AnimatedContent(
- targetState = carouselState.activeSlideIndex,
+ targetState = carouselState.activeItemIndex,
transitionSpec = {
if (carouselState.isMovingBackward) {
- contentTransformBackward
+ contentTransformEndToStart
} else {
- contentTransformForward
+ contentTransformStartToEnd
}
}
- ) { activeSlideIndex ->
+ ) { activeItemIndex ->
LaunchedEffect(Unit) {
[email protected] {
// Outer box is focused
@@ -166,13 +165,13 @@
}
}
}
- // it is possible for the slideCount to have changed during the transition.
- // This can cause the slideIndex to be greater than or equal to slideCount and cause
- // IndexOutOfBoundsException. Guarding against this by checking against slideCount
+ // it is possible for the itemCount to have changed during the transition.
+ // This can cause the itemIndex to be greater than or equal to itemCount and cause
+ // IndexOutOfBoundsException. Guarding against this by checking against itemCount
// before invoking.
- if (slideCount > 0) {
+ if (itemCount > 0) {
CarouselScope(carouselState = carouselState)
- .content(if (activeSlideIndex < slideCount) activeSlideIndex else 0)
+ .content(if (activeItemIndex < itemCount) activeItemIndex else 0)
}
}
this.carouselIndicator()
@@ -197,13 +196,13 @@
@Composable
private fun AutoScrollSideEffect(
autoScrollDurationMillis: Long,
- slideCount: Int,
+ itemCount: Int,
carouselState: CarouselState,
doAutoScroll: Boolean,
onAutoScrollChange: (isAutoScrollActive: Boolean) -> Unit = {},
) {
- // Needed to ensure that the code within LaunchedEffect receives updates to the slideCount.
- val updatedSlideCount by rememberUpdatedState(newValue = slideCount)
+ // Needed to ensure that the code within LaunchedEffect receives updates to the itemCount.
+ val updatedItemCount by rememberUpdatedState(newValue = itemCount)
if (doAutoScroll) {
LaunchedEffect(carouselState) {
while (true) {
@@ -213,7 +212,7 @@
snapshotFlow { carouselState.activePauseHandlesCount }
.first { pauseHandleCount -> pauseHandleCount == 0 }
}
- carouselState.moveToNextSlide(updatedSlideCount)
+ carouselState.moveToNextItem(updatedItemCount)
}
}
}
@@ -226,7 +225,7 @@
carouselState: CarouselState,
outerBoxFocusRequester: FocusRequester,
focusManager: FocusManager,
- slideCount: Int,
+ itemCount: Int,
isLtr: Boolean
): Modifier = onKeyEvent {
// Ignore KeyUp action type
@@ -234,20 +233,20 @@
return@onKeyEvent KeyEventPropagation.ContinuePropagation
}
- val showPreviousSlideAndGetKeyEventPropagation = {
- if (carouselState.isFirstSlide()) {
+ val showPreviousItemAndGetKeyEventPropagation = {
+ if (carouselState.isFirstItem()) {
KeyEventPropagation.ContinuePropagation
} else {
- carouselState.moveToPreviousSlide(slideCount)
+ carouselState.moveToPreviousItem(itemCount)
outerBoxFocusRequester.requestFocus()
KeyEventPropagation.StopPropagation
}
}
- val showNextSlideAndGetKeyEventPropagation = {
- if (carouselState.isLastSlide(slideCount)) {
+ val showNextItemAndGetKeyEventPropagation = {
+ if (carouselState.isLastItem(itemCount)) {
KeyEventPropagation.ContinuePropagation
} else {
- carouselState.moveToNextSlide(slideCount)
+ carouselState.moveToNextItem(itemCount)
outerBoxFocusRequester.requestFocus()
KeyEventPropagation.StopPropagation
}
@@ -266,9 +265,9 @@
}
if (isLtr) {
- showPreviousSlideAndGetKeyEventPropagation()
+ showPreviousItemAndGetKeyEventPropagation()
} else {
- showNextSlideAndGetKeyEventPropagation()
+ showNextItemAndGetKeyEventPropagation()
}
}
@@ -279,9 +278,9 @@
}
if (isLtr) {
- showNextSlideAndGetKeyEventPropagation()
+ showNextItemAndGetKeyEventPropagation()
} else {
- showPreviousSlideAndGetKeyEventPropagation()
+ showPreviousItemAndGetKeyEventPropagation()
}
}
@@ -291,31 +290,31 @@
@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
-private fun CarouselStateUpdater(carouselState: CarouselState, slideCount: Int) {
- LaunchedEffect(carouselState, slideCount) {
- if (slideCount != 0) {
- carouselState.activeSlideIndex = floorMod(carouselState.activeSlideIndex, slideCount)
+private fun CarouselStateUpdater(carouselState: CarouselState, itemCount: Int) {
+ LaunchedEffect(carouselState, itemCount) {
+ if (itemCount != 0) {
+ carouselState.activeItemIndex = floorMod(carouselState.activeItemIndex, itemCount)
}
}
}
/**
- * State of the Carousel which allows the user to specify the first slide that is shown when the
+ * State of the Carousel which allows the user to specify the first item that is shown when the
* Carousel is instantiated in the constructor.
*
* It also provides the user with support to pause and resume the auto-scroll behaviour of the
* Carousel.
- * @param initialActiveSlideIndex the index of the first active slide
+ * @param initialActiveItemIndex the index of the first active item
*/
@Stable
@ExperimentalTvMaterial3Api
-class CarouselState(initialActiveSlideIndex: Int = 0) {
+class CarouselState(initialActiveItemIndex: Int = 0) {
internal var activePauseHandlesCount by mutableStateOf(0)
/**
- * The index of the slide that is currently displayed by the carousel
+ * The index of the item that is currently displayed by the carousel
*/
- var activeSlideIndex by mutableStateOf(initialActiveSlideIndex)
+ var activeItemIndex by mutableStateOf(initialActiveItemIndex)
internal set
/**
@@ -327,38 +326,38 @@
/**
* Pauses the auto-scrolling behaviour of Carousel.
- * The pause request is ignored if [slideIndex] is not the current slide that is visible.
+ * The pause request is ignored if [itemIndex] is not the current item that is visible.
* Returns a [ScrollPauseHandle] that can be used to resume
*/
- fun pauseAutoScroll(slideIndex: Int): ScrollPauseHandle {
- if (this.activeSlideIndex != slideIndex) {
+ fun pauseAutoScroll(itemIndex: Int): ScrollPauseHandle {
+ if (this.activeItemIndex != itemIndex) {
return NoOpScrollPauseHandle
}
return ScrollPauseHandleImpl(this)
}
- internal fun isFirstSlide() = activeSlideIndex == 0
+ internal fun isFirstItem() = activeItemIndex == 0
- internal fun isLastSlide(slideCount: Int) = activeSlideIndex == slideCount - 1
+ internal fun isLastItem(itemCount: Int) = activeItemIndex == itemCount - 1
- internal fun moveToPreviousSlide(slideCount: Int) {
- // No slides available for carousel
- if (slideCount == 0) return
+ internal fun moveToPreviousItem(itemCount: Int) {
+ // No items available for carousel
+ if (itemCount == 0) return
isMovingBackward = true
- // Go to previous slide
- activeSlideIndex = floorMod(activeSlideIndex - 1, slideCount)
+ // Go to previous item
+ activeItemIndex = floorMod(activeItemIndex - 1, itemCount)
}
- internal fun moveToNextSlide(slideCount: Int) {
- // No slides available for carousel
- if (slideCount == 0) return
+ internal fun moveToNextItem(itemCount: Int) {
+ // No items available for carousel
+ if (itemCount == 0) return
isMovingBackward = false
- // Go to next slide
- activeSlideIndex = floorMod(activeSlideIndex + 1, slideCount)
+ // Go to next item
+ activeItemIndex = floorMod(activeItemIndex + 1, itemCount)
}
}
@@ -403,34 +402,33 @@
@ExperimentalTvMaterial3Api
object CarouselDefaults {
/**
- * Default time for which the slide is visible to the user.
+ * Default time for which the item is visible to the user.
*/
- const val TimeToDisplaySlideMillis: Long = 5000
+ const val TimeToDisplayItemMillis: Long = 5000
/**
* Transition applied when bringing it into view and removing it from the view
*/
- @OptIn(ExperimentalAnimationApi::class)
val contentTransform: ContentTransform
@Composable get() =
fadeIn(animationSpec = tween(100))
.with(fadeOut(animationSpec = tween(100)))
/**
- * An indicator showing the position of the current active slide among the slides of the
+ * An indicator showing the position of the current active item among the items of the
* carousel.
*
- * @param slideCount total number of slides in the carousel
- * @param activeSlideIndex the current active slide index
+ * @param itemCount total number of items in the carousel
+ * @param activeItemIndex the current active item index
* @param modifier Modifier applied to the indicators' container
* @param spacing spacing between the indicator dots
- * @param indicator indicator dot representing each slide in the carousel
+ * @param indicator indicator dot representing each item in the carousel
*/
@ExperimentalTvMaterial3Api
@Composable
fun IndicatorRow(
- slideCount: Int,
- activeSlideIndex: Int,
+ itemCount: Int,
+ activeItemIndex: Int,
modifier: Modifier = Modifier,
spacing: Dp = 8.dp,
indicator: @Composable (isActive: Boolean) -> Unit = { isActive ->
@@ -451,8 +449,8 @@
verticalAlignment = Alignment.CenterVertically,
modifier = modifier,
) {
- repeat(slideCount) {
- val isActive = it == activeSlideIndex
+ repeat(itemCount) {
+ val isActive = it == activeItemIndex
indicator(isActive = isActive)
}
}
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/CarouselSlide.kt b/tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt
similarity index 86%
rename from tv/tv-material/src/main/java/androidx/tv/material3/CarouselSlide.kt
rename to tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt
index 162f167..14650f7 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/CarouselSlide.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/CarouselItem.kt
@@ -48,10 +48,10 @@
* - a [background] layer that is rendered as soon as the composable is visible.
* - a [content] layer that is rendered on top of the [background]
*
- * @param background composable defining the background of the slide
- * @param slideIndex current active slide index of the carousel
- * @param modifier modifier applied to the CarouselSlide
- * @param contentTransform content transform to be applied to the content of the slide when
+ * @param background composable defining the background of the item
+ * @param itemIndex current active item index of the carousel
+ * @param modifier modifier applied to the CarouselItem
+ * @param contentTransform content transform to be applied to the content of the item when
* scrolling
* @param content composable defining the content displayed on top of the background
*/
@@ -59,12 +59,12 @@
@OptIn(ExperimentalAnimationApi::class, ExperimentalComposeUiApi::class)
@ExperimentalTvMaterial3Api
@Composable
-internal fun CarouselSlide(
- slideIndex: Int,
+internal fun CarouselItem(
+ itemIndex: Int,
modifier: Modifier = Modifier,
background: @Composable () -> Unit = {},
contentTransform: ContentTransform =
- CarouselSlideDefaults.contentTransformForward,
+ CarouselItemDefaults.contentTransformStartToEnd,
content: @Composable () -> Unit,
) {
var containerBoxFocusState: FocusState? by remember { mutableStateOf(null) }
@@ -73,7 +73,7 @@
var isVisible by remember { mutableStateOf(false) }
- DisposableEffect(slideIndex) {
+ DisposableEffect(itemIndex) {
isVisible = true
onDispose { isVisible = false }
}
@@ -112,13 +112,11 @@
}
@ExperimentalTvMaterial3Api
-object CarouselSlideDefaults {
+object CarouselItemDefaults {
/**
* Transform the content from right to left
*/
// Keeping this as public so that users can access it directly without the isLTR helper
- @Suppress("IllegalExperimentalApiUsage")
- @OptIn(ExperimentalAnimationApi::class)
val contentTransformRightToLeft: ContentTransform
@Composable get() =
slideInHorizontally { it * 4 }
@@ -128,8 +126,6 @@
* Transform the content from left to right
*/
// Keeping this as public so that users can access it directly without the isLTR helper
- @Suppress("IllegalExperimentalApiUsage")
- @OptIn(ExperimentalAnimationApi::class)
val contentTransformLeftToRight: ContentTransform
@Composable get() =
slideInHorizontally()
@@ -138,9 +134,7 @@
/**
* Content transform applied when moving forward taking isLTR into account
*/
- @Suppress("IllegalExperimentalApiUsage")
- @OptIn(ExperimentalAnimationApi::class)
- val contentTransformForward
+ val contentTransformStartToEnd
@Composable get() =
if (isLtr())
contentTransformRightToLeft
@@ -150,9 +144,7 @@
/**
* Content transform applied when moving backward taking isLTR into account
*/
- @Suppress("IllegalExperimentalApiUsage")
- @OptIn(ExperimentalAnimationApi::class)
- val contentTransformBackward
+ val contentTransformEndToStart
@Composable get() =
if (isLtr())
contentTransformLeftToRight
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/CarouselScope.kt b/tv/tv-material/src/main/java/androidx/tv/material3/CarouselScope.kt
index 838e1e6..665ceb9 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/CarouselScope.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/CarouselScope.kt
@@ -17,51 +17,48 @@
package androidx.tv.material3
import androidx.compose.animation.ContentTransform
-import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
/**
- * CarouselScope provides a [CarouselScope.CarouselSlide] function which you can use to
- * provide the slide's animation, background and the inner content.
+ * CarouselScope provides a [CarouselScope.CarouselItem] function which you can use to
+ * provide the carousel item's animation, background and the inner content.
*/
@ExperimentalTvMaterial3Api
class CarouselScope @OptIn(ExperimentalTvMaterial3Api::class)
internal constructor(private val carouselState: CarouselState) {
/**
- * [CarouselScope.CarouselSlide] can be used to define a slide's animation, background, and
- * content. Using this is optional and you can choose to define your own CarouselSlide from
+ * [CarouselScope.CarouselItem] can be used to define a item's animation, background, and
+ * content. Using this is optional and you can choose to define your own CarouselItem from
* scratch
*
- * @param modifier modifier applied to the CarouselSlide
- * @param background composable defining the background of the slide
- * @param contentTransformForward content transform to be applied to the content of the slide
+ * @param modifier modifier applied to the CarouselItem
+ * @param background composable defining the background of the item
+ * @param contentTransformStartToEnd content transform to be applied to the content of the item
* when scrolling forward in the carousel
- * @param contentTransformBackward content transform to be applied to the content of the slide
+ * @param contentTransformEndToStart content transform to be applied to the content of the item
* when scrolling backward in the carousel
* @param content composable defining the content displayed on top of the background
*/
@Composable
- @Suppress("IllegalExperimentalApiUsage")
- @OptIn(ExperimentalAnimationApi::class)
@ExperimentalTvMaterial3Api
- fun CarouselSlide(
+ fun CarouselItem(
modifier: Modifier = Modifier,
background: @Composable () -> Unit = {},
- contentTransformForward: ContentTransform =
- CarouselSlideDefaults.contentTransformForward,
- contentTransformBackward: ContentTransform =
- CarouselSlideDefaults.contentTransformBackward,
+ contentTransformStartToEnd: ContentTransform =
+ CarouselItemDefaults.contentTransformStartToEnd,
+ contentTransformEndToStart: ContentTransform =
+ CarouselItemDefaults.contentTransformEndToStart,
content: @Composable () -> Unit
) {
- CarouselSlide(
+ CarouselItem(
background = background,
- slideIndex = carouselState.activeSlideIndex,
+ itemIndex = carouselState.activeItemIndex,
contentTransform =
if (carouselState.isMovingBackward)
- contentTransformBackward
+ contentTransformEndToStart
else
- contentTransformForward,
+ contentTransformStartToEnd,
modifier = modifier,
content = content,
)