Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
Refactor to new Compose APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes authored and renovate[bot] committed Oct 16, 2024
1 parent 41c168b commit 33dae30
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package app.tivi.common.compose

import androidx.compose.animation.Crossfade
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -80,7 +79,6 @@ import kotlin.math.roundToInt
import org.jetbrains.compose.resources.stringResource

@OptIn(
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class,
)
@Composable
Expand Down Expand Up @@ -190,7 +188,7 @@ fun <E : Entry> EntryGrid(
entry = entry.entry,
onClick = onClick,
modifier = Modifier
.animateItemPlacement()
.animateItem()
.fillMaxWidth(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@

package app.tivi.common.compose

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.snapping.SnapFlingBehavior
import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider
import androidx.compose.foundation.gestures.snapping.SnapPositionInLayout
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridItemScope
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridScope
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp

Expand Down Expand Up @@ -91,24 +84,3 @@ inline fun LazyStaggeredGridScope.fullSpanItem(
content = content,
)
}

@ExperimentalFoundationApi
private val startToStart = SnapPositionInLayout { _, _, _, _, _ -> 0 }

@ExperimentalFoundationApi
val SnapPositionInLayout.Companion.StartToStart: SnapPositionInLayout
get() = startToStart

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun rememberSnapFlingBehavior(
lazyListState: LazyListState,
position: SnapPositionInLayout,
): SnapFlingBehavior = rememberSnapFlingBehavior(
snapLayoutInfoProvider = remember(lazyListState) {
SnapLayoutInfoProvider(
lazyListState = lazyListState,
positionInLayout = position,
)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ actual fun Paywall(
sheetState = sheetState,
onDismissRequest = onDismissRequest,
dragHandle = null,
windowInsets = BottomSheetDefaults.windowInsets.only(WindowInsetsSides.Top),
contentWindowInsets = { BottomSheetDefaults.windowInsets.only(WindowInsetsSides.Top) },
modifier = modifier,
) {
Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ package app.tivi.home.discover

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.snapping.SnapPositionInLayout
import androidx.compose.foundation.gestures.snapping.SnapPosition
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -67,9 +68,7 @@ import app.tivi.common.compose.Layout
import app.tivi.common.compose.LocalTiviTextCreator
import app.tivi.common.compose.LocalWindowSizeClass
import app.tivi.common.compose.ReportDrawnWhen
import app.tivi.common.compose.StartToStart
import app.tivi.common.compose.bodyWidth
import app.tivi.common.compose.rememberSnapFlingBehavior
import app.tivi.common.compose.theme.shouldUseDarkColors
import app.tivi.common.compose.ui.AsyncImage
import app.tivi.common.compose.ui.AutoSizedCircularProgressIndicator
Expand Down Expand Up @@ -258,10 +257,7 @@ internal fun Discover(
vertical = Layout.gutter,
),
horizontalArrangement = Arrangement.spacedBy(12.dp),
flingBehavior = rememberSnapFlingBehavior(
carouselState,
SnapPositionInLayout.StartToStart,
),
flingBehavior = rememberSnapFlingBehavior(carouselState, SnapPosition.Start),
) {
items(
items = state.nextEpisodesToWatch,
Expand All @@ -273,7 +269,7 @@ internal fun Discover(
episode = item.episode,
onClick = { openEpisodeDetails(item.episode.id) },
modifier = Modifier
.animateItemPlacement()
.animateItem()
.width(260.dp),
)
}
Expand All @@ -288,7 +284,7 @@ internal fun Discover(
refreshing = state.trendingRefreshing,
onItemClick = { openShowDetails(it.id) },
onMoreClick = openTrendingShows,
modifier = Modifier.animateItemPlacement(),
modifier = Modifier.animateItem(),
)
}

Expand All @@ -300,7 +296,7 @@ internal fun Discover(
refreshing = state.popularRefreshing,
onItemClick = { openShowDetails(it.id) },
onMoreClick = openPopularShows,
modifier = Modifier.animateItemPlacement(),
modifier = Modifier.animateItem(),
)
}

Expand All @@ -312,7 +308,7 @@ internal fun Discover(
refreshing = state.anticipatedRefreshing,
onItemClick = { openShowDetails(it.id) },
onMoreClick = openAnticipatedShows,
modifier = Modifier.animateItemPlacement(),
modifier = Modifier.animateItem(),
)
}

Expand All @@ -324,7 +320,7 @@ internal fun Discover(
refreshing = state.recommendedRefreshing,
onItemClick = { openShowDetails(it.id) },
onMoreClick = openRecommendedShows,
modifier = Modifier.animateItemPlacement(),
modifier = Modifier.animateItem(),
)
}

Expand Down Expand Up @@ -492,7 +488,7 @@ private fun <T : EntryWithShow<*>> EntryShowCarousel(
modifier = modifier
.padding(horizontal = Layout.bodyMargin, vertical = Layout.gutter)
.clip(MaterialTheme.shapes.extraLarge),
flingBehavior = rememberSnapFlingBehavior(lazyListState, SnapPositionInLayout.StartToStart),
flingBehavior = rememberSnapFlingBehavior(lazyListState, SnapPosition.Start),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
items(
Expand All @@ -517,7 +513,7 @@ private fun <T : EntryWithShow<*>> EntryShowCarousel(
},
modifier = Modifier
.testTag("${tagPrefix}_carousel_item")
.animateItemPlacement()
.animateItem()
.width(
when (LocalWindowSizeClass.current.widthSizeClass) {
WindowWidthSizeClass.Expanded -> 320.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private fun LibraryGrid(
onClick = { openShowDetails(entry.show.id) },
contentPadding = PaddingValues(8.dp),
modifier = Modifier
.animateItemPlacement()
.animateItem()
.fillMaxWidth(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private fun SearchList(
SearchRow(
show = show,
modifier = Modifier
.animateItemPlacement()
.animateItem()
.fillMaxWidth()
.clickable { onShowClicked(show) },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.snapping.SnapPositionInLayout
import androidx.compose.foundation.gestures.snapping.SnapPosition
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -88,11 +89,9 @@ import androidx.compose.ui.unit.sp
import app.tivi.common.compose.HazeScaffold
import app.tivi.common.compose.Layout
import app.tivi.common.compose.LocalTiviTextCreator
import app.tivi.common.compose.StartToStart
import app.tivi.common.compose.bodyWidth
import app.tivi.common.compose.gutterSpacer
import app.tivi.common.compose.itemSpacer
import app.tivi.common.compose.rememberSnapFlingBehavior
import app.tivi.common.compose.ui.ArrowBackForPlatform
import app.tivi.common.compose.ui.AsyncImage
import app.tivi.common.compose.ui.Backdrop
Expand Down Expand Up @@ -699,7 +698,7 @@ private fun RelatedShows(
LazyRow(
state = lazyListState,
modifier = modifier,
flingBehavior = rememberSnapFlingBehavior(lazyListState, SnapPositionInLayout.StartToStart),
flingBehavior = rememberSnapFlingBehavior(lazyListState, SnapPosition.Start),
contentPadding = contentPadding,
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
Expand All @@ -711,7 +710,7 @@ private fun RelatedShows(
show = item.show,
onClick = { openShowDetails(item.show.id) },
modifier = Modifier
.animateItemPlacement()
.animateItem()
.fillParentMaxWidth(0.21f) // 21% of the available width
.aspectRatio(2 / 3f),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ internal fun UpNext(
SwipeUpNextItem(
onSwipe = { openTrackEpisode(entry.episode.id) },
modifier = Modifier
.animateItemPlacement()
.animateItem()
.fillMaxWidth(),
) {
UpNextItem(
Expand Down

0 comments on commit 33dae30

Please sign in to comment.