Update
I awarded already a bounty to the answer I am currently using, however, if there is a native/better way to handle this, I will award that person a bounty of 500 points.
Problem
I have been struggling with this problem for awhile, I checked a lot of similar questions, but I never got it working. What I want is pretty straightforward, considering this requirements:
- Jetpack Compose is the root view
- Views are wrapped inside a
Surface->Scaffold-> content in aBottom Bar - The keyboard is inside an
AndroidView, I don't think it matters though
Goal
So there is a TopAppBar and Bottom Bar. When the keyboard appears, it should just slide OVER the Bottom Bar and ofcourse the TopAppBar should be visible.
Result
Without doing any configuration in the Manifest file, this is the result (TopAppBar is hidden):
When using the famous adjustResize mode, the Bottom Bar will be on top of the keyboard:
I tried adjustPan as well, the TopAppBar will be hidden.
Code
A full reproduction project is available at: https://github.com/Jasperav/JetpackComposeNavigation, this is the relevant code:
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Screen() {
val items = listOf(
Triple("a", Icons.Default.Person, Icons.Filled.Person),
Triple("b", Icons.Default.Notifications, Icons.Filled.Notifications),
)
var selectedTab = items[0]
val navHostController = rememberNavController()
Scaffold(
bottomBar = {
NavigationBar {
items.forEachIndexed { index, item ->
selectedTab = item
val isSelected = index == items.indexOf(selectedTab)
NavigationBarItem(
icon = {
Icon(
if (isSelected) item.second else item.third,
contentDescription = null
)
},
label = { Text(text = item.first) },
selected = isSelected,
onClick = {
navHostController.navigate(item.first) {
popUpTo(navHostController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
}
) {
NavHost(
navHostController,
startDestination = items[0].first,
Modifier.padding(it)
) {
composable(items[0].first) {
Scaffold(topBar = {
TopAppBar(
title = {
Text(text = "Text",
)
},
)
}) {
AndroidView(modifier = Modifier.padding(it).fillMaxSize(), factory = { context ->
val constraintLayout = ConstraintLayout(context)
constraintLayout.setBackgroundColor(context.getColor(android.R.color.holo_red_dark))
val editText = EditText(context)
editText.setText("Click here")
editText.id = View.generateViewId()
constraintLayout.addView(editText)
val constraintSet = ConstraintSet()
constraintSet.clone(constraintLayout)
constraintSet.connect(editText.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
constraintSet.connect(editText.id, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START)
constraintSet.connect(editText.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END)
constraintSet.applyTo(constraintLayout)
constraintLayout
})
}
}
composable(items[1].first) {
Column {
Text("Second")
Button(onClick = {
navHostController.navigate(
"nested/" + UUID.randomUUID().toString()
)
}) {
Text(text = "Go to nested")
}
}
}
composable("nested/{id}") {
Text("nested")
}
}
}
}


