我有一个代表消息的可组合组件。每条消息都可以是传入或传出,具体取决于我想要反转消息组件中的所有项目。
我发现的唯一方法是强制 RTL 布局,但这也会导致文本被反转。

还有其他办法解决这个问题吗?
MessageView.kt
@Composable
fun MessageView(
message: Message
) = Row(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
verticalAlignment = Alignment.Bottom
) {
val (isIncoming) = message
val direction = if (isIncoming) {
LayoutDirection.Ltr
} else {
LayoutDirection.Rtl
}
CompositionLocalProvider(
LocalLayoutDirection provides direction
) {
MessageViewContent(message)
}
}
@Composable
private fun MessageViewContent(
message: Message
) = Row(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
verticalAlignment = Alignment.Bottom
) {
val (isIncoming, text, at) = message
val background: Color
val textColor: Color …Run Code Online (Sandbox Code Playgroud)