Skip to content

Commit

Permalink
improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 25, 2024
1 parent 9ea4d3f commit 352c1df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,14 @@ import dev.datlag.aniflow.ui.theme.rememberSchemeThemeDominantColorState
@Composable
fun MediumCard(
medium: Medium,
isHighlighted: Boolean,
modifier: Modifier = Modifier,
onClick: (Medium) -> Unit
) {
val scale by animateFloatAsState(
targetValue = if (isHighlighted) 1F else 0.95F,
animationSpec = tween()
)

SchemeTheme(
key = medium.id
) {
Card(
modifier = modifier.scale(scale),
modifier = modifier,
onClick = {
onClick(medium)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,16 @@ private fun SuccessContent(
StateSaver.List.Home.popularNextOverviewOffset
},
)
var highlightedItem by remember { mutableIntStateOf(0) }

LaunchedEffect(listState) {
snapshotFlow {
val layoutInfo = listState.layoutInfo
layoutInfo.visibleItemsInfo
.firstOrNull { it.offset >= layoutInfo.viewportStartOffset }
?.index ?: 0
}.distinctUntilChanged().collect {
highlightedItem = it
}
}

LazyRow(
state = listState,
modifier = Modifier.fillMaxSize(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(horizontal = 16.dp)
) {
itemsIndexed(data, key = { _, it -> it.id }) {index, medium ->
itemsIndexed(data, key = { _, it -> it.id }) { _, medium ->
MediumCard(
medium = Medium(medium),
isHighlighted = index == highlightedItem,
modifier = Modifier.width(200.dp).height(280.dp),
onClick = onClick
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,16 @@ private fun SuccessContent(
initialFirstVisibleItemIndex = StateSaver.List.Home.trendingOverview,
initialFirstVisibleItemScrollOffset = StateSaver.List.Home.trendingOverviewOffset
)
var highlightedItem by remember { mutableIntStateOf(0) }

LaunchedEffect(listState) {
snapshotFlow {
val layoutInfo = listState.layoutInfo
layoutInfo.visibleItemsInfo
.firstOrNull { it.offset >= layoutInfo.viewportStartOffset }
?.index ?: 0
}.distinctUntilChanged().collect {
highlightedItem = it
}
}

LazyRow(
state = listState,
modifier = Modifier.fillMaxSize(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(horizontal = 16.dp)
) {
itemsIndexed(data, key = { _, it -> it.id }) {index, medium ->
itemsIndexed(data, key = { _, it -> it.id }) { _, medium ->
MediumCard(
medium = Medium(medium),
isHighlighted = index == highlightedItem,
modifier = Modifier.width(200.dp).height(280.dp),
onClick = onClick
)
Expand Down

0 comments on commit 352c1df

Please sign in to comment.