Skip to content

Commit

Permalink
Upgrade core compose version to 1.7.0-beta01 and remove tv-foundation…
Browse files Browse the repository at this point in the history
… from the dependencies as a result of the update
  • Loading branch information
chikoski committed May 16, 2024
1 parent 95bad32 commit 7ece945
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 112 deletions.
17 changes: 9 additions & 8 deletions JetStreamCompose/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ android-test-plugin = "8.4.0"
benchmark-macro-junit4 = "1.2.4"
coil-compose = "2.6.0"
compose-bom = "2024.05.00"
tv-foundation = "1.0.0-alpha10"
compose-foundation = "1.7.0-beta01"
compose-ui = "1.7.0-beta01"
tv-material = "1.0.0-beta01"
core-ktx = "1.13.1"
core-splashscreen = "1.0.1"
hilt-navigation-compose = "1.2.0"
hilt-android = "2.51.1"
junit = "1.1.5"
kotlin-android = "1.9.23"
kotlin-android = "1.9.24"
kotlinx-serialization = "1.6.0"
ksp = "1.9.23-1.0.20"
lifecycle-runtime-ktx = "2.7.0"
ksp = "1.9.24-1.0.20"
lifecycle-runtime-ktx = "2.8.0"
media3-ui = "1.3.1"
media3-exoplayer = "1.3.1"
navigation-compose = "2.7.7"
Expand All @@ -26,9 +27,10 @@ uiautomator = "2.3.0"
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" }
androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "benchmark-macro-junit4" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "compose-bom" }
androidx-compose-ui-base = { module = "androidx.compose.ui:ui" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
androidx-compose-foundation-base = { module = "androidx.compose.foundation:foundation", version.ref = "compose-foundation"}
androidx-compose-ui-base = { module = "androidx.compose.ui:ui", version.ref = "compose-ui" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose-ui" }
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose-ui" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "core-splashscreen" }
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hilt-navigation-compose" }
Expand All @@ -41,7 +43,6 @@ androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "medi
androidx-media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3-exoplayer" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation-compose" }
androidx-profileinstaller = { module = "androidx.profileinstaller:profileinstaller", version.ref = "profileinstaller" }
androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "tv-foundation" }
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "tv-material" }
androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "uiautomator" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" }
Expand Down
8 changes: 5 additions & 3 deletions JetStreamCompose/jetstream/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ android {
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.13"
kotlinCompilerExtensionVersion = "1.5.14"
}
packaging {
resources {
Expand All @@ -90,11 +90,13 @@ dependencies {
implementation(libs.androidx.compose.ui.base)
implementation(libs.androidx.compose.ui.tooling.preview)

// Compose foundation library to replace tv-foundation
implementation(libs.androidx.compose.foundation.base)

// extra material icons
implementation(libs.androidx.material.icons.extended)

// TV Compose
implementation(libs.androidx.tv.foundation)
// Material components optimized for TV apps
implementation(libs.androidx.tv.material)

// ViewModel in Compose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -38,6 +40,7 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
Expand All @@ -49,9 +52,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.foundation.PivotOffsets
import androidx.tv.foundation.lazy.list.TvLazyRow
import androidx.tv.foundation.lazy.list.itemsIndexed
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.google.jetstream.data.entities.Movie
Expand Down Expand Up @@ -99,10 +99,9 @@ fun MoviesRow(
) { movieState ->
val focusRestorerModifiers = createInitialFocusRestorerModifiers()

TvLazyRow(
LazyRow(
modifier = Modifier
.then(focusRestorerModifiers.parentModifier),
pivotOffsets = PivotOffsets(parentFraction = 0.07f),
contentPadding = PaddingValues(
start = startPadding,
end = endPadding,
Expand Down Expand Up @@ -165,9 +164,8 @@ fun ImmersiveListMoviesRow(
targetState = movieList,
label = "",
) { movieState ->
TvLazyRow(
// modifier = Modifier.focusRestorer(),
pivotOffsets = PivotOffsets(parentFraction = 0.07f),
LazyRow(
modifier = Modifier.focusRestorer(),
contentPadding = PaddingValues(start = startPadding, end = endPadding),
horizontalArrangement = Arrangement.spacedBy(20.dp)
) {
Expand All @@ -194,7 +192,6 @@ fun ImmersiveListMoviesRow(
}

@Composable
@OptIn(ExperimentalComposeUiApi::class)
private fun MoviesRowItem(
index: Int,
movie: Movie,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand All @@ -40,10 +44,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.grid.TvGridCells
import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid
import androidx.tv.foundation.lazy.grid.itemsIndexed
import androidx.tv.foundation.lazy.grid.rememberTvLazyGridState
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.google.jetstream.data.entities.MovieCategoryList
Expand Down Expand Up @@ -89,11 +89,11 @@ private fun Catalog(
onScroll: (isTopBarVisible: Boolean) -> Unit,
) {
val childPadding = rememberChildPadding()
val tvLazyGridState = rememberTvLazyGridState()
val lazyGridState = rememberLazyGridState()
val shouldShowTopBar by remember {
derivedStateOf {
tvLazyGridState.firstVisibleItemIndex == 0 &&
tvLazyGridState.firstVisibleItemScrollOffset < 100
lazyGridState.firstVisibleItemIndex == 0 &&
lazyGridState.firstVisibleItemScrollOffset < 100
}
}
LaunchedEffect(shouldShowTopBar) {
Expand All @@ -107,10 +107,10 @@ private fun Catalog(
.padding(top = childPadding.top),
label = "",
) { it ->
TvLazyVerticalGrid(
state = tvLazyGridState,
LazyVerticalGrid(
state = lazyGridState,
modifier = modifier,
columns = TvGridCells.Fixed(gridColumns),
columns = GridCells.Fixed(gridColumns),
) {
itemsIndexed(it) { index, movieCategory ->
var isFocused by remember { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -32,9 +35,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.grid.TvGridCells
import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid
import androidx.tv.foundation.lazy.grid.itemsIndexed
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.google.jetstream.data.entities.Movie
Expand Down Expand Up @@ -104,8 +104,8 @@ private fun CategoryDetails(
vertical = childPadding.top.times(3.5f)
)
)
TvLazyVerticalGrid(
columns = TvGridCells.Fixed(6),
LazyVerticalGrid(
columns = GridCells.Fixed(6),
contentPadding = PaddingValues(bottom = JetStreamBottomListPadding)
) {
itemsIndexed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand All @@ -30,7 +31,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.grid.rememberTvLazyGridState
import com.google.jetstream.data.entities.MovieList
import com.google.jetstream.presentation.common.Loading
import com.google.jetstream.presentation.screens.dashboard.rememberChildPadding
Expand Down Expand Up @@ -74,7 +74,7 @@ private fun Catalog(
modifier: Modifier = Modifier,
) {
val childPadding = rememberChildPadding()
val filteredMoviesGridState = rememberTvLazyGridState()
val filteredMoviesGridState = rememberLazyGridState()
val shouldShowTopBar by remember {
derivedStateOf {
filteredMoviesGridState.firstVisibleItemIndex == 0 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.grid.TvGridCells
import androidx.tv.foundation.lazy.grid.TvLazyGridState
import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid
import androidx.tv.foundation.lazy.grid.items
import com.google.jetstream.data.entities.MovieList
import com.google.jetstream.presentation.common.MovieCard
import com.google.jetstream.presentation.common.PosterImage
import com.google.jetstream.presentation.theme.JetStreamBottomListPadding

@Composable
fun FilteredMoviesGrid(
state: TvLazyGridState,
state: LazyGridState,
movieList: MovieList,
onMovieClick: (movieId: String) -> Unit,
) {
TvLazyVerticalGrid(
LazyVerticalGrid(
state = state,
modifier = Modifier.fillMaxSize(),
columns = TvGridCells.Fixed(6),
columns = GridCells.Fixed(6),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(bottom = JetStreamBottomListPadding),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand All @@ -33,9 +35,6 @@ import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.PivotOffsets
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.foundation.lazy.list.rememberTvLazyListState
import com.google.jetstream.data.entities.Movie
import com.google.jetstream.data.entities.MovieList
import com.google.jetstream.data.util.StringConstants
Expand Down Expand Up @@ -87,33 +86,31 @@ private fun Catalog(
isTopBarVisible: Boolean = true,
) {

val tvLazyListState = rememberTvLazyListState()
val lazyListState = rememberLazyListState()
val childPadding = rememberChildPadding()
val pivotOffset = remember { PivotOffsets() }
val pivotOffsetForImmersiveList = remember { PivotOffsets(0f, 0f) }
var immersiveListHasFocus by remember { mutableStateOf(false) }

val shouldShowTopBar by remember {
derivedStateOf {
tvLazyListState.firstVisibleItemIndex == 0 &&
tvLazyListState.firstVisibleItemScrollOffset < 300
lazyListState.firstVisibleItemIndex == 0 &&
lazyListState.firstVisibleItemScrollOffset < 300
}
}

LaunchedEffect(shouldShowTopBar) {
onScroll(shouldShowTopBar)
}
LaunchedEffect(isTopBarVisible) {
if (isTopBarVisible) tvLazyListState.animateScrollToItem(0)
if (isTopBarVisible) lazyListState.animateScrollToItem(0)
}

TvLazyColumn(
pivotOffsets = if (immersiveListHasFocus) pivotOffsetForImmersiveList else pivotOffset,
state = tvLazyListState,
LazyColumn(
state = lazyListState,
contentPadding = PaddingValues(bottom = 108.dp),
// Setting overscan margin to bottom to ensure the last row's visibility
modifier = modifier
modifier = modifier,
) {

item(contentType = "FeaturedMoviesCarousel") {
FeaturedMoviesCarousel(
movies = featuredMovies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand All @@ -35,9 +37,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.foundation.PivotOffsets
import androidx.tv.foundation.lazy.list.TvLazyRow
import androidx.tv.foundation.lazy.list.items
import androidx.tv.material3.Border
import androidx.tv.material3.CardDefaults
import androidx.tv.material3.ClassicCard
Expand Down Expand Up @@ -66,13 +65,11 @@ fun CastAndCrewList(castAndCrew: List<MovieCast>) {
),
modifier = Modifier.padding(start = childPadding.start)
)
TvLazyRow(
// ToDo: specify the pivot offset
LazyRow(
modifier = Modifier
.padding(top = 16.dp)
.focusRestorer(),
pivotOffsets = PivotOffsets(
parentFraction = 0.07f
),
contentPadding = PaddingValues(start = childPadding.start)
) {
items(castAndCrew, key = { it.id }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
Expand All @@ -36,7 +37,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.material3.MaterialTheme
import com.google.jetstream.R
import com.google.jetstream.data.entities.Movie
Expand Down Expand Up @@ -94,7 +94,7 @@ private fun Details(
val childPadding = rememberChildPadding()

BackHandler(onBack = onBackPressed)
TvLazyColumn(
LazyColumn(
contentPadding = PaddingValues(bottom = 135.dp),
modifier = modifier,
) {
Expand Down
Loading

0 comments on commit 7ece945

Please sign in to comment.