https://kotlinlang.org logo
Title
c

Cicero

06/25/2021, 4:55 PM
Hey people, I’ve experienced a recent behavior while using interoperability where in my MainActivity this other dev set up a bottom navigation and I’ve been nesting compose navigations from it. The behavior is the be bottom navigation bar is bumped up with the keyboard. Is this an interoperability glitch? If you suggest it could be a glitch I would be happy to write a repo with the issue.
class MainActivity : AppCompatActivity() {

    lateinit var bottomNavView: BottomNavigationView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // later probably in Application class
        setContentView(R.layout.activity_main)
        setupBottomNavigation()
    }

    private fun setupBottomNavigation() {
        val navController = findNavController(R.id.fragment_navigation_host)
        val navGraph = navController.navInflater.inflate(R.navigation.bottom_navigation_graph)
        bottomNavView = findViewById(R.id.bottom_navigation_view)
        bottomNavView.setupWithNavController(navController)
        // Pass the IDs of top-level destinations to AppBarConfiguration to hide back button in the main screens
        val appBarConfiguration = AppBarConfiguration(
            topLevelDestinationIds = setOf(
                R.id.fragment1,
                R.id.fragment2,
                R.id.fragment3,
                R.id.fragment4
            )
        )
        navController.addOnDestinationChangedListener { _, destination, _ ->
            var showNavigationElements = true
            var screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
            when (destination.id) {
                R.id.fragment6 -> {
                    showNavigationElements = false
                }
                R.id.fragment2 -> {
                    if (navGraph.startDestination != R.id.fragment2) {
                        navGraph.startDestination = R.id.fragment2
                        navController.graph = navGraph
                    }
                }
                R.id.fragment5 -> {
                    showNavigationElements = false
                    screenOrientation = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
                }
            }
            showNavigationUiElements(showNavigationElements)
            requestedOrientation = screenOrientation
        }
    }

    private fun showNavigationUiElements(shouldShow: Boolean) {
        if (shouldShow) {
            bottomNavView.visibility = View.VISIBLE
            supportActionBar?.show()
        } else {
            bottomNavView.visibility = View.GONE
            supportActionBar?.hide()
        }
    }
}
This first is my main activity with the bottom navigation configuration and the following is what I would call from one of the fragment destinations
class Fragment12 : BaseFragment() {
    private val args: ModuleOverviewFragmentArgs by navArgs()
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {

        (requireActivity() as AppCompatActivity).supportActionBar?.hide()
        return ComposeView(requireContext()).apply {
            setContent {
                12Navigation(
                    externalNavigation = findNavController(),
                )
            }
        }
    }
}

@Composable
fun 12Navigation(
    externalNavigation: NavController
) {
    val navHostController = NavigationHostController()

    AppTheme {
        NavHost(
            navController = navHostController,
            startDestination = "startingDest"
        ) {
            composable("startingDest") {
                12Introduction(externalNavigation)
            }
        }
    }
}
i

Ian Lake

06/25/2021, 5:36 PM
The bottom navigation bar height has nothing to do with your app, that's how IMEs work (you can't have the collapse arrow to close the IME in the navigation bar if the navigation bar is too small)
c

Cicero

06/25/2021, 5:42 PM
My confusion is why the bottom navigation bar is being bumped up with the keyboard. I would expect that only Scaffolds bottombar would be bumped.
In this picture I understand the pink region being bumped as it is inside of Scaffold bottom bar But the green region is the bottom “tab” navigation Is this really related to IME? I thought that I could resolve this just refactoring the whole implementation into compose navigation. Seems I guessed wrong
i

Ian Lake

06/25/2021, 6:30 PM
Ah, I thought you were talking about the system navigation bar, my mistake
👌🏽 1
c

Cicero

06/26/2021, 10:05 AM
I need to investigate why this is happening and I was fishing to see if anyone had any experience with interoperability 🙂 But it seems I’m going to need to implement something similar.