Skip to content

Commit

Permalink
[SearchView] Restore modal for accessibility and back handling state …
Browse files Browse the repository at this point in the history
…in onAttachedToWindow() and remove modal for accessibility state in onDetachedFromWindow()

Fixes an issue where nothing is focusable in TalkBack after removing SearchView, due to the modal for accessibility behavior

Resolves #4176

PiperOrigin-RevId: 644038017
  • Loading branch information
dsn5ft authored and kendrickumstattd committed Jun 20, 2024
1 parent b345f37 commit 34adcb0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/java/com/google/android/material/search/SearchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,16 @@ protected void onAttachedToWindow() {
super.onAttachedToWindow();

MaterialShapeUtils.setParentAbsoluteElevation(this);
TransitionState state = getCurrentTransitionState();
updateModalForAccessibility(state);
updateListeningForBackCallbacks(state);
}

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

setModalForAccessibility(/* isSearchViewModal= */ false);
backOrchestrator.stopListeningForBackCallbacks();
}

Expand Down Expand Up @@ -810,11 +814,7 @@ private void setTransitionState(
}

if (updateModalForAccessibility) {
if (state == TransitionState.SHOWN) {
setModalForAccessibility(true);
} else if (state == TransitionState.HIDDEN) {
setModalForAccessibility(false);
}
updateModalForAccessibility(state);
}

TransitionState previousState = currentTransitionState;
Expand All @@ -827,6 +827,14 @@ private void setTransitionState(
updateListeningForBackCallbacks(state);
}

private void updateModalForAccessibility(@NonNull TransitionState state) {
if (state == TransitionState.SHOWN) {
setModalForAccessibility(true);
} else if (state == TransitionState.HIDDEN) {
setModalForAccessibility(false);
}
}

private void updateListeningForBackCallbacks(@NonNull TransitionState state) {
// Only automatically handle back if we have a search bar to collapse to, and if back handling
// is enabled for the SearchView.
Expand Down

1 comment on commit 34adcb0

@AndroidDeveloperLB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it related to this:

#4185

?

Please sign in to comment.