Fix(TopAppBar): Fix the bug that the TopAppBar can be scrolled and hidden when the search box is opened

This commit is contained in:
2024-08-20 16:54:36 +08:00
parent da4c58b631
commit b115d3d598
3 changed files with 28 additions and 15 deletions

View File

@@ -80,12 +80,18 @@ fun OxygenApp(appState: OxygenAppState) {
val noConnectMessage = stringResource(R.string.core_no_connect)
val topAppBarScrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
var canScroll by remember { mutableStateOf(true) }
val topAppBarScrollBehavior =
if (canScroll) TopAppBarDefaults.enterAlwaysScrollBehavior() else TopAppBarDefaults.pinnedScrollBehavior()
var activeSearch by remember { mutableStateOf(false) }
var searchValue by remember { mutableStateOf("") }
var searchCount by remember { mutableIntStateOf(0) }
LaunchedEffect(activeSearch) {
canScroll = !activeSearch
}
LaunchedEffect(destination) {
activeSearch = false
searchValue = ""
@@ -194,20 +200,20 @@ fun OxygenApp(appState: OxygenAppState) {
OxygenNavHost(
appState = appState,
onShowSnackbar = { message, action ->
snackbarHostState.showSnackbar(
message = message,
actionLabel = action,
duration = SnackbarDuration.Short
) == SnackbarResult.ActionPerformed
},
startDestination = when (appState.launchPageConfig) {
LaunchPageConfig.Tools -> TOOLS_ROUTE
LaunchPageConfig.Star -> STAR_ROUTE
},
isVertical = appState.shouldShowBottomBar,
searchValue = searchValue,
searchCount = searchCount
searchCount = searchCount,
onShowSnackbar = { message, action ->
snackbarHostState.showSnackbar(
message = message,
actionLabel = action,
duration = SnackbarDuration.Short
) == SnackbarResult.ActionPerformed
}
)
}
}

View File

@@ -41,6 +41,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -107,13 +108,19 @@ internal fun LibrariesScreen(
var dialogContent by remember { mutableStateOf("") }
var dialogUrl by remember { mutableStateOf("") }
val topAppBarScrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
var canScroll by remember { mutableStateOf(true) }
val topAppBarScrollBehavior =
if (canScroll) TopAppBarDefaults.enterAlwaysScrollBehavior() else TopAppBarDefaults.pinnedScrollBehavior()
val infiniteTransition = rememberInfiniteTransition(label = "infiniteTransition")
var activeSearch by remember { mutableStateOf(false) }
var searchValue by remember { mutableStateOf("") }
LaunchedEffect(activeSearch) {
canScroll = !activeSearch
}
Scaffold(
modifier = Modifier
.nestedScroll(topAppBarScrollBehavior.nestedScrollConnection),