@@ -2,13 +2,11 @@ package zed.rainxch.home.presentation
22
33import androidx.compose.animation.AnimatedVisibility
44import androidx.compose.animation.animateColorAsState
5- import androidx.compose.animation.core.Spring
6- import androidx.compose.animation.core.spring
75import androidx.compose.animation.core.tween
6+ import androidx.compose.animation.expandVertically
87import androidx.compose.animation.fadeIn
98import androidx.compose.animation.fadeOut
10- import androidx.compose.animation.slideInVertically
11- import androidx.compose.animation.slideOutVertically
9+ import androidx.compose.animation.shrinkVertically
1210import androidx.compose.foundation.Image
1311import androidx.compose.foundation.background
1412import androidx.compose.foundation.clickable
@@ -19,12 +17,14 @@ import androidx.compose.foundation.layout.Column
1917import androidx.compose.foundation.layout.PaddingValues
2018import androidx.compose.foundation.layout.Row
2119import androidx.compose.foundation.layout.Spacer
20+ import androidx.compose.foundation.layout.WindowInsets
2221import androidx.compose.foundation.layout.fillMaxSize
2322import androidx.compose.foundation.layout.fillMaxWidth
2423import androidx.compose.foundation.layout.height
2524import androidx.compose.foundation.layout.padding
2625import androidx.compose.foundation.layout.size
2726import androidx.compose.foundation.layout.width
27+ import androidx.compose.foundation.lazy.LazyColumn
2828import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState
2929import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
3030import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
@@ -85,6 +85,7 @@ import zed.rainxch.core.presentation.locals.LocalBottomNavigationHeight
8585import zed.rainxch.core.presentation.locals.LocalBottomNavigationLiquid
8686import zed.rainxch.core.presentation.theme.GithubStoreTheme
8787import zed.rainxch.core.presentation.utils.ObserveAsEvents
88+ import zed.rainxch.core.presentation.utils.isScrollingUp
8889import zed.rainxch.core.presentation.utils.toIcons
8990import zed.rainxch.core.presentation.utils.toLabel
9091import zed.rainxch.githubstore.core.presentation.res.*
@@ -185,11 +186,9 @@ fun HomeScreen(
185186 }
186187 }
187188
188- val currentOnAction by rememberUpdatedState(onAction)
189-
190189 LaunchedEffect (shouldLoadMore) {
191190 if (shouldLoadMore) {
192- currentOnAction (HomeAction .LoadMore )
191+ onAction (HomeAction .LoadMore )
193192 }
194193 }
195194
@@ -227,20 +226,16 @@ fun HomeScreen(
227226 ) {
228227 AnimatedVisibility (
229228 visible = isHeaderVisible,
230- enter = slideInVertically(
231- initialOffsetY = { - it },
232- animationSpec = spring(
233- dampingRatio = Spring .DampingRatioNoBouncy ,
234- stiffness = Spring .StiffnessMediumLow ,
235- ),
236- ) + fadeIn(tween(200 )),
237- exit = slideOutVertically(
238- targetOffsetY = { - it },
239- animationSpec = spring(
240- dampingRatio = Spring .DampingRatioNoBouncy ,
241- stiffness = Spring .StiffnessMediumLow ,
242- ),
243- ) + fadeOut(tween(150 )),
229+ enter =
230+ expandVertically(
231+ expandFrom = Alignment .Top ,
232+ animationSpec = tween(250 ),
233+ ) + fadeIn(tween(200 )),
234+ exit =
235+ shrinkVertically(
236+ shrinkTowards = Alignment .Top ,
237+ animationSpec = tween(200 ),
238+ ) + fadeOut(tween(150 )),
244239 ) {
245240 Column {
246241 HomeTopAppBar (
@@ -340,20 +335,22 @@ private fun TopicChips(
340335 modifier = Modifier .size(18 .dp),
341336 )
342337 },
343- colors = FilterChipDefaults .filterChipColors(
344- containerColor = containerColor,
345- labelColor = labelColor,
346- iconColor = labelColor,
347- selectedContainerColor = containerColor,
348- selectedLabelColor = labelColor,
349- selectedLeadingIconColor = labelColor,
350- ),
351- border = FilterChipDefaults .filterChipBorder(
352- borderColor = Color .Transparent ,
353- selectedBorderColor = Color .Transparent ,
354- enabled = true ,
355- selected = isSelected,
356- ),
338+ colors =
339+ FilterChipDefaults .filterChipColors(
340+ containerColor = containerColor,
341+ labelColor = labelColor,
342+ iconColor = labelColor,
343+ selectedContainerColor = containerColor,
344+ selectedLabelColor = labelColor,
345+ selectedLeadingIconColor = labelColor,
346+ ),
347+ border =
348+ FilterChipDefaults .filterChipBorder(
349+ borderColor = Color .Transparent ,
350+ selectedBorderColor = Color .Transparent ,
351+ enabled = true ,
352+ selected = isSelected,
353+ ),
357354 shape = RoundedCornerShape (12 .dp),
358355 )
359356 }
@@ -604,6 +601,8 @@ private fun HomeTopAppBar(
604601 }
605602 },
606603 modifier = Modifier .padding(12 .dp),
604+ contentPadding = PaddingValues (),
605+ windowInsets = WindowInsets (),
607606 )
608607}
609608
@@ -663,31 +662,6 @@ private fun PlatformsPopup(
663662 }
664663}
665664
666- /* *
667- * Tracks scroll direction — returns true when the user is scrolling up
668- * (or is at the very top of the list), false when scrolling down.
669- */
670- @Composable
671- private fun LazyStaggeredGridState.isScrollingUp (): State <Boolean > {
672- var previousIndex by remember(this ) { mutableIntStateOf(firstVisibleItemIndex) }
673- var previousScrollOffset by remember(this ) { mutableIntStateOf(firstVisibleItemScrollOffset) }
674-
675- return remember(this ) {
676- derivedStateOf {
677- if (firstVisibleItemIndex == 0 && firstVisibleItemScrollOffset == 0 ) {
678- true // at the very top — always show header
679- } else if (previousIndex != firstVisibleItemIndex) {
680- previousIndex > firstVisibleItemIndex
681- } else {
682- previousScrollOffset >= firstVisibleItemScrollOffset
683- }.also {
684- previousIndex = firstVisibleItemIndex
685- previousScrollOffset = firstVisibleItemScrollOffset
686- }
687- }
688- }
689- }
690-
691665@Preview
692666@Composable
693667private fun Preview () {
0 commit comments