Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21d36180 authored by Alan Viverette's avatar Alan Viverette
Browse files

Fix exit transition and dismiss callback for popup exit transition

We should run the transition only when the anchor root IS attached,
and we should only call the dismiss callback when the animation has
completed and the window has been removed.

Bug: 25323707
Bug: 26647820
Change-Id: I2bcdc901885d4c0a6c48c2b2c949797def1d7512
parent 8baf238a
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -1632,6 +1632,7 @@ public class PopupWindow {

        final PopupDecorView decorView = mDecorView;
        final View contentView = mContentView;
        final OnDismissListener dismissListener = mOnDismissListener;

        final ViewGroup contentHolder;
        final ViewParent contentParent = contentView.getParent();
@@ -1653,7 +1654,7 @@ public class PopupWindow {
        // can expect the OnAttachStateChangeListener to have been called prior
        // to executing this method, so we can rely on that instead.
        final Transition exitTransition = mExitTransition;
        if (!mIsAnchorRootAttached && exitTransition != null && decorView.isLaidOut()) {
        if (mIsAnchorRootAttached && exitTransition != null && decorView.isLaidOut()) {
            // The decor view is non-interactive during exit transitions.
            final LayoutParams p = (LayoutParams) decorView.getLayoutParams();
            p.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
@@ -1675,19 +1676,16 @@ public class PopupWindow {
                    new TransitionListenerAdapter() {
                        @Override
                        public void onTransitionEnd(Transition transition) {
                            dismissImmediate(decorView, contentHolder, contentView);
                            dismissImmediate(decorView, contentHolder,
                                    contentView, dismissListener);
                        }
                    });
        } else {
            dismissImmediate(decorView, contentHolder, contentView);
            dismissImmediate(decorView, contentHolder, contentView, dismissListener);
        }

        // Clears the anchor view.
        unregisterForViewTreeChanges();

        if (mOnDismissListener != null) {
            mOnDismissListener.onDismiss();
        }
    }

    /**
@@ -1729,7 +1727,8 @@ public class PopupWindow {
     * Removes the popup from the window manager and tears down the supporting
     * view hierarchy, if necessary.
     */
    private void dismissImmediate(View decorView, ViewGroup contentHolder, View contentView) {
    private void dismissImmediate(View decorView, ViewGroup contentHolder,
            View contentView, OnDismissListener listener) {
        // If this method gets called and the decor view doesn't have a parent,
        // then it was either never added or was already removed. That should
        // never happen, but it's worth checking to avoid potential crashes.
@@ -1746,6 +1745,10 @@ public class PopupWindow {
        mDecorView = null;
        mBackgroundView = null;
        mIsTransitioningToDismiss = false;

        if (mOnDismissListener != null) {
            mOnDismissListener.onDismiss();
        }
    }

    /**