Wait for library to load before creating Pager (#7623)

This commit is contained in:
Andreas 2022-07-27 15:00:09 +02:00 committed by GitHub
parent 5bb1133f0f
commit f8d8cf9f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 52 deletions

View File

@ -1,11 +1,13 @@
package eu.kanade.presentation.library package eu.kanade.presentation.library
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import eu.kanade.domain.category.model.Category import eu.kanade.domain.category.model.Category
import eu.kanade.presentation.components.LibraryBottomActionMenu import eu.kanade.presentation.components.LibraryBottomActionMenu
import eu.kanade.presentation.components.LoadingScreen
import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.Scaffold
import eu.kanade.presentation.library.components.LibraryContent import eu.kanade.presentation.library.components.LibraryContent
import eu.kanade.presentation.library.components.LibraryToolbar import eu.kanade.presentation.library.components.LibraryToolbar
@ -28,7 +30,10 @@ fun LibraryScreen(
onClickFilter: () -> Unit, onClickFilter: () -> Unit,
onClickRefresh: (Category?) -> Unit, onClickRefresh: (Category?) -> Unit,
) { ) {
Scaffold( Crossfade(targetState = presenter.isLoading) { state ->
when (state) {
true -> LoadingScreen()
false -> Scaffold(
modifier = Modifier.safeDrawingPadding(), modifier = Modifier.safeDrawingPadding(),
topBar = { topBar = {
val title by presenter.getToolbarTitle() val title by presenter.getToolbarTitle()
@ -73,4 +78,6 @@ fun LibraryScreen(
isDownloadOnly = presenter.isDownloadOnly, isDownloadOnly = presenter.isDownloadOnly,
) )
} }
}
}
} }

View File

@ -14,7 +14,6 @@ import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import eu.kanade.core.prefs.PreferenceMutableState import eu.kanade.core.prefs.PreferenceMutableState
import eu.kanade.domain.category.model.Category import eu.kanade.domain.category.model.Category
import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.EmptyScreen
import eu.kanade.presentation.components.LoadingScreen
import eu.kanade.presentation.components.SwipeRefreshIndicator import eu.kanade.presentation.components.SwipeRefreshIndicator
import eu.kanade.presentation.library.LibraryState import eu.kanade.presentation.library.LibraryState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -44,21 +43,15 @@ fun LibraryContent(
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>, getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
) { ) {
val categories = state.categories val categories = state.categories
val pagerState = rememberPagerState(currentPage.coerceAtMost(categories.lastIndex)) val pagerState = rememberPagerState(currentPage.coerceAtMost(categories.lastIndex))
if (categories.isEmpty()) {
LoadingScreen()
return
}
Column( Column(
modifier = Modifier.padding(contentPadding), modifier = Modifier.padding(contentPadding),
) { ) {
if (showPageTabs && categories.size > 1) { if (showPageTabs && categories.size > 1) {
LibraryTabs( LibraryTabs(
state = pagerState, state = pagerState,
categories = state.categories, categories = categories,
showMangaCount = showMangaCount, showMangaCount = showMangaCount,
getNumberOfMangaForCategory = getNumberOfMangaForCategory, getNumberOfMangaForCategory = getNumberOfMangaForCategory,
isDownloadOnly = isDownloadOnly, isDownloadOnly = isDownloadOnly,