From 52f1737dd8f4fe3dad9e12512475c360002126d3 Mon Sep 17 00:00:00 2001 From: dsn5ft <1420597+dsn5ft@users.noreply.github.com> Date: Thu, 27 Apr 2023 10:55:33 -0400 Subject: [PATCH] [Predictive Back][Side Sheets] Fix subtle detached side sheet glitch where after predictive back the sheet does not fully slide off screen PiperOrigin-RevId: 527577382 --- .../motion/MaterialSideContainerBackHelper.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java b/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java index 0c9a628d73c..543a97ad9be 100644 --- a/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java +++ b/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java @@ -30,6 +30,8 @@ import android.view.Gravity; import android.view.View; import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.view.ViewGroup.MarginLayoutParams; import android.window.BackEvent; import androidx.annotation.GravityInt; import androidx.annotation.NonNull; @@ -130,7 +132,7 @@ public void finishBackProgress( @Nullable AnimatorUpdateListener finishAnimatorUpdateListener) { boolean leftSwipeEdge = backEvent.getSwipeEdge() == BackEvent.EDGE_LEFT; boolean leftGravity = checkAbsoluteGravity(gravity, Gravity.LEFT); - float scaledWidth = view.getWidth() * view.getScaleX(); + float scaledWidth = view.getWidth() * view.getScaleX() + getEdgeMargin(leftGravity); ObjectAnimator finishAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, leftGravity ? -scaledWidth : scaledWidth); if (finishAnimatorUpdateListener != null) { @@ -179,4 +181,13 @@ private boolean checkAbsoluteGravity(@GravityInt int gravity, @GravityInt int ch GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(view)); return (absoluteGravity & checkFor) == checkFor; } + + private int getEdgeMargin(boolean leftGravity) { + LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams instanceof MarginLayoutParams) { + MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams; + return leftGravity ? marginLayoutParams.leftMargin : marginLayoutParams.rightMargin; + } + return 0; + } }