Skip to content

Commit bb66150

Browse files
PM-14179: Update generator screen copy button (#4530)
1 parent 9c2a902 commit bb66150

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/platform/components/field/BitwardenTextField.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ import kotlinx.collections.immutable.toImmutableList
6969
* @param keyboardType the preferred type of keyboard input.
7070
* @param textToolbarType The type of [TextToolbar] to use on the text field.
7171
*/
72-
@Suppress("LongMethod")
72+
@Suppress("LongMethod", "CyclomaticComplexMethod")
7373
@Composable
7474
fun BitwardenTextField(
75-
label: String,
75+
label: String?,
7676
value: String,
7777
onValueChange: (String) -> Unit,
7878
modifier: Modifier = Modifier,
@@ -136,7 +136,7 @@ fun BitwardenTextField(
136136
.focusRequester(focusRequester)
137137
.fillMaxWidth(),
138138
enabled = enabled,
139-
label = { Text(text = label) },
139+
label = label?.let { { Text(text = it) } },
140140
value = textFieldValue,
141141
leadingIcon = leadingIconResource?.let { iconResource ->
142142
{

app/src/main/java/com/x8bit/bitwarden/ui/platform/components/field/BitwardenTextFieldWithActions.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import androidx.compose.ui.Modifier
1010
import androidx.compose.ui.platform.TextToolbar
1111
import androidx.compose.ui.platform.testTag
1212
import androidx.compose.ui.semantics.semantics
13-
import androidx.compose.ui.semantics.testTag
1413
import androidx.compose.ui.text.TextStyle
1514
import androidx.compose.ui.text.input.KeyboardType
1615
import androidx.compose.ui.text.input.VisualTransformation
@@ -48,7 +47,7 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
4847
*/
4948
@Composable
5049
fun BitwardenTextFieldWithActions(
51-
label: String,
50+
label: String?,
5251
value: String,
5352
onValueChange: (String) -> Unit,
5453
modifier: Modifier = Modifier,

app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt

+20-13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenMediumTopAppBa
3939
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
4040
import com.x8bit.bitwarden.ui.platform.components.appbar.action.BitwardenOverflowActionItem
4141
import com.x8bit.bitwarden.ui.platform.components.appbar.action.OverflowMenuItemData
42+
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton
4243
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton
4344
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTonalIconButton
4445
import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard
@@ -302,8 +303,8 @@ private fun ScrollContent(
302303
.fillMaxHeight()
303304
.verticalScroll(rememberScrollState()),
304305
) {
306+
Spacer(modifier = Modifier.height(12.dp))
305307
if (state.isUnderPolicy) {
306-
Spacer(modifier = Modifier.height(8.dp))
307308
BitwardenInfoCalloutCard(
308309
text = stringResource(id = R.string.password_generator_policy_in_effect),
309310
modifier = Modifier
@@ -312,16 +313,29 @@ private fun ScrollContent(
312313
.fillMaxWidth(),
313314
)
314315

315-
Spacer(modifier = Modifier.height(8.dp))
316+
Spacer(modifier = Modifier.height(12.dp))
316317
}
317318

318319
GeneratedStringItem(
319320
generatedText = state.generatedText,
320-
onCopyClick = onCopyClick,
321321
onRegenerateClick = onRegenerateClick,
322+
modifier = Modifier
323+
.padding(horizontal = 16.dp)
324+
.fillMaxWidth(),
325+
)
326+
327+
Spacer(modifier = Modifier.height(12.dp))
328+
329+
BitwardenFilledButton(
330+
label = stringResource(id = R.string.copy),
331+
onClick = onCopyClick,
332+
modifier = Modifier
333+
.testTag(tag = "CopyValueButton")
334+
.fillMaxWidth()
335+
.padding(horizontal = 16.dp),
322336
)
323337

324-
Spacer(modifier = Modifier.height(16.dp))
338+
Spacer(modifier = Modifier.height(24.dp))
325339

326340
BitwardenListHeaderText(
327341
label = stringResource(id = R.string.options),
@@ -365,22 +379,15 @@ private fun ScrollContent(
365379
@Composable
366380
private fun GeneratedStringItem(
367381
generatedText: String,
368-
onCopyClick: () -> Unit,
369382
onRegenerateClick: () -> Unit,
370383
modifier: Modifier = Modifier,
371384
) {
372385
BitwardenTextFieldWithActions(
373-
label = "",
386+
label = null,
374387
textFieldTestTag = "GeneratedPasswordLabel",
375388
value = generatedText,
376389
singleLine = false,
377390
actions = {
378-
BitwardenTonalIconButton(
379-
vectorIconRes = R.drawable.ic_copy,
380-
contentDescription = stringResource(id = R.string.copy),
381-
onClick = onCopyClick,
382-
modifier = Modifier.testTag("CopyValueButton"),
383-
)
384391
BitwardenTonalIconButton(
385392
vectorIconRes = R.drawable.ic_generate,
386393
contentDescription = stringResource(id = R.string.generate_password),
@@ -393,7 +400,7 @@ private fun GeneratedStringItem(
393400
textStyle = BitwardenTheme.typography.sensitiveInfoSmall,
394401
shouldAddCustomLineBreaks = true,
395402
visualTransformation = nonLetterColorVisualTransformation(),
396-
modifier = modifier.padding(horizontal = 16.dp),
403+
modifier = modifier,
397404
textToolbarType = TextToolbarType.NONE,
398405
)
399406
}

app/src/test/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreenTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class GeneratorScreenTest : BaseComposeTest() {
193193
@Test
194194
fun `clicking the Copy button should send CopyClick action`() {
195195
composeTestRule
196-
.onNodeWithContentDescription(label = "Copy")
196+
.onNodeWithText(text = "Copy")
197197
.performClick()
198198

199199
verify {

0 commit comments

Comments
 (0)