Implement Compose Bottom Navigation using Fragments

I followed the compose documentation to create a bottom navigation bar by creating such a sealed class

sealed class Screen(val route: String, val label: String, val icon: ImageVector) {
    object ScreenA: Screen("screenA", "ScreenA", Icons.Default.AccountBox)
    object ScreenB: Screen("screenB", "ScreenB", Icons.Default.ThumbUp
}

with something such as the following screen, simply containing a Text item.

@Composable
fun ScreenA() {
    Text(text = "This is ScreenA",
        style = TextStyle(color = Color.Black, fontSize = 36.sp),
        textAlign = TextAlign.Center)
}

and have also implemented the Scaffold, BottomNavigation, and NavHost exactly like in the docs and everything is working just fine.

Let´s say I now want to have one of the screens with a whole bunch of data displayed in a list with all sorts of business logic methods which would need a Fragment, ViewModel, Repository, and so on.
What would be the correct approach be? Can I still create the fragments and somehow pass them to the sealed class or should we forget about fragments and make everything composable?

Source: Android Questions

LEAVE A COMMENT