Skip to content

Commit

Permalink
[Predictive Back] Fixed MaterialBackAnimationHelper.onCancelBackProgr…
Browse files Browse the repository at this point in the history
…ess being called twice.

PiperOrigin-RevId: 543622236
  • Loading branch information
hunterstich authored and raajkumars committed Jun 27, 2023
1 parent 27abfdb commit ad60bbf
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -123,11 +123,17 @@ OnBackInvokedCallback createOnBackInvokedCallback(@NonNull MaterialBackHandler b

@Override
public void onBackStarted(@NonNull BackEvent backEvent) {
if (!isListeningForBackCallbacks()) {
return;
}
backHandler.startBackProgress(new BackEventCompat(backEvent));
}

@Override
public void onBackProgressed(@NonNull BackEvent backEvent) {
if (!isListeningForBackCallbacks()) {
return;
}
backHandler.updateBackProgress(new BackEventCompat(backEvent));
}

Expand All @@ -138,6 +144,9 @@ public void onBackInvoked() {

@Override
public void onBackCancelled() {
if (!isListeningForBackCallbacks()) {
return;
}
backHandler.cancelBackProgress();
}
};
Expand All @@ -149,6 +158,10 @@ private static class Api33BackCallbackDelegate implements BackCallbackDelegate {

@Nullable private OnBackInvokedCallback onBackInvokedCallback;

boolean isListeningForBackCallbacks() {
return onBackInvokedCallback != null;
}

@DoNotInline
@Override
public void startListeningForBackCallbacks(
Expand Down

0 comments on commit ad60bbf

Please sign in to comment.