Код: Выделить всё
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun CustomTextField(
value: String,
onValueChange: (String) -> Unit
) {
val bringIntoViewRequester = remember { BringIntoViewRequester() }
val coroutineScope = rememberCoroutineScope()
var textFieldValue by remember { mutableStateOf(TextFieldValue(value)) }
BasicTextField(
value = textFieldValue,
onValueChange = {
textFieldValue = it
onValueChange(it.text)
},
onTextLayout = {
val cursorRect = it.getCursorRect(textFieldValue.selection.start)
coroutineScope.launch {
bringIntoViewRequester.bringIntoView(cursorRect)
}
},
modifier = Modifier.bringIntoViewRequester(bringIntoViewRequester)
)
}
Итак, я попробовал использовать OutlinedTextField с DecorationBox, но этот подход не увенчался успехом.
Код: Выделить всё
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun CustomTextField(
value: String,
textStyle: TextStyle,
modifier: Modifier,
onValueChange: (String) -> Unit
) {
val bringIntoViewRequester = remember { BringIntoViewRequester() }
val coroutineScope = rememberCoroutineScope()
var textFieldValue by remember { mutableStateOf(TextFieldValue(value)) }
BasicTextField(
value = textFieldValue,
onValueChange = {
textFieldValue = it
onValueChange(it.text)
},
onTextLayout = {
val cursorRect = it.getCursorRect(textFieldValue.selection.start)
coroutineScope.launch {
bringIntoViewRequester.bringIntoView(cursorRect)
}
},
decorationBox = @Composable { innerTextField ->
OutlinedTextField(
value = textFieldValue.text,
onValueChange = {},
modifier = modifier.fillMaxWidth(),
textStyle = textStyle,
)
innerTextField()
},
modifier = Modifier.bringIntoViewRequester(bringIntoViewRequester)
)
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ck-compose