How do I move a lazy Columns contents up with the keybaord? Compose

So I am trying to make a text messaging app as a learning project. I have the text messages uploaded from firebase and loaded into a lazy column, I also have a textfield that you use to send and type messages, I broke them down in to a few different composeables
here he where the lazy column is

Composable
fun TextSectionAndKeyBoard(
    state:LazyListState,
    messageList:List<MessageModel>,
    currentUserSenderId:String,
    match:MatchedUserModel = MatchedUserModel(),
    message:String,
    sendMessage: () -> Unit,
    sendAttachment: () -> Unit,
    messageChange: (String) -> Unit,
    feedBack:Boolean = false
){
    Column(
        Modifier.fillMaxSize()
    ) {
        LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .statusBarsPadding()
                .weight(1f)
                .imePadding(),
            state = state
        ) {
            itemsIndexed(messageList) { index, message ->
                val last = index == (messageList.size -1)
                val isCurrentUser = message.senderId.contains(currentUserSenderId.replaceFirstChar { "" })
                val time = message.currentTime
                if(feedBack){
                    MessageItemFeedBack(message = message, isCurrentUser = isCurrentUser, timeStamp = time, last)
                }else{
                    MessageItem(match = match ,message = message, isCurrentUser = isCurrentUser, timeStamp = time, last)
                }
            }
        }
    }
}

as you can see I have an item with the id keyboard, I originally had the keybaord there, and when it was there I was able to effect the lazy column when I opened the keybaord, moved all the items up when needed. but the keybaor was also the bottom item, so you didn’t see the keybaord section at all times with is not ideal

@Composable
fun MessagingBar(
    modifier: Modifier,
    message:String,
    messageChange: (String) -> Unit,
    sendMessage: () -> Unit,
    sendAttachment: () -> Unit
){
    Row(modifier = Modifier
        .background(AppTheme.colorScheme.onTertiary)
        .fillMaxWidth()
        .padding(12.dp)){
        Row (
            modifier = Modifier.fillMaxWidth(),
            //horizontalArrangement = Arrangement.SpaceEvenly
        ){
            IconButton(onClick = sendAttachment,
                modifier = Modifier
                    .offset(y = 5.dp)
                    .weight(1.0F),
                colors= IconButtonDefaults.iconButtonColors(
                    containerColor = Color.Transparent,
                    contentColor = AppTheme.colorScheme.secondary,
                ),
            ) {
                Icon(imageVector = ImageVector.vectorResource(id = R.drawable.attachment), contentDescription = "Send")
            }
            OutlinedTextField(
                modifier = Modifier
                    .fillMaxWidth()
                    .weight(7.5F),
                value = message, onValueChange = messageChange,
                textStyle = baseAppTextTheme(),
                keyboardOptions = KeyboardOptions(
                    keyboardType = KeyboardType.Text,
                    capitalization = KeyboardCapitalization.Sentences,
                    autoCorrect = true,
                ),
                maxLines = 4,

                )
            IconButton(onClick = sendMessage,
                modifier = Modifier
                    .offset(y = 5.dp)
                    .weight(1.0F),
                colors= IconButtonDefaults.iconButtonColors(
                    containerColor = Color.Transparent,
                    contentColor = AppTheme.colorScheme.secondary,
                ),
            ) {
                Icon(imageVector = ImageVector.vectorResource(id = R.drawable.send), contentDescription = "Send")
            }
        }
    }
}

this is the keybaord, simple row with buttons for sending messages and attachements and an outlined textfield

@Composable
fun MessagerScreen(navController: NavHostController, vm: ViewModel){
    val talkedUser by vmDating.selectedUser.collectAsState()
    val avail by remember {mutableStateOf(talkedUser == null)}
    if(avail && talkedUser == null){
        InsideMessages(
            nav = navController,
            titleText = "Loading",
            chatSettings = {},
            messages = {}
        )
    }else{
        val chatId = vm.getChatId(vm.getUser().number, talkedUser!!.number) //change to UID later need to account for reverses
        var message by rememberSaveable { mutableStateOf("") }
        val messageModel = viewModel { MessageViewModel(MyApp.x) }
        val messageList by messageModel.getChatData(chatId).collectAsState(listOf())
        //TODO need to make this work
        var scrollValue by remember { mutableIntStateOf(Int.MAX_VALUE) }
        val lazyListState = rememberLazyListState()
        LaunchedEffect(messageList) {
            lazyListState.scrollToItem(scrollValue) //NEED this to update when keybaord opens
        }
        InsideMessages(
            nav = navController,
            titleText = talkedUser!!.name,
            goToProfile = { navController.navigate("MatchedUserProfile") },
            chatSettings = {},
            startCall = {/* TODO Start normal Call (Need to make a screen for it)*/},
            startVideoCall = {/* TODO Start Video Call (Need to make a screen for it)*/},
            messageBar = {MessagingBar(
                modifier = Modifier.imePadding(),
                message = message,
                messageChange = { message = it },
                sendMessage = {
                    if (message != "") {
                        messageModel.storeChatData(chatId, message)
                    }
                    message = ""
                    scrollValue = messageList.size + 2
                },
                sendAttachment = {/* TODO photos or attachments Message...advise if we should keep*/ }
            )},
            messages = {
                TextSectionAndKeyBoard(
                    lazyListState = lazyListState,
                    messageList = messageList,
                    currentUserSenderId = messageModel.getCurrentUserSenderId(),
                    match = talkedUser!!,
                )
            },
        )
    }
}

this where it is held on the screen, nothing here is very important, it has the LazyListState, that updates when you send a new message, ensure that it stays at the bottom.

I need help on figuring out what do I need to do to my lazy column that it is aware of the keyboard and keeps the last item above MessagingBar() so you can read the last message properly

I do have android:windowSoftInputMode=”adjustResize” inside my manifest

EDIT: I changed the keyboard so that is the bottom bar of my scoffed so its always at the bottom.

//rest of the code[enter image description here][1]
            bottomBar = {
                messageBar()
            },
        ) {
                paddingValues ->
            Column(
                Modifier
                    .padding(paddingValues)
                    .fillMaxSize()
            ){
                messages()

            }

you can see I have no issue when I open the chat, or when I send a message, its just when I open the keyboard, if I can add to my LaunchedEffect something that reacts with the keyboard opening I should be golden
Sample of issue

1

Check out the documentation of the imePadding Modifier. It automatically applies the necessary padding to a Composable when the keyboard opens.

You can apply it to your MessagingBar Composable as follows:

MessagingBar(
    modifier = Modifier.imePadding(),
    message = message,
    messageChange = messageChange,
    sendMessage = sendMessage,
    sendAttachment = sendAttachment
)

Be sure to actually apply the passed Modifier in the MessagingBar Composable, what you currently aren’t doing:

@Composable
fun MessagingBar(
    modifier: Modifier,
    message:String,
    messageChange: (String) -> Unit,
    sendMessage: () -> Unit,
    sendAttachment: () -> Unit
){
    Row(modifier = modifier  // APPLY PASSED MODIFIER HERE
        .background(AppTheme.colorScheme.onTertiary)
        .fillMaxWidth()
        .padding(12.dp)) {
        //...
    }
}

Note that you should not set the weight Modifier on the MessagingBar, it is not needed there.

Finally, remove all the code that you used to manually set padding when the keyboard opens. It is no longer needed.


Also check out the official JetChat sample app. It provides a demo implementation of a chat app, it might help you. Especially take a look at the Conversation.kt file.


Example:

@Composable
fun ChatScreen() {
    Column(
        Modifier.fillMaxSize()
    ) {
        LazyColumn(
            modifier = Modifier.weight(1f),
            contentPadding = PaddingValues(16.dp),
            reverseLayout = true
        ) {
            items(100) {
                Text(
                    modifier = Modifier.fillMaxWidth(),
                    text = "Message $it",
                    fontSize = 20.sp
                )
            }
        }
        TextField(
            modifier = Modifier
                .fillMaxWidth()
                .imePadding(),
            value = "", 
            onValueChange = {}
        )
    }
}

Output:

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật