ADVERTISEMENT
Android Resource
  • About
  • Contact Us
  • Android
  • Extras
  • Tools & Tutorials
No Result
View All Result
Android Resource
  • About
  • Contact Us
  • Android
  • Extras
  • Tools & Tutorials
No Result
View All Result
Android Resource
No Result
View All Result
Home Android

Improvements and Changes to Compose’s Pointer Input

vivekpanchal64@gmail.com by vivekpanchal64@gmail.com
April 17, 2023
in Android
0 0
0
Improvements and Changes to Compose’s Pointer Input
0
SHARES
9
VIEWS
Share on FacebookShare on Twitter


Pointer Input in Compose

We’ve finished refactoring Modifier.pointerInput{ … } to use the new Modifier.Node implementation (as of version compose-ui 1.5.0-alpha02), which is part of a larger project to reduce memory and improve performance in Compose.

A majority of you should see improvements with no changes to your codebase (other than bumping up the library version).

However, if you are writing your own custom gesture detectors or using pointerInput(), you may be impacted by the change. Let me explain.

The previous iteration (Version 1.5.0-alpha01 and everything before) of pointerInput() worked by executing the whole block of code up to awaitPointerEvent() (in the AwaitPointerEventScope block).

Here’s an example:

Everything before awaitPointerEvent() executes right away (see comments).

Once the code gets to awaitPointerEvent(), it will suspend until an event comes in.

In the new implementation (compose-ui 1.5.0-alpha02), pointerInput() lazily executes.

That means nothing will happen until the first pointer event is fired — for example, when a user presses down on the screen.

Why would we make such a significant change? Performance! 🙂

Similar to LazyColumn, we don’t want to execute work until it is needed.

The previous implementation executed each pointer input block of code up to the awaitPointerEvent() regardless of whether a user ever interacted with the composable or not.

The Compose gesture detectors, for example, tapping/pressing, dragging, and multi-touch, are actually built on top of pointerInput() as well, which means that anytime anyone uses a gesture detector, a good chunk of code is executed. Well, in many cases, that code might never be needed, for instance, if the user never interacts with your composable.

The new implementation avoids that. We never execute any of the code until it is needed because a user is interacting with your composable.

Let’s revisit the example above to see how it has changed in the new implementation:

Now, the entire block (see comments) will not execute until the first event comes in, and, if there is no pointer event, it will never execute.

Once an event is triggered, the block will be executed (including the first awaitPointerEvent() call). The code will suspend once again on any following awaitPointerEvent() calls until the next event is triggered.

If you have a custom gesture handler (or any code using pointerInput()) where you rely on code in that block executing right away (before an event or even if there isn’t an event), you will want to adjust your code to take this new change into account.

This is probably a pretty rare occurrence for most of you, but it is something to keep in mind as you get the improvements.

Happy coding!

-Jeremy



Source link

Post Views: 50

Related

Previous Post

How Can Augmented Reality Prompt Your Business Growth?

Next Post

Problem solving in Compose Text

vivekpanchal64@gmail.com

vivekpanchal64@gmail.com

Next Post
Problem solving in Compose Text

Problem solving in Compose Text

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You might also like

Now in Android #96

Now in Android #96

November 30, 2023
10 Most Valuable Mobile App Development Company

10 Most Valuable Mobile App Development Company

November 24, 2023
Now in Android #95

Now in Android #95

November 17, 2023
New APIs for adaptive layouts in Jetpack Compose

New APIs for adaptive layouts in Jetpack Compose

November 16, 2023
Squaring the Circle on Google TV

Squaring the Circle on Google TV

November 10, 2023
Now in Android #94 : The Halloween and Android Show Edition

Now in Android #94 : The Halloween and Android Show Edition

November 1, 2023
Android Resource

© 2023 Androidresource - Quality Android Blogs by androidresource.

  • About
  • Contact Us
  • Android
  • Extras
  • Tools & Tutorials

Follow Us

No Result
View All Result
  • About
  • Contact Us
  • Android
  • Extras
  • Tools & Tutorials

© 2023 Androidresource - Quality Android Blogs by androidresource.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In