App crashes on putting more than 28 'composable' element inside AnimatedNavHost (Jetpack Compose)

412 Views Asked by At

My app is a single activity app with different screens represented by composables. I am using navigation component to handle screen navigation.

My navigation component has AnimatedNavHost as:

AnimatedNavHost(
            navController = navController,
            startDestination = Constants.SPLASH,
            enterTransition = { initial, _ ->
                slideInHorizontally(initialOffsetX = { 1000 })

            },
            exitTransition = { _, target ->
                slideOutHorizontally(targetOffsetX = { -1000 })

            },
            popEnterTransition = { initial, _ ->

                slideInHorizontally(initialOffsetX = { -1000 })

            },

            popExitTransition = { _, target ->

                slideOutHorizontally(targetOffsetX = { 1000 })

            }

        ) {
            composable(Constants.SPLASH) {
                Splash(navController = navController)


            }
            composable(Constants.HIW) {

                LogoPage(
                    false,
                    true,
                    navController = navController
                ) { HowItWorks(navController = navController, false) }

.
.
.

//Other 26 'composable' elements
}

When I add even 1 more 'composable' element, my app crashes, and the logcat says:

 java.lang.ArrayIndexOutOfBoundsException: length=29; index=29
        at androidx.collection.SparseArrayCompat.valueAt(SparseArrayCompat.java:379)
        at androidx.navigation.NavController.setGraph(NavController.kt:948)
        at androidx.navigation.NavController.setGraph(NavController.kt:95)
        at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:146)
        at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:85)

How do I solve this?

Been trying a lot of things, but not able to solve. Also, there doesn't seem to be any online information regarding this.

Please help!

1

There are 1 best solutions below

5
On

It is reported in this issue.

RelNote: "There will no longer be an ArrayIndexOutOfBoundsException when calling setGraph with a graph with 13 or 29 destinations."

It should be fixed with Navigation 2.4.0-alpha08