Added auto-focus in the ask me anything dialog
This commit is contained in:
parent
774adb608d
commit
170dc6b655
@ -5,10 +5,14 @@ import androidx.compose.foundation.layout.*
|
|||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.RectangleShape
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@ -18,6 +22,7 @@ import ch.mathieubroillet.jarvis.android.R
|
|||||||
import ch.mathieubroillet.jarvis.android.ui.theme.JarvisComposeTheme
|
import ch.mathieubroillet.jarvis.android.ui.theme.JarvisComposeTheme
|
||||||
import ch.mathieubroillet.jarvis.android.ui.theme.productSansFont
|
import ch.mathieubroillet.jarvis.android.ui.theme.productSansFont
|
||||||
|
|
||||||
|
@OptIn(ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun IconAlertDialogTextField(
|
fun IconAlertDialogTextField(
|
||||||
buttonIcon: Int = R.drawable.ic_baseline_error_24,
|
buttonIcon: Int = R.drawable.ic_baseline_error_24,
|
||||||
@ -72,6 +77,7 @@ fun IconAlertDialogTextField(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
|
val (focusRequester) = FocusRequester.createRefs()
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = text,
|
value = text,
|
||||||
onValueChange = textFieldValue,
|
onValueChange = textFieldValue,
|
||||||
@ -79,8 +85,15 @@ fun IconAlertDialogTextField(
|
|||||||
colors = TextFieldDefaults.outlinedTextFieldColors(
|
colors = TextFieldDefaults.outlinedTextFieldColors(
|
||||||
focusedBorderColor = MaterialTheme.colors.secondaryVariant,
|
focusedBorderColor = MaterialTheme.colors.secondaryVariant,
|
||||||
focusedLabelColor = MaterialTheme.colors.secondary
|
focusedLabelColor = MaterialTheme.colors.secondary
|
||||||
|
),
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.focusRequester(focusRequester)
|
||||||
)
|
)
|
||||||
)
|
//Auto-focus on the textfield when opening the dialog which opens the keyboard directly.
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
onDispose { }
|
||||||
|
}
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
Modifier
|
Modifier
|
||||||
|
Loading…
Reference in New Issue
Block a user