Skip to content

Conversation

@vRallev
Copy link
Contributor

@vRallev vRallev commented Apr 28, 2025

Implement a shared transition animation when the user taps the profile picture. This sample highlights how animations can be implemented when switching between different models and templates.

Animation.mp4

@vRallev vRallev force-pushed the rwo/shared-animation branch from 833aaec to dca283e Compare April 28, 2025 22:07
@vRallev vRallev marked this pull request as ready for review April 28, 2025 22:12
@vRallev vRallev force-pushed the rwo/full-screen-page branch from 66491d8 to eb000a3 Compare April 29, 2025 06:01
Base automatically changed from rwo/full-screen-page to main April 29, 2025 06:07
@vRallev vRallev force-pushed the rwo/shared-animation branch from dca283e to 6ae7285 Compare April 29, 2025 06:09
// Use the key from AnimationContentKey as indicator when content has changed
// that needs to be animated. If this key is doesn't change (the default behavior),
// then no animation occurs.
it.contentKey

Choose a reason for hiding this comment

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

This poses the "Where did it come from?" problem. Here, I think it === model, but hard to say. If it is the model, maybe state this as model.contentKey. Otherwise, I think it would be good to name it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed it to template

            contentKey = { template ->
              // Use the key from AnimationContentKey as indicator when content has changed
              // that needs to be animated. If this key is doesn't change (the default behavior),
              // then no animation occurs.
              template.contentKey
            },

import software.amazon.app.platform.presenter.BaseModel

/**
* The sample application supports animations between model and even templates. [BaseModel] classes
Copy link

Choose a reason for hiding this comment

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

Probably should say "between models and even templates."

}

/**
* All UI composable functions in the sample application a wrapped within a [AnimatedContent]. This
Copy link

Choose a reason for hiding this comment

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

This KDoc doesn't parse well. Maybe 'are' is missing in "application a wrapped within". The first phrase lacks a verb. Even guessing though, it isn't clear what this KDoc is trying to tell me.

Is this scope nested in the following LocalSharedTransitionScope, or do we have all Venn diagram possibilities?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"a" was supposed to be "are".

I updated the documentation to this:

/**
 * All UI composable functions for renderers in the sample application are wrapped within a
 * [SharedTransitionLayout]. This composition local gives access to this wrapper instance to run a
 * shared element transition. For more information see the the
 * [shared element transition documentation](https://developer.android.com/develop/ui/compose/animation/shared-elements#shared-bounds).
 *
 * The [BaseModel] must implement [AnimationContentKey] to indicate that an animation should be
 * played. See [AnimationContentKey] for more details.
 */

And updated the documentation for AnimationContentKey to this with a sample:

/**
 * The sample application supports animations between models and templates. [BaseModel] classes can
 * implement this interface to indicate when a change occurred that should be animated. [contentKey]
 * represents a unique value for an animation state. If the value doesn't change between new models,
 * then no animation will be started.
 *
 * An example may look like this:
 * ```
 * data class Model(
 *     val showPictureFullscreen: Boolean,
 *     ...
 * ) : BaseModel, AnimationContentKey {
 *     override val contentKey: Int =
 *         if (showPictureFullscreen) 1 else AnimationContentKey.DEFAULT_CONTENT_KEY
 * }
 * ```
 *
 * In this sample when `showPictureFullscreen` changes from `true` to `false` and vice versa then an
 * animation will be started using [AnimatedContent]. Use [LocalAnimatedVisibilityScope] and
 * [LocalSharedTransitionScope] to get access to the right scopes.
 */

val LocalNavAnimatedVisibilityScope = compositionLocalOf<AnimatedVisibilityScope?> { null }

/**
* All UI composable functions in the sample application a wrapped within a
Copy link

Choose a reason for hiding this comment

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

Similar KDoc concerns to the preceeding.

Implement a shared transition animation when the user taps the profile picture. This sample highlights how animations can be implemented when switching between different models and templates.
@vRallev vRallev force-pushed the rwo/shared-animation branch from 6ae7285 to 68a514a Compare May 1, 2025 19:30
@vRallev vRallev merged commit ec1aa6b into main May 2, 2025
18 checks passed
@vRallev vRallev deleted the rwo/shared-animation branch May 2, 2025 22:18
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