Просмотр исходного кода

added opening keyboard in edit mode

sirekanian 3 лет назад
Родитель
Сommit
5e4427e188
1 измененных файлов с 9 добавлено и 1 удалено
  1. 9 1
      app/src/main/java/com/sirekanian/spacetime/ui/ImagePageContent.kt

+ 9 - 1
app/src/main/java/com/sirekanian/spacetime/ui/ImagePageContent.kt

@@ -12,6 +12,8 @@ import androidx.compose.runtime.*
 import androidx.compose.ui.ExperimentalComposeUiApi
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.draw.blur
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
 import androidx.compose.ui.layout.ContentScale
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.pluralStringResource
@@ -94,14 +96,20 @@ fun ImagePageContent(
         topSpaceWeight.let { weight -> if (weight > 0) Spacer(Modifier.weight(weight)) }
         val textStyle = MaterialTheme.typography.h2.copy(textAlign = TextAlign.Center)
         if (isEditMode) {
+            val focusRequester = remember { FocusRequester() }
             OutlinedTextField(
                 value = name,
                 onValueChange = { name = it },
-                modifier = Modifier.fillMaxWidth(),
+                modifier = Modifier
+                    .fillMaxWidth()
+                    .focusRequester(focusRequester),
                 textStyle = textStyle,
                 placeholder = { Text("Title", Modifier.fillMaxWidth(), style = textStyle) },
                 maxLines = 2,
             )
+            LaunchedEffect(Unit) {
+                focusRequester.requestFocus()
+            }
             OutlinedTextField(
                 value = date.value,
                 onValueChange = { date = DateField(it) },