mirror of
https://github.com/bitwarden/android.git
synced 2026-04-29 20:38:41 -05:00
Add BitwardenPasswordFieldWithActions with manual password visibility (#294)
This commit is contained in:
committed by
Álison Fernandes
parent
90f565e02b
commit
d404b95b6d
@@ -4,6 +4,10 @@ import androidx.compose.foundation.layout.Row
|
|||||||
import androidx.compose.foundation.layout.RowScope
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
@@ -18,10 +22,12 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
|||||||
* Represents a Bitwarden-styled password field that hoists show/hide password state to the caller
|
* Represents a Bitwarden-styled password field that hoists show/hide password state to the caller
|
||||||
* and provides additional actions.
|
* and provides additional actions.
|
||||||
*
|
*
|
||||||
* See overloaded [BitwardenPasswordField] for self managed show/hide state.
|
* See overloaded [BitwardenPasswordFieldWithActions] for managed show/hide state.
|
||||||
*
|
*
|
||||||
* @param label Label for the text field.
|
* @param label Label for the text field.
|
||||||
* @param value Current next on the text field.
|
* @param value Current next on the text field.
|
||||||
|
* @param showPassword Whether or not password should be shown.
|
||||||
|
* @param showPasswordChange Lambda that is called when user request show/hide be toggled.
|
||||||
* @param onValueChange Callback that is triggered when the password changes.
|
* @param onValueChange Callback that is triggered when the password changes.
|
||||||
* @param modifier Modifier for the composable.
|
* @param modifier Modifier for the composable.
|
||||||
* @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.
|
||||||
@@ -35,6 +41,8 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
|||||||
fun BitwardenPasswordFieldWithActions(
|
fun BitwardenPasswordFieldWithActions(
|
||||||
label: String,
|
label: String,
|
||||||
value: String,
|
value: String,
|
||||||
|
showPassword: Boolean,
|
||||||
|
showPasswordChange: (Boolean) -> Unit,
|
||||||
onValueChange: (String) -> Unit,
|
onValueChange: (String) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
readOnly: Boolean = false,
|
readOnly: Boolean = false,
|
||||||
@@ -48,6 +56,8 @@ fun BitwardenPasswordFieldWithActions(
|
|||||||
BitwardenPasswordField(
|
BitwardenPasswordField(
|
||||||
label = label,
|
label = label,
|
||||||
value = value,
|
value = value,
|
||||||
|
showPasswordChange = showPasswordChange,
|
||||||
|
showPassword = showPassword,
|
||||||
onValueChange = onValueChange,
|
onValueChange = onValueChange,
|
||||||
readOnly = readOnly,
|
readOnly = readOnly,
|
||||||
singleLine = singleLine,
|
singleLine = singleLine,
|
||||||
@@ -59,6 +69,50 @@ fun BitwardenPasswordFieldWithActions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Bitwarden-styled password field that manages the state of a show/hide indicator
|
||||||
|
* internally.
|
||||||
|
*
|
||||||
|
* See overloaded [BitwardenPasswordFieldWithActions] for self managed show/hide state.
|
||||||
|
*
|
||||||
|
* @param label Label for the text field.
|
||||||
|
* @param value Current next on the text field.
|
||||||
|
* @param onValueChange Callback that is triggered when the password changes.
|
||||||
|
* @param modifier Modifier for the composable.
|
||||||
|
* @param readOnly `true` if the input should be read-only and not accept user interactions.
|
||||||
|
* @param singleLine when `true`, this text field becomes a single line that horizontally scrolls
|
||||||
|
* instead of wrapping onto multiple lines.
|
||||||
|
* @param initialShowPassword The initial state of the show/hide password control. A value of
|
||||||
|
* `false` (the default) indicates that that password should begin in the hidden state.
|
||||||
|
* @param actions A lambda containing the set of actions (usually icons or similar) to display
|
||||||
|
* in the app bar's trailing side. This lambda extends [RowScope], allowing flexibility in
|
||||||
|
* defining the layout of the actions.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun BitwardenPasswordFieldWithActions(
|
||||||
|
label: String,
|
||||||
|
value: String,
|
||||||
|
onValueChange: (String) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
readOnly: Boolean = false,
|
||||||
|
singleLine: Boolean = false,
|
||||||
|
initialShowPassword: Boolean = false,
|
||||||
|
actions: @Composable RowScope.() -> Unit = {},
|
||||||
|
) {
|
||||||
|
var shouldShowPassword by remember { mutableStateOf(initialShowPassword) }
|
||||||
|
BitwardenPasswordFieldWithActions(
|
||||||
|
label = label,
|
||||||
|
value = value,
|
||||||
|
showPassword = shouldShowPassword,
|
||||||
|
showPasswordChange = { shouldShowPassword = !shouldShowPassword },
|
||||||
|
onValueChange = onValueChange,
|
||||||
|
modifier = modifier,
|
||||||
|
readOnly = readOnly,
|
||||||
|
singleLine = singleLine,
|
||||||
|
actions = actions,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun BitwardenPasswordFieldWithActions_preview() {
|
private fun BitwardenPasswordFieldWithActions_preview() {
|
||||||
|
|||||||
Reference in New Issue
Block a user