Skip to content

Commit f5a8cbe

Browse files
committed
feat(account): add password visibility toggle
1 parent 0350cec commit f5a8cbe

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

  • ZalithLauncher/src/main/java/com/movtery/zalithlauncher/ui/screens/content/elements

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/ui/screens/content/elements/AccountElements.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import androidx.compose.material.icons.filled.Refresh
3434
import androidx.compose.material.icons.filled.RestartAlt
3535
import androidx.compose.material.icons.outlined.Checkroom
3636
import androidx.compose.material.icons.outlined.Link
37+
import androidx.compose.material.icons.outlined.Visibility
38+
import androidx.compose.material.icons.outlined.VisibilityOff
3739
import androidx.compose.material3.Button
3840
import androidx.compose.material3.DropdownMenu
3941
import androidx.compose.material3.DropdownMenuItem
@@ -70,6 +72,7 @@ import androidx.compose.ui.text.buildAnnotatedString
7072
import androidx.compose.ui.text.font.FontWeight
7173
import androidx.compose.ui.text.input.ImeAction
7274
import androidx.compose.ui.text.input.PasswordVisualTransformation
75+
import androidx.compose.ui.text.input.VisualTransformation
7376
import androidx.compose.ui.text.withStyle
7477
import androidx.compose.ui.unit.dp
7578
import androidx.compose.ui.window.Dialog
@@ -689,6 +692,8 @@ fun OtherServerLoginDialog(
689692
shape = MaterialTheme.shapes.large
690693
)
691694
Spacer(modifier = Modifier.size(8.dp))
695+
/** 是否显示密码 */
696+
var showPassword by rememberSaveable { mutableStateOf(false) }
692697
OutlinedTextField(
693698
modifier = Modifier
694699
.fillMaxWidth()
@@ -697,10 +702,22 @@ fun OtherServerLoginDialog(
697702
onValueChange = { password = it },
698703
isError = password.isEmpty(),
699704
label = { Text(text = stringResource(R.string.account_label_password)) },
700-
visualTransformation = PasswordVisualTransformation(),
705+
visualTransformation = if (showPassword) {
706+
VisualTransformation.None
707+
} else {
708+
PasswordVisualTransformation()
709+
},
701710
colors = TextFieldDefaults.colors(
702711
unfocusedContainerColor = Transparent,
703712
),
713+
trailingIcon = {
714+
IconButton(onClick = { showPassword = !showPassword }) {
715+
Icon(
716+
imageVector = if (showPassword) Icons.Outlined.Visibility else Icons.Outlined.VisibilityOff,
717+
contentDescription = stringResource(R.string.account_label_password)
718+
)
719+
}
720+
},
704721
supportingText = {
705722
if (password.isEmpty()) {
706723
Text(text = stringResource(R.string.account_supporting_password_invalid_empty))

0 commit comments

Comments
 (0)