将动画应用到NavigationSuite时,不使用目标状态参数“it”

问题描述 投票:0回答:1

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()
                    }
                    }
                }
            }
        }
    }
}
android kotlin android-jetpack-compose android-jetpack-compose-material3
1个回答
0
投票

请尝试像这样更新您的

Crossfade

Crossfade(
    targetState = currentDestination,
    label = "CurrentPage"
) { targetDestination ->
    when(targetDestination) {
        AppDestinations.HOME -> DestinationHome()
        AppDestinations.PROFILE -> DestinationProfile()
    }
}

当前设置的

targetState
作为参数传递到lamdba中,并且应该在lamdba内部使用。

© www.soinside.com 2019 - 2024. All rights reserved.