Status Update
Comments
ia...@gmail.com <ia...@gmail.com> #2
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
Author: Ben Trengrove <
Link:
Add a LocalActivity composition local
Expand for full commit details
Add a LocalActivity composition local
Provides a fallback for being able to access Activity for APIs that
haven't been placed behind a testable interface. A common mistake when
faced with this situation is to directly cast Context, however this is not
always an activity. This CL provides a new LocalActivity computed composition local
that correctly walks up the context reference to find the current activity.
As compositionLocalWithComputedDefaultOf is only available in Compose runtime 1.7.0,
this required bumping the Compose runtime dependency.
Fixes: 283009666
Test: LocalActivityTest
Relnote: Add a `LocalActivity` composition local
Relnote: Activity Compose now depends on Compose Runtime 1.7.0
Change-Id: I7746aaaeb779d7af79867b4d9143b9d5c5545543
Files:
- M
activity/activity-compose/api/current.txt
- M
activity/activity-compose/api/restricted_current.txt
- M
activity/activity-compose/build.gradle
- A
activity/activity-compose/src/androidTest/java/androidx/activity/compose/LocalActivityTest.kt
- A
activity/activity-compose/src/main/java/androidx/activity/compose/LocalActivity.kt
- M
activity/activity-compose/src/main/java/androidx/activity/compose/PredictiveBackHandler.kt
Hash: 2faccf37d34db809b3a8be4846c424b094d4d8c2
Date: Thu Oct 10 10:20:23 2024
il...@google.com <il...@google.com> #4
This has been added internally and will be available in Activity 1.10.0-alpha03.
pr...@google.com <pr...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.activity:activity-compose:1.10.0-alpha03
na...@gmail.com <na...@gmail.com> #7
ju...@veepee.com <ju...@veepee.com> #8
Hey, why is LocalActivity nullable?
Couldn't androidx provide a root composable like ActivityContainer(activity){ content}
and make the instance not null?
It would be devs job to provide the instance.
How could we get something like AppCompatActivity/FragmentActivity too? They provide different things that are not available in ComponentActivity.
Description
The use case is that I would like to start Activity being sure that the context used will not crash my app in case I missed a flag or I had to instantiate a Dialog using the local context.