Skip to content

Commit 34adcb0

Browse files
dsn5ftkendrickumstattd
authored andcommitted
[SearchView] Restore modal for accessibility and back handling state 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
1 parent b345f37 commit 34adcb0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/java/com/google/android/material/search/SearchView.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,16 @@ protected void onAttachedToWindow() {
263263
super.onAttachedToWindow();
264264

265265
MaterialShapeUtils.setParentAbsoluteElevation(this);
266+
TransitionState state = getCurrentTransitionState();
267+
updateModalForAccessibility(state);
268+
updateListeningForBackCallbacks(state);
266269
}
267270

268271
@Override
269272
protected void onDetachedFromWindow() {
270273
super.onDetachedFromWindow();
271274

275+
setModalForAccessibility(/* isSearchViewModal= */ false);
272276
backOrchestrator.stopListeningForBackCallbacks();
273277
}
274278

@@ -810,11 +814,7 @@ private void setTransitionState(
810814
}
811815

812816
if (updateModalForAccessibility) {
813-
if (state == TransitionState.SHOWN) {
814-
setModalForAccessibility(true);
815-
} else if (state == TransitionState.HIDDEN) {
816-
setModalForAccessibility(false);
817-
}
817+
updateModalForAccessibility(state);
818818
}
819819

820820
TransitionState previousState = currentTransitionState;
@@ -827,6 +827,14 @@ private void setTransitionState(
827827
updateListeningForBackCallbacks(state);
828828
}
829829

830+
private void updateModalForAccessibility(@NonNull TransitionState state) {
831+
if (state == TransitionState.SHOWN) {
832+
setModalForAccessibility(true);
833+
} else if (state == TransitionState.HIDDEN) {
834+
setModalForAccessibility(false);
835+
}
836+
}
837+
830838
private void updateListeningForBackCallbacks(@NonNull TransitionState state) {
831839
// Only automatically handle back if we have a search bar to collapse to, and if back handling
832840
// is enabled for the SearchView.

0 commit comments

Comments
 (0)