Commit 7b814dac authored by Vlad Baicu's avatar Vlad Baicu
Browse files

Bug 1586770 - Fix activity stream invalid viewholders crash. r=petru, a=RyanVM

Disable predictive animations. There is a bug in RecyclerView which causes views that
are being reloaded to pull invalid ViewHolders from the internal recycler stack if the
adapter size has decreased since the ViewHolder was recycled.

Differential Revision: https://phabricator.services.mozilla.com/D48929
parent 11da9e36
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ import android.support.annotation.NonNull;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.widget.FrameLayout;
@@ -74,7 +73,7 @@ public class ActivityStreamPanel extends FrameLayout {

        contentRecyclerView = findViewById(R.id.activity_stream_main_recyclerview);
        contentRecyclerView.setAdapter(adapter);
        contentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        contentRecyclerView.setLayoutManager(new NpaLinearLayoutManager(getContext()));
        contentRecyclerView.setHasFixedSize(true);
        // Override item animations to avoid horrible topsites refreshing
        contentRecyclerView.setItemAnimator(new StreamItemAnimator());
+36 −0
Original line number Diff line number Diff line
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.activitystream.homepanel;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;

/**
 * No Predictive Animations LinearLayoutManager
 */
public class NpaLinearLayoutManager extends LinearLayoutManager {
    public NpaLinearLayoutManager(Context context) {
        super(context);
    }

    public NpaLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }

    public NpaLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    /**
     * Disable predictive animations. There is a bug in RecyclerView which causes views that
     * are being reloaded to pull invalid ViewHolders from the internal recycler stack if the
     * adapter size has decreased since the ViewHolder was recycled.
     */
    @Override
    public boolean supportsPredictiveItemAnimations() {
        return false;
    }
}