Skip to content

Conversation

@riggaroo
Copy link
Collaborator

@riggaroo riggaroo commented Apr 4, 2024

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.

jetsnack.mp4

@riggaroo riggaroo changed the title Adding Shared elements to Jetsnack Adding shared elements to Jetsnack 🎉 Apr 5, 2024
@riggaroo riggaroo marked this pull request as ready for review April 22, 2024 14:31
@yongsuk44
Copy link
Contributor

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

riggaroo and others added 6 commits June 19, 2024 09:52
# Conflicts:
#	Jetsnack/app/src/main/java/com/example/jetsnack/model/Snack.kt
#	Jetsnack/app/src/main/java/com/example/jetsnack/ui/components/Snacks.kt
#	Jetsnack/app/src/main/java/com/example/jetsnack/ui/snackdetail/SnackDetail.kt
#	Jetsnack/app/src/main/res/drawable-nodpi/almonds.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/cupcake.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/fruit.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/gingerbread.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/gluten_free.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/nuts.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/paleo.jpg
#	Jetsnack/app/src/main/res/drawable-nodpi/pretzels.jpg
@riggaroo riggaroo changed the title Adding shared elements to Jetsnack 🎉 [Jetsnack] Adding shared elements to Jetsnack 🎉 Aug 2, 2024
@riggaroo riggaroo merged commit d5c7da6 into compose-latest Aug 8, 2024
@riggaroo riggaroo deleted the jetsnack/shared-element branch August 8, 2024 15:15
qqvladik added a commit to qqvladik/RnM that referenced this pull request Feb 24, 2025
- Add `sharedBounds` and `sharedElement` to `CharacterCard` and `CharacterDetailScreen` for animated transitions.

- As It said in https://developer.android.com/develop/ui/compose/animation/shared-elements#shared-bounds: "When using Text composables, sharedBounds() is preferred to support font changes such as transitioning between italic and bold or color changes."
- Also in future Modifier.skipToLookaheadSize() can be used for animation of big texts, as it said here https://fvilarino.medium.com/shared-element-transitions-in-jetpack-compose-8f553078101e : "The skipToLookaheadSize() modifier instructs the animation framework to measure the animated child at its final size and to layout the child at that size."

- Theoretically for image animation also can be sharedBounds(). For example, in case if higher resolution image is uploaded in Details. SharedBound() vs sharedElement():  android/compose-samples#1314 - "It depends, if you have an Async image like this in this case, you'd want to use shared bounds as you may be loading up a higher resolution image. If you are using a standard image that you dont expect to be different, then yes you can use sharedElement :)"
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.

4 participants