mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/16424 - Focus the right item in tabs tray when using Talkback (https://github.com/mozilla-mobile/fenix/pull/16472)
To get the index of the current selected browser tab when using reverse layout we should also account for items placed below of the browser tabs. The patch here unifies the logic already used for some calls but not all.
This commit is contained in:
parent
23ff2851e6
commit
da543114c3
@ -291,7 +291,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
|
|||||||
getString(R.string.snackbar_deleted_undo),
|
getString(R.string.snackbar_deleted_undo),
|
||||||
{
|
{
|
||||||
requireComponents.useCases.tabsUseCases.undo.invoke()
|
requireComponents.useCases.tabsUseCases.undo.invoke()
|
||||||
_tabTrayView?.scrollToTab(tab.id)
|
_tabTrayView?.scrollToSelectedBrowserTab(tab.id)
|
||||||
},
|
},
|
||||||
operation = { },
|
operation = { },
|
||||||
elevation = ELEVATION,
|
elevation = ELEVATION,
|
||||||
|
@ -157,9 +157,6 @@ class TabTrayView(
|
|||||||
|
|
||||||
val tabs = getTabs(isPrivate)
|
val tabs = getTabs(isPrivate)
|
||||||
|
|
||||||
val selectedBrowserTabIndex = tabs
|
|
||||||
.indexOfFirst { it.id == view.context.components.core.store.state.selectedTabId }
|
|
||||||
|
|
||||||
updateBottomSheetBehavior()
|
updateBottomSheetBehavior()
|
||||||
|
|
||||||
setTopOffset(isInLandscape())
|
setTopOffset(isInLandscape())
|
||||||
@ -208,14 +205,14 @@ class TabTrayView(
|
|||||||
}
|
}
|
||||||
if (!hasLoaded) {
|
if (!hasLoaded) {
|
||||||
hasLoaded = true
|
hasLoaded = true
|
||||||
scrollToTab(view.context.components.core.store.state.selectedTabId)
|
scrollToSelectedBrowserTab()
|
||||||
if (view.context.settings().accessibilityServicesEnabled) {
|
if (view.context.settings().accessibilityServicesEnabled) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
delay(SELECTION_DELAY.toLong())
|
delay(SELECTION_DELAY.toLong())
|
||||||
lifecycleScope.launch(Main) {
|
lifecycleScope.launch(Main) {
|
||||||
layoutManager?.findViewByPosition(selectedBrowserTabIndex)
|
layoutManager?.findViewByPosition(getSelectedBrowserTabViewIndex())
|
||||||
?.requestFocus()
|
?.requestFocus()
|
||||||
layoutManager?.findViewByPosition(selectedBrowserTabIndex)
|
layoutManager?.findViewByPosition(getSelectedBrowserTabViewIndex())
|
||||||
?.sendAccessibilityEvent(
|
?.sendAccessibilityEvent(
|
||||||
AccessibilityEvent.TYPE_VIEW_FOCUSED
|
AccessibilityEvent.TYPE_VIEW_FOCUSED
|
||||||
)
|
)
|
||||||
@ -367,7 +364,7 @@ class TabTrayView(
|
|||||||
toggleSaveToCollectionButton(isPrivateModeSelected)
|
toggleSaveToCollectionButton(isPrivateModeSelected)
|
||||||
|
|
||||||
updateUINormalMode(view.context.components.core.store.state)
|
updateUINormalMode(view.context.components.core.store.state)
|
||||||
scrollToTab(view.context.components.core.store.state.selectedTabId)
|
scrollToSelectedBrowserTab()
|
||||||
|
|
||||||
if (isPrivateModeSelected) {
|
if (isPrivateModeSelected) {
|
||||||
components.analytics.metrics.track(Event.TabsTrayPrivateModeTapped)
|
components.analytics.metrics.track(Event.TabsTrayPrivateModeTapped)
|
||||||
@ -682,22 +679,9 @@ class TabTrayView(
|
|||||||
return interactor.onBackPressed()
|
return interactor.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scrollToTab(sessionId: String?) {
|
fun scrollToSelectedBrowserTab(selectedTabId: String? = null) {
|
||||||
view.tabsTray.apply {
|
view.tabsTray.apply {
|
||||||
val tabs = if (isPrivateModeSelected) {
|
val recyclerViewIndex = getSelectedBrowserTabViewIndex(selectedTabId)
|
||||||
view.context.components.core.store.state.privateTabs
|
|
||||||
} else {
|
|
||||||
view.context.components.core.store.state.normalTabs
|
|
||||||
}
|
|
||||||
|
|
||||||
val selectedBrowserTabIndex = tabs
|
|
||||||
.indexOfFirst { it.id == sessionId }
|
|
||||||
|
|
||||||
// We offset the tab index by the number of items in the other adapters.
|
|
||||||
// We add the offset, because the layoutManager is initialized with `reverseLayout`.
|
|
||||||
val recyclerViewIndex = selectedBrowserTabIndex +
|
|
||||||
collectionsButtonAdapter.itemCount +
|
|
||||||
syncedTabsController.adapter.itemCount
|
|
||||||
|
|
||||||
layoutManager?.scrollToPosition(recyclerViewIndex)
|
layoutManager?.scrollToPosition(recyclerViewIndex)
|
||||||
smoothScrollBy(
|
smoothScrollBy(
|
||||||
@ -707,6 +691,30 @@ class TabTrayView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSelectedBrowserTabViewIndex(sessionId: String? = null): Int {
|
||||||
|
val tabs = if (isPrivateModeSelected) {
|
||||||
|
view.context.components.core.store.state.privateTabs
|
||||||
|
} else {
|
||||||
|
view.context.components.core.store.state.normalTabs
|
||||||
|
}
|
||||||
|
|
||||||
|
val selectedBrowserTabIndex = if (sessionId != null) {
|
||||||
|
tabs.indexOfFirst { it.id == sessionId }
|
||||||
|
} else {
|
||||||
|
tabs.indexOfFirst { it.id == view.context.components.core.store.state.selectedTabId }
|
||||||
|
}
|
||||||
|
|
||||||
|
// We offset the tab index by the number of items in the other adapters.
|
||||||
|
// We add the offset, because the layoutManager is initialized with `reverseLayout`.
|
||||||
|
return if (view.context.settings().listTabView) {
|
||||||
|
selectedBrowserTabIndex +
|
||||||
|
collectionsButtonAdapter.itemCount +
|
||||||
|
syncedTabsController.adapter.itemCount
|
||||||
|
} else {
|
||||||
|
selectedBrowserTabIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAB_COUNT_SHOW_CFR = 6
|
private const val TAB_COUNT_SHOW_CFR = 6
|
||||||
private const val DEFAULT_TAB_ID = 0
|
private const val DEFAULT_TAB_ID = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user