For #11542: Update tabs positions in tab tray reported by screen readers
This commit is contained in:
parent
06e6cfa696
commit
fe97dc9d2e
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.tabtray
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import mozilla.components.browser.tabstray.TabViewHolder
|
||||||
import mozilla.components.browser.tabstray.TabsAdapter
|
import mozilla.components.browser.tabstray.TabsAdapter
|
||||||
import mozilla.components.concept.tabstray.Tabs
|
import mozilla.components.concept.tabstray.Tabs
|
||||||
import mozilla.components.support.images.loader.ImageLoader
|
import mozilla.components.support.images.loader.ImageLoader
|
||||||
|
@ -26,9 +27,17 @@ class FenixTabsAdapter(
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
var onTabsUpdated: (() -> Unit)? = null
|
var onTabsUpdated: (() -> Unit)? = null
|
||||||
|
var tabCount = 0
|
||||||
|
|
||||||
override fun updateTabs(tabs: Tabs) {
|
override fun updateTabs(tabs: Tabs) {
|
||||||
super.updateTabs(tabs)
|
super.updateTabs(tabs)
|
||||||
onTabsUpdated?.invoke()
|
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)
|
TabsTouchHelper(tray.tabsAdapter).attachToRecyclerView(tray)
|
||||||
(tray.tabsAdapter as? FenixTabsAdapter)?.also { adapter ->
|
(tray.tabsAdapter as? FenixTabsAdapter)?.also { adapter ->
|
||||||
adapter.onTabsUpdated = {
|
adapter.onTabsUpdated = {
|
||||||
|
if (hasAccessibilityEnabled) {
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
}
|
||||||
if (!hasLoaded) {
|
if (!hasLoaded) {
|
||||||
hasLoaded = true
|
hasLoaded = true
|
||||||
tray.layoutManager?.scrollToPosition(selectedBrowserTabIndex)
|
tray.layoutManager?.scrollToPosition(selectedBrowserTabIndex)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
package org.mozilla.fenix.tabtray
|
package org.mozilla.fenix.tabtray
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.accessibility.AccessibilityNodeInfo
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
|
@ -176,6 +177,28 @@ class TabTrayViewHolder(
|
||||||
closeView.context.getString(R.string.close_tab_title, title)
|
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 {
|
companion object {
|
||||||
private const val PLAY_PAUSE_BUTTON_EXTRA_DPS = 24
|
private const val PLAY_PAUSE_BUTTON_EXTRA_DPS = 24
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user