Attempt to fix showing keyboard for new tasks

pull/4090/head
Alex Baker 3 days ago
parent 098ade6111
commit e46ecfa44e

@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
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
@ -102,16 +101,25 @@ fun EditTextView(
context.resources.getDimension(R.dimen.task_edit_text_size)
)
linkify?.linkify(this)
if (requestFocus) {
post { shouldRequestFocus = true }
}
}
},
update = { view ->
if (shouldRequestFocus) {
shouldRequestFocus = false
view.post {
if (view.requestFocus()) {
val imm = context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
fun tryFocus(attempts: Int = 3) {
if (view.requestFocus()) {
val imm = context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
} else if (attempts > 1) {
view.postDelayed({ tryFocus(attempts - 1) }, 50)
}
}
tryFocus()
}
}
view.paintFlags = if (strikethrough) {
@ -121,10 +129,4 @@ fun EditTextView(
}
},
)
LaunchedEffect(Unit) {
if (requestFocus) {
shouldRequestFocus = true
}
}
}
}

Loading…
Cancel
Save