Skip to content

Commit b9d70d3

Browse files
committed
[Motion] Fix zero-length motion path container transform bug.
getPosTan, which calculates the translation of the conatienr bounds, no-ops if the startView doesn't move to a new position (when the startView and endView are top aligned and centered horizontally on one another). This was causing motionPathPositions, the int array holding the x and y of the animated bounds to never be initialized, defaulting to 0, and throwing off the bounds calculation. This CL updates the int array with actual default x and y values so when getPosTan no-ops, the motionPathPosition array contains the correct values. Resolves #1161 PiperOrigin-RevId: 319247326 (cherry picked from commit 3c9096d)
1 parent 47ab850 commit b9d70d3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,12 @@ private TransitionDrawable(
11391139
Path motionPath = pathMotion.getPath(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
11401140
motionPathMeasure = new PathMeasure(motionPath, false);
11411141
motionPathLength = motionPathMeasure.getLength();
1142+
// Fill the motion path with default positions in case a zero-length path is specified which
1143+
// causes motionPathMeasure.getPosTan to skip filling this int array.
1144+
// A zero-length path happens when the startBounds are top aligned and horizontally centered
1145+
// on the endBounds.
1146+
motionPathPosition[0] = startBounds.centerX();
1147+
motionPathPosition[1] = startBounds.top;
11421148

11431149
scrimPaint.setStyle(Paint.Style.FILL);
11441150
scrimPaint.setShader(createColorShader(scrimColor));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,12 @@ private TransitionDrawable(
11441144
Path motionPath = pathMotion.getPath(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
11451145
motionPathMeasure = new PathMeasure(motionPath, false);
11461146
motionPathLength = motionPathMeasure.getLength();
1147+
// Fill the motion path with default positions in case a zero-length path is specified which
1148+
// causes motionPathMeasure.getPosTan to skip filling this int array.
1149+
// A zero-length path happens when the startBounds are top aligned and horizontally centered
1150+
// on the endBounds.
1151+
motionPathPosition[0] = startBounds.centerX();
1152+
motionPathPosition[1] = startBounds.top;
11471153

11481154
scrimPaint.setStyle(Paint.Style.FILL);
11491155
scrimPaint.setShader(createColorShader(scrimColor));

0 commit comments

Comments
 (0)