Focus to new message after resume
This commit is contained in:
@@ -65,6 +65,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
@@ -462,6 +464,7 @@ class ChatActivity : ComponentActivity() {
|
|||||||
mutableStateOf(TextFieldValue(""))
|
mutableStateOf(TextFieldValue(""))
|
||||||
}
|
}
|
||||||
var textFieldLoaded by remember { mutableStateOf(false) }
|
var textFieldLoaded by remember { mutableStateOf(false) }
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
|
||||||
EventListener {
|
EventListener {
|
||||||
when (it) {
|
when (it) {
|
||||||
@@ -506,23 +509,17 @@ class ChatActivity : ComponentActivity() {
|
|||||||
) {
|
) {
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = newMessage.value.text,
|
value = newMessage.value,
|
||||||
placeholder = { Text(stringResource(R.string.new_message)) },
|
placeholder = { Text(stringResource(R.string.new_message)) },
|
||||||
onValueChange = {
|
onValueChange = { newMessage.value = it },
|
||||||
newMessage.value = newMessage.value.copy(text = it)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(end = 8.dp)
|
.padding(end = 8.dp)
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
|
.focusRequester(focusRequester)
|
||||||
.onGloballyPositioned {
|
.onGloballyPositioned {
|
||||||
if (!textFieldLoaded) {
|
if (!textFieldLoaded)
|
||||||
textFieldLoaded = true
|
textFieldLoaded = true
|
||||||
//val textLength = newMessage.value.text.length
|
|
||||||
//newMessage.value = newMessage.value.copy(
|
|
||||||
// selection = TextRange(textLength)
|
|
||||||
//)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
onClick = {
|
onClick = {
|
||||||
@@ -607,6 +604,8 @@ class ChatActivity : ComponentActivity() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
if (newMessage.value.text.isNotEmpty())
|
||||||
|
focusRequester.requestFocus()
|
||||||
}
|
}
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.drawable.send),
|
painter = painterResource(id = R.drawable.send),
|
||||||
|
|||||||
Reference in New Issue
Block a user