gpt4 book ai didi

android - 将 Compose 的导航库升级到 Alpha 7 后出现的问题

转载 作者:行者123 更新时间:2023-12-04 07:14:08 26 4
gpt4 key购买 nike

我目前正在使用 的 alpha 版本Compose 的导航库 ,在版本 6 中一切正常,但是当升级到 Alpha 7 时,我似乎收到了一个错误 AnimatedNavHost (com.google.accompanist:accompanist-navigation-animation:0.16.1)。
问题是,现在在模拟器或物理设备上编译和运行应用程序时,应用程序崩溃并关闭(我理解这是因为它无法实例化或加载 AnimatedNavHost)。
日志显示了以下错误:

    java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost$lambda-3(AnimatedNavHost.kt:323)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:158)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:85)
at com.jeluchu.inook.core.navigation.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:136)
at com.jeluchu.inook.core.navigation.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:134)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1$measurables$1.invoke(BoxWithConstraints.kt:66)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1$measurables$1.invoke(BoxWithConstraints.kt:66)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2$1$1.invoke(SubcomposeLayout.kt:241)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2$1$1.invoke(SubcomposeLayout.kt:241)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3330)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2577)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2573)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(SnapshotState.kt:540)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2566)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:2517)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:476)
at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:727)
at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_release(Composer.kt:2980)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:432)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcomposeInto(SubcomposeLayout.kt:259)
at androidx.compose.ui.layout.SubcomposeLayoutState.access$subcomposeInto(SubcomposeLayout.kt:145)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:234)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:231)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.withNoObservations(SnapshotStateObserver.kt:144)
at androidx.compose.ui.node.OwnerSnapshotObserver.withNoSnapshotReadObservation$ui_release(OwnerSnapshotObserver.kt:49)
at androidx.compose.ui.node.LayoutNode.withNoSnapshotReadObservation$ui_release(LayoutNode.kt:1107)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:231)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:226)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose$ui_release(SubcomposeLayout.kt:215)
at androidx.compose.ui.layout.SubcomposeLayoutState$Scope.subcompose(SubcomposeLayout.kt:466)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke-0kLqBqw(BoxWithConstraints.kt:66)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke(BoxWithConstraints.kt:64)
图书馆:
implementation("androidx.navigation:navigation-compose:2.4.0-alpha07")
implementation("com.google.accompanist:accompanist-navigation-animation:0.16.1")
当前实现:
setContent {

BoxWithConstraints {
val navController = rememberAnimatedNavController()
AnimatedNavHost(
navController = navController,
startDestination = Screen.Phone.route,
builder = {
addPhone(
navController = navController,
width = constraints.maxWidth / 2
)
...
}
)
}
}
@ExperimentalFoundationApi
@ExperimentalComposeUiApi
@ExperimentalAnimationApi
fun NavGraphBuilder.addPhone(
navController: NavController,
width: Int,
) {
composable(
route = Screen.Phone.route,
exitTransition = { _, _ ->
slideOutHorizontally(
targetOffsetX = { -width },
animationSpec = tween(
durationMillis = 500,
easing = FastOutSlowInEasing
)
) + fadeOut(animationSpec = tween(300))
},
popEnterTransition = { initial, _ ->
slideInHorizontally(
initialOffsetX = { -width },
animationSpec = tween(
durationMillis = 500,
easing = FastOutSlowInEasing
)
) + fadeIn(animationSpec = tween(300))
},
) {
PhoneMain(navController = navController)
}
}
sealed class Screen(val route: String, val arguments: List<NamedNavArgument>) {

object Phone : Screen(
route = "phone",
arguments = emptyList()
)

...
}

最佳答案

尝试更新 Accompanist0.17.0来自 changelog :

Update to depend on Navigation 2.4.0-alpha07 (#668) @ianhanniballake

关于android - 将 Compose 的导航库升级到 Alpha 7 后出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68889238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com