Skip to content

Commit 02dc779

Browse files
afohrmandsn5ft
authored andcommitted
[Predictive Back] Fixed IllegalStateException crashes caused by MaterialBackAnimationHelper.
PiperOrigin-RevId: 555180647
1 parent af7d09a commit 02dc779

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

lib/java/com/google/android/material/motion/MaterialBackAnimationHelper.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
import android.animation.TimeInterpolator;
2121
import android.content.Context;
22+
import android.util.Log;
2223
import android.view.View;
2324
import androidx.activity.BackEventCompat;
2425
import androidx.annotation.NonNull;
2526
import androidx.annotation.Nullable;
2627
import androidx.annotation.RestrictTo;
2728
import androidx.annotation.RestrictTo.Scope;
2829
import androidx.core.view.animation.PathInterpolatorCompat;
29-
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3030

3131
/**
3232
* Base helper class for views that support back handling, which assists with common animation
@@ -37,6 +37,7 @@
3737
@RestrictTo(Scope.LIBRARY_GROUP)
3838
public abstract class MaterialBackAnimationHelper<V extends View> {
3939

40+
private static final String TAG = "MaterialBackHelper";
4041
private static final int HIDE_DURATION_MAX_DEFAULT = 300;
4142
private static final int HIDE_DURATION_MIN_DEFAULT = 150;
4243
private static final int CANCEL_DURATION_DEFAULT = 100;
@@ -78,11 +79,14 @@ protected void onStartBackProgress(@NonNull BackEventCompat backEvent) {
7879
this.backEvent = backEvent;
7980
}
8081

81-
protected void onUpdateBackProgress(@NonNull BackEventCompat backEvent) {
82+
@Nullable
83+
protected BackEventCompat onUpdateBackProgress(@NonNull BackEventCompat backEvent) {
8284
if (this.backEvent == null) {
83-
throw new IllegalStateException("Must call startBackProgress() before updateBackProgress()");
85+
Log.w(TAG, "Must call startBackProgress() before updateBackProgress()");
8486
}
87+
BackEventCompat finalBackEvent = this.backEvent;
8588
this.backEvent = backEvent;
89+
return finalBackEvent;
8690
}
8791

8892
@Nullable
@@ -92,11 +96,11 @@ public BackEventCompat onHandleBackInvoked() {
9296
return finalBackEvent;
9397
}
9498

95-
@CanIgnoreReturnValue
96-
@NonNull
99+
@Nullable
97100
protected BackEventCompat onCancelBackProgress() {
98101
if (this.backEvent == null) {
99-
throw new IllegalStateException(
102+
Log.w(
103+
TAG,
100104
"Must call startBackProgress() and updateBackProgress() before cancelBackProgress()");
101105
}
102106
BackEventCompat finalBackEvent = this.backEvent;

lib/java/com/google/android/material/motion/MaterialBottomContainerBackHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public void startBackProgress(@NonNull BackEventCompat backEvent) {
6262
}
6363

6464
public void updateBackProgress(@NonNull BackEventCompat backEvent) {
65-
super.onUpdateBackProgress(backEvent);
65+
if (super.onUpdateBackProgress(backEvent) == null) {
66+
return;
67+
}
6668

6769
updateBackProgress(backEvent.getProgress());
6870
}
@@ -131,7 +133,9 @@ public void onAnimationEnd(Animator animation) {
131133
}
132134

133135
public void cancelBackProgress() {
134-
super.onCancelBackProgress();
136+
if (super.onCancelBackProgress() == null) {
137+
return;
138+
}
135139

136140
Animator animator = createResetScaleAnimator();
137141
animator.setDuration(cancelDuration);

lib/java/com/google/android/material/motion/MaterialMainContainerBackHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public void startBackProgress(float touchY, @Nullable View collapsedView) {
9999

100100
public void updateBackProgress(
101101
@NonNull BackEventCompat backEvent, @Nullable View collapsedView, float collapsedCornerSize) {
102-
super.onUpdateBackProgress(backEvent);
102+
if (super.onUpdateBackProgress(backEvent) == null) {
103+
return;
104+
}
103105

104106
if (collapsedView != null && collapsedView.getVisibility() != View.INVISIBLE) {
105107
collapsedView.setVisibility(View.INVISIBLE);
@@ -150,7 +152,9 @@ public void finishBackProgress(long duration, @Nullable View collapsedView) {
150152
}
151153

152154
public void cancelBackProgress(@Nullable View collapsedView) {
153-
super.onCancelBackProgress();
155+
if (super.onCancelBackProgress() == null) {
156+
return;
157+
}
154158

155159
AnimatorSet cancelAnimatorSet = createResetScaleAndTranslationAnimator(collapsedView);
156160
if (view instanceof ClippableRoundedCornerLayout) {

lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public void startBackProgress(@NonNull BackEventCompat backEvent) {
7272
}
7373

7474
public void updateBackProgress(@NonNull BackEventCompat backEvent, @GravityInt int gravity) {
75-
super.onUpdateBackProgress(backEvent);
75+
if (super.onUpdateBackProgress(backEvent) == null) {
76+
return;
77+
}
7678

7779
boolean leftSwipeEdge = backEvent.getSwipeEdge() == BackEventCompat.EDGE_LEFT;
7880
updateBackProgress(backEvent.getProgress(), leftSwipeEdge, gravity);
@@ -155,7 +157,9 @@ public void onAnimationEnd(Animator animation) {
155157
}
156158

157159
public void cancelBackProgress() {
158-
super.onCancelBackProgress();
160+
if (super.onCancelBackProgress() == null) {
161+
return;
162+
}
159163

160164
AnimatorSet cancelAnimatorSet = new AnimatorSet();
161165
cancelAnimatorSet.playTogether(

0 commit comments

Comments
 (0)