Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.theveloper.pixelplay.presentation.components

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -123,10 +122,7 @@ fun HomeGradientTopBar(

val animatedAlpha by animateFloatAsState(
targetValue = if (isScrolled) 1f else 0f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
),
animationSpec = tween(durationMillis = 300),
label = "topbar_alpha_transition"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -229,8 +230,10 @@ fun HomeScreen(
val weeklyStats by statsViewModel.weeklyOverview.collectAsStateWithLifecycle()

val listState = rememberLazyListState()
val density = LocalDensity.current
val scrollThresholdPx = remember(density) { with(density) { 180.dp.toPx() } }
val isScrolledPastThreshold = remember {
derivedStateOf { listState.firstVisibleItemIndex > 0 || listState.firstVisibleItemScrollOffset > 180 }
derivedStateOf { listState.firstVisibleItemIndex > 0 || listState.firstVisibleItemScrollOffset > scrollThresholdPx }
Comment on lines 235 to +236

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recreate derived scroll state when density changes

isScrolledPastThreshold is created with remember { ... } but reads scrollThresholdPx, so when LocalDensity changes at runtime (for example after display-size/font-scale changes in a live composition), the derived state keeps using the old captured threshold and the top bar transition triggers at the wrong offset until recreation. Key the remember with scrollThresholdPx (or compute threshold inside the derived block) so the threshold actually updates with density.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct.

}

// Drawer state for sidebar
Expand Down
Loading