-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Description
Why not pass topbar as a parameter to Scaffold?
- I'm also trying a single top level Scaffold, but there are different implementations for topbar and floatingActionButton for different Screens, and the method that needs to be called for clicking on the topbar/floatingActionButton is likely to be the corresponding Screen's state switching , I don't know how to correctly pass that state switching method to the top level Scaffold
While looking up the official specification, I found the code for this project:
Scaffold(
modifier = modifier.semantics {
testTagsAsResourceId = true
},
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onBackground,
contentWindowInsets = WindowInsets(0, 0, 0, 0),
snackbarHost = {
SnackbarHost(
snackbarHostState,
modifier = Modifier.windowInsetsPadding(
WindowInsets.safeDrawing.exclude(
WindowInsets.ime,
),
),
)
},
) { padding ->
Column(
Modifier
.fillMaxSize()
.padding(padding)
.consumeWindowInsets(padding)
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal,
),
),
) {
// Show the top app bar on top level destinations.
val destination = appState.currentTopLevelDestination
var shouldShowTopAppBar = false
if (destination != null) {
shouldShowTopAppBar = true
NiaTopAppBar(
titleRes = destination.titleTextId,
navigationIcon = NiaIcons.Search,
navigationIconContentDescription = stringResource(
id = settingsR.string.feature_settings_top_app_bar_navigation_icon_description,
),
actionIcon = NiaIcons.Settings,
actionIconContentDescription = stringResource(
id = settingsR.string.feature_settings_top_app_bar_action_icon_description,
),
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
),
onActionClick = { onTopAppBarActionClick() },
onNavigationClick = { appState.navigateToSearch() },
)
}
Why do we need to do this? According to the official specification, we need to pass the topbar as a parameter to Scaffold.
DamienLevel
Metadata
Metadata
Assignees
Labels
No labels