@@ -29,8 +29,10 @@ import androidx.compose.foundation.layout.Arrangement
2929import androidx.compose.foundation.layout.Box
3030import androidx.compose.foundation.layout.Column
3131import androidx.compose.foundation.layout.Row
32+ import androidx.compose.foundation.layout.Spacer
3233import androidx.compose.foundation.layout.fillMaxWidth
3334import androidx.compose.foundation.layout.padding
35+ import androidx.compose.foundation.layout.requiredSize
3436import androidx.compose.foundation.layout.width
3537import androidx.compose.foundation.shape.RoundedCornerShape
3638import androidx.compose.foundation.text.BasicSecureTextField
@@ -648,9 +650,9 @@ private fun TextSample(samples: Map<String, @Composable () -> Unit>) {
648650
649651private const val SAMPLE_LONG_TEXT =
650652 " Jetpack Compose is Android’s modern toolkit for building native UI. " +
651- " It simplifies and accelerates UI development on Android bringing your apps " +
652- " to life with less code, powerful tools, and intuitive Kotlin APIs. " +
653- " It makes building Android UI faster and easier."
653+ " It simplifies and accelerates UI development on Android bringing your apps " +
654+ " to life with less code, powerful tools, and intuitive Kotlin APIs. " +
655+ " It makes building Android UI faster and easier."
654656
655657@Composable
656658@Preview
@@ -819,7 +821,7 @@ fun PhoneNumber() {
819821// [END android_compose_text_auto_format_phone_number_textfieldconfig]
820822
821823// [START android_compose_text_auto_format_phone_number_transformtext]
822- class NanpVisualTransformation () : VisualTransformation {
824+ class NanpVisualTransformation : VisualTransformation {
823825
824826 override fun filter (text : AnnotatedString ): TransformedText {
825827 val trimmed = if (text.text.length >= 10 ) text.text.substring(0 .. 9 ) else text.text
@@ -880,27 +882,37 @@ fun PasswordTextField() {
880882 } else {
881883 TextObfuscationMode .RevealLastTyped
882884 },
883- modifier = Modifier .fillMaxWidth()
885+ modifier = Modifier
886+ .fillMaxWidth()
884887 .padding(6 .dp)
885888 .border(1 .dp, Color .LightGray , RoundedCornerShape (6 .dp))
886889 .padding(6 .dp),
887- decorator = {
888- Icon (
889- if (showPassword) {
890- Icons .Filled .Visibility
891- } else {
892- Icons .Filled .VisibilityOff
893- },
894- contentDescription = " Toggle password visibility" ,
895- modifier = Modifier .clickable { showPassword = ! showPassword }
896- )
890+ decorator = { innerTextField ->
891+ Box (modifier = Modifier .fillMaxWidth()) {
892+ Box (modifier = Modifier
893+ .align(Alignment .CenterStart )
894+ .padding(start = 16 .dp,end = 48 .dp)) {
895+ innerTextField()
896+ }
897+ Icon (
898+ if (showPassword) {
899+ Icons .Filled .Visibility
900+ } else {
901+ Icons .Filled .VisibilityOff
902+ },
903+ contentDescription = " Toggle password visibility" ,
904+ modifier = Modifier
905+ .align(Alignment .CenterEnd )
906+ .requiredSize(48 .dp).padding(16 .dp)
907+ .clickable { showPassword = ! showPassword }
908+ )
909+ }
897910 }
898911 )
899912}
900913// [END android_compose_text_auto_format_phone_number_showhidepassword]
901914
902915
903-
904916// [START android_compose_text_auto_format_phone_number_validatetext]
905917class EmailViewModel : ViewModel () {
906918 var email by mutableStateOf(" " )
@@ -945,7 +957,7 @@ fun ValidatingInputTextField(
945957@Preview
946958@Composable
947959fun ValidateInput () {
948- val emailViewModel : EmailViewModel = viewModel<EmailViewModel >()
960+ val emailViewModel: EmailViewModel = viewModel<EmailViewModel >()
949961 ValidatingInputTextField (
950962 email = emailViewModel.email,
951963 updateState = { input -> emailViewModel.updateEmail(input) },
0 commit comments