Quellcode durchsuchen

login screen set focus

Khubaib vor 9 Monaten
Ursprung
Commit
1735bdd407

+ 1 - 1
.idea/deploymentTargetSelector.xml

@@ -4,7 +4,7 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
-        <DropdownSelection timestamp="2024-07-01T09:12:48.052197565Z">
+        <DropdownSelection timestamp="2024-07-01T15:57:05.181697550Z">
           <Target type="DEFAULT_BOOT">
             <handle>
               <DeviceId pluginId="LocalEmulator" identifier="path=/home/ubuntu/.android/avd/Television_1080p_API_31.avd" />

+ 31 - 28
app/src/main/java/com/vpn/fastestvpnservice/screensTV/LoginScreenTV.kt

@@ -1,5 +1,6 @@
 package com.vpn.fastestvpnservice.screensTV
 
+import android.util.Log
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
@@ -25,6 +26,7 @@ import androidx.compose.material3.Text
 import androidx.compose.material3.TextField
 import androidx.compose.material3.TextFieldDefaults
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
@@ -62,15 +64,20 @@ import com.vpn.fastestvpnservice.ui.theme.customTypography
 @Composable
 fun LoginTV(navHostController: NavHostController) {
     val context = LocalContext.current
-    val basePreferenceHelper = BasePreferenceHelper(context)
     val keyboardController = LocalSoftwareKeyboardController.current
     val focusManager = LocalFocusManager.current
     var textChanged by remember { mutableStateOf("") }
     var passwordChanged by remember { mutableStateOf("") }
-    var showErrorEmail by remember { mutableStateOf(false) }
-    var isTextFieldFocused by remember { mutableStateOf(false) }
-    var isTextFieldFocused2 by remember { mutableStateOf(false) }
-//    val focusRequester = remember { FocusRequester() }
+    val showErrorEmail by remember { mutableStateOf(false) }
+    val isTextFieldFocused by remember { mutableStateOf(false) }
+    val isTextFieldFocused2 by remember { mutableStateOf(false) }
+    val focusRequester1 = remember { FocusRequester() }
+    val focusRequester2 = remember { FocusRequester() }
+    val focusRequester3 = remember { FocusRequester() }
+
+    LaunchedEffect(key1 = Unit) {
+        focusRequester1.requestFocus()
+    }
 
     Scaffold(
         content = { padding ->
@@ -124,13 +131,12 @@ fun LoginTV(navHostController: NavHostController) {
                                 shape = RoundedCornerShape(16.dp)
                             )
                             .background(color = colorResource(id = R.color.transparent))
-//                            .focusRequester(focusRequester)
+                            .focusRequester(focusRequester1)
 //                            .onFocusChanged {
-//                                isTextFieldFocused = it.isFocused
-//                                keyboardController?.show()
+////                                isTextFieldFocused = it.isFocused
+//                                focusRequester2.requestFocus()
 //                            }
 //                            .focusable()
-//                            .clickable() {}
                         ,
                         shape = RoundedCornerShape(16.dp),
                         label = {
@@ -166,6 +172,7 @@ fun LoginTV(navHostController: NavHostController) {
                             onDone = {
                                 focusManager.clearFocus()
                                 keyboardController?.hide()
+                                focusRequester2.requestFocus()
                             }
                         ),
                     )
@@ -189,12 +196,12 @@ fun LoginTV(navHostController: NavHostController) {
                                 else colorResource(id = R.color.white),
                                 shape = RoundedCornerShape(16.dp)
                             )
+                            .focusRequester(focusRequester2)
 //                            .background(color = colorResource(id = R.color.transparent))
 //                            .onFocusChanged {
 //                                isTextFieldFocused2 = it.isFocused
 //                            }
 //                            .focusable()
-//                            .clickable() {}
                         ,
 
                         leadingIcon = {
@@ -231,11 +238,12 @@ fun LoginTV(navHostController: NavHostController) {
                             onDone = {
                                 focusManager.clearFocus()
                                 keyboardController?.hide()
+                                focusRequester3.requestFocus()
                             }
                         ),
                     )
                     Spacer(modifier = Modifier.height(25.dp))
-                    LoginButtonTV(navHostController)
+                    LoginButtonTV(navHostController, focusRequester3)
                 }
             }
         }
@@ -243,25 +251,21 @@ fun LoginTV(navHostController: NavHostController) {
 }
 
 @Composable
-fun ColumnScope.LoginButtonTV(navHostController: NavHostController) {
+fun ColumnScope.LoginButtonTV(navHostController: NavHostController,
+                              focusRequester3: FocusRequester) {
     var isButtonFocused by remember { mutableStateOf(false) }
-    val focusRequester = remember { FocusRequester() }
-    val focusManager = LocalFocusManager.current
-    val context = LocalContext.current
     Button(
         modifier = Modifier
             .background(colorResource(id = R.color.transparent))
             .fillMaxWidth(fraction = 0.5f)
             .height(60.dp)
-            .focusRequester(focusRequester)
+            .focusRequester(focusRequester3)
             .onFocusChanged {
                 isButtonFocused = it.isFocused
             }
-            .focusable()
-//            .clickable() { }
+//            .focusable()
         ,
         onClick = {
-                  focusRequester.requestFocus()
 //            Toast.makeText(
 //                context, "Test", Toast.LENGTH_SHORT
 //            ).show()
@@ -284,14 +288,14 @@ fun ColumnScope.LoginButtonTV(navHostController: NavHostController) {
             focusedContainerColor = if (isButtonFocused) colorResource(id = R.color.white) else colorResource(id = R.color.lightNavy),
             disabledContainerColor = if (isButtonFocused) colorResource(id = R.color.white) else colorResource(id = R.color.lightNavy),
         ),
-        border = ButtonDefaults.border(
-            border = Border(
-                border = BorderStroke(
-                    0.dp, if(isButtonFocused) colorResource(id = R.color.transparent)
-                    else colorResource(id = R.color.transparent)
-                )
-            ),
-        )
+//        border = ButtonDefaults.border(
+//            border = Border(
+//                border = BorderStroke(
+//                    0.dp, if(isButtonFocused) colorResource(id = R.color.transparent)
+//                    else colorResource(id = R.color.transparent)
+//                )
+//            ),
+//        )
     ) {
         Surface(
             modifier = Modifier
@@ -302,7 +306,6 @@ fun ColumnScope.LoginButtonTV(navHostController: NavHostController) {
                 contentColor = if (isButtonFocused) colorResource(id = R.color.blue_text) else colorResource(id = R.color.white),
                 containerColor = if (isButtonFocused) colorResource(id = R.color.white) else colorResource(id = R.color.lightNavy),
             )
-
         ) {
             Text(
                 modifier = Modifier