PM-12668: Update TopAppBars accross the app (#4074)

This commit is contained in:
David Perez 2024-10-11 14:05:24 -05:00 committed by GitHub
parent cd9f4e8723
commit 86db9bd3fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 86 additions and 35 deletions

View file

@ -29,7 +29,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.x8bit.bitwarden.R import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetReason import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetReason
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenMediumTopAppBar import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton
import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard
import com.x8bit.bitwarden.ui.platform.components.dialog.BasicDialogState import com.x8bit.bitwarden.ui.platform.components.dialog.BasicDialogState
@ -101,8 +101,9 @@ fun ResetPasswordScreen(
.fillMaxSize() .fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection), .nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = { topBar = {
BitwardenMediumTopAppBar( BitwardenTopAppBar(
title = stringResource(id = R.string.update_master_password), title = stringResource(id = R.string.update_master_password),
navigationIcon = null,
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
actions = { actions = {
BitwardenTextButton( BitwardenTextButton(

View file

@ -28,7 +28,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.x8bit.bitwarden.R import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenMediumTopAppBar import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton
import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard
import com.x8bit.bitwarden.ui.platform.components.dialog.BasicDialogState import com.x8bit.bitwarden.ui.platform.components.dialog.BasicDialogState
@ -62,8 +62,9 @@ fun SetPasswordScreen(
.fillMaxSize() .fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection), .nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = { topBar = {
BitwardenMediumTopAppBar( BitwardenTopAppBar(
title = stringResource(id = R.string.set_master_password), title = stringResource(id = R.string.set_master_password),
navigationIcon = null,
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
actions = { actions = {
BitwardenTextButton( BitwardenTextButton(

View file

@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MediumTopAppBar import androidx.compose.material3.MediumTopAppBar
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState import androidx.compose.material3.rememberTopAppBarState
@ -45,13 +46,14 @@ fun BitwardenMediumTopAppBar(
dividerStyle: TopAppBarDividerStyle = TopAppBarDividerStyle.ON_SCROLL, dividerStyle: TopAppBarDividerStyle = TopAppBarDividerStyle.ON_SCROLL,
actions: @Composable RowScope.() -> Unit = {}, actions: @Composable RowScope.() -> Unit = {},
) { ) {
MediumTopAppBar( TopAppBar(
colors = bitwardenTopAppBarColors(), colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
expandedHeight = 56.dp,
title = { title = {
Text( Text(
text = title, text = title,
style = BitwardenTheme.typography.titleLarge, style = BitwardenTheme.typography.headlineMedium,
modifier = Modifier.testTag(tag = "PageTitleLabel"), modifier = Modifier.testTag(tag = "PageTitleLabel"),
) )
}, },

View file

@ -19,6 +19,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.R import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.mirrorIfRtl import com.x8bit.bitwarden.ui.platform.base.util.mirrorIfRtl
import com.x8bit.bitwarden.ui.platform.base.util.scrolledContainerBottomDivider import com.x8bit.bitwarden.ui.platform.base.util.scrolledContainerBottomDivider
@ -107,6 +108,8 @@ fun BitwardenTopAppBar(
colors = bitwardenTopAppBarColors(), colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
navigationIcon = navigationIconContent, navigationIcon = navigationIconContent,
collapsedHeight = 48.dp,
expandedHeight = 96.dp,
title = { title = {
// The height of the component is controlled and will only allow for 1 extra row, // The height of the component is controlled and will only allow for 1 extra row,
// making adding any arguments for softWrap and minLines superfluous. // making adding any arguments for softWrap and minLines superfluous.
@ -127,6 +130,7 @@ fun BitwardenTopAppBar(
colors = bitwardenTopAppBarColors(), colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
navigationIcon = navigationIconContent, navigationIcon = navigationIconContent,
expandedHeight = 48.dp,
title = { title = {
Text( Text(
text = title, text = title,

View file

@ -70,9 +70,7 @@ fun SettingsScreen(
} }
} }
val scrollBehavior = val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
BitwardenScaffold( BitwardenScaffold(
topBar = { topBar = {
BitwardenMediumTopAppBar( BitwardenMediumTopAppBar(

View file

@ -179,14 +179,7 @@ fun GeneratorScreen(
RandomWordHandlers.create(viewModel = viewModel) RandomWordHandlers.create(viewModel = viewModel)
} }
val scrollBehavior = when (state.generatorMode) { val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
GeneratorMode.Default -> {
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
}
else -> TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
}
BitwardenScaffold( BitwardenScaffold(
topBar = { topBar = {
when (state.generatorMode) { when (state.generatorMode) {

View file

@ -103,7 +103,7 @@ fun SendScreen(
) )
val sendHandlers = remember(viewModel) { SendHandlers.create(viewModel) } val sendHandlers = remember(viewModel) { SendHandlers.create(viewModel) }
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior( val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(
state = rememberTopAppBarState(), state = rememberTopAppBarState(),
) )
BitwardenScaffold( BitwardenScaffold(

View file

@ -179,7 +179,7 @@ private fun VaultScreenScaffold(
onDimBottomNavBarRequest(shouldShowMenu) onDimBottomNavBarRequest(shouldShowMenu)
} }
var shouldShowExitConfirmationDialog by rememberSaveable { mutableStateOf(false) } var shouldShowExitConfirmationDialog by rememberSaveable { mutableStateOf(false) }
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior( val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(
state = rememberTopAppBarState(), state = rememberTopAppBarState(),
canScroll = { !accountMenuVisible }, canScroll = { !accountMenuVisible },
) )

View file

@ -12,7 +12,10 @@ import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDialog import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.isDisplayed import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.isPopup import androidx.compose.ui.test.isPopup
import androidx.compose.ui.test.onAllNodesWithContentDescription
import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.onLast
import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performClick
@ -37,6 +40,7 @@ import org.junit.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@Suppress("LargeClass")
class SendScreenTest : BaseComposeTest() { class SendScreenTest : BaseComposeTest() {
private var onNavigateToNewSendCalled = false private var onNavigateToNewSendCalled = false
@ -438,14 +442,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -462,14 +472,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -492,14 +508,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -522,14 +544,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -552,14 +580,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -582,14 +616,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -611,14 +651,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()
@ -646,14 +692,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content( viewState = SendState.ViewState.Content(
textTypeCount = 0, textTypeCount = 0,
fileTypeCount = 1, fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM), sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
), ),
) )
} }
composeTestRule.assertNoDialogExists() composeTestRule.assertNoDialogExists()
// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule composeTestRule
.onNodeWithContentDescription("Options") .onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed() .assertIsDisplayed()
.performClick() .performClick()