Can't change cursor positon when in focused mode

1k views Asked by At

I have a dialog with and an editable textfield. Everything is working fine but I cant't change cursor positon when I have already started editing the field. I have to press the back button and focus it again in correct spot. Any ideas?

@Composable
inline fun DialogInputText(display: MutableState<Boolean>, text: String, title: String, noinline onTextSet: (String)->Unit){

    BaseDialog(display = display ) {

        var text by remember { mutableStateOf(TextFieldValue(text)) }

        DialogHeader(title = title)


        EditText(text, { text = it}, modifier = Modifier.padding(8.dp).height(30.dp))

        DialogButtons {
            TextButton(onClick = {display.value = false} ) {
                Text(text = "ZPĚT")
            }

            TextButton(onClick = {onTextSet.invoke(text.text)}) {
                Text(text = "POKRAČOVAT")
            }
        }
    }

}
@Composable
fun EditText(
    text: TextFieldValue,
    onValueChange: (TextFieldValue)->Unit,
    validate: (TextFieldValue)->Boolean = {true},
    modifier: Modifier = Modifier,
    label: String = "",
    textStyle:TextStyle = TextStyle(
        fontSize = 16.sp,
        fontWeight = FontWeight.Bold
    ),
    keyboardType: KeyboardType = KeyboardType.Text,
    color: Color = Colors.ChipGray
){
    val valid = validate(text)

    val color = if (valid) color else Colors.NotCompleted

    Stack(modifier.background(color, shape = RoundedCornerShape(50)), alignment = Alignment.Center) {

        if (text.text.isEmpty())
            Text(text = label)

        BaseTextField(
            value = text,
            onValueChange = onValueChange,
            textStyle = textStyle,
            modifier = Modifier.padding(start = 8.dp, end = 8.dp).fillMaxWidth(),
            keyboardType = keyboardType,
        )
    }
}

It was discussed here. But I couldn't get working solution out of it. Change Cursor Position and force SingleLine of TextField in Jetpack Compose

0

There are 0 answers