Skip to content

Commit 0429d44

Browse files
committed
[Transition] Update MaterialContainerTransform to use getLocationInWindow() instead of getLocationOnScreen() when calculating bounds
Fixes issue where start / end view jump during transition in landscape mode when there is an artificial inset due to the camera hole / other display cutouts PiperOrigin-RevId: 631421213
1 parent 41eb087 commit 0429d44

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

lib/java/com/google/android/material/transition/MaterialContainerTransform.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static com.google.android.material.transition.TransitionUtils.defaultIfNull;
2727
import static com.google.android.material.transition.TransitionUtils.findAncestorById;
2828
import static com.google.android.material.transition.TransitionUtils.findDescendantOrAncestorById;
29-
import static com.google.android.material.transition.TransitionUtils.getLocationOnScreen;
29+
import static com.google.android.material.transition.TransitionUtils.getLocationInWindow;
3030
import static com.google.android.material.transition.TransitionUtils.getRelativeBounds;
3131
import static com.google.android.material.transition.TransitionUtils.lerp;
3232
import static com.google.android.material.transition.TransitionUtils.transform;
@@ -828,7 +828,7 @@ private static void captureValues(
828828

829829
if (ViewCompat.isLaidOut(view) || view.getWidth() != 0 || view.getHeight() != 0) {
830830
// Capture location in screen co-ordinates
831-
RectF bounds = view.getParent() == null ? getRelativeBounds(view) : getLocationOnScreen(view);
831+
RectF bounds = view.getParent() == null ? getRelativeBounds(view) : getLocationInWindow(view);
832832
transitionValues.values.put(PROP_BOUNDS, bounds);
833833
transitionValues.values.put(
834834
PROP_SHAPE_APPEARANCE,
@@ -919,7 +919,7 @@ public Animator createAnimator(
919919
}
920920

921921
// Calculate drawable bounds and offset start/end bounds as needed
922-
RectF drawingViewBounds = getLocationOnScreen(drawingView);
922+
RectF drawingViewBounds = getLocationInWindow(drawingView);
923923
float offsetX = -drawingViewBounds.left;
924924
float offsetY = -drawingViewBounds.top;
925925
RectF drawableBounds = calculateDrawableBounds(drawingView, boundingView, offsetX, offsetY);
@@ -1023,7 +1023,7 @@ private static float getElevationOrDefault(float elevation, View view) {
10231023
private static RectF calculateDrawableBounds(
10241024
View drawingView, @Nullable View boundingView, float offsetX, float offsetY) {
10251025
if (boundingView != null) {
1026-
RectF drawableBounds = getLocationOnScreen(boundingView);
1026+
RectF drawableBounds = getLocationInWindow(boundingView);
10271027
drawableBounds.offset(offsetX, offsetY);
10281028
return drawableBounds;
10291029
} else {

lib/java/com/google/android/material/transition/TransitionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ static Rect getRelativeBoundsRect(View view) {
295295
return new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
296296
}
297297

298-
static RectF getLocationOnScreen(View view) {
298+
static RectF getLocationInWindow(View view) {
299299
int[] location = new int[2];
300-
view.getLocationOnScreen(location);
300+
view.getLocationInWindow(location);
301301
int left = location[0];
302302
int top = location[1];
303303
int right = left + view.getWidth();

lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static com.google.android.material.transition.platform.TransitionUtils.defaultIfNull;
3131
import static com.google.android.material.transition.platform.TransitionUtils.findAncestorById;
3232
import static com.google.android.material.transition.platform.TransitionUtils.findDescendantOrAncestorById;
33-
import static com.google.android.material.transition.platform.TransitionUtils.getLocationOnScreen;
33+
import static com.google.android.material.transition.platform.TransitionUtils.getLocationInWindow;
3434
import static com.google.android.material.transition.platform.TransitionUtils.getRelativeBounds;
3535
import static com.google.android.material.transition.platform.TransitionUtils.lerp;
3636
import static com.google.android.material.transition.platform.TransitionUtils.transform;
@@ -833,7 +833,7 @@ private static void captureValues(
833833

834834
if (ViewCompat.isLaidOut(view) || view.getWidth() != 0 || view.getHeight() != 0) {
835835
// Capture location in screen co-ordinates
836-
RectF bounds = view.getParent() == null ? getRelativeBounds(view) : getLocationOnScreen(view);
836+
RectF bounds = view.getParent() == null ? getRelativeBounds(view) : getLocationInWindow(view);
837837
transitionValues.values.put(PROP_BOUNDS, bounds);
838838
transitionValues.values.put(
839839
PROP_SHAPE_APPEARANCE,
@@ -924,7 +924,7 @@ public Animator createAnimator(
924924
}
925925

926926
// Calculate drawable bounds and offset start/end bounds as needed
927-
RectF drawingViewBounds = getLocationOnScreen(drawingView);
927+
RectF drawingViewBounds = getLocationInWindow(drawingView);
928928
float offsetX = -drawingViewBounds.left;
929929
float offsetY = -drawingViewBounds.top;
930930
RectF drawableBounds = calculateDrawableBounds(drawingView, boundingView, offsetX, offsetY);
@@ -1028,7 +1028,7 @@ private static float getElevationOrDefault(float elevation, View view) {
10281028
private static RectF calculateDrawableBounds(
10291029
View drawingView, @Nullable View boundingView, float offsetX, float offsetY) {
10301030
if (boundingView != null) {
1031-
RectF drawableBounds = getLocationOnScreen(boundingView);
1031+
RectF drawableBounds = getLocationInWindow(boundingView);
10321032
drawableBounds.offset(offsetX, offsetY);
10331033
return drawableBounds;
10341034
} else {

lib/java/com/google/android/material/transition/platform/TransitionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ static Rect getRelativeBoundsRect(View view) {
300300
return new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
301301
}
302302

303-
static RectF getLocationOnScreen(View view) {
303+
static RectF getLocationInWindow(View view) {
304304
int[] location = new int[2];
305-
view.getLocationOnScreen(location);
305+
view.getLocationInWindow(location);
306306
int left = location[0];
307307
int top = location[1];
308308
int right = left + view.getWidth();

0 commit comments

Comments
 (0)