https://kotlinlang.org logo
#compose
Title
# compose
j

joadar

11/24/2021, 1:21 PM
Hello guys, do you know how to migrate step by step a BottomNavigationView to Compose? I can’t find any articles about this topic. So far I can’t reuse the fragments from my BottomNavigation because of the new navigation system form Compose. Maybe I am doing it wrongly?
l

Laurence Muller

11/24/2021, 2:04 PM
https://developer.android.com/jetpack/compose/navigation#bottom-nav does this help? Although I initially had the same issue I let go of using fragments and replaced those screens with compose equivalent replacements
j

joadar

11/24/2021, 2:08 PM
I already follow this documentation and I am blocked after it. Yeah, I think I will convert all my fragment to compose. Thanks!
l

Laurence Muller

11/24/2021, 2:09 PM
Sorry, I didn't find a better way to salvage already written fragment code but don't regret writing new compose code
j

joadar

11/24/2021, 2:13 PM
Oh I don’t. Just I can’t find the way to do a lot of stuff (normal, I am learning something new with Compose) such as managing click/tracking/authentication as I have just one Activity now.
I answer to myself: we can implement step by step by adding Compose in fragment:
Copy code
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return ComposeView(requireContext()).apply {
            setViewCompositionStrategy(
                ViewCompositionStrategy.DisposeOnLifecycleDestroyed(viewLifecycleOwner)
            )

            setContent {
                BloomingTheme {
                    MenuScreen(viewModel = viewModel, onItemClicked = {
                        onItemClick(it)
                    })
                }
            }
        }
    }
It’s better than doing everything from scratch 🙂
2 Views