Created
August 10, 2021 11:05
-
-
Save ibrajix/5353814e8729bbda3de7c38dbe0b250b to your computer and use it in GitHub Desktop.
Main Activity Kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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