Skip to content

Commit

Permalink
[Predictive Back] Update SearchView and NavigationView to unregister …
Browse files Browse the repository at this point in the history
…back callbacks when detached from window

Resolves #4176

PiperOrigin-RevId: 633969673
  • Loading branch information
dsn5ft committed May 15, 2024
1 parent a89e38c commit d13bfdf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public void startListeningForBackCallbacks(
@DoNotInline
@Override
public void stopListeningForBackCallbacks(@NonNull View view) {
if (onBackInvokedCallback == null) {
return;
}
OnBackInvokedDispatcher onBackInvokedDispatcher = view.findOnBackInvokedDispatcher();
if (onBackInvokedDispatcher == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ protected void onDetachedFromWindow() {
DrawerLayout drawerLayout = (DrawerLayout) parent;
drawerLayout.removeDrawerListener(backDrawerListener);
}

backOrchestrator.stopListeningForBackCallbacks();
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions lib/java/com/google/android/material/search/SearchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ protected void onAttachedToWindow() {
MaterialShapeUtils.setParentAbsoluteElevation(this);
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();

backOrchestrator.stopListeningForBackCallbacks();

This comment has been minimized.

Copy link
@grahammendick

grahammendick May 15, 2024

@dsn5ft Thanks for working on this!
Don't you have to start listening for back callbacks again when it's attached to window? So, in the example in #4176, that's equivalent to tabbing back to the dashboard tab and then gesture back

}

@Override
@NonNull
public CoordinatorLayout.Behavior<SearchView> getBehavior() {
Expand Down

0 comments on commit d13bfdf

Please sign in to comment.