Skip to content

Commit

Permalink
Update Predictive Back README.md to include information on shared ele…
Browse files Browse the repository at this point in the history
…ment transitions.
  • Loading branch information
ashnohe committed Jan 16, 2024
1 parent 3bf5ff0 commit 1bc486e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions samples/user-interface/predictiveback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Shows different types of predictive back animations, including:
+ Cross-activity
+ Custom cross-activity
+ Cross-fragment animation
+ Shared element cross-fragment animation
+ Custom Progress API animation
+ Custom AndroidX Transition

## Custom cross-activity

Expand Down Expand Up @@ -48,6 +50,39 @@ Example code uses navigation component default animations.
app:popExitAnim="@animator/nav_default_pop_exit_anim" />
```

## Shared element cross-fragment animation

Example code shows a simple cross-fragment animation between two [shared elements](https://developer.android.com/guide/fragments/animate#shared)
that automatically works with predictive back gesture navigation provided fragment and androidx
transitions dependencies are upgraded to
[1.7.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.7.0-alpha08) and
[1.5.0](https://developer.android.com/jetpack/androidx/releases/transition#1.5.0-alpha06) respectively.

On the first fragment, where "second_card" is the `android:transitionName` of a view in the second
fragment:
```kotlin
binding.sharedElementCrossFragment.setOnClickListener {
findNavController().navigate(
R.id.show_PBSharedElementTransitionFragment,
null,
null,
FragmentNavigatorExtras(it to "second_card")
)
}
```

On the second fragment:
```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = AutoTransition()
sharedElementEnterTransition = AutoTransition()
}
```

Note that `enterTransition` must be specified in addition to `sharedElementEnterTransition`, which
will mark the shared element as seekable and therefore enable the predictive back gesture to play.

## Custom Progress API animation

The following example using the Progress API follows the
Expand Down

0 comments on commit 1bc486e

Please sign in to comment.