LazyColumnFor is cant smooth scrolling.What is the...
# compose
m
LazyColumnFor is cant smooth scrolling.What is the problem?
z
Do you mean there’s no API to request a smooth scroll to a particular location, or that manual scrolling isn’t smooth?
The API for controlling scroll state is coming, and if manual scrolling is janky, they are still doing a lot of optimizations there.
m
I use LazyColumnFor for show list.Scrolling is not like recyclerview.
The cause of the problem is use LazyColumnFor in ScrollableColumn.Scrolling is not smoothly.
How i solve this problem?
z
You might be able to do some optimization of your individual item composables, but there have been a few discussions of its performance in this channel and for the most part I think all you can do is wait for them to optimize more. That said, if you can make your code public, you can always file an issue on the Compose issue tracker linked in the channel topic.
h
You have mentioned about using lazycolumnfor inside a scrollablecolumn. In that case, all the content of LazyColumnFor will be rendered to figure out the layout of ScrollableColumn. That will disable all the benefits of using LazyColumnFor.
m
What should i do?I have a other composable functions besides of LazyColumnFor.I want to use them together.Is it possible to disable the LazyColumnFor scroll feature?Maybe this will fix the problem
z
Can you share any code? If you're using a lazy column inside a scrollable column I think it should be fine as long as you constrain the height.
m
@Zach Klippenstein (he/him) [MOD]
Copy code
@Composable
fun FridayMessageScreen() {
    val context = ContextAmbient.current
    val color = ContextCompat.getColor(context,R.color.grey200)
    val messageList = ContextAmbient.current.resources.getStringArray(R.array.fridayMessage).toList()
    Scaffold(topBar = { FridayMessageAppBar() },backgroundColor = Color(color)) {
        ScrollableColumn() {
                Text("Example of Scrollable Column")
                Text("Example of Scrollable Column")
                Text("Example of Scrollable Column")
            LazyColumnFor(items = messageList) {
                FridayMessageCard(it)
            }
        }
    }
}

@Composable
fun FridayMessageAppBar() {
    val title = ContextAmbient.current.resources.getString(R.string.title_friday_message)
    TopAppBar(
            title = { Text(text = title) },
            backgroundColor = Color.White,
            navigationIcon = {
                IconButton(onClick = { MainActivity.popBackStack() }) {
                    Icon(vectorResource(id = R.drawable.ic_baseline_arrow_back_ios_24), tint = Color.Black)
                }
            }
    )
}

@Composable
fun FridayMessageCard(s: String) {
    val context = ContextAmbient.current
    Card(modifier = Modifier.fillMaxWidth().gravity(Alignment.CenterVertically).padding(top = 8.dp),shape = RectangleShape) {
        Column {
            Text(style = TextStyle(fontSize = 14.sp), text = s, modifier = Modifier.padding(8.dp)
            )
            Spacer(modifier = Modifier.height(4.dp))
            Divider(modifier = Modifier.height(0.3.dp), color = Color.Black)
            Row(modifier = Modifier.gravity(Alignment.End), verticalGravity = Alignment.CenterVertically) {
                val color = context.getColorFromAttr(R.attr.colorPrimary)
                Text(text = "Share", color = Color(color))
                IconButton(onClick = {}) {
                    val color = context.getColorFromAttr(R.attr.colorPrimary)
                    Icon(vectorResource(id = R.drawable.ic_baseline_share_24), tint = Color(color))
                }
            }
        }
    }
}
z
Yea that's not gonna work. I think you want something like
Copy code
LazyColumn {
  item { Text() }
  item { Text() }
  item { Text() }
  items(messageList) {
    FridayMessageCard()
  }
}
m
Thank your very much but ı got this error: This is an experimental API for demonstrating how LazyColumn / LazyRow should workusing a DSL implementation. This is a prototype and its implementation is not suited for PagedList or large lists.
What is meaning large list?
z
It basically just means it’s not optimized yet.
m
Thank you again
z
You can also use
LazyColumnFor
, but you’d need to prepend your static items to your list and then render them differently somehow (e.g. using a sealed class to represent your two item types). Using
LazyColumn
is just simpler since the API is designed to support this sort of use case. But like the warning says, it’s basically a proof-of-concept at this point, and the API will probably change.
h
thanks @Zach Klippenstein (he/him) [MOD] I wasn't aware of
LazyColumn
API.
m
@Zach Klippenstein (he/him) [MOD] thank you for your answer.i learned one more android programming logic