Skip to content

Instantly share code, notes, and snippets.

@ibrajix
Created August 10, 2021 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibrajix/5353814e8729bbda3de7c38dbe0b250b to your computer and use it in GitHub Desktop.
Save ibrajix/5353814e8729bbda3de7c38dbe0b250b to your computer and use it in GitHub Desktop.
Main Activity Kt
class MainActivity : AppCompatActivity() {
private val binding by viewBinding(ActivityMainBinding::inflate)
lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.Theme_SnapchatClone)
super.onCreate(savedInstanceState)
transparentStatusBar()
setContentView(binding.root)
initViews()
}
private fun initViews(){
setUpBottomNavigation()
}
private fun setUpBottomNavigation(){
val navHost = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHost.navController
binding.bottomNavigation.setupWithNavController(navController)
binding.bottomNavigation.setOnItemReselectedListener {
//do something when selected twice
}
binding.bottomNavigation.setOnItemSelectedListener { item ->
NavigationUI.onNavDestinationSelected(
item,
Navigation.findNavController(this, R.id.nav_host_fragment)
)
}
binding.bottomNavigation.itemIconTintList = null
//if we are viewing stories, hide the bottom navigation
navController.addOnDestinationChangedListener { _, destination, _ ->
if(destination.id == R.id.viewStoriesFragment) {
binding.bottomNavigation.visibility = View.GONE
} else {
binding.bottomNavigation.visibility = View.VISIBLE
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment