Skip to content

Commit

Permalink
PM-12668: Update TopAppBars accross the app (#4074)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-livefront authored Oct 11, 2024
1 parent cd9f4e8 commit 86db9bd
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.x8bit.bitwarden.R
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.card.BitwardenInfoCalloutCard
import com.x8bit.bitwarden.ui.platform.components.dialog.BasicDialogState
Expand Down Expand Up @@ -101,8 +101,9 @@ fun ResetPasswordScreen(
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
BitwardenMediumTopAppBar(
BitwardenTopAppBar(
title = stringResource(id = R.string.update_master_password),
navigationIcon = null,
scrollBehavior = scrollBehavior,
actions = {
BitwardenTextButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
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.card.BitwardenInfoCalloutCard
import com.x8bit.bitwarden.ui.platform.components.dialog.BasicDialogState
Expand Down Expand Up @@ -62,8 +62,9 @@ fun SetPasswordScreen(
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
BitwardenMediumTopAppBar(
BitwardenTopAppBar(
title = stringResource(id = R.string.set_master_password),
navigationIcon = null,
scrollBehavior = scrollBehavior,
actions = {
BitwardenTextButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MediumTopAppBar
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState
Expand Down Expand Up @@ -45,13 +46,14 @@ fun BitwardenMediumTopAppBar(
dividerStyle: TopAppBarDividerStyle = TopAppBarDividerStyle.ON_SCROLL,
actions: @Composable RowScope.() -> Unit = {},
) {
MediumTopAppBar(
TopAppBar(
colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior,
expandedHeight = 56.dp,
title = {
Text(
text = title,
style = BitwardenTheme.typography.titleLarge,
style = BitwardenTheme.typography.headlineMedium,
modifier = Modifier.testTag(tag = "PageTitleLabel"),
)
},
Expand Down
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 com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.mirrorIfRtl
import com.x8bit.bitwarden.ui.platform.base.util.scrolledContainerBottomDivider
Expand Down Expand Up @@ -107,6 +108,8 @@ fun BitwardenTopAppBar(
colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior,
navigationIcon = navigationIconContent,
collapsedHeight = 48.dp,
expandedHeight = 96.dp,
title = {
// The height of the component is controlled and will only allow for 1 extra row,
// making adding any arguments for softWrap and minLines superfluous.
Expand All @@ -127,6 +130,7 @@ fun BitwardenTopAppBar(
colors = bitwardenTopAppBarColors(),
scrollBehavior = scrollBehavior,
navigationIcon = navigationIconContent,
expandedHeight = 48.dp,
title = {
Text(
text = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ fun SettingsScreen(
}
}

val scrollBehavior =
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
BitwardenScaffold(
topBar = {
BitwardenMediumTopAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,7 @@ fun GeneratorScreen(
RandomWordHandlers.create(viewModel = viewModel)
}

val scrollBehavior = when (state.generatorMode) {
GeneratorMode.Default -> {
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
}

else -> TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
}

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
BitwardenScaffold(
topBar = {
when (state.generatorMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fun SendScreen(
)

val sendHandlers = remember(viewModel) { SendHandlers.create(viewModel) }
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(
state = rememberTopAppBarState(),
)
BitwardenScaffold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private fun VaultScreenScaffold(
onDimBottomNavBarRequest(shouldShowMenu)
}
var shouldShowExitConfirmationDialog by rememberSaveable { mutableStateOf(false) }
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(
state = rememberTopAppBarState(),
canScroll = { !accountMenuVisible },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.isPopup
import androidx.compose.ui.test.onAllNodesWithContentDescription
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.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -37,6 +40,7 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test

@Suppress("LargeClass")
class SendScreenTest : BaseComposeTest() {

private var onNavigateToNewSendCalled = false
Expand Down Expand Up @@ -438,14 +442,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand All @@ -462,14 +472,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand All @@ -492,14 +508,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand All @@ -522,14 +544,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand All @@ -552,14 +580,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand All @@ -582,14 +616,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand All @@ -611,14 +651,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand Down Expand Up @@ -646,14 +692,20 @@ class SendScreenTest : BaseComposeTest() {
viewState = SendState.ViewState.Content(
textTypeCount = 0,
fileTypeCount = 1,
sendItems = listOf(DEFAULT_SEND_ITEM),
sendItems = listOf(
DEFAULT_SEND_ITEM,
DEFAULT_SEND_ITEM.copy(id = "mockId-2"),
),
),
)
}
composeTestRule.assertNoDialogExists()

// We scroll to the last item but click the first one to avoid clicking the FAB by mistake
composeTestRule
.onNodeWithContentDescription("Options")
.onAllNodesWithContentDescription("Options")
.apply { onLast().performScrollTo() }
.onFirst()
.assertIsDisplayed()
.performClick()

Expand Down

0 comments on commit 86db9bd

Please sign in to comment.