Hello guys, do you know how to migrate step by ste...
# compose
j
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
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
I already follow this documentation and I am blocked after it. Yeah, I think I will convert all my fragment to compose. Thanks!
l
Sorry, I didn't find a better way to salvage already written fragment code but don't regret writing new compose code
j
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 🙂