共享元素动画优化
This commit is contained in:
@@ -2,7 +2,9 @@ package io.legado.app.ui.main.bookshelf
|
|||||||
|
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.net.Uri
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.activity.compose.ManagedActivityResultLauncher
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
@@ -58,6 +60,7 @@ import androidx.compose.material3.pulltorefresh.pullToRefresh
|
|||||||
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
|
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
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
|
||||||
@@ -226,17 +229,29 @@ fun BookshelfScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentTabGroupId =
|
val currentTabGroupId by remember {
|
||||||
uiState.groups.getOrNull(pagerState.currentPage)?.groupId ?: BookGroup.IdAll
|
derivedStateOf {
|
||||||
val searchGroupExists = uiState.allGroups.any { it.groupId == uiState.selectedGroupId }
|
uiState.groups.getOrNull(pagerState.currentPage)?.groupId ?: BookGroup.IdAll
|
||||||
val currentGroupId = if (uiState.isSearch && searchGroupExists) {
|
}
|
||||||
uiState.selectedGroupId
|
|
||||||
} else {
|
|
||||||
currentTabGroupId
|
|
||||||
}
|
}
|
||||||
val isUsingStandaloneSearchGroup = uiState.isSearch &&
|
val searchGroupExists by remember {
|
||||||
uiState.groups.none { it.groupId == currentGroupId }
|
derivedStateOf { uiState.allGroups.any { it.groupId == uiState.selectedGroupId } }
|
||||||
val currentGroupBookCount = uiState.currentGroupBookCount
|
}
|
||||||
|
val currentGroupId by remember {
|
||||||
|
derivedStateOf {
|
||||||
|
if (uiState.isSearch && searchGroupExists) {
|
||||||
|
uiState.selectedGroupId
|
||||||
|
} else {
|
||||||
|
currentTabGroupId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val isUsingStandaloneSearchGroup by remember {
|
||||||
|
derivedStateOf {
|
||||||
|
uiState.isSearch && uiState.groups.none { it.groupId == currentGroupId }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val currentGroupBookCount by remember { derivedStateOf { uiState.currentGroupBookCount } }
|
||||||
|
|
||||||
val clearSelection = {
|
val clearSelection = {
|
||||||
viewModel.clearSelection()
|
viewModel.clearSelection()
|
||||||
@@ -263,7 +278,7 @@ fun BookshelfScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentGroupName = uiState.currentGroupName
|
val currentGroupName by remember { derivedStateOf { uiState.currentGroupName } }
|
||||||
|
|
||||||
if (bookGroupStyle == 2 && !isInFolderRoot && !isEditMode) {
|
if (bookGroupStyle == 2 && !isInFolderRoot && !isEditMode) {
|
||||||
BackHandler {
|
BackHandler {
|
||||||
@@ -273,22 +288,37 @@ fun BookshelfScreen(
|
|||||||
|
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
val bookshelfLayoutMode =
|
val bookshelfLayoutMode by remember {
|
||||||
if (isLandscape) BookshelfConfig.bookshelfLayoutModeLandscape else BookshelfConfig.bookshelfLayoutModePortrait
|
derivedStateOf {
|
||||||
val bookshelfLayoutGrid =
|
if (isLandscape) BookshelfConfig.bookshelfLayoutModeLandscape else BookshelfConfig.bookshelfLayoutModePortrait
|
||||||
if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape else BookshelfConfig.bookshelfLayoutGridPortrait
|
}
|
||||||
val bookshelfLayoutList =
|
}
|
||||||
if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait
|
val bookshelfLayoutGrid by remember {
|
||||||
val currentMenuGroupId = if (uiState.isSearch) uiState.selectedGroupId else currentTabGroupId
|
derivedStateOf {
|
||||||
val editStickySummary = if (isEditMode) {
|
if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape else BookshelfConfig.bookshelfLayoutGridPortrait
|
||||||
BookshelfEditStickySummary(
|
}
|
||||||
selectedCount = selectedBookUrls.size,
|
}
|
||||||
currentGroupTotalCount = currentGroupBookCount,
|
val bookshelfLayoutList by remember {
|
||||||
groupName = currentGroupName,
|
derivedStateOf {
|
||||||
showGroupName = bookGroupStyle != 0
|
if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait
|
||||||
)
|
}
|
||||||
} else {
|
}
|
||||||
null
|
val currentMenuGroupId by remember {
|
||||||
|
derivedStateOf { if (uiState.isSearch) uiState.selectedGroupId else currentTabGroupId }
|
||||||
|
}
|
||||||
|
val editStickySummary by remember {
|
||||||
|
derivedStateOf {
|
||||||
|
if (isEditMode) {
|
||||||
|
BookshelfEditStickySummary(
|
||||||
|
selectedCount = selectedBookUrls.size,
|
||||||
|
currentGroupTotalCount = currentGroupBookCount,
|
||||||
|
groupName = currentGroupName,
|
||||||
|
showGroupName = bookGroupStyle != 0
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListScaffold(
|
ListScaffold(
|
||||||
@@ -604,12 +634,18 @@ fun BookshelfScreen(
|
|||||||
} else null
|
} else null
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
val pullToRefreshState = rememberPullToRefreshState()
|
val pullToRefreshState = rememberPullToRefreshState()
|
||||||
val currentGroup = if (uiState.isSearch) {
|
val currentGroup by remember {
|
||||||
uiState.allGroups.firstOrNull { it.groupId == currentGroupId }
|
derivedStateOf {
|
||||||
} else {
|
if (uiState.isSearch) {
|
||||||
uiState.groups.getOrNull(pagerState.currentPage)
|
uiState.allGroups.firstOrNull { it.groupId == currentGroupId }
|
||||||
|
} else {
|
||||||
|
uiState.groups.getOrNull(pagerState.currentPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val pullToRefreshEnabled by remember {
|
||||||
|
derivedStateOf { (currentGroup?.enableRefresh ?: true) && !isEditMode }
|
||||||
}
|
}
|
||||||
val pullToRefreshEnabled = (currentGroup?.enableRefresh ?: true) && !isEditMode
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -900,6 +936,27 @@ fun BookshelfScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BookshelfOverlays(
|
||||||
|
activeOverlay = activeOverlay,
|
||||||
|
uiState = uiState,
|
||||||
|
viewModel = viewModel,
|
||||||
|
selectedBookUrls = selectedBookUrls,
|
||||||
|
importLauncher = importLauncher,
|
||||||
|
exportLauncher = exportLauncher,
|
||||||
|
clearSelection = clearSelection
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun BookshelfOverlays(
|
||||||
|
activeOverlay: BookshelfOverlay?,
|
||||||
|
uiState: BookshelfUiState,
|
||||||
|
viewModel: BookshelfViewModel,
|
||||||
|
selectedBookUrls: Set<String>,
|
||||||
|
importLauncher: ManagedActivityResultLauncher<Array<String>, Uri?>,
|
||||||
|
exportLauncher: ManagedActivityResultLauncher<String, Uri?>,
|
||||||
|
clearSelection: () -> Unit
|
||||||
|
) {
|
||||||
BookshelfConfigSheet(
|
BookshelfConfigSheet(
|
||||||
show = activeOverlay == BookshelfOverlay.ConfigSheet,
|
show = activeOverlay == BookshelfOverlay.ConfigSheet,
|
||||||
onDismissRequest = { viewModel.dismissOverlay() }
|
onDismissRequest = { viewModel.dismissOverlay() }
|
||||||
|
|||||||
Reference in New Issue
Block a user