Bug 895549 - Only remove transforms when we're about to recycle a view. r=lucasr
authorWes Johnston <wjohnston@mozilla.com>
Fri, 26 Jul 2013 09:24:51 -0700
changeset 140181 f8d184e3879d19db5522d64c9634eaa5bc54346d
parent 140180 bff7e921c95d46c7428db9e8e358ee5d8e492d8e
child 140182 79f46ef3804794096cb053e5782c8bdb5b5a6d56
push id1945
push userryanvm@gmail.com
push dateSat, 27 Jul 2013 02:27:26 +0000
treeherderfx-team@4874fa438b1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs895549
milestone25.0a1
Bug 895549 - Only remove transforms when we're about to recycle a view. r=lucasr
mobile/android/base/TabsTray.java
--- a/mobile/android/base/TabsTray.java
+++ b/mobile/android/base/TabsTray.java
@@ -44,16 +44,17 @@ public class TabsTray extends TwoWayView
     private int mCloseAnimationCount;
 
     private TabSwipeGestureListener mSwipeListener;
 
     // Time to animate non-flinged tabs of screen, in milliseconds
     private static final int ANIMATION_DURATION = 250;
 
     private static final String ABOUT_HOME = "about:home";
+    private int mOriginalSize = 0;
 
     public TabsTray(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
 
         mCloseAnimationCount = 0;
         mPendingClosedTabs = new ArrayList<View>();
 
@@ -256,27 +257,44 @@ public class TabsTray extends TwoWayView
                 row.thumbnail.setImageResource(R.drawable.abouthome_thumbnail);
             else
                 row.thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
 
             row.title.setText(tab.getDisplayTitle());
             row.close.setTag(row);
         }
 
+        private void resetTransforms(View view) {
+            ViewHelper.setAlpha(view, 1);
+            if (mOriginalSize == 0)
+                return;
+
+            if (isVertical()) {
+                ViewHelper.setHeight(view, mOriginalSize);
+                ViewHelper.setTranslationX(view, 0);
+            } else {
+                ViewHelper.setWidth(view, mOriginalSize);
+                ViewHelper.setTranslationY(view, 0);
+            }
+        }
+
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
             TabRow row;
 
             if (convertView == null) {
                 convertView = mInflater.inflate(R.layout.tabs_row, null);
                 row = new TabRow(convertView);
                 row.close.setOnClickListener(mOnCloseClickListener);
                 convertView.setTag(row);
             } else {
                 row = (TabRow) convertView.getTag();
+                // If we're recycling this view, there's a chance it was transformed during
+                // the close animation. Remove any of those properties.
+                resetTransforms(convertView);
             }
 
             Tab tab = mTabs.get(position);
             assignValues(row, tab);
 
             return convertView;
         }
     }
@@ -326,33 +344,25 @@ public class TabsTray extends TwoWayView
         final boolean isVertical = isVertical();
         if (isVertical)
             animator.attach(view, Property.HEIGHT, 1);
         else
             animator.attach(view, Property.WIDTH, 1);
 
         TabRow tab = (TabRow)view.getTag();
         final int tabId = tab.id;
-        final int originalSize = (isVertical ? view.getHeight() : view.getWidth());
+        // Caching this assumes that all rows are the same height
+	if (mOriginalSize == 0)
+            mOriginalSize = (isVertical ? view.getHeight() : view.getWidth());
 
         animator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
             @Override
             public void onPropertyAnimationStart() { }
             @Override
             public void onPropertyAnimationEnd() {
-                ViewHelper.setAlpha(view, 1);
-
-                if (isVertical) {
-                    ViewHelper.setHeight(view, originalSize);
-                    ViewHelper.setTranslationX(view, 0);
-                } else {
-                    ViewHelper.setWidth(view, originalSize);
-                    ViewHelper.setTranslationY(view, 0);
-                }
-
                 Tabs tabs = Tabs.getInstance();
                 Tab tab = tabs.getTab(tabId);
                 tabs.closeTab(tab);
             }
         });
 
         animator.start();
     }