为什么 BasicTextField(在撰写中)不能正常工作?

Why BasicTextField (in compose) doesn't work well?

我正在尝试将 BasicTextFieldTextAlignment.End 一起用于 RTL。这是我的代码:

val textState = remember { mutableStateOf(TextFieldValue("")) }
val shape = RoundedCornerShape(CornerSize(4.dp))
BasicTextField(
    value = textState.value,
    onValueChange = { newText -> textState.value = newText },
    textStyle = LocalTextStyle.current.copy(
        color = ColorPrimaryDarkText,
        fontWeight = FontWeight.Medium,
        textAlign = TextAlign.End,
        fontSize = 14.sp,
    ),
    maxLines = 1,
    singleLine = true,
    modifier = Modifier
        .fillMaxWidth()
        .padding(32.dp, 0.dp)
        .clip(shape)
        .background(color = Color.White),
    keyboardOptions = KeyboardOptions(
        keyboardType = KeyboardType.Text,
        imeAction = ImeAction.Done
    ),

    decorationBox = { innerTextField ->
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .background(Color.White, shape)
                .padding(8.dp),
        ) {
            if (textState.value.text.isEmpty()) {
                Text(
                    text = "hint",
                    textAlign = TextAlign.End,
                    fontWeight = FontWeight.Medium,
                    modifier = Modifier.fillMaxWidth(),
                    fontSize = 14.sp,
                )
            } else {
                innerTextField()
            }
        }
    }
)

当它为空时还可以,但当您尝试键入任何内容时它就无法正常工作(它开始从中心开始键入):

删除 textAlign = TextAlign.End 并使用如下内容:

CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl ) {
    BasicTextField( /* your code */)
}

否则,如果您想使用您的代码,请在 decorationBox 参数中的 Row 中添加 horizontalArrangement = Arrangement.End

    decorationBox = { innerTextField ->
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .background(Color.White, shape)
                .padding(8.dp),
            horizontalArrangement = Arrangement.End){
              //your code
     }