BIT-1018: Add visual transformation to generated string field (#340)

This commit is contained in:
David Perez 2023-12-06 16:22:27 -06:00 committed by Álison Fernandes
parent 30a9d76d70
commit 3a42d3e58a
3 changed files with 16 additions and 4 deletions

View file

@ -14,6 +14,7 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.text import androidx.compose.ui.semantics.text
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview 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.R
@ -28,7 +29,9 @@ import com.x8bit.bitwarden.R
* @param label Label for the text field. * @param label Label for the text field.
* @param value Current text in the text field. * @param value Current text in the text field.
* @param modifier [Modifier] applied to this layout composable. * @param modifier [Modifier] applied to this layout composable.
* @param readOnly If `true`, user input is disabled for the text field, making it read-only. * @param singleLine when `true`, this text field becomes a single line that horizontally scrolls
* instead of wrapping onto multiple lines.
* @param visualTransformation Transforms the visual representation of the input [value].
* @param actions A lambda containing the set of actions (usually icons or similar) to display * @param actions A lambda containing the set of actions (usually icons or similar) to display
* next to the text field. This lambda extends [RowScope], * next to the text field. This lambda extends [RowScope],
* providing flexibility in the layout definition. * providing flexibility in the layout definition.
@ -38,7 +41,8 @@ fun BitwardenReadOnlyTextFieldWithActions(
label: String, label: String,
value: String, value: String,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
readOnly: Boolean = true, singleLine: Boolean = true,
visualTransformation: VisualTransformation = VisualTransformation.None,
actions: @Composable RowScope.() -> Unit = {}, actions: @Composable RowScope.() -> Unit = {},
) { ) {
Row( Row(
@ -54,10 +58,12 @@ fun BitwardenReadOnlyTextFieldWithActions(
contentDescription = "$label, $value" contentDescription = "$label, $value"
text = AnnotatedString(label) text = AnnotatedString(label)
}, },
readOnly = readOnly, readOnly = true,
singleLine = singleLine,
label = label, label = label,
value = value, value = value,
onValueChange = {}, onValueChange = {},
visualTransformation = visualTransformation,
) )
BitwardenRowOfActions(actions) BitwardenRowOfActions(actions)
} }
@ -69,7 +75,6 @@ private fun BitwardenReadOnlyTextFieldWithActions_preview() {
BitwardenReadOnlyTextFieldWithActions( BitwardenReadOnlyTextFieldWithActions(
label = "Username", label = "Username",
value = "john.doe", value = "john.doe",
readOnly = true,
actions = { actions = {
Icon( Icon(
painter = painterResource(id = R.drawable.ic_tooltip), painter = painterResource(id = R.drawable.ic_tooltip),

View file

@ -8,6 +8,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import com.x8bit.bitwarden.ui.platform.components.model.IconResource import com.x8bit.bitwarden.ui.platform.components.model.IconResource
@ -26,6 +27,7 @@ import com.x8bit.bitwarden.ui.platform.components.model.IconResource
* instead of wrapping onto multiple lines. * instead of wrapping onto multiple lines.
* @param readOnly `true` if the input should be read-only and not accept user interactions. * @param readOnly `true` if the input should be read-only and not accept user interactions.
* @param enabled Whether or not the text field is enabled. * @param enabled Whether or not the text field is enabled.
* @param visualTransformation Transforms the visual representation of the input [value].
* @param keyboardType the preferred type of keyboard input. * @param keyboardType the preferred type of keyboard input.
*/ */
@Composable @Composable
@ -41,6 +43,7 @@ fun BitwardenTextField(
readOnly: Boolean = false, readOnly: Boolean = false,
enabled: Boolean = true, enabled: Boolean = true,
keyboardType: KeyboardType = KeyboardType.Text, keyboardType: KeyboardType = KeyboardType.Text,
visualTransformation: VisualTransformation = VisualTransformation.None,
) { ) {
OutlinedTextField( OutlinedTextField(
modifier = modifier, modifier = modifier,
@ -71,6 +74,7 @@ fun BitwardenTextField(
singleLine = singleLine, singleLine = singleLine,
readOnly = readOnly, readOnly = readOnly,
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = keyboardType), keyboardOptions = KeyboardOptions.Default.copy(keyboardType = keyboardType),
visualTransformation = visualTransformation,
) )
} }

View file

@ -62,6 +62,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField
import com.x8bit.bitwarden.ui.platform.components.BitwardenWideSwitch import com.x8bit.bitwarden.ui.platform.components.BitwardenWideSwitch
import com.x8bit.bitwarden.ui.platform.components.model.IconResource import com.x8bit.bitwarden.ui.platform.components.model.IconResource
import com.x8bit.bitwarden.ui.platform.components.model.TooltipData import com.x8bit.bitwarden.ui.platform.components.model.TooltipData
import com.x8bit.bitwarden.ui.platform.components.util.nonLetterColorVisualTransformation
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Passcode.PasscodeType.Passphrase.Companion.PASSPHRASE_MAX_NUMBER_OF_WORDS import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Passcode.PasscodeType.Passphrase.Companion.PASSPHRASE_MAX_NUMBER_OF_WORDS
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Passcode.PasscodeType.Passphrase.Companion.PASSPHRASE_MIN_NUMBER_OF_WORDS import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Passcode.PasscodeType.Passphrase.Companion.PASSPHRASE_MIN_NUMBER_OF_WORDS
@ -271,6 +272,7 @@ private fun GeneratedStringItem(
BitwardenReadOnlyTextFieldWithActions( BitwardenReadOnlyTextFieldWithActions(
label = "", label = "",
value = generatedText, value = generatedText,
singleLine = false,
actions = { actions = {
BitwardenIconButtonWithResource( BitwardenIconButtonWithResource(
iconRes = IconResource( iconRes = IconResource(
@ -287,6 +289,7 @@ private fun GeneratedStringItem(
onClick = onRegenerateClick, onClick = onRegenerateClick,
) )
}, },
visualTransformation = nonLetterColorVisualTransformation(),
modifier = Modifier.padding(horizontal = 16.dp), modifier = Modifier.padding(horizontal = 16.dp),
) )
} }