Fix derivedStateOf errors (#8008)

(cherry picked from commit 6865c21c75b67708b26cc78d68747945ea206641)

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
This commit is contained in:
Ivan Iskandar 2022-09-14 22:36:13 +07:00 committed by Jobobby04
parent 2f458fec9f
commit 897651a75a
5 changed files with 20 additions and 26 deletions

View File

@ -88,7 +88,9 @@ fun LibraryScreen(
onRefresh = onClickRefresh,
onGlobalSearchClicked = onGlobalSearchClicked,
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
// SY -->
getDisplayModeForPage = { presenter.getDisplayMode(index = it) },
// SY <--
getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
getLibraryForPage = { presenter.getMangaForCategory(page = it) },
isIncognitoMode = presenter.isIncognitoMode,

View File

@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -48,9 +47,9 @@ fun LibraryContent(
onRefresh: (Category?) -> Boolean,
onGlobalSearchClicked: () -> Unit,
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
getDisplayModeForPage: @Composable (Int) -> State<LibraryDisplayMode>,
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
// SY -->
onOpenReader: (LibraryManga) -> Unit,
getCategoryName: (Context, Category, Int, String) -> String,
@ -77,9 +76,9 @@ fun LibraryContent(
// SY -->
getCategoryName = { category, name ->
val context = LocalContext.current
derivedStateOf {
remember(context, category, state.groupType, name) {
getCategoryName(context, category, state.groupType, name)
}.value
}
},
// SY <--
)

View File

@ -3,7 +3,6 @@ package eu.kanade.presentation.library.components
import android.content.res.Configuration
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -24,9 +23,9 @@ fun LibraryPager(
selectedManga: List<LibraryManga>,
searchQuery: String?,
onGlobalSearchClicked: () -> Unit,
getDisplayModeForPage: @Composable (Int) -> State<LibraryDisplayMode>,
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
onClickManga: (LibraryManga) -> Unit,
onLongClickManga: (LibraryManga) -> Unit,
// SY -->
@ -43,8 +42,8 @@ fun LibraryPager(
// To make sure only one offscreen page is being composed
return@HorizontalPager
}
val library by getLibraryForPage(page)
val displayMode by getDisplayModeForPage(page)
val library = getLibraryForPage(page)
val displayMode = getDisplayModeForPage(page)
val columns by if (displayMode != LibraryDisplayMode.List) {
val configuration = LocalConfiguration.current
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE

View File

@ -962,13 +962,13 @@ class LibraryPresenter(
// SY -->
@Composable
fun getMangaForCategory(page: Int): androidx.compose.runtime.State<List<LibraryItem>> {
val categoryId = remember(categories) {
categories.getOrNull(page)?.id ?: -1
fun getMangaForCategory(page: Int): List<LibraryItem> {
val unfiltered = remember(categories, loadedManga) {
val categoryId = categories.getOrNull(page)?.id ?: -1
loadedManga[categoryId] ?: emptyList()
}
val unfiltered = loadedManga[categoryId] ?: emptyList()
return produceState(initialValue = unfiltered, unfiltered, searchQuery) {
val items = produceState(initialValue = unfiltered, unfiltered, searchQuery) {
val query = searchQuery
value = withIOContext {
if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) {
@ -1023,6 +1023,8 @@ class LibraryPresenter(
}
}
}
return items.value
}
private fun filterManga(
@ -1114,9 +1116,9 @@ class LibraryPresenter(
// SY <--
@Composable
fun getDisplayMode(index: Int): androidx.compose.runtime.State<LibraryDisplayMode> {
fun getDisplayMode(index: Int): LibraryDisplayMode {
val category = categories[index]
return derivedStateOf {
return remember(groupType, libraryDisplayMode, category) {
// SY -->
if (groupType != LibraryGroup.BY_DEFAULT) {
libraryDisplayMode

View File

@ -11,7 +11,6 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -158,13 +157,6 @@ class MangaController : FullComposeController<MangaPresenter> {
return
}
val dialog by derivedStateOf {
when (val state = state) {
MangaScreenState.Loading -> null
is MangaScreenState.Success -> state.dialog
}
}
val successState = state as MangaScreenState.Success
val isHttpSource = remember { successState.source is HttpSource }
val scope = rememberCoroutineScope()
@ -210,7 +202,7 @@ class MangaController : FullComposeController<MangaPresenter> {
)
val onDismissRequest = { presenter.dismissDialog() }
when (val dialog = dialog) {
when (val dialog = (state as? MangaScreenState.Success)?.dialog) {
is Dialog.ChangeCategory -> {
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,