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 269173 a829347b8691b54ab85103a9c391a8d6ce5c2b28
parent 269172 9200ea11d07f7273a7e404bb8ba07a0ab2d7c36b
child 269174 0a5d8b46660d7bdfe50dfaafd6514a37f942e1c8
child 269296 9b328712d6cd729984ab946294bad62e426e5713
push id15838
push users.kaspari@gmail.com
push dateFri, 23 Oct 2015 14:21:04 +0000
treeherderfx-team@a829347b8691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1202753
milestone44.0a1
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);