Skip to content

Instantly share code, notes, and snippets.

@andrewsafwatsamuel
Created October 17, 2019 22:02
Show Gist options
  • Save andrewsafwatsamuel/82a2abbf296c37a4667e25b924de8ad4 to your computer and use it in GitHub Desktop.
Save andrewsafwatsamuel/82a2abbf296c37a4667e25b924de8ad4 to your computer and use it in GitHub Desktop.
class HomeFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.fragment_home, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val navController = Navigation.findNavController(activity!!, R.id.home_navigation_fragment)
bottomNavigationView.onItemClicked(0){ navController.navigate(R.id.action_global_feed) }
bottomNavigationView.onItemClicked(1){ navController.navigate(R.id.action_global_orders)}
navController.addOnDestinationChangedListener { _, destination, _ ->
toolbar.title = destination.label
}
}
fun BottomNavigationView.onItemClicked(index: Int, action: (MenuItem) -> Unit) = menu[index]
.setOnMenuItemClickListener { it.isChecked = true;action(it);true }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment