@@ -2,7 +2,6 @@ package dev.dimension.flare.ui.screen.home
22
33import androidx.compose.animation.AnimatedVisibility
44import androidx.compose.animation.ExperimentalSharedTransitionApi
5- import androidx.compose.animation.animateColorAsState
65import androidx.compose.animation.slideInVertically
76import androidx.compose.animation.slideOutVertically
87import androidx.compose.foundation.layout.Arrangement
@@ -50,13 +49,15 @@ import androidx.compose.material3.VerticalDivider
5049import androidx.compose.runtime.Composable
5150import androidx.compose.runtime.CompositionLocalProvider
5251import androidx.compose.runtime.LaunchedEffect
52+ import androidx.compose.runtime.derivedStateOf
5353import androidx.compose.runtime.getValue
5454import androidx.compose.runtime.mutableStateListOf
5555import androidx.compose.runtime.remember
5656import androidx.compose.runtime.rememberCoroutineScope
5757import androidx.compose.ui.Alignment
5858import androidx.compose.ui.Modifier
5959import androidx.compose.ui.graphics.Color
60+ import androidx.compose.ui.graphics.lerp
6061import androidx.compose.ui.input.nestedscroll.nestedScroll
6162import androidx.compose.ui.platform.LocalContext
6263import androidx.compose.ui.platform.LocalLayoutDirection
@@ -97,7 +98,6 @@ import dev.dimension.flare.ui.model.onError
9798import dev.dimension.flare.ui.model.onLoading
9899import dev.dimension.flare.ui.model.onSuccess
99100import dev.dimension.flare.ui.model.takeSuccess
100- import dev.dimension.flare.ui.model.takeSuccessOr
101101import dev.dimension.flare.ui.presenter.HomeTimelineWithTabsPresenter
102102import dev.dimension.flare.ui.presenter.home.DeepLinkPresenter
103103import dev.dimension.flare.ui.presenter.home.LoggedInPresenter
@@ -222,30 +222,47 @@ internal fun HomeTimelineScreen(
222222 } else {
223223 TopAppBarDefaults .enterAlwaysScrollBehavior()
224224 }
225- val appearance = LocalTimelineAppearance .current
226- val displayMode =
227- remember(
228- state.tabState,
229- state.pagerState.takeSuccess()?.currentPage,
230- appearance,
231- ) {
232- state.tabState
233- .map {
234- it
235- .getOrNull(state.pagerState.takeSuccess()?.currentPage ? : 0 )
236- ?.resolveTimelineAppearance(appearance)
237- ?.timelineDisplayMode ? : TimelineDisplayMode .Plain
238- }.takeSuccessOr(TimelineDisplayMode .Plain )
239- }
240- val color by animateColorAsState(
241- when (displayMode) {
242- TimelineDisplayMode .Plain if isLightTheme() && isCompatScreen() -> MaterialTheme .colorScheme.surface
243- else -> MaterialTheme .colorScheme.background
244- },
245- label = " TopAppBarBackground" ,
246- )
247225 FlareScaffold (
248226 topBar = {
227+ val appearance = LocalTimelineAppearance .current
228+ val backgroundColor = MaterialTheme .colorScheme.background
229+ val plainColor =
230+ if (isLightTheme() && isCompatScreen()) {
231+ MaterialTheme .colorScheme.surface
232+ } else {
233+ backgroundColor
234+ }
235+ val tabs = state.tabState.takeSuccess()
236+ val tabBackgroundColors =
237+ remember(tabs, appearance, plainColor, backgroundColor) {
238+ tabs
239+ ?.map { tab ->
240+ when (tab.resolveTimelineAppearance(appearance).timelineDisplayMode) {
241+ TimelineDisplayMode .Plain -> plainColor
242+ else -> backgroundColor
243+ }
244+ }.orEmpty()
245+ }
246+ val pagerState = state.pagerState.takeSuccess()
247+ val color by remember(pagerState, tabBackgroundColors, backgroundColor) {
248+ derivedStateOf {
249+ if (pagerState == null || tabBackgroundColors.isEmpty()) {
250+ backgroundColor
251+ } else {
252+ val pagePosition =
253+ (pagerState.currentPage + pagerState.currentPageOffsetFraction)
254+ .coerceIn(0f , tabBackgroundColors.lastIndex.toFloat())
255+ val startIndex = pagePosition.toInt().coerceIn(0 , tabBackgroundColors.lastIndex)
256+ val endIndex = (startIndex + 1 ).coerceAtMost(tabBackgroundColors.lastIndex)
257+ val fraction = (pagePosition - startIndex).coerceIn(0f , 1f )
258+ lerp(
259+ tabBackgroundColors[startIndex],
260+ tabBackgroundColors[endIndex],
261+ fraction,
262+ )
263+ }
264+ }
265+ }
249266 FlareTopAppBar (
250267 colors =
251268 TopAppBarDefaults .topAppBarColors(
0 commit comments