navigation-3
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigration guide
迁移指南
- Navigation 2 to Navigation 3 migration guide: Step-by-step guide to migrate an Android application from Navigation 2 to Navigation 3, covering dependency updates, route changes, state management, and UI component replacements.
- Navigation 2 迁移至 Navigation 3 指南:逐步指导将Android应用从Navigation 2迁移至Navigation 3,涵盖依赖更新、路由变更、状态管理和UI组件替换。
Requirements
要求
- Guide: Migrate to type-safe navigation in Compose : Step-by-step guide to migrating an Android application from string-based navigation to Type-Safe Navigation in Jetpack Compose using Jetpack Navigation 2.
- 指南:在Compose中迁移至类型安全导航 : 逐步指导将Android应用从基于字符串的导航迁移至使用Jetpack Navigation 2的Jetpack Compose中的Type-Safe Navigation。
Developer documentation
开发者文档
- *Navigation 3. Search documentation for more information on basics, saving and managing navigation state, modularizing navigation code, creating custom layouts using Scenes, animating between destinations, or applying logic or wrappers to destinations.
- Navigation 3:查阅文档获取更多关于基础用法、导航状态的保存与管理、导航代码模块化、使用Scenes创建自定义布局、页面间动画实现,或为页面应用逻辑与包装器的相关信息。
Recipes
示例代码
Code examples showcasing common patterns.
展示常见模式的代码示例。
Basic API usage
基础API使用
- Basic: Shows most basic API usage.
- Saveable back stack: Shows basic API usage with a persistent back stack.
- Entry provider DSL: Shows basic API usage using the entryProvider DSL.
- 基础用法:展示最基础的API使用方式。
- 可保存返回栈:展示带有持久化返回栈的基础API使用方式。
- Entry Provider DSL:展示使用entryProvider DSL的基础API使用方式。
Common UI
通用UI
- Common UI: Demonstrates how to implement a common navigation UI pattern with a bottom navigation bar and multiple back stacks, where each tab in the navigation bar has its own navigation history.
- 通用UI:演示如何实现带有底部导航栏和多返回栈的通用导航UI模式,其中导航栏中的每个标签页都有自己的导航历史。
Deep links
深度链接
- Basic: Shows how to parse a deep link URL from an Android Intent into a navigation key.
- Advanced: Shows how to handle deep links with a synthetic back stack and correct "Up" navigation behavior.
- 基础用法:展示如何将Android Intent中的深度链接URL解析为导航键。
- 进阶用法:展示如何处理带有合成返回栈和正确“向上”导航行为的深度链接。
Scenes
场景
Use built-in Scenes
使用内置场景
- Dialog: Shows how to create a Dialog.
- 对话框:展示如何创建Dialog。
Create custom Scenes
创建自定义场景
- BottomSheet: Shows how to create a BottomSheet destination.
- List-Detail Scene: Demonstrates how to implement adaptive list-detail layouts using the Navigation 3 Scenes API.
- Two pane Scene: Demonstrates how to implement adaptive two-pane layouts using the Navigation 3 Scenes API.
- 底部表单:展示如何创建BottomSheet页面。
- 列表-详情场景:演示如何使用Navigation 3 Scenes API实现自适应列表-详情布局。
- 双窗格场景:演示如何使用Navigation 3 Scenes API实现自适应双窗格布局。
Material Adaptive
Material自适应
- Material List-Detail: Demonstrates how to implement an adaptive list-detail layout using Material 3 Adaptive.
- Material Supporting Pane: Demonstrates how to implement an adaptive supporting pane layout using Material 3 Adaptive.
- Material列表-详情:演示如何使用Material 3 Adaptive实现自适应列表-详情布局。
- Material辅助窗格:演示如何使用Material 3 Adaptive实现自适应辅助窗格布局。
Animations
动画
- Animations: Shows how to override the default animations for all destinations and a single destination.
- 动画:展示如何覆盖所有页面和单个页面的默认动画。
Common back stack behavior
通用返回栈行为
- 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
条件导航
- Conditional navigation: Switch to a different navigation flow when a condition is met. For example, for authentication or first-time user onboarding.
- 条件导航:当满足某个条件时切换到不同的导航流程。例如,用于身份验证或首次用户引导。
Architecture
架构
- Modularized navigation code (Hilt): Demonstrates how to decouple navigation code into separate modules using Hilt or Dagger for DI.
- Modularized navigation code (Koin): Demonstrates how to decouple navigation code into separate modules using Koin for DI.
- 模块化导航代码(Hilt):演示如何使用Hilt或Dagger进行依赖注入,将导航代码解耦到单独的模块中。
- 模块化导航代码(Koin):演示如何使用Koin进行依赖注入,将导航代码解耦到单独的模块中。
Working with ViewModel
与ViewModel协作
Passing navigation arguments
传递导航参数
- Basic ViewModel : Navigation arguments are passed to a constructed using
ViewModelviewModel()
- 基础ViewModel:导航参数会传递给使用构建的
viewModel()ViewModel
Returning results
返回结果
- Returning Results as Events : Returning results as events to content in another
NavEntry - Returning Results as State : Returning results as state stored in a
CompositionLocal
- 以事件形式返回结果:以事件形式将结果返回给另一个中的内容
NavEntry - 以状态形式返回结果:以状态形式将结果存储在中并返回
CompositionLocal