https://kotlinlang.org logo
#compose
Title
# compose
m

Mehmet Peker

09/10/2020, 5:44 PM
LazyColumnFor is cant smooth scrolling.What is the problem?
z

Zach Klippenstein (he/him) [MOD]

09/10/2020, 5:52 PM
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

Mehmet Peker

09/10/2020, 6:06 PM
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

Zach Klippenstein (he/him) [MOD]

09/10/2020, 7:19 PM
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

Halil Ozercan

09/10/2020, 9:35 PM
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

Mehmet Peker

09/11/2020, 9:26 AM
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

Zach Klippenstein (he/him) [MOD]

09/11/2020, 2:27 PM
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

Mehmet Peker

09/11/2020, 3:26 PM
@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

Zach Klippenstein (he/him) [MOD]

09/11/2020, 3:34 PM
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

Mehmet Peker

09/11/2020, 5:02 PM
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

Zach Klippenstein (he/him) [MOD]

09/11/2020, 5:44 PM
It basically just means it’s not optimized yet.
m

Mehmet Peker

09/11/2020, 5:45 PM
Thank you again
z

Zach Klippenstein (he/him) [MOD]

09/11/2020, 5:45 PM
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

Halil Ozercan

09/12/2020, 2:45 PM
thanks @Zach Klippenstein (he/him) [MOD] I wasn't aware of
LazyColumn
API.
m

Mehmet Peker

09/12/2020, 10:06 PM
@Zach Klippenstein (he/him) [MOD] thank you for your answer.i learned one more android programming logic
6 Views