{"record":{"id":"15319fc173ed1e5b","repo":"material-components/material-components-android","slug":"slide-distance-must-be-positive-if-attempting-to","errorCode":null,"errorMessage":"Slide distance must be positive. If attempting to reverse the direction of the slide, use setSlideEdge(int) instead.","messagePattern":"Slide distance must be positive\\. If attempting to reverse the direction of the slide, use setSlideEdge\\(int\\) instead\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/transition/SlideDistanceProvider.java","lineNumber":95,"sourceCode":"   * @see #setSlideDistance(int)\n   */\n  @Px\n  public int getSlideDistance() {\n    return slideDistance;\n  }\n\n  /**\n   * Set the distance this animator will translate its target.\n   *\n   * <p>By default, this value is set to -1 which indicates that the default slide distance,\n   * R.dimen.mtrl_transition_shared_axis_slide_distance will be used. Setting the slide distance to\n   * any other value will override this default.\n   *\n   * @throws IllegalArgumentException If {@code slideDistance} is negative.\n   */\n  public void setSlideDistance(@Px int slideDistance) {\n    if (slideDistance < 0) {\n      throw new IllegalArgumentException(\n          \"Slide distance must be positive. If attempting to reverse the direction of the slide,\"\n              + \" use setSlideEdge(int) instead.\");\n    }\n    this.slideDistance = slideDistance;\n  }\n\n  @Nullable\n  @Override\n  public Animator createAppear(@NonNull ViewGroup sceneRoot, @NonNull View view) {\n    return createTranslationAppearAnimator(\n        sceneRoot, view, slideEdge, getSlideDistanceOrDefault(view.getContext()));\n  }\n\n  @Nullable\n  @Override\n  public Animator createDisappear(@NonNull ViewGroup sceneRoot, @NonNull View view) {\n    return createTranslationDisappearAnimator(\n        sceneRoot, view, slideEdge, getSlideDistanceOrDefault(view.getContext()));","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/transition/SlideDistanceProvider.java#L77-L113","documentation":"SlideDistanceProvider.setSlideDistance (SlideDistanceProvider.java:95) validates that the pixel distance used to slide a view during a MaterialSharedAxis transition is non-negative. A negative distance would reverse the slide direction, but direction is expressed separately via the slide edge; to keep the two concerns disjoint, negative distances are rejected with IllegalArgumentException (note: the Javadoc says negative throws, the check is slideDistance < 0, so 0 is accepted).","triggerScenarios":"Calling provider.setSlideDistance(-120) intending to reverse motion; computing distance from a dimension resource that resolves negative; passing -1 as a sentinel/\"unset\" value (the default sentinel is -1 internally but is not a legal user value).","commonSituations":"Developers trying to flip slide direction with a negative number instead of setSlideEdge or swapping forward flag; using dimension math that can go negative in RTL or scaled densities; porting code from other libraries where negative distances are allowed.","solutions":["To reverse direction, change the edge/side the animation comes from (setSlideEdge or the forward boolean passed to MaterialSharedAxis), keeping distance positive.","If distance is computed, wrap with Math.abs() once you have verified the intended magnitude.","Never pass -1 as \"use default\" — omit setSlideDistance entirely to keep the default R.dimen.mtrl_transition_shared_axis_slide_distance."],"exampleFix":"// before\nprovider.setSlideDistance(-distancePx); // attempt to reverse\n\n// after\nprovider.setSlideDistance(distancePx);\n// reverse by constructing with forward=false or a different slide edge:\nnew MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false);","handlingStrategy":"validation","validationCode":"static int sanitizeSlideDistance(int px) {\n  if (px < 0) throw new IllegalArgumentException(\"slideDistance must be >= 0; got \" + px);\n  return px;\n}\nprovider.setSlideDistance(sanitizeSlideDistance(computedPx));\n// or simply: provider.setSlideDistance(Math.abs(computedPx)) when only magnitude matters","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Express direction via slide edge or the forward flag; keep distance a positive magnitude.","Avoid -1 sentinels; to use the default distance, do not call setSlideDistance at all.","Unit-test dimension math (RTL, density scaling) that feeds slideDistance."],"tags":["android","material-components","shared-axis","slide-distance","input-validation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}