[英]How to add shared element transition when navigating from recycler view to a fragment while using navigation components and safeArgs?
I want to show shared element transition from my recycler view to a fragment class, I've wriiten the following code:我想显示从我的回收器视图到片段 class 的共享元素转换,我编写了以下代码:
holder.view.setOnClickListener {
val extras = FragmentNavigatorExtras(
holder.view.ivPersonImage to "imageView"
)
it.findNavController().navigate(
HomeFragmentDirections.actionNavHomeToTransactionFragment(
customerId,
customerName,
customerPhoneNumber,
imageString
), null, null, extras
)
}
it's showing error at.navigate as:它显示错误 at.navigate 为:
None of the following functions can be called with the arguments supplied:
private open fun navigate(@NonNull p0: NavDestination, @Nullable p1: Bundle?, @Nullable p2: NavOptions?, @Nullable p3: Navigator.Extras?): Unit defined in androidx.navigation.NavController
public open fun navigate(@IdRes p0: Int, @Nullable p1: Bundle?, @Nullable p2: NavOptions?, @Nullable p3: Navigator.Extras?): Unit defined in androidx.navigation.NavController
in Fragment class, I'm using:在片段 class 中,我正在使用:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = TransitionInflater.from(context).inflateTransition(android.R.transition.move)
}
seems like safeArgs are not allowing to show transition.似乎 safeArgs 不允许显示转换。 I'm new to Android and finding it very difficult to understand transitions and animations.我是 Android 的新手,发现很难理解过渡和动画。 Please help me, I'm stuck here for so many days now请帮帮我,我在这里卡了这么多天了
SafeArgs
allows you to set shared transition. SafeArgs
允许您设置共享过渡。 Just check navigate()
documentation , there is overload with two parameters: NavDirections
and Navigator.Extras
.只需检查navigate()
文档,有两个参数重载: NavDirections
和Navigator.Extras
。 So your code should look like this:所以你的代码应该是这样的:
holder.view.setOnClickListener {
val extras = FragmentNavigatorExtras(holder.view.ivPersonImage to "imageView")
it.findNavController().navigate(
HomeFragmentDirections.actionNavHomeToTransactionFragment(
customerId,
customerName,
customerPhoneNumber,
imageString
),
extras
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.