android / compose-samples

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

[Jetsnack] Adding shared elements to Jetsnack 🎉 #1314

Closed riggaroo closed 3 months ago

riggaroo commented 7 months ago

Adding shared elements between Home feed and SnackDetail.

Introduced SnackSharedElementKey to create a unique key for the shared element to match.

Using Modifier.sharedBounds() on the Card container, and Modifier.sharedElement() on the Image.

Using Modifier.sharedBounds() with Modifier.animateEnterExit() on Text.

The above modifiers require being in an AnimatedVisibilityScope and SharedTransitionScope, in order to use the correct scope at the correct point, we save the scopes in a CompositionLocal and retrieve it when required.

https://github.com/android/compose-samples/assets/9973046/2d0cf1d9-4ef2-4051-a2e9-b3255d45ac78

yongsuk44 commented 5 months ago

Will values be added to the 'element' tab later, or is it normal for it to be empty. In my opinion, it would be convenient for debugging to display the values applied to parameters other than the key in sharedContentState.

스크린샷 2024-05-21 오후 5 34 40