简体   繁体   English

TextDecoration 不适用于 LazyColumn 项目

[英]TextDecoration not applying in LazyColumn item

I've started a todo-list app to get into jetpack compose.我已经启动了一个待办事项列表应用程序来进入 jetpack compose。 Here's what I've got so far.这是我到目前为止所得到的。

I have a composable for a Todo:我有一个 Todo 的组合:

@Composable
fun Todo(
    todo: TodoItem = TodoItem()
) {
    Row() {
        Checkbox

        Spacer

        if (todo.editing)
            EditTodo(todo, onEditingFinished = onEditingFinished)
        else
            TodoText(todo = todo)
    }
}

I've omitted the styling bits in here to highlight the actual components我在这里省略了样式位以突出显示实际组件

For reference, here's the TodoItem :作为参考,这里是TodoItem

data class TodoItem(
    val id: String,
    val title: String,
    val done: Boolean,
    val editing: Boolean,
    val createdAt: Date,
)

The TodoText method is where I think my problem lies: TodoText方法是我认为我的问题所在:

@Composable
private fun TodoText(todo: TodoItem) {
    Text(
        text = todo.title,
        style = if (todo.done)
            TextStyle(
                textDecoration = TextDecoration.LineThrough,
                color = Color.LightGray,
                fontSize = 18.sp,
            )
        else
            TextStyle(
                textDecoration = TextDecoration.None,
                color = Color.Black,
                fontSize = 18.sp,
            )
    )
}

If the todo is done, I want to change the text style accordingly and as you can see from the following gif, the colour changes properly, but the decoration remains as LineThrough :如果待办事项完成,我想相应地更改文本样式,正如您从以下 gif 中看到的那样,颜色会正确更改,但装饰仍为LineThrough

待办事项清单检查项目


That said, I don't know exactly what's happening.也就是说,我不知道到底发生了什么。 I do put this all inside a LazyColumFor which I might not be recycling the views properly, there's also a viewmodel with mutable state here in the mix... All in all, there might be way more things at work here.我确实把这一切都放在了一个LazyColumFor ,我可能没有正确地回收视图,还有一个具有可变状态的视图模型在这里混合......总而言之,这里可能有更多的东西在工作。 I've added the code to github.我已将代码添加到github。 If you want to check it, please use this branch .如果你想检查它,请使用这个分支 I plan to keep updating master with code changes.我计划通过代码更改继续更新master

Apparently, this was an issue with the version of compose I was using, which was 1.0.0-alpha04 .显然,这是我使用的 compose 版本的问题,即1.0.0-alpha04

On 1.0.0-alpha06 the issue doesn't occur anymore.1.0.0-alpha06此问题不再发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM