mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Add BitwardenPasswordFieldWithActions with manual password visibility (#294)
This commit is contained in:
parent
90f565e02b
commit
d404b95b6d
1 changed files with 55 additions and 1 deletions
|
@ -4,6 +4,10 @@ import androidx.compose.foundation.layout.Row
|
|||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.Modifier
|
||||
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
|
||||
* 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 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 modifier Modifier for the composable.
|
||||
* @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(
|
||||
label: String,
|
||||
value: String,
|
||||
showPassword: Boolean,
|
||||
showPasswordChange: (Boolean) -> Unit,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
readOnly: Boolean = false,
|
||||
|
@ -48,6 +56,8 @@ fun BitwardenPasswordFieldWithActions(
|
|||
BitwardenPasswordField(
|
||||
label = label,
|
||||
value = value,
|
||||
showPasswordChange = showPasswordChange,
|
||||
showPassword = showPassword,
|
||||
onValueChange = onValueChange,
|
||||
readOnly = readOnly,
|
||||
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)
|
||||
@Composable
|
||||
private fun BitwardenPasswordFieldWithActions_preview() {
|
||||
|
|
Loading…
Add table
Reference in a new issue