mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 07:05:35 +03:00
Update the 'BitwardenTopAppBar' to make the navigation icon optional (#232)
This commit is contained in:
parent
3136c686b2
commit
238f6e92c8
1 changed files with 57 additions and 11 deletions
|
@ -36,6 +36,35 @@ fun BitwardenTopAppBar(
|
|||
navigationIcon: Painter,
|
||||
navigationIconContentDescription: String,
|
||||
onNavigationIconClick: () -> Unit,
|
||||
actions: @Composable RowScope.() -> Unit = { },
|
||||
) {
|
||||
BitwardenTopAppBar(
|
||||
title = title,
|
||||
scrollBehavior = scrollBehavior,
|
||||
navigationIcon = NavigationIcon(
|
||||
navigationIcon = navigationIcon,
|
||||
navigationIconContentDescription = navigationIconContentDescription,
|
||||
onNavigationIconClick = onNavigationIconClick,
|
||||
),
|
||||
actions = actions,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Bitwarden styled [TopAppBar] that assumes the following components:
|
||||
*
|
||||
* - an optional single navigation control in the upper-left defined by [navigationIcon].
|
||||
* - a [title] in the middle.
|
||||
* - a [actions] lambda containing the set of actions (usually icons or similar) to display
|
||||
* in the app bar's trailing side. This lambda extends [RowScope], allowing flexibility in
|
||||
* defining the layout of the actions.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BitwardenTopAppBar(
|
||||
title: String,
|
||||
scrollBehavior: TopAppBarScrollBehavior,
|
||||
navigationIcon: NavigationIcon?,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
) {
|
||||
TopAppBar(
|
||||
|
@ -45,14 +74,16 @@ fun BitwardenTopAppBar(
|
|||
),
|
||||
scrollBehavior = scrollBehavior,
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = { onNavigationIconClick() },
|
||||
) {
|
||||
Icon(
|
||||
painter = navigationIcon,
|
||||
contentDescription = navigationIconContentDescription,
|
||||
tint = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
navigationIcon?.let {
|
||||
IconButton(
|
||||
onClick = it.onNavigationIconClick,
|
||||
) {
|
||||
Icon(
|
||||
painter = it.navigationIcon,
|
||||
contentDescription = it.navigationIconContentDescription,
|
||||
tint = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
title = {
|
||||
|
@ -77,9 +108,24 @@ private fun BitwardenTopAppBar_preview() {
|
|||
.exitUntilCollapsedScrollBehavior(
|
||||
rememberTopAppBarState(),
|
||||
),
|
||||
navigationIcon = painterResource(id = R.drawable.ic_close),
|
||||
navigationIconContentDescription = stringResource(id = R.string.close),
|
||||
onNavigationIconClick = {},
|
||||
navigationIcon = NavigationIcon(
|
||||
navigationIcon = painterResource(id = R.drawable.ic_close),
|
||||
navigationIconContentDescription = stringResource(id = R.string.close),
|
||||
onNavigationIconClick = { },
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents all data required to display a [navigationIcon].
|
||||
*
|
||||
* @property navigationIcon The [Painter] displayed as part of the icon.
|
||||
* @property navigationIconContentDescription The content description associated with the icon.
|
||||
* @property onNavigationIconClick The click action that is invoked when the icon is tapped.
|
||||
*/
|
||||
data class NavigationIcon(
|
||||
val navigationIcon: Painter,
|
||||
val navigationIconContentDescription: String,
|
||||
val onNavigationIconClick: () -> Unit,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue