Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Compose - CollectAsStateWithLifecycle #714

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

JuxBzh
Copy link
Contributor

@JuxBzh JuxBzh commented Apr 3, 2024

Description

As suggested by this article from Manuel Vivo, a flow can be consumed in a lifecycle-aware manner to avoid wasting app resources.
Following this advice, I updated MavericksComposeExtension file to expose lifecycle-aware version of collectAsState functions.

Changes

  • Add a new dependency to lifecycle-runtime-compose to be able to use Flow.collectAsStateWithLifecycle function
  • 3 new functions collectAsStateWithLifecycle functions mirroring the existing collectAsState functions
  • Update sample-compose to use collectAsStateWithLifecycle and collectAsState functions

Copy link
Contributor

@elihart elihart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Overall looks pretty good. Would you be able to add unit tests for the new functions?

@@ -1,11 +1,6 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change please

Add Compose-related convenience functions to collect a State variable in a lifecycle-aware manner.
Mirror `collectAsState` extension functions and create the lifecycle-aware version `collectAsStateWithLifecycle`.

Add new dependency to `androidx.lifecycle:lifecycle-runtime-compose`.

Update `ComposeSampleActivity` to use one of the new `collectAsStateWithLifecycle` extension function.
@JuxBzh JuxBzh force-pushed the f/collectAsStateWithLifecycle branch from 5f035f5 to 008cf3b Compare April 4, 2024 07:17
@elihart elihart merged commit 9e999be into airbnb:main Apr 16, 2024
3 checks passed
@JuxBzh JuxBzh deleted the f/collectAsStateWithLifecycle branch April 22, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants