Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bottomnav blinks for a second when keyboard is closed again. #65

Open
Berki2021 opened this issue Feb 5, 2021 · 0 comments
Open

Bottomnav blinks for a second when keyboard is closed again. #65

Berki2021 opened this issue Feb 5, 2021 · 0 comments

Comments

@Berki2021
Copy link

  1. your Activity's windowSoftInputMode: Adjustresize

  2. Android version: 10

  3. Android device: Pixel 3 XL API 29

  4. and other stuff you think might be helpful:

The problem I encounter is, that I am trying to hide my bottom navigation bar, but it does not work 100%. When I click on an edittext, the bottomnav is hidden and everything is fine. But when I close the keyboard, the bottom nav blinks for a second above the keyboard and this looks hideous

What am I doing wrong here?

Code:

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        hideBottomNavWhenKeyboardClicked()
    }
fun Fragment.hideBottomNavWhenKeyboardClicked() {
    KeyboardVisibilityEvent.setEventListener(
        requireActivity(),
        viewLifecycleOwner,
        object : KeyboardVisibilityEventListener {
            override fun onVisibilityChanged(isOpen: Boolean) {
                if (isOpen) hideBottomNav() else showBottomNav()
            }
        }
    )
}
fun Fragment.hideBottomNav() {
    if ((requireActivity() as MainActivity).isBottomNavVisible()) (requireActivity() as MainActivity).hideBottomNav()
}

fun Fragment.showBottomNav() {
    if (!(requireActivity() as MainActivity).isBottomNavVisible()) (requireActivity() as MainActivity).showBottomNav()
}
    fun isBottomNavVisible(): Boolean {
        return binding.bottomNavigationView.visibility == View.VISIBLE
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant