Skip to content

Commit

Permalink
minor code fixes to predictive back progress api sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ashnohe committed Sep 25, 2023
1 parent f15fc99 commit 7c17b67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 5 additions & 3 deletions samples/user-interface/predictiveback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Shows different types of predictive back animations, including:

## Custom cross-activity

Although animation resources are expected for `overrideActivityTransition`, we strongly recommend to
stop using animation and to instead use animator and androidx transitions for most use cases.
In general, rely on the default cross-activity animation; however, if required use
overrideActivityTransition in place of overridePendingTransition. Although animation resources are
expected for `overrideActivityTransition`, we strongly recommend to stop using animation and to
instead use animator and androidx transitions for most use cases.

```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -47,7 +49,7 @@ Example code uses navigation component default animations.

## Custom Progress API animation

The following example using Progress API follows the
The following example using the Progress API follows the
[Predictive Back Design Guidance](https://developer.android.com/design/ui/mobile/guides/patterns/predictive-back).

```kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ class PBProgressAPI : Fragment() {
"Disable the callback to go back.",
Toast.LENGTH_SHORT
).show()
resetState()
resetCallbackState()
}

override fun handleOnBackCancelled() {
resetState()
resetCallbackState()
}

private fun resetState() {
private fun resetCallbackState() {
binding.box.scaleX = 1F
binding.box.scaleY = 1F
binding.box.translationX = 0F
Expand All @@ -88,11 +88,11 @@ class PBProgressAPI : Fragment() {
this.viewLifecycleOwner,
predictiveBackCallback
)
updateState(predictiveBackCallback)
updateCallbackState(predictiveBackCallback)

binding.button.setOnClickListener {
predictiveBackCallback.isEnabled = !predictiveBackCallback.isEnabled
updateState(predictiveBackCallback)
updateCallbackState(predictiveBackCallback)
}
}

Expand All @@ -101,13 +101,13 @@ class PBProgressAPI : Fragment() {
_binding = null
}

private fun updateState(callback: OnBackPressedCallback) {
private fun updateCallbackState(callback: OnBackPressedCallback) {
when (callback.isEnabled) {
true -> {
binding.button.text = "disable callback"
binding.body.text =
"Swipe back to see the box move using the Predictive Back Progress APIs" +
" on Android 14+ devices."
"Swipe back to see the box move using the Predictive Back" +
" Progress APIs on Android 14+ devices."
}
false -> {
binding.button.text = "enable callback"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="168dp"
android:text="@string/fragment_header"
android:textAppearance="?attr/textAppearanceTitleMedium"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/box"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down Expand Up @@ -69,7 +67,6 @@
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="70dp"
android:fontFamily="sans-serif"
android:maxWidth="300dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
Expand Down

0 comments on commit 7c17b67

Please sign in to comment.