Skip to content

Commit

Permalink
PM-11187 show import success bottom sheet after success import sync (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dseverns-livefront authored Oct 24, 2024
1 parent 6f535c0 commit 1c10a94
Show file tree
Hide file tree
Showing 21 changed files with 701 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.bottomDivider
Expand Down Expand Up @@ -88,6 +89,7 @@ fun BitwardenTopAppBar(
modifier: Modifier = Modifier,
dividerStyle: TopAppBarDividerStyle = TopAppBarDividerStyle.ON_SCROLL,
actions: @Composable RowScope.() -> Unit = {},
minimunHeight: Dp = 48.dp,
) {
var titleTextHasOverflow by remember {
mutableStateOf(false)
Expand Down Expand Up @@ -131,7 +133,7 @@ fun BitwardenTopAppBar(
colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior,
navigationIcon = navigationIconContent,
collapsedHeight = 48.dp,
collapsedHeight = minimunHeight,
expandedHeight = 96.dp,
title = {
// The height of the component is controlled and will only allow for 1 extra row,
Expand All @@ -151,7 +153,7 @@ fun BitwardenTopAppBar(
colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior,
navigationIcon = navigationIconContent,
expandedHeight = 48.dp,
expandedHeight = minimunHeight,
title = {
Text(
text = title,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.x8bit.bitwarden.ui.platform.components.bottomsheet

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.appbar.NavigationIcon
import com.x8bit.bitwarden.ui.platform.components.scaffold.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme

/**
* A reusable modal bottom sheet that applies provides a bottom sheet layout with the
* standard [BitwardenScaffold] and [BitwardenTopAppBar] and expected scrolling behavior with
* passed in [sheetContent]
*
* @param sheetTitle The title to display in the [BitwardenTopAppBar]
* @param onDismiss The action to perform when the bottom sheet is dismissed will also be performed
* when the "close" icon is clicked, caller must handle any desired animation or hiding of the
* bottom sheet.
* @param showBottomSheet Whether or not to show the bottom sheet, by default this is true assuming
* the showing/hiding will be handled by the caller.
* @param sheetContent Content to display in the bottom sheet. The content is passed the padding
* from the containing [BitwardenScaffold].
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BitwardenModalBottomSheet(
sheetTitle: String,
onDismiss: () -> Unit,
modifier: Modifier = Modifier,
showBottomSheet: Boolean = true,
sheetState: SheetState = rememberModalBottomSheetState(),
sheetContent: @Composable (PaddingValues) -> Unit,
) {
if (!showBottomSheet) return
ModalBottomSheet(
onDismissRequest = onDismiss,
modifier = modifier,
dragHandle = null,
sheetState = sheetState,
contentWindowInsets = {
WindowInsets(left = 0, top = 0, right = 0, bottom = 0)
},
shape = BitwardenTheme.shapes.bottomSheet,
) {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
BitwardenScaffold(
topBar = {
BitwardenTopAppBar(
title = sheetTitle,
navigationIcon = NavigationIcon(
navigationIcon = rememberVectorPainter(R.drawable.ic_close),
onNavigationIconClick = onDismiss,
navigationIconContentDescription = stringResource(R.string.close),
),
scrollBehavior = scrollBehavior,
minimunHeight = 64.dp,
)
},
modifier = Modifier
.nestedScroll(scrollBehavior.nestedScrollConnection)
.fillMaxSize(),
) { paddingValues ->
sheetContent(paddingValues)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.x8bit.bitwarden.ui.platform.components.content

import androidx.annotation.DrawableRes
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -14,33 +15,33 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.ui.platform.components.model.ContentBlockData
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme

/**
* An overloaded version [BitwardenContentBlock] which takes a [String] for the header text.
* An overloaded version [BitwardenContentBlock] which takes a [ContentBlockData] for the
* header text.
*/
@Composable
fun BitwardenContentBlock(
headerText: String,
data: ContentBlockData,
modifier: Modifier = Modifier,
headerTextStyle: TextStyle = BitwardenTheme.typography.titleSmall,
subtitleText: String? = null,
subtitleTextStyle: TextStyle = BitwardenTheme.typography.bodyMedium,
iconPainter: Painter? = null,
backgroundColor: Color = BitwardenTheme.colorScheme.background.secondary,
) {
BitwardenContentBlock(
headerText = AnnotatedString(headerText),
headerText = data.headerText,
modifier = modifier,
headerTextStyle = headerTextStyle,
subtitleText = subtitleText,
subtitleText = data.subtitleText,
subtitleTextStyle = subtitleTextStyle,
iconPainter = iconPainter,
iconVectorResource = data.iconVectorResource,
backgroundColor = backgroundColor,
)
}
Expand All @@ -50,13 +51,13 @@ fun BitwardenContentBlock(
* Implemented to match design component.
*/
@Composable
fun BitwardenContentBlock(
private fun BitwardenContentBlock(
headerText: AnnotatedString,
modifier: Modifier = Modifier,
headerTextStyle: TextStyle = BitwardenTheme.typography.titleSmall,
subtitleText: String? = null,
subtitleTextStyle: TextStyle = BitwardenTheme.typography.bodyMedium,
iconPainter: Painter? = null,
@DrawableRes iconVectorResource: Int? = null,
backgroundColor: Color = BitwardenTheme.colorScheme.background.secondary,
) {
Row(
Expand All @@ -65,15 +66,16 @@ fun BitwardenContentBlock(
.background(backgroundColor),
verticalAlignment = Alignment.CenterVertically,
) {
iconPainter
iconVectorResource
?.let {
Spacer(Modifier.width(12.dp))
Icon(
painter = it,
painter = rememberVectorPainter(it),
contentDescription = null,
tint = BitwardenTheme.colorScheme.icon.secondary,
modifier = Modifier.size(24.dp),
)
Spacer(Modifier.width(12.dp))
}
?: Spacer(Modifier.width(16.dp))

Expand Down Expand Up @@ -102,9 +104,11 @@ fun BitwardenContentBlock(
private fun BitwardenContentBlock_preview() {
BitwardenTheme {
BitwardenContentBlock(
headerText = "Header",
subtitleText = "Subtitle",
iconPainter = null,
data = ContentBlockData(
headerText = "Header",
subtitleText = "Subtitle",
iconVectorResource = null,
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.x8bit.bitwarden.ui.platform.components.model

import androidx.annotation.DrawableRes
import androidx.compose.runtime.Immutable
import androidx.compose.ui.text.AnnotatedString
import com.x8bit.bitwarden.ui.platform.components.content.BitwardenContentBlock

/**
* Wrapper class for data to display in a
* [BitwardenContentBlock]
*/
@Immutable
data class ContentBlockData(
val headerText: AnnotatedString,
val subtitleText: String? = null,
@DrawableRes val iconVectorResource: Int? = null,
) {
/**
* Overloaded constructor for [ContentBlockData] that takes a [String] for the
* header text.
*/
constructor(
headerText: String,
subtitleText: String? = null,
@DrawableRes iconVectorResource: Int? = null,
) : this(
headerText = AnnotatedString(headerText),
subtitleText = subtitleText,
iconVectorResource = iconVectorResource,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ fun NavGraphBuilder.vaultUnlockedGraph(
)
importLoginsScreenDestination(
onNavigateBack = { navController.popBackStack() },
onNavigateToImportSuccessScreen = {
// TODO: PM-11187 navigate to success screen with popping this screen from stack
navController.popBackStack()
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ data class BitwardenShapes(
val menu: CornerBasedShape,
val segmentedControl: CornerBasedShape,
val snackbar: CornerBasedShape,
val bottomSheet: CornerBasedShape,
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ val bitwardenShapes: BitwardenShapes = BitwardenShapes(
menu = RoundedCornerShape(size = 4.dp),
segmentedControl = CircleShape,
snackbar = RoundedCornerShape(size = 8.dp),
bottomSheet = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp),
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ fun NavController.navigateToImportLoginsScreen(navOptions: NavOptions? = null) {
*/
fun NavGraphBuilder.importLoginsScreenDestination(
onNavigateBack: () -> Unit,
onNavigateToImportSuccessScreen: () -> Unit,
) {
composableWithSlideTransitions(
route = IMPORT_LOGINS_ROUTE,
) {
ImportLoginsScreen(
onNavigateBack = onNavigateBack,
onNavigateToImportSuccessScreen = onNavigateToImportSuccessScreen,
)
}
}
Loading

0 comments on commit 1c10a94

Please sign in to comment.