Circular Reveal animation stops working after re-adding fragment

162 views Asked by At

I defined a curcular reveal animation for my searchview and it works. But when re-adding the frgament (via ft.add(R.id.main_content, frag), the reveal animation does not occur. Typing a search query the letters are seamingly invisible and the listview for auocomplete will not appear. But if after typing (invisibly) I hit search, the free search is indeed performed. Debugging shows the code is executed and views are measured properly. If I change the code to ft.replace() instead of add, there's no bug. Please note I change out the toolbar with every fragment, so the re-added fragment's toolbar, the one that is not showing the reveal, should in theory be a fresh occurrence of all UI elements.

 <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/toolbar_gradient"
    android:minHeight="?attr/actionBarSize"
    android:paddingTop="@dimen/toolbar_padding_top"

   />

    <android.support.v7.widget.Toolbar
        android:id="@+id/searchtoolbar"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        app:collapseIcon="@drawable/ic_grey_arrow_back"
        app:titleTextColor="@color/app_theme_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_accent"
        android:minHeight="?attr/actionBarSize"
        android:layout_marginTop="@dimen/toolbar_padding_top"
        android:visibility="invisible"
        android:clickable="true"
        />

</FrameLayout>

public void circleReveal(int viewID, int posFromRight, final boolean isShow) {
    final View myView = findViewById(viewID);

    int width = myView.getWidth();

    if (posFromRight > 0)
        width -= (posFromRight * getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_material)) -
                (getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_material) / 2);

    int cx = width;
    int cy = myView.getHeight()/2;

    Animator anim;
    if (isShow)
        anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, (float)width);
    else
        anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, (float) width, 0);

    anim.setDuration((long) 220);

    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!isShow) {
                super.onAnimationEnd(animation);
                myView.setVisibility(View.GONE);
                getSupportActionBar().setTitle(actionBarTitle);
            }

        }
    });

    // make the view visible and start the animation
    if (isShow)
        myView.setVisibility(View.VISIBLE);

    // start the animation
    anim.start();
}
0

There are 0 answers