{"record":{"id":"a4f69484b3f976be","repo":"material-components/material-components-android","slug":"navigationview-back-progress-requires-the-direct-p","errorCode":null,"errorMessage":"NavigationView back progress requires the direct parent view to be a DrawerLayout.","messagePattern":"NavigationView back progress requires the direct parent view to be a DrawerLayout\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/navigation/NavigationView.java","lineNumber":1087,"sourceCode":"    sideContainerBackHelper.finishBackProgress(\n        backEvent, gravity, scrimCloseAnimatorListener, scrimCloseAnimatorUpdateListener);\n  }\n\n  @Override\n  public void cancelBackProgress() {\n    requireDrawerLayoutParent();\n    sideContainerBackHelper.cancelBackProgress();\n    maybeClearCornerSizeAnimationForDrawerLayout();\n  }\n\n  @CanIgnoreReturnValue\n  private Pair<DrawerLayout, DrawerLayout.LayoutParams> requireDrawerLayoutParent() {\n    ViewParent parent = getParent();\n    ViewGroup.LayoutParams layoutParams = getLayoutParams();\n    if (parent instanceof DrawerLayout && layoutParams instanceof DrawerLayout.LayoutParams) {\n      return new Pair<>((DrawerLayout) parent, (DrawerLayout.LayoutParams) layoutParams);\n    } else {\n      throw new IllegalStateException(\n          \"NavigationView back progress requires the direct parent view to be a DrawerLayout.\");\n    }\n  }\n\n  @VisibleForTesting\n  MaterialSideContainerBackHelper getBackHelper() {\n    return sideContainerBackHelper;\n  }\n\n  private MenuInflater getMenuInflater() {\n    if (menuInflater == null) {\n      menuInflater = new SupportMenuInflater(getContext());\n    }\n    return menuInflater;\n  }\n\n  @Nullable\n  private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) {","sourceCodeStart":1069,"sourceCodeEnd":1105,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/navigation/NavigationView.java#L1069-L1105","documentation":"NavigationView's predictive-back progress APIs (updateBackProgress, handleBackInvoked, cancelBackProgress, etc.) only work when the view is a direct child of a DrawerLayout with DrawerLayout.LayoutParams. requireDrawerLayoutParent throws IllegalStateException when that structural assumption fails, because the back-progress animation math depends on the drawer's drag layout params.","triggerScenarios":"Calling navView.updateBackProgress(...)/cancelBackProgress() (typically from an OnBackAnimationCallback) while the NavigationView's parent is a FragmentContainerView, FrameLayout, or any non-DrawerLayout, or the layout params are not DrawerLayout.LayoutParams.","commonSituations":"Embedding NavigationView in a custom container or bottom-drawer layout; registerAnimationCallback copied from drawer sample code into a non-drawer screen; fragments where the parent was swapped at runtime.","solutions":["Make the NavigationView a direct child of androidx.drawerlayout.widget.DrawerLayout in XML","Remove the back-progress callback registration when the view is not in a DrawerLayout","Guard calls with getParent() instanceof DrawerLayout before invoking back progress APIs"],"exampleFix":"<!-- before -->\n<FrameLayout ...>\n  <com.google.android.material.navigation.NavigationView .../>\n</FrameLayout>\n<!-- after -->\n<androidx.drawerlayout.widget.DrawerLayout ...>\n  <com.google.android.material.navigation.NavigationView\n      android:layout_gravity=\"start\" .../>\n</androidx.drawerlayout.widget.DrawerLayout>","handlingStrategy":"type-guard","validationCode":"fun isInDrawerLayout(view: View): Boolean =\n    view.parent is DrawerLayout && view.layoutParams is DrawerLayout.LayoutParams","typeGuard":"fun View.parentIsDrawer(): Boolean = this.parent is DrawerLayout","tryCatchPattern":"catch (e: IllegalStateException) { Log.w(TAG, \"Back progress called outside DrawerLayout; ignoring\", e) }","preventionTips":["Only register OnBackAnimationCallback when the NavigationView's parent is a DrawerLayout","Declare NavigationView directly inside DrawerLayout with layout_gravity","Guard back-progress calls behind a parent-type check"],"tags":["android","material-components","navigationview","drawerlayout","predictive-back"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}