Commit c427ebf8 authored by mcarare's avatar mcarare Committed by Mihai Adrian Carare
Browse files

For #16416: Remove save to collection button from tab a11y list.

parent a8db85fc
......@@ -8,6 +8,7 @@ import android.graphics.Rect
import android.os.Build
import android.view.TouchDelegate
import android.view.View
import android.view.accessibility.AccessibilityNodeInfo
import androidx.annotation.Dimension
import androidx.annotation.Dimension.DP
import androidx.annotation.VisibleForTesting
......@@ -33,6 +34,38 @@ fun View.removeTouchDelegate() {
}
}
/**
* Removes a child view from accessibility node info of an accessibility parent view.
* If the child does not exist in the node, calling this has no effect.
*/
fun View.removeChildFromAccessibilityNodeInfo(child: View) {
this.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.removeChild(child)
}
}
}
/**
* Add a child view to the accessibility node info of a view that becomes it's accessibility parent.
* If the child already exists in the node, calling this has no effect.
*/
fun View.addChildToAccessibilityNodeInfo(child: View) {
this.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.addChild(child)
}
}
}
/**
* Fills a [Rect] with data about a view's location in the screen.
*
......
......@@ -7,11 +7,14 @@ package org.mozilla.fenix.tabtray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityNodeInfo
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.addChildToAccessibilityNodeInfo
import org.mozilla.fenix.ext.removeChildFromAccessibilityNodeInfo
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.Item
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.ViewHolder
......@@ -34,6 +37,21 @@ class SaveToCollectionsButtonAdapter(
}
override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList<Any>) {
// remove button from node info of tabs list for a11y services,and add it to the tab tray node
holder.itemView.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.collectionItemInfo = null
(holder.itemView.parentForAccessibility as View).apply {
removeChildFromAccessibilityNodeInfo(holder.itemView)
(this.parentForAccessibility as View).addChildToAccessibilityNodeInfo(holder.itemView)
}
}
}
if (payloads.isNullOrEmpty()) {
onBindViewHolder(holder, position)
return
......
......@@ -18,7 +18,6 @@ A FrameLayout here is an efficient way of having a views stack while allowing:
android:layout_height="202dp"
android:clipChildren="false"
android:clipToPadding="false"
android:importantForAccessibility="no"
android:padding="8dp">
<com.google.android.material.card.MaterialCardView
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment