From d94f4cf639c92d488cb873eef457686ef756782f Mon Sep 17 00:00:00 2001 From: DatLag Date: Wed, 22 May 2024 00:26:04 +0200 Subject: [PATCH] fix all loading not shown --- .../dev/datlag/aniflow/other/StateSaver.kt | 16 +++- .../ui/navigation/screen/home/HomeScreen.kt | 92 ++++++++++--------- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt index 5a9f699..abfe019 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt @@ -72,22 +72,30 @@ data object StateSaver { }.flowOn(ioDispatcher()).distinctUntilChanged() fun updateAiring(state: HomeAiringState): HomeAiringState { - airingLoading.update { false } + if (!state.isLoading) { + airingLoading.update { false } + } return state } fun updateTrending(state: HomeDefaultState): HomeDefaultState { - trendingLoading.update { false } + if (!state.isLoading) { + trendingLoading.update { false } + } return state } fun updatePopularCurrent(state: HomeDefaultState): HomeDefaultState { - popularCurrentLoading.update { false } + if (!state.isLoading) { + popularCurrentLoading.update { false } + } return state } fun updatePopularNext(state: HomeDefaultState): HomeDefaultState { - popularNextLoading.update { false } + if (!state.isLoading) { + popularNextLoading.update { false } + } return state } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt index 0edcc81..c49bc0e 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt @@ -6,9 +6,11 @@ import androidx.compose.animation.core.LinearOutSlowInEasing import androidx.compose.animation.core.tween import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically +import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.CameraEnhance import androidx.compose.material.icons.rounded.GetApp @@ -17,6 +19,7 @@ import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalDensity @@ -173,62 +176,67 @@ fun HomeScreen(component: HomeComponent) { onFavorites = component::viewFavorites ) } - ) { - CompositionLocalProvider( - LocalPaddingValues provides it - ) { - AllLoadingView( - loadingContent = { + ) { targetPadding -> + val smoothPadding by animatePaddingAsState(targetPadding) + AllLoadingView( + loadingContent = { + Box( + modifier = Modifier.padding(smoothPadding).fillMaxSize().background(MaterialTheme.colorScheme.background), + contentAlignment = Alignment.Center + ) { + LinearProgressIndicator( + modifier = Modifier.fillMaxWidth(fraction = 0.2F).clip(CircleShape) + ) } - ) { - val viewType by component.viewing.collectAsStateWithLifecycle(MediaType.UNKNOWN__) - val isManga = remember(viewType) { - viewType == MediaType.MANGA - } - val titleLanguage by component.titleLanguage.collectAsStateWithLifecycle(null) + } + ) { + val viewType by component.viewing.collectAsStateWithLifecycle(MediaType.UNKNOWN__) + val isManga = remember(viewType) { + viewType == MediaType.MANGA + } + val titleLanguage by component.titleLanguage.collectAsStateWithLifecycle(null) - LazyColumn( - state = listState, - modifier = Modifier.fillMaxSize().haze(state = LocalHaze.current), - verticalArrangement = Arrangement.spacedBy(32.dp), - contentPadding = LocalPadding(vertical = 16.dp) - ) { - if (!isManga) { - item { - ScheduleOverview( - flow = component.airing, - titleLanguage = titleLanguage, - onMediumClick = component::details - ) - } - } + LazyColumn( + state = listState, + modifier = Modifier.fillMaxSize().haze(state = LocalHaze.current), + verticalArrangement = Arrangement.spacedBy(32.dp), + contentPadding = smoothPadding.plus(PaddingValues(vertical = 16.dp)) + ) { + if (!isManga) { item { - DefaultOverview( - title = stringResource(SharedRes.strings.trending), - flow = component.trending, + ScheduleOverview( + flow = component.airing, titleLanguage = titleLanguage, onMediumClick = component::details ) } + } + item { + DefaultOverview( + title = stringResource(SharedRes.strings.trending), + flow = component.trending, + titleLanguage = titleLanguage, + onMediumClick = component::details + ) + } + item { + DefaultOverview( + title = stringResource(SharedRes.strings.popular), + flow = component.popularNow, + titleLanguage = titleLanguage, + onMediumClick = component::details + ) + } + if (!isManga) { item { DefaultOverview( - title = stringResource(SharedRes.strings.popular), - flow = component.popularNow, + title = stringResource(SharedRes.strings.upcoming), + flow = component.popularNext, titleLanguage = titleLanguage, onMediumClick = component::details ) } - if (!isManga) { - item { - DefaultOverview( - title = stringResource(SharedRes.strings.upcoming), - flow = component.popularNext, - titleLanguage = titleLanguage, - onMediumClick = component::details - ) - } - } } } }