2

Compose for Wear OS: ScalingLazyColumn

 2 years ago
source link: https://proandroiddev.com/compose-for-wear-os-scalinglazycolumn-63f754e91edb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Compose for Wear OS: ScalingLazyColumn

In this blog post, we will explore the ScalingLazyColumn composable. It makes adding scaling and alpha animations in a scrollable container really easy.

If you are interested in exploring other components in Compose for Wear OS you can check out other blogs that I have written.

Series pitstops

If you have used LazyColumn in Jetpack Compose, you will find this composable similar to it. In fact, internally ScalingLazyColumn uses LazyColumn. Let’s understand the differences between these two composables and when to use which one while making apps in Wear OS.

Let’s add the required dependencies

Let’s have a look at the method signature of ScalingLazyColumn

If you have used LazyColumn before, most of these parameters would look familiar to you. reverseLayout will lay the items of the list from bottom to top and reverse the direction of scrolling if given the true value. verticalArrangement lays the items of the list with a top or bottom alignment based on the reverseLayout value and gives a default spacing to all the items of the list. horizontalAlignment as the name suggests lays the the items of the list horizontally. Similar to other composables you can provide modifier, contentPadding, state and content to it.

scalingParams is the parameter responsible for adding the scaling and alpha animations for the list items that are at the top or bottom edge of the screen. The gif later in the blog will help you to visualise this animation. The method ScalingLazyColumnDefaults.scalingParams() takes a bunch of parameters that have default values. This is how the method signature of the above method looks like

I won’t go into detail about what each of these parameters is, I would suggest to just play around with these values to get the desired scaling and alpha animations for your list. All these float values are between 0f and 1f which represents the percentage of the normal values so if edgeScale has a value of 0.5f, its size will be 50% of its normal size when animated along the edge.

Let’s have a look at this video to see the difference between LazyColumn and ScalingLazyColumn

1*cz_4wjhmXWwp1qQ9DgUpwQ.gif?q=20
compose-for-wear-os-scalinglazycolumn-63f754e91edb

On the right, you will notice that the ScalingLazyColumn adds a subtle animation on the edges when you scroll the content inside it. While making an app in Wear OS if you want to have such animations then you should use the ScalingLazyColumn otherwise you can use LazyColumn and avoid the cost of calculating the scaling and alpha animations required for the list items.

This is the code required to implement ScalingLazyColumn like the one shown in the video

The composable used inside ScalingLazyColumn is Chip, it is another composable that is part of the Compose for Wear OS library. You can use it to add a material design chip in your wearable apps.

If you have feedback, feel free to tweet/message me on Twitter.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK