我有一个导航组合,它将参数传递给开始动画,特别是
scaleIn
和
scaleOut
物业。然而
offSetX
和
offSetY
值为null。
但问题是:当我从以下位置访问这些值时
it.arguments
,它们显示了正确的值。你能帮我理解为什么会发生这种情况吗?
composable(
route = NavigationRoute.PreviewImage.route,
deepLinks = listOf(navDeepLink { uriPattern = "suntuk://preview/{id}/{type}/{x}/{y}" }),
arguments = listOf(
navArgument("id") { type = NavType.StringType },
navArgument("type") { type = NavType.IntType },
navArgument("x") { type = NavType.FloatType },
navArgument("y") { type = NavType.FloatType }
),
enterTransition = {
val offsetX = initialState.arguments?.getFloat("x") ?: 0f
val offsetY = initialState.arguments?.getFloat("y") ?: 0f
scaleIn(
animationSpec = tween(durationMillis = 5000),
transformOrigin = TransformOrigin(
offsetX,
offsetY
)
)
},
exitTransition = {
val offsetX = initialState.arguments?.getFloat("x") ?: 0f
val offsetY = initialState.arguments?.getFloat("y") ?: 0f
Timber.i("Offset: $offsetX, $offsetY")
scaleOut(
animationSpec = tween(durationMillis = 5000),
transformOrigin = TransformOrigin(
offsetX,
offsetY
)
)
}
) {
val id = it.arguments?.getString("id") ?: ""
val type = it.arguments?.getInt("type") ?: 0
val x = it.arguments?.getFloat("x") ?: 0f
val y = it.arguments?.getFloat("y") ?: 0f
Timber.i("Preview image: $id, $type, $x, $y")
val viewModel: PreviewImageViewModel = koinViewModel { parameterSetOf(id, type) }
PreviewImageScreen(
viewModel = viewModel,
onBack = {
navController.navigateUp()
}
)
}