[fenix] For https://github.com/mozilla-mobile/fenix/issues/15543 - Adjust the height of the tabs tray depending on the number of tabs (https://github.com/mozilla-mobile/fenix/pull/15749)

pull/600/head
Mugurell 4 years ago committed by GitHub
parent 6ff5ec846b
commit ebcb172781

@ -161,14 +161,13 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
if (newConfig.orientation != currentOrientation) { if (newConfig.orientation != currentOrientation) {
tabTrayView.dismissMenu() tabTrayView.dismissMenu()
tabTrayView.expand() tabTrayView.updateBottomSheetBehavior()
if (requireContext().settings().gridTabView) { if (requireContext().settings().gridTabView) {
// Update the number of columns to use in the grid view when the screen // Update the number of columns to use in the grid view when the screen
// orientation changes. // orientation changes.
tabTrayView.updateTabsTrayLayout() tabTrayView.updateTabsTrayLayout()
} }
currentOrientation = newConfig.orientation currentOrientation = newConfig.orientation
} }
} }
@ -205,8 +204,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
), ),
store = tabTrayDialogStore, store = tabTrayDialogStore,
isPrivate = isPrivate, isPrivate = isPrivate,
startingInLandscape = requireContext().resources.configuration.orientation == isInLandscape = ::isInLandscape,
Configuration.ORIENTATION_LANDSCAPE,
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
) { private -> ) { private ->
val filter: (TabSessionState) -> Boolean = { state -> private == state.content.private } val filter: (TabSessionState) -> Boolean = { state -> private == state.content.private }
@ -450,6 +448,10 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
} }
} }
private fun isInLandscape(): Boolean {
return requireContext().resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
companion object { companion object {
private const val ELEVATION = 80f private const val ELEVATION = 80f
} }

@ -40,6 +40,7 @@ import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.normalTabs import mozilla.components.browser.state.selector.normalTabs
import mozilla.components.browser.state.selector.privateTabs import mozilla.components.browser.state.selector.privateTabs
import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.tabstray.TabViewHolder import mozilla.components.browser.tabstray.TabViewHolder
import mozilla.components.feature.syncedtabs.SyncedTabsFeature import mozilla.components.feature.syncedtabs.SyncedTabsFeature
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
@ -54,6 +55,7 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange
import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode
import java.text.NumberFormat import java.text.NumberFormat
import kotlin.math.max
import mozilla.components.browser.storage.sync.Tab as SyncTab import mozilla.components.browser.storage.sync.Tab as SyncTab
/** /**
@ -66,7 +68,7 @@ class TabTrayView(
private val interactor: TabTrayInteractor, private val interactor: TabTrayInteractor,
store: TabTrayDialogFragmentStore, store: TabTrayDialogFragmentStore,
isPrivate: Boolean, isPrivate: Boolean,
startingInLandscape: Boolean, private val isInLandscape: () -> Boolean,
lifecycleOwner: LifecycleOwner, lifecycleOwner: LifecycleOwner,
private val filterTabs: (Boolean) -> Unit private val filterTabs: (Boolean) -> Unit
) : LayoutContainer, TabLayout.OnTabSelectedListener { ) : LayoutContainer, TabLayout.OnTabSelectedListener {
@ -145,20 +147,14 @@ class TabTrayView(
view.tab_layout.addOnTabSelectedListener(this) view.tab_layout.addOnTabSelectedListener(this)
val tabs = if (isPrivate) { val tabs = getTabs(isPrivate)
view.context.components.core.store.state.privateTabs
} else {
view.context.components.core.store.state.normalTabs
}
val selectedBrowserTabIndex = tabs val selectedBrowserTabIndex = tabs
.indexOfFirst { it.id == view.context.components.core.store.state.selectedTabId } .indexOfFirst { it.id == view.context.components.core.store.state.selectedTabId }
if (tabs.size > EXPAND_AT_SIZE || startingInLandscape) { updateBottomSheetBehavior()
expand()
}
setTopOffset(startingInLandscape) setTopOffset(isInLandscape())
if (view.context.settings().syncedTabsInTabsTray) { if (view.context.settings().syncedTabsInTabsTray) {
syncedTabsFeature.set( syncedTabsFeature.set(
@ -280,6 +276,27 @@ class TabTrayView(
} }
} }
private fun getTabs(isPrivate: Boolean): List<TabSessionState> = if (isPrivate) {
view.context.components.core.store.state.privateTabs
} else {
view.context.components.core.store.state.normalTabs
}
private fun getTabsNumberInAnyMode(): Int {
return max(
view.context.components.core.store.state.normalTabs.size,
view.context.components.core.store.state.privateTabs.size
)
}
private fun getTabsNumberForExpandingTray(): Int {
return if (container.context.settings().gridTabView) {
EXPAND_AT_GRID_SIZE
} else {
EXPAND_AT_LIST_SIZE
}
}
private fun handleTabClicked(tab: SyncTab) { private fun handleTabClicked(tab: SyncTab) {
interactor.onSyncedTabClicked(tab) interactor.onSyncedTabClicked(tab)
} }
@ -312,8 +329,17 @@ class TabTrayView(
components.analytics.metrics.track(eventToSend) components.analytics.metrics.track(eventToSend)
} }
fun expand() { /**
* Updates the bottom sheet height based on the number tabs or screen orientation.
* Show the bottom sheet fully expanded if it is in landscape mode or the number of
* tabs are greater or equal to the expand size limit.
*/
fun updateBottomSheetBehavior() {
if (isInLandscape() || getTabsNumberInAnyMode() >= getTabsNumberForExpandingTray()) {
behavior.state = BottomSheetBehavior.STATE_EXPANDED behavior.state = BottomSheetBehavior.STATE_EXPANDED
} else {
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
} }
enum class TabChange { enum class TabChange {
@ -668,7 +694,10 @@ class TabTrayView(
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
private const val PRIVATE_TAB_ID = 1 private const val PRIVATE_TAB_ID = 1
private const val EXPAND_AT_SIZE = 3 // Minimum number of list items for which to show the tabs tray as expanded.
private const val EXPAND_AT_LIST_SIZE = 4
// Minimum number of grid items for which to show the tabs tray as expanded.
private const val EXPAND_AT_GRID_SIZE = 3
private const val SLIDE_OFFSET = 0 private const val SLIDE_OFFSET = 0
private const val SELECTION_DELAY = 500 private const val SELECTION_DELAY = 500
private const val NORMAL_HANDLE_PERCENT_WIDTH = 0.1F private const val NORMAL_HANDLE_PERCENT_WIDTH = 0.1F

Loading…
Cancel
Save