Skip to content

android/nav3-recipes

Repository files navigation

Navigation 3 - Code recipes

Jetpack Navigation 3 is a library for app navigation. This repository contains recipes for how to use its APIs to implement common navigation use cases. Each recipe introduces a single concept. Instead of making existing recipes more complex, there should be a new recipe for that particular concept.

Every Navigation 3 release will be an opportunity for patterns you see in recipes to "graduate" and become (optional) helpers in the library itself. Then we'll update the recipe to use that prebuilt helper, thus ensuring that the recipes continue to be a good way to approach these kinds of problems.

Recipes

These are the recipes and what they demonstrate.

Basic API examples

Layouts using Scenes

  • List-Detail Scene: Shows how to create a custom, list-detail layout using a Scene and SceneStrategy (see video of UI behavior below).
  • Two pane Scene: Shows how to create a custom, 2-pane layout.
  • BottomSheet: Shows how to create a BottomSheet destination.
  • Dialog: Shows how to create a Dialog.

Material adaptive layouts

Examples showing how to use the layouts provided by the Compose Material3 Adaptive Navigation3 library

  • List-Detail: Shows how to use a Material adaptive list-detail layout.
  • Supporting Pane: Shows how to use a Material adaptive supporting pane layout.

Animations

  • Animations: Shows how to override the default animations for all destinations and a single destination.

Common use cases

  • Common navigation UI: A common navigation toolbar where each item in the toolbar navigates to a top level destination.
  • Multiple back stacks: Shows how to create multiple top level routes, each with its own back stack. Top level routes are displayed in a navigation bar allowing users to switch between them. State is retained for each top level route, and the navigation state persists config changes and process death.
  • Conditional navigation: Switch to a different navigation flow when a condition is met. For example, for authentication or first-time user onboarding.

Architecture

Passing navigation arguments to ViewModels

  • Basic ViewModel: Navigation arguments are passed to a ViewModel constructed using viewModel()
  • Hilt injected ViewModel: Navigation arguments are passed to a ViewModel constructed using hiltViewModel()
  • Koin injected ViewModel: Navigation arguments are passed to a ViewModel constructed using koinViewModel()

Returning Results

Planned

  • Deeplinks: Create and handle deeplinks to specific destinations
  • Android XR: Custom navigation and layout behavior for Android XR

Custom layout example

The following is a screen recording showing the navigation behavior of a custom, list-detail Scene.

Custom layout example

Instructions

Clone this repository and open the root folder in Android Studio. Each recipe is contained in its own package with its own Activity.

Found an issue?

If the issue is directly related to this project, as in, it's reproducible without modifying this project's source code, then please file an issue on github. If you've found an issue with the Jetpack Navigation 3 library, please file an issue on the issue tracker.

Contributing

We'd love to accept your contributions. Please follow these instructions.

Compose Multiplatform Recipes

CMP recipes can be found here.

License

Copyright 2025 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Implement common use cases with Jetpack Navigation 3

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages