Browse Source

@fun: Login

bai 2 years ago
parent
commit
1f7b2812fa
1 changed files with 38 additions and 36 deletions
  1. 38 36
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Login.kt

+ 38 - 36
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Login.kt

@@ -43,22 +43,33 @@ fun Login() {
     var password by remember { mutableStateOf("123456") }
     var visualState: VisualTransformation by remember { mutableStateOf(PasswordVisualTransformation()) }
 
-    var usernameLeadingIconColor by remember { mutableStateOf(Color(0xFFC3C7CB)) }
-    var passwordLeadingIconColor by remember { mutableStateOf(Color(0xFFC3C7CB)) }
+    var usernameLeadingIconColor by remember { mutableStateOf(grayColor) }
+    var passwordLeadingIconColor by remember { mutableStateOf(grayColor) }
 
     val snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
     val scope = rememberCoroutineScope()
 
     val nav = LocalNavHostController.current!!
 
+    val textFieldColors = TextFieldDefaults.outlinedTextFieldColors(
+        textColor = textBlackColor,
+        cursorColor = blueColor,
+        focusedBorderColor = blueColor,
+        unfocusedBorderColor = grayColor,
+        focusedLabelColor = blueColor,
+        unfocusedLabelColor = grayColor,
+        backgroundColor = Color.Transparent
+    )
+
     OutlinedTextField(
         value = username,
-        modifier = Modifier.fillMaxWidth().onFocusChanged { focusState: FocusState ->
-            usernameLeadingIconColor = if (focusState.isFocused)
-                blueColor
-            else
-                grayColor
-        },
+        modifier = Modifier.fillMaxWidth()
+            .onFocusChanged { focusState: FocusState ->
+                usernameLeadingIconColor = if (focusState.isFocused)
+                    blueColor
+                else
+                    grayColor
+            },
         onValueChange = {
             username = it
             isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
@@ -66,15 +77,7 @@ fun Login() {
         label = {
             Text(text = "请输入账号")
         },
-        colors = TextFieldDefaults.outlinedTextFieldColors(
-            textColor = textBlackColor,
-            cursorColor = blueColor,
-            focusedBorderColor = blueColor,
-            unfocusedBorderColor = grayColor,
-            focusedLabelColor = blueColor,
-            unfocusedLabelColor = grayColor,
-            backgroundColor = Color.Transparent
-        ),
+        colors = textFieldColors,
         leadingIcon = {
             Icon(
                 painter = painterResource(R.drawable.login_user),
@@ -90,6 +93,7 @@ fun Login() {
                         isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
                     },
                     enabled = username.isNotEmpty(),
+                    modifier = Modifier.size(32.dp)
                 ) {
                     Icon(
                         painter = painterResource(R.drawable.login_delete),
@@ -119,15 +123,7 @@ fun Login() {
             isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
         },
         label = { Text(text = "请输入密码") },
-        colors = TextFieldDefaults.outlinedTextFieldColors(
-            textColor = textBlackColor,
-            cursorColor = blueColor,
-            focusedBorderColor = blueColor,
-            unfocusedBorderColor = grayColor,
-            focusedLabelColor = blueColor,
-            unfocusedLabelColor = grayColor,
-            backgroundColor = Color.Transparent
-        ),
+        colors = textFieldColors,
         visualTransformation = visualState,
         leadingIcon = {
             Icon(
@@ -138,12 +134,12 @@ fun Login() {
         },
         trailingIcon = {
             Row(
-                horizontalArrangement = Arrangement.End,
                 verticalAlignment = Alignment.CenterVertically
             ) {
                 if (password.isNotBlank()) {
                     IconButton(
-                        onClick = { isShowPassword = !isShowPassword }
+                        onClick = { isShowPassword = !isShowPassword },
+                        modifier = Modifier.size(32.dp)
                     ) {
                         val icon =
                             if (isShowPassword) R.drawable.login_eye_open else R.drawable.login_eye_close
@@ -153,33 +149,33 @@ fun Login() {
                         Icon(
                             painter = painterResource(icon),
                             contentDescription = description,
-                            modifier = Modifier.size(18.dp).padding(0.dp),
+                            modifier = Modifier.size(16.dp),
                             tint = grayColor
                         )
                     }
-
                     IconButton(
                         onClick = {
                             password = ""
                             isShowPassword = false
                             isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
                         },
-                        enabled = password.isNotEmpty()
+                        enabled = password.isNotEmpty(),
+                        modifier = Modifier.size(32.dp)
                     ) {
                         Icon(
                             painter = painterResource(R.drawable.login_delete),
                             contentDescription = "",
-                            modifier = Modifier.size(18.dp),
+                            modifier = Modifier.size(16.dp),
                             tint = grayColor
                         )
                     }
+                    Spacer(modifier = Modifier.width(8.dp))
                 }
             }
         }
     )
 
-
-    Spacer(modifier = Modifier.height(32.dp))
+    Spacer(modifier = Modifier.height(40.dp))
 
     Button(
         onClick = {
@@ -215,7 +211,14 @@ fun Login() {
         },
         enabled = isLoginBtnEnable,
         modifier = Modifier.fillMaxWidth().height(48.dp),
-        shape = RoundedCornerShape(4),
+        shape = RoundedCornerShape(8),
+        elevation = ButtonDefaults.elevation(
+            defaultElevation = 0.dp,
+            pressedElevation = 0.dp,
+            disabledElevation = 0.dp,
+            hoveredElevation = 0.dp,
+            focusedElevation = 0.dp
+        ),
         colors = ButtonDefaults.buttonColors(
             backgroundColor = Color(0xFF0091FF),
             disabledBackgroundColor = Color(0xFFEFF0F1)
@@ -229,7 +232,6 @@ fun Login() {
     }
 
     Spacer(modifier = Modifier.fillMaxWidth().height(24.dp))
-
     SnackbarHost(
         hostState = snackbarHostState
     ) { data ->