material-components/material-components-android · error · IllegalArgumentException

Invalid transition direction: > transitionDirection <

Error message

Invalid transition direction: > transitionDirection <

What it means

Platform-package copy of the direction check in transition/platform/MaterialContainerTransform.java:1046. isEntering() interprets setTransitionDirection(): AUTO compares start/end areas, ENTER forces entering, RETURN forces return; any other int throws IllegalArgumentException when the transition computes its direction at draw/setup time — which may be later than the setter call.

Source

Thrown at lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java:1046

    if (boundingView != null) {
      RectF drawableBounds = getLocationInWindow(boundingView);
      drawableBounds.offset(offsetX, offsetY);
      return drawableBounds;
    } else {
      return new RectF(0, 0, drawingView.getWidth(), drawingView.getHeight());
    }
  }

  private boolean isEntering(@NonNull RectF startBounds, @NonNull RectF endBounds) {
    switch (transitionDirection) {
      case TRANSITION_DIRECTION_AUTO:
        return calculateArea(endBounds) > calculateArea(startBounds);
      case TRANSITION_DIRECTION_ENTER:
        return true;
      case TRANSITION_DIRECTION_RETURN:
        return false;
      default:
        throw new IllegalArgumentException("Invalid transition direction: " + transitionDirection);
    }
  }

  private ProgressThresholdsGroup buildThresholdsGroup(boolean entering) {
    PathMotion pathMotion = getPathMotion();
    if (pathMotion instanceof ArcMotion || pathMotion instanceof MaterialArcMotion) {
      return getThresholdsOrDefault(
          entering, DEFAULT_ENTER_THRESHOLDS_ARC, DEFAULT_RETURN_THRESHOLDS_ARC);
    } else {
      return getThresholdsOrDefault(entering, DEFAULT_ENTER_THRESHOLDS, DEFAULT_RETURN_THRESHOLDS);
    }
  }

  private ProgressThresholdsGroup getThresholdsOrDefault(
      boolean entering,
      ProgressThresholdsGroup defaultEnterThresholds,
      ProgressThresholdsGroup defaultReturnThresholds) {
    ProgressThresholdsGroup defaultThresholds =

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Use TRANSITION_DIRECTION_AUTO / TRANSITION_DIRECTION_ENTER / TRANSITION_DIRECTION_RETURN from the platform class.
  2. Sanitize restored or remote values immediately: default to TRANSITION_DIRECTION_AUTO on mismatch.
  3. Validate at set-time in a wrapper so the failure points at the culprit code, not at transition runtime.

Example fix

// before
transform.setTransitionDirection(-1);

// after
transform.setTransitionDirection(MaterialContainerTransform.TRANSITION_DIRECTION_RETURN);
Defensive patterns

Strategy: validation

Validate before calling

import com.google.android.material.transition.platform.MaterialContainerTransform;

static int coercePlatformDirection(int d) {
  return (d == MaterialContainerTransform.TRANSITION_DIRECTION_AUTO
       || d == MaterialContainerTransform.TRANSITION_DIRECTION_ENTER
       || d == MaterialContainerTransform.TRANSITION_DIRECTION_RETURN)
      ? d : MaterialContainerTransform.TRANSITION_DIRECTION_AUTO;
}
transform.setTransitionDirection(coercePlatformDirection(restoredDir));

Type guard

static boolean isValidPlatformDirection(int d) {
  return d == MaterialContainerTransform.TRANSITION_DIRECTION_AUTO
      || d == MaterialContainerTransform.TRANSITION_DIRECTION_ENTER
      || d == MaterialContainerTransform.TRANSITION_DIRECTION_RETURN;
}

Prevention

When it happens

Trigger: Calling setTransitionDirection() with an invalid int on the platform MaterialContainerTransform; the crash surfacing only when the transition actually runs (direction is evaluated lazily in isEntering); persisted direction ints restored without validation.

Common situations: Hardcoded direction ints; values shared between androidx and platform transform variants; late crash confusing developers because the bad value was set much earlier.

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/188d10e8dd52d1b8. Report an issue: GitHub.