Video first

If you can easily watch videos, just go to Bilibili or YouTube.

Below is a transcript of the video. If you’ve seen the video, skip the script below and go straight to the bottom of the comments section.

Word version

How do I write property animation?

Call the animator’s start() function to play the animation:

We can also use the reverse() function to play the animation backwards:

Very simple, very convenient.

Compose’s animation can be even simpler. You just wrap the variable in a function, and the rest is done. The animation is automatic:

Make development more efficient, and we can relax a little bit. If we relax, the company can hire fewer programmers! (not)

“Easier” is not the real reason

Hi, I’m Zhu Kai from throwline.

Android properties animation, is very easy to use: powerful and simple. In Jetpack Compose, however, the property animation suite is not ported.

Why is that? As you just saw, Compose’s animation is much easier to write than the property animation. But!!! That’s not the reason it doesn’t have a porting property animation, because it’s just a facade, the real reason is the essence behind it.

The essential difference between the attribute animation and the Compose animation

Android property animation, in essence, is the View of the property gradient, that is, continuously modify the View object property value. So we need to get the View object first and then animate its properties. Now, in Compose, there’s no View; Not only is there no View, there is no other interface element equivalent to a View. The Compose code we wrote is only a description of the interface, not the interface elements themselves. The interface element is certainly there, and it certainly doesn’t come out of the air, but Compose’s interface element is active at the bottom and we can’t get it, so we can’t manipulate it.

However, we can use a method called State reactive power to expose the properties in the interface and then directly animate them. Due to the declarative nature of Compose, the property changes are applied directly to the interface and the animation is rendered. This is how the Compose animation is written, which is the function I demonstrated at the beginning: animateFloatAsState(). In addition to animateFloatAsState(), Compose also has animateDpAsState() animateColorAsState(), which is suitable for state transition animations. Compose also has an API for state transitions for multiple properties, animations for specific scenarios, and fine customization for complex animations.

The real reason

That…… Why write it differently instead of continuing with property animation? That’s what I was saying: the property animation is “take the View object, manipulate the properties of the object”, and Compose no longer has any interface elements for that object.

So why? Why don’t you let us have it? — Which brings us back to that word: declarative. Compose’s interface is declarative, and its core idea is to let developers describe the interface rather than manipulate its components. It’s more straightforward, dumber thinking, and easier to write. So this is actually progress.

But what if I really need to manipulate interface elements to do something else? — What do you want to do? Compose can do custom drawing, custom layout, custom touches, and custom listeners for Compose, all of which don’t require any of the so-called “interface elements.” It may sound crazy, but you’ll find out after you learn and write. Compose is a mature, integrated framework, so while it’s unlikely to break through the limitations of Android itself, you have to trust that it does.

So, why hasn’t the property animation been ported to Compose? The entire theoretical model of property animation is no longer applicable because Compose can’t get the interface element object. If I had to port the property animation to Compose, would I be able to do that? It’s technically possible, but it doesn’t have to be, and it shouldn’t be. We’re already familiar with attribute animations, but since Compose makes a more powerful and useful animation system than attribute animations, why not switch?

Compose is ready to start

Compose is ready to learn. Let me give you the facts. I have a Compose course, which has been remade since the second half of last year. Now the chapter of “animation” is about to be updated. During this period, we often receive feedback from some overseas students, mainly from the United States and Singapore, that they have already used Compose. The company requires me to learn Compose, so I hope I can update it soon. Although for new technology, our country will be more conservative than foreign countries, for example, from Eclipse to Android Studio, from Java to Kotlin, including the widespread acceptance of RxJava, the domestic acceptance of new technology will always be later than foreign countries. However, it’s only a matter of time before China will gradually switch to Compose. In fact, there are already some companies and teams in China for Compose, so it won’t be long before the “full switch” is made.

If you’re going to learn Compose, consider my course. I’ve spent more than a year working on Compose almost full-time, talking directly to people on the Android core team about some of the deeper issues, and people can verify my ability to deliver knowledge — especially deep knowledge — from my public videos, so if you’re looking for a Compose mentor, Looking for someone to take you from beginner to expert, I’m probably your best bet. Of course, you can learn Compose without taking my course. My role is to help you learn Compose at the speed of light and to help you reach the ultimate depth. It’s not easy to become a Compose expert in your spare time in a short period of time, but with my course, a month of Compose time is enough for you to become a Compose expert — a real one, and your knowledge of Compose will beat most of the big interviewers — except for those who already sign up for the course.

But Compose is ready to learn, whether you’re taking my class or not. It can help us greatly improve the efficiency of developing interfaces and reduce the difficulty of developing complex interfaces. These two things have always been very valuable and very difficult, and Compose has an immediate effect on both. So let’s do it! Now, for Compose, it should be the last wave of early bird bonus for domestic developers.

The last

I’ll probably talk more about Compose in the next installment, maybe some other content for Jetpack, or some other Android development thing. Or if you have any questions you want to ask me, let me know in the comments section, and I can choose some to answer in future videos. Well, this video is over here, if you like, welcome to like forwarding collection attention, everyone’s recognition is very helpful for me to do this account. I’m a throwline. I don’t compete with you. I just help you grow. See you next time.