将
Crossfade
动画应用于 NavigationSuiteScaffold
时,会返回以下错误。关于 it
这个词应该添加到哪里有什么想法吗?
目标状态参数
未使用it
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MyAdaptiveAppTheme {
var currentDestination by remember { mutableStateOf(AppDestinations.HOME) }
val adaptiveInfo = currentWindowAdaptiveInfo()
val layoutType = with(adaptiveInfo) {
if (windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED) { NavigationSuiteType.NavigationDrawer } else { NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(adaptiveInfo) }
}
NavigationSuiteScaffold(
layoutType = layoutType,
navigationSuiteItems = {
AppDestinations.entries.forEach {
item(
selected = currentDestination == it,
onClick = { currentDestination = it },
icon = {
Icon(
imageVector = it.icon,
contentDescription = it.contentDescription.toString()
)
},
label = { Text(text = stringResource(id = it.label)) }
)
}
},
) {
Crossfade(
targetState = currentDestination,
label = "CurrentPage"
) {
when(currentDestination) {
AppDestinations.HOME -> DestinationHome()
AppDestinations.PROFILE -> DestinationProfile()
}
}
}
}
}
}
}
Crossfade
:
Crossfade(
targetState = currentDestination,
label = "CurrentPage"
) { targetDestination ->
when(targetDestination) {
AppDestinations.HOME -> DestinationHome()
AppDestinations.PROFILE -> DestinationProfile()
}
}
当前设置的
targetState
作为参数传递到lamdba中,并且应该在lamdba内部使用。