mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Problem 1. The back layer contains all views for an expanded experience, even if they are hidden behind the content layer, this makes them accessible through Talkback when the back layer is collapsed when all views outside of CollapsedBackLayerContents must be for all intents and purposes disabled. They still need to remain visible to accomodate for semi transparent views, so changing their visibility to GONE is not an option. Solution: Add ChildViewAccessibilityHelper that keeps track of the importantForAccessibility property for subviews of the BackLayer and overrides them to IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDENTS when collapsed and then reverts them to their original values when the back layer is expanded. - Caveat: This new object has to implement ViewGroup.OnHierarchyChangeListener so it can remove mappings for removed views, this way guaranteeing there is no memory leak. This also means users of BackLayerLayout MUST NOT set their own OnHierarchyChangeListener. - Caveat 2: this new object does not modify any CollapsedBackLayerContents, since views in that subview must still be accessible when collapsed. Problem 2. When the backlayer expands, the content layer remains active through accessibility services, we want to completely disable it. Furthermore a content description needs to be set on the content layer view that may not match what it already has. Solution: Add ContentViewAccessibilityPropertiesHelper that overrides the content layer's contentDescription, importantForAccessibility and focusable properties (and reverts them once the back layer is collapsed), and reuses the ChildViewAccessibilityHelper to make its child views not focusable. Tested: Sadly this is too hard to test on Espresso, I tested this manually, I'm trying to find a way to test them automatically. PiperOrigin-RevId: 164661912