Unverified Commit 85dd2f83 authored by Mihai Adrian Carare's avatar Mihai Adrian Carare Committed by GitHub
Browse files

For #16511 - Change a11y parent of button without breaking the tab list. (#16555)

parent af666d8c
......@@ -37,33 +37,16 @@ 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.
* Sets the new a11y parent.
*/
fun View.removeChildFromAccessibilityNodeInfo(child: View) {
fun View.setNewAccessibilityParent(newParent: 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)
info?.setParent(newParent)
}
}
}
......
......@@ -13,8 +13,7 @@ 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.ext.setNewAccessibilityParent
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.Item
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.ViewHolder
......@@ -45,9 +44,8 @@ class SaveToCollectionsButtonAdapter(
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.collectionItemInfo = null
(holder.itemView.parentForAccessibility as View).apply {
removeChildFromAccessibilityNodeInfo(holder.itemView)
(this.parentForAccessibility as View).addChildToAccessibilityNodeInfo(holder.itemView)
(holder.itemView.parentForAccessibility.parentForAccessibility as? View)?.let {
holder.itemView.setNewAccessibilityParent(it)
}
}
}
......
Markdown is supported
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