raazza
raazza

Reputation: 129

Have LazyColumn and textfield pinned to bottom of screen. when textfield is focused, items in lazy column push it below keyboard

I have a lazy column that contains a number of Text(string = "...") and a textfield pinned to the bottom of the screen below the LazyColumn. when the textfield is focused, the keyboard shows up and it pushes the textfield above the keyboard which is expected. however, when the items in the LazyColumn r too much, the textfield goes below the keyboard instead of allowing the user to scroll the lazy column. any reason for this? I already have set android:windowSoftInputMode="adjustResize" in my manifest's activity. here's the full code:

Column(modifier = Modifier
        .fillMaxSize()
        .padding(16.dp),
       verticalArrangement = Arrangement.SpaceBetween) {
                    
    LazyColumn {                      
      items(viewModel.options) { option ->                            
        Text(option.message)
      }
    }
                

  Row(modifier = Modifier.fillMaxWidth()) {
            
   TextField(
     modifier = Modifier.weight(1f),
     value = optionsText, 
     onValueChange = {optionsText = it }, 
     singleLine = true
    )
           
   Icon(
     Icons.Filled.Send, 
     contentDescription = "", 
     modifier = Modifier.align(Alignment.CenterVertically).clickable {...}
   )
  }
}

Upvotes: 0

Views: 1455

Answers (1)

Richard Onslow Roper
Richard Onslow Roper

Reputation: 6863

Solution, WEIGHTS 🤪 !

LazyColumn(Modifier.weight(9f)) {
    items(listItems) {
        Text(it)
    }
}
Row(modifier = Modifier.fillMaxWidth().weight(1f, /*false*/)) {
    var loremText by remember { mutableStateOf("") }
    TextField(
        modifier = Modifier.weight(1f),
        value = loremText,
        onValueChange = { loremText = it },
        singleLine = true
    )
    Icon(
        Icons.Filled.Send,
        contentDescription = "",
        modifier = Modifier
            .align(Alignment.CenterVertically)
            .clickable { }
    )
}

You may remove the adjustResize from your manifest.

Upvotes: 1

Related Questions