Ryan Simon
12/06/2023, 7:50 PMLazyColumn
to properly add padding to accommodate the software keyboard on iOS, what should I do? I tried adding imePadding
to my modifier, and it kinda works, but ends up with way more padding than needed and doesn't allow me to scroll all the way to the top.
Included a video and code to look at in thread 🧵Ryan Simon
12/06/2023, 7:53 PMRyan Simon
12/06/2023, 7:53 PMAlexander Maryanovsky
12/07/2023, 5:31 AMLocalSoftwareKeyboardController.current?.hide()
in the composition. Composition is supposed to be free of side effects. Put it in a LaunchedEffect.Ryan Simon
12/07/2023, 8:38 PMAlexander Maryanovsky
12/07/2023, 8:44 PMimePadding()
and fillMaxSize()
.
2. Don’t use a LazyColumn
for a single item (and fillMaxSize
!)? Just use Modifier.verticalScroll()
on the Column
.Alexander Maryanovsky
12/07/2023, 8:44 PMAlexander Maryanovsky
12/07/2023, 9:27 PMLazyColumn
don’t put items into it that are fillMaxHeight
.Alexander Maryanovsky
12/07/2023, 9:28 PMRyan Simon
12/07/2023, 9:29 PMLaunchedEffect(showImage) {
if (showImage) {
softwareKeyboardController?.hide()
}
}
LazyColumn(Modifier.imePadding().fillMaxSize()) {
item {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth()
) {
Ryan Simon
12/07/2023, 9:30 PMRyan Simon
12/07/2023, 9:32 PMAlexander Maryanovsky
12/07/2023, 9:32 PMRyan Simon
12/07/2023, 9:33 PMAlexander Maryanovsky
12/07/2023, 9:43 PMAlexander Maryanovsky
12/07/2023, 9:48 PMAlexander Maryanovsky
12/07/2023, 10:05 PM@Composable
fun IosApp() {
MaterialTheme {
LazyColumn(Modifier.imePadding().fillMaxSize().background(Color.Yellow)) {
items(10) {
ListItem()
}
}
}
}
@Composable
private fun ListItem() {
var text by remember { mutableStateOf("") }
TextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.fillMaxWidth().padding(vertical = 40.dp, horizontal = 20.dp)
)
}
Alexander Maryanovsky
12/08/2023, 5:46 AMRyan Simon
12/11/2023, 4:38 PM