For #11542: Update tabs positions in tab tray reported by screen readers
parent
06e6cfa696
commit
fe97dc9d2e
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.tabtray
|
|||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import mozilla.components.browser.tabstray.TabViewHolder
|
||||
import mozilla.components.browser.tabstray.TabsAdapter
|
||||
import mozilla.components.concept.tabstray.Tabs
|
||||
import mozilla.components.support.images.loader.ImageLoader
|
||||
|
@ -26,9 +27,17 @@ class FenixTabsAdapter(
|
|||
}
|
||||
) {
|
||||
var onTabsUpdated: (() -> Unit)? = null
|
||||
var tabCount = 0
|
||||
|
||||
override fun updateTabs(tabs: Tabs) {
|
||||
super.updateTabs(tabs)
|
||||
onTabsUpdated?.invoke()
|
||||
tabCount = tabs.list.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: TabViewHolder, position: Int) {
|
||||
super.onBindViewHolder(holder, position)
|
||||
val newIndex = tabCount - position - 1
|
||||
(holder as TabTrayViewHolder).updateAccessibilityRowIndex(holder.itemView, newIndex)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,6 +117,9 @@ class TabTrayView(
|
|||
TabsTouchHelper(tray.tabsAdapter).attachToRecyclerView(tray)
|
||||
(tray.tabsAdapter as? FenixTabsAdapter)?.also { adapter ->
|
||||
adapter.onTabsUpdated = {
|
||||
if (hasAccessibilityEnabled) {
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
if (!hasLoaded) {
|
||||
hasLoaded = true
|
||||
tray.layoutManager?.scrollToPosition(selectedBrowserTabIndex)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package org.mozilla.fenix.tabtray
|
||||
|
||||
import android.view.View
|
||||
import android.view.accessibility.AccessibilityNodeInfo
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.VisibleForTesting
|
||||
|
@ -176,6 +177,28 @@ class TabTrayViewHolder(
|
|||
closeView.context.getString(R.string.close_tab_title, title)
|
||||
}
|
||||
|
||||
internal fun updateAccessibilityRowIndex(item: View, newIndex: Int) {
|
||||
item.setAccessibilityDelegate(object : View.AccessibilityDelegate() {
|
||||
override fun onInitializeAccessibilityNodeInfo(
|
||||
host: View?,
|
||||
info: AccessibilityNodeInfo?
|
||||
) {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info)
|
||||
info?.let {
|
||||
val initialInfo = info.collectionItemInfo
|
||||
info.collectionItemInfo = AccessibilityNodeInfo.CollectionItemInfo.obtain(
|
||||
newIndex,
|
||||
initialInfo.rowSpan,
|
||||
initialInfo.columnIndex,
|
||||
initialInfo.columnSpan,
|
||||
false,
|
||||
initialInfo.isSelected
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PLAY_PAUSE_BUTTON_EXTRA_DPS = 24
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue