Bug 1202753 - Tabs tray (Grid): Scroll to selected tab if it is not visible. r=margaret
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 23 Oct 2015 12:57:17 +0200
changeset 304334 a829347b8691b54ab85103a9c391a8d6ce5c2b28
parent 304333 9200ea11d07f7273a7e404bb8ba07a0ab2d7c36b
child 304399 9b328712d6cd729984ab946294bad62e426e5713
child 304476 0a5d8b46660d7bdfe50dfaafd6514a37f942e1c8
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1202753
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1202753 - Tabs tray (Grid): Scroll to selected tab if it is not visible. r=margaret
mobile/android/base/tabs/TabsGridLayout.java
--- a/mobile/android/base/tabs/TabsGridLayout.java
+++ b/mobile/android/base/tabs/TabsGridLayout.java
@@ -166,19 +166,25 @@ class TabsGridLayout extends GridView
 
     @Override
     public void show() {
         setVisibility(View.VISIBLE);
         Tabs.getInstance().refreshThumbnails();
         Tabs.registerOnTabsChangedListener(this);
         refreshTabsData();
 
-        Tab currentlySelectedTab = Tabs.getInstance().getSelectedTab();
-        if (lastSelectedTabId != currentlySelectedTab.getId()) {
-            smoothScrollToPosition(tabsAdapter.getPositionForTab(currentlySelectedTab));
+        final Tab currentlySelectedTab = Tabs.getInstance().getSelectedTab();
+        final int position =  currentlySelectedTab != null ? tabsAdapter.getPositionForTab(currentlySelectedTab) : -1;
+        if (position != -1) {
+            final boolean selectionChanged = lastSelectedTabId != currentlySelectedTab.getId();
+            final boolean positionIsVisible = position >= getFirstVisiblePosition() && position <= getLastVisiblePosition();
+
+            if (selectionChanged || !positionIsVisible) {
+                smoothScrollToPosition(position);
+            }
         }
     }
 
     @Override
     public void hide() {
         lastSelectedTabId = Tabs.getInstance().getSelectedTab().getId();
         setVisibility(View.GONE);
         Tabs.unregisterOnTabsChangedListener(this);