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:
parent
2f458fec9f
commit
897651a75a
@ -88,7 +88,9 @@ fun LibraryScreen(
|
|||||||
onRefresh = onClickRefresh,
|
onRefresh = onClickRefresh,
|
||||||
onGlobalSearchClicked = onGlobalSearchClicked,
|
onGlobalSearchClicked = onGlobalSearchClicked,
|
||||||
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
||||||
|
// SY -->
|
||||||
getDisplayModeForPage = { presenter.getDisplayMode(index = it) },
|
getDisplayModeForPage = { presenter.getDisplayMode(index = it) },
|
||||||
|
// SY <--
|
||||||
getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
|
getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
|
||||||
getLibraryForPage = { presenter.getMangaForCategory(page = it) },
|
getLibraryForPage = { presenter.getMangaForCategory(page = it) },
|
||||||
isIncognitoMode = presenter.isIncognitoMode,
|
isIncognitoMode = presenter.isIncognitoMode,
|
||||||
|
@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@ -48,9 +47,9 @@ fun LibraryContent(
|
|||||||
onRefresh: (Category?) -> Boolean,
|
onRefresh: (Category?) -> Boolean,
|
||||||
onGlobalSearchClicked: () -> Unit,
|
onGlobalSearchClicked: () -> Unit,
|
||||||
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
||||||
getDisplayModeForPage: @Composable (Int) -> State<LibraryDisplayMode>,
|
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
|
||||||
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
||||||
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
|
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
|
||||||
// SY -->
|
// SY -->
|
||||||
onOpenReader: (LibraryManga) -> Unit,
|
onOpenReader: (LibraryManga) -> Unit,
|
||||||
getCategoryName: (Context, Category, Int, String) -> String,
|
getCategoryName: (Context, Category, Int, String) -> String,
|
||||||
@ -77,9 +76,9 @@ fun LibraryContent(
|
|||||||
// SY -->
|
// SY -->
|
||||||
getCategoryName = { category, name ->
|
getCategoryName = { category, name ->
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
derivedStateOf {
|
remember(context, category, state.groupType, name) {
|
||||||
getCategoryName(context, category, state.groupType, name)
|
getCategoryName(context, category, state.groupType, name)
|
||||||
}.value
|
}
|
||||||
},
|
},
|
||||||
// SY <--
|
// SY <--
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,6 @@ package eu.kanade.presentation.library.components
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@ -24,9 +23,9 @@ fun LibraryPager(
|
|||||||
selectedManga: List<LibraryManga>,
|
selectedManga: List<LibraryManga>,
|
||||||
searchQuery: String?,
|
searchQuery: String?,
|
||||||
onGlobalSearchClicked: () -> Unit,
|
onGlobalSearchClicked: () -> Unit,
|
||||||
getDisplayModeForPage: @Composable (Int) -> State<LibraryDisplayMode>,
|
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
|
||||||
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
||||||
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
|
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
|
||||||
onClickManga: (LibraryManga) -> Unit,
|
onClickManga: (LibraryManga) -> Unit,
|
||||||
onLongClickManga: (LibraryManga) -> Unit,
|
onLongClickManga: (LibraryManga) -> Unit,
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -43,8 +42,8 @@ fun LibraryPager(
|
|||||||
// To make sure only one offscreen page is being composed
|
// To make sure only one offscreen page is being composed
|
||||||
return@HorizontalPager
|
return@HorizontalPager
|
||||||
}
|
}
|
||||||
val library by getLibraryForPage(page)
|
val library = getLibraryForPage(page)
|
||||||
val displayMode by getDisplayModeForPage(page)
|
val displayMode = getDisplayModeForPage(page)
|
||||||
val columns by if (displayMode != LibraryDisplayMode.List) {
|
val columns by if (displayMode != LibraryDisplayMode.List) {
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
|
@ -962,13 +962,13 @@ class LibraryPresenter(
|
|||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
@Composable
|
@Composable
|
||||||
fun getMangaForCategory(page: Int): androidx.compose.runtime.State<List<LibraryItem>> {
|
fun getMangaForCategory(page: Int): List<LibraryItem> {
|
||||||
val categoryId = remember(categories) {
|
val unfiltered = remember(categories, loadedManga) {
|
||||||
categories.getOrNull(page)?.id ?: -1
|
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
|
val query = searchQuery
|
||||||
value = withIOContext {
|
value = withIOContext {
|
||||||
if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) {
|
if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) {
|
||||||
@ -1023,6 +1023,8 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return items.value
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterManga(
|
private fun filterManga(
|
||||||
@ -1114,9 +1116,9 @@ class LibraryPresenter(
|
|||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun getDisplayMode(index: Int): androidx.compose.runtime.State<LibraryDisplayMode> {
|
fun getDisplayMode(index: Int): LibraryDisplayMode {
|
||||||
val category = categories[index]
|
val category = categories[index]
|
||||||
return derivedStateOf {
|
return remember(groupType, libraryDisplayMode, category) {
|
||||||
// SY -->
|
// SY -->
|
||||||
if (groupType != LibraryGroup.BY_DEFAULT) {
|
if (groupType != LibraryGroup.BY_DEFAULT) {
|
||||||
libraryDisplayMode
|
libraryDisplayMode
|
||||||
|
@ -11,7 +11,6 @@ import androidx.compose.material3.SnackbarHostState
|
|||||||
import androidx.compose.material3.SnackbarResult
|
import androidx.compose.material3.SnackbarResult
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
@ -158,13 +157,6 @@ class MangaController : FullComposeController<MangaPresenter> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val dialog by derivedStateOf {
|
|
||||||
when (val state = state) {
|
|
||||||
MangaScreenState.Loading -> null
|
|
||||||
is MangaScreenState.Success -> state.dialog
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val successState = state as MangaScreenState.Success
|
val successState = state as MangaScreenState.Success
|
||||||
val isHttpSource = remember { successState.source is HttpSource }
|
val isHttpSource = remember { successState.source is HttpSource }
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@ -210,7 +202,7 @@ class MangaController : FullComposeController<MangaPresenter> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val onDismissRequest = { presenter.dismissDialog() }
|
val onDismissRequest = { presenter.dismissDialog() }
|
||||||
when (val dialog = dialog) {
|
when (val dialog = (state as? MangaScreenState.Success)?.dialog) {
|
||||||
is Dialog.ChangeCategory -> {
|
is Dialog.ChangeCategory -> {
|
||||||
ChangeCategoryDialog(
|
ChangeCategoryDialog(
|
||||||
initialSelection = dialog.initialSelection,
|
initialSelection = dialog.initialSelection,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user