![](/img/trans.png)
[英]Jetpack Navigation Compose Animation incorrect pop animation
[英]Pop enter animation not working with the Jetpack Navigation Component
我一直在使用 Jetpack Navigation 组件(2.3.5,虽然我也测试过旧版本)并尝试在两个简单目的地之间添加转换。 但是,使用popEnterAnim
属性指定的过渡根本不会运行。 相反,重新进入的片段会立即出现。
我设法用一个非常简单的例子重新创建了它。 片段布局只是一个TextView
。
主要活动
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
class ActivityMain : AppCompatActivity(R.layout.main)
片段 1
class Fragment1 : Fragment(R.layout.fragment_1) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.setOnClickListener {
findNavController().navigate(R.id.action_fragment1_to_fragment2)
}
}
}
片段 2
class Fragment2: Fragment(R.layout.fragment_2)
导航图
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph.xml"
app:startDestination="@id/fragment1">
<fragment
android:id="@+id/fragment1"
android:name="uk.henrytwist.projectsource.Fragment1"
android:label="MainFragment" >
<action
android:id="@+id/action_fragment1_to_fragment2"
app:destination="@id/fragment2"
app:enterAnim="@anim/transition_rise_up_enter"
app:exitAnim="@anim/transition_fade_exit"
app:popEnterAnim="@anim/transition_fade_pop_enter"
app:popExitAnim="@anim/transition_rise_up_pop_exit" />
</fragment>
<fragment
android:id="@+id/fragment2"
android:name="uk.henrytwist.projectsource.Fragment2"
android:label="Fragment2" />
</navigation>
事实证明,这实际上是由于 AndroidX 片段库 ( androidx.fragment:fragment:1.3.2
) 中的一个错误,该错误现已在1.3.3
版本中得到纠正。 更改日志确认修复:
修复了 Fragment 1.3.2 中引入的回归,该回归会导致 popEnter 动画在弹出包含 setPrimaryNavFragment 操作的 FragmentTransaction 时无法运行,例如 NavHostFragment 使用的那些。 (I38c87, b/183877426)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.