navigationevent

  
导航事件库提供了一个 KMP-first API,用于处理系统返回以及预测性返回
最近更新时间 稳定版 候选版 Beta 版 Alpha 版
2025 年 7 月 2 日 - - - 1.0.0-alpha04

声明依赖项

如需添加 navigationevent 的依赖项,您必须将 Google Maven 制品库添加到项目中。如需了解详情,请参阅 Google 的 Maven 代码库

在应用或模块的 build.gradle 文件中添加所需工件的依赖项:

Groovy

dependencies {
    implementation "androidx.navigationevent:navigationevent:1.0.0-alpha04"
}

Kotlin

dependencies {
    implementation("androidx.navigationevent:navigationevent:1.0.0-alpha04")
}

如需详细了解依赖项,请参阅添加 build 依赖项

反馈

您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。

创建新问题

如需了解详情,请参阅问题跟踪器文档

此工件没有版本说明。

版本 1.0

版本 1.0.0-alpha04

2025 年 7 月 2 日

发布了 androidx.navigationevent:navigationevent-*:1.0.0-alpha04。版本 1.0.0-alpha04 中包含这些提交内容

bug 修复

  • 使用 implementedInJetBrainsForknavigationevent-compose 添加到 commonStubs 目标,以符合 Compose 惯例。JetBrains 的 Ivan Matkov 提出的更改。(f60c79)
  • 修复了将 Compose 编译器插件应用于 Kotlin/Native 的问题,以确保正确生成桩。对公开 API 或行为没有影响。(1890c9)

版本 1.0.0-alpha03

2025 年 6 月 18 日

发布了 androidx.navigationevent:navigationevent-*:1.0.0-alpha03。版本 1.0.0-alpha03 中包含这些提交内容

新功能

  • 引入了新的 navigationevent-compose 模块,以支持 navigationevent 库中的 Jetpack Compose 功能。(980d78)
  • NavigationEvent Compose 添加了新的 LocalNavigationEventDispatcherOwner 本地组合。它会返回可为 null 的值,以更好地确定其在当前组合中是否可用。现在,如果未找到底层所有者,NavigationEventHandler 会抛出错误。(62ffda)
  • NavigationEvent Compose 添加了一个新的 NavigationEventHandler 可组合项来处理(预测性返回手势)事件。它提供了一个 Flow,其中包含您提供的挂起 lambda 中必须收集的 NavigationEvent 对象 c42ba6
NavigationEventHandler { progress: Flow<NavigationEvent> ->
  // This block is executed when the back gesture begins.
  try {
    progress.collect { backEvent ->
      // Handle gesture progress updates here.
    }
    // This block is executed if the gesture completes successfully.
  } catch (e: CancellationException) {
    // This block is executed if the gesture is cancelled
    throw e
  } finally {
    // This block is executed either the gesture is completed or cancelled
  }
}

API 变更

  • 现在,每个 NavigationEventCallback 一次只能注册一个 NavigationEventDispatcher;如果将其添加到多个调度程序,则会抛出 IllegalStateException。请注意,此行为与允许使用多个调度程序的 OnBackPressedDispatcher 不同。(e82c19)
  • isPassThrough 设为 val,以防止在导航期间发生突变,从而避免破坏 NavigationEvent 的调度。(I0b287)

版本 1.0.0-alpha02

2025 年 6 月 4 日

发布了 androidx.navigationevent:navigationevent-*:1.0.0-alpha02。版本 1.0.0-alpha02 中包含这些提交内容

API 变更

  • NavigationEventDispatcher 的次构造函数替换为具有默认实参的次构造函数。(I716a0)
  • NavigationEventCallback 中移除了优先级属性。请改为将优先级传递给 NavigationEventDispatcher.addCallback()。(I13cae)

bug 修复

  • 修复了在调用 NavigationEventCallback.remove() 时可能因同时修改可关闭对象的内部列表而发生的 ConcurrentModificationException。(b/420919815)

版本 1.0.0-alpha01

2025 年 5 月 20 日

发布了 androidx.navigationevent:navigationevent-*:1.0.0-alpha01。版本 1.0.0-alpha01 中包含这些提交内容

新功能

  • androidx.navigationevent 库提供了一个 KMP 优先的 API,用于处理系统返回以及预测性返回NavigationEventDispatcher 用作注册一个或多个 NavigationEventCallback 实例以接收系统返回事件的通用 API。
  • 此层位于 androidx.activity 中之前发布的 API 之下,旨在成为一种更灵活的替代方案,用于在更高级别的组件中使用 Activity API 或直接使用 Android 框架 OnBackInvokedDispatcher API。androidx.activity API 已在 Navigation Event API 的基础上重写,作为 Activity 1.12.0-alpha01 的一部分。