iex
10/03/2025, 5:23 AMScaffold
?
(and which also works with a bottom bar, and for Android / iOS)
I'm trying using e.g. the Scaffold's innerPadding
or applying imePadding()
to the containing column, but there's always some issue, like a gap appearing between input and keyboard, topbar moved out of screen..
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@Preview
fun App() {
Scaffold(
topBar = {
Column {
TopAppBar(title = { Text("topbar") })
}
},
bottomBar = { TabsBar() }
) { innerPadding ->
// Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier.padding(innerPadding)) {
// Box {
Contents()
}
}
}
@Composable
private fun Contents() {
val focusManager = LocalFocusManager.current
Box {
Column(
modifier = Modifier
// .imePadding()
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures(onTap = {
focusManager.clearFocus()
})
},
) {
Box(
modifier = Modifier
.weight(1f)
.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
Text("Main content area")
}
BasicText()
}
}
}
@Composable
private fun BasicText() {
var textState by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue("..."))
}
BasicTextField(
value = textState,
onValueChange = { textState = it },
modifier = Modifier
.height(60.dp)
.fillMaxWidth()
.background(Color.Yellow),
)
}
@Composable
fun TabsBar() {
NavigationBar(
modifier = Modifier.height(100.dp),
containerColor = Color.Green,
) { }
}
Here's also a minimal project with this code: https://github.com/ivnsch/textfieldpadding/tree/6717e4d247970316bcc36d52427de408514cff83Jack Boswell
10/03/2025, 7:08 AMiex
10/03/2025, 8:58 AMweight(1f)
box (replacing Text("Main content area")
). The scrolling there works fine and seems unrelated to the topbar.Jack Boswell
10/03/2025, 8:58 AMiex
10/03/2025, 9:00 AMJack Boswell
10/03/2025, 9:01 AMiex
10/03/2025, 9:04 AMBox(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
.imePadding(),
contentAlignment = Alignment.Center
) {
Text("Main content area")
}
Jack Boswell
10/03/2025, 9:06 AMiex
10/03/2025, 9:11 AMimePadding
to the text field or a new box containing the text field, the text field effectively disappears when opening the keyboard (and the top bar is still pushed out)iex
10/03/2025, 9:11 AMBox(
modifier = Modifier
.height(60.dp)
.fillMaxWidth()
.imePadding()
.background(Color.Yellow),
) {
BasicTextField(
value = textState,
onValueChange = { textState = it },
modifier = Modifier
// .height(60.dp)
.fillMaxSize()
)
}
Jack Boswell
10/03/2025, 9:13 AMiex
10/03/2025, 9:20 AMprivate fun Contents() {
val focusManager = LocalFocusManager.current
Box(
modifier = Modifier
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures(onTap = {
focusManager.clearFocus()
})
}
) {
Box(
modifier = Modifier
.fillMaxSize().imePadding(),
contentAlignment = Alignment.Center
) {
Text("Main content area")
}
BasicText(
modifier = Modifier
.align(Alignment.BottomCenter)
// .imePadding()
)
}
}
@Composable
private fun BasicText(modifier: Modifier) {
var textState by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue("..."))
}
BasicTextField(
value = textState,
onValueChange = { textState = it },
modifier = modifier
.height(60.dp)
.fillMaxWidth()
.background(Color.Yellow),
)
}
that still pushes the top bar out (with or without imePadding on the box)Jack Boswell
10/03/2025, 9:22 AMwindowSoftInputMode
set to?Jack Boswell
10/03/2025, 9:27 AMadjustResize
)iex
10/03/2025, 11:59 AMwindowSoftInputMode
to adjustResize
in the manifest and still looks the same (top bar pushed out)iex
10/03/2025, 12:29 PM...
bottomBar = { TabsBar() },
@Composable
fun TabsBar() {
NavigationBar(
modifier = Modifier.height(100.dp),
containerColor = Color.Green,
) { }
}