android / compose-samples

Official Jetpack Compose samples.
https://developer.android.com/jetpack/compose
Apache License 2.0
19.84k stars 4.71k forks source link

Experimenting with safe versions of Shared element modifiers. #1417

Closed riggaroo closed 1 month ago

riggaroo commented 2 months ago

Sometimes your composables may be created from places that don't have a AnimatedContentScope or SharedTransitionScope - for instance if you are opening up your app from a notifcation. Instead of throwing an IllegalArgumentException in these cases, it'd be best if the shared element modifiers, just didn't do anything if the scopes are not present. This pull request creates new modifiers that wrap the shared element APIs, to skip their operation if the scopes are null. Modifiers such as: Modifier.safeSharedElement(), Modifier.safeSharedBounds(), Modifier.safeSkipToLookaheadSize(), Modifier.safeRenderInSharedTransitionScope().

Please note: This is in no way a complete solution at present, this is an experiment and subject to change. Please do leave feedback if you'd like to see changes to shared element APIs based on this use case.