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

@@ -9,11 +9,11 @@ import top.fatweb.oxygen.toolbox.ui.OxygenAppState
fun OxygenNavHost(
modifier: Modifier = Modifier,
appState: OxygenAppState,
onShowSnackbar: suspend (message: String, action: String?) -> Boolean,
startDestination: String,
isVertical: Boolean,
searchValue: String,
searchCount: Int
searchCount: Int,
onShowSnackbar: suspend (message: String, action: String?) -> Boolean
) {
val navController = appState.navController
NavHost(
@@ -41,13 +41,13 @@ fun OxygenNavHost(
onNavigateToToolView = navController::navigateToToolView,
onNavigateToToolStore = { appState.navigateToTopLevelDestination(TopLevelDestination.ToolStore) }
)
toolViewScreen(
onBackClick = navController::popBackStack
)
starScreen(
isVertical = isVertical,
searchValue = searchValue,
onNavigateToToolView = navController::navigateToToolView
)
toolViewScreen(
onBackClick = navController::popBackStack
)
}
}

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),