Remove dismiss target only when it's attached to a parent.

Bug: 258120818
Change-Id: I63bd5b5cf43db7c794cba84d680b5e168f0e2350
Test: n/a
This commit is contained in:
Mateusz Cicheński
2023-02-21 20:39:32 +00:00
parent b8b7a2304c
commit 329b65045f

View File

@@ -235,21 +235,14 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen
/** Adds the magnetic target view to the WindowManager so it's ready to be animated in. */
public void createOrUpdateDismissTarget() {
if (!mTargetViewContainer.isAttachedToWindow()) {
if (mTargetViewContainer.getParent() == null) {
mTargetViewContainer.cancelAnimators();
mTargetViewContainer.setVisibility(View.INVISIBLE);
mTargetViewContainer.getViewTreeObserver().removeOnPreDrawListener(this);
mHasDismissTargetSurface = false;
try {
mWindowManager.addView(mTargetViewContainer, getDismissTargetLayoutParams());
} catch (IllegalStateException e) {
// This shouldn't happen, but if the target is already added, just update its layout
// params.
mWindowManager.updateViewLayout(
mTargetViewContainer, getDismissTargetLayoutParams());
}
mWindowManager.addView(mTargetViewContainer, getDismissTargetLayoutParams());
} else {
mWindowManager.updateViewLayout(mTargetViewContainer, getDismissTargetLayoutParams());
}
@@ -306,7 +299,7 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen
* Removes the dismiss target and cancels any pending callbacks to show it.
*/
public void cleanUpDismissTarget() {
if (mTargetViewContainer.isAttachedToWindow()) {
if (mTargetViewContainer.getParent() != null) {
mWindowManager.removeViewImmediate(mTargetViewContainer);
}
}