Hi, I am trying to handle the keyboard when the Mo...
# compose
t
Hi, I am trying to handle the keyboard when the ModalSheet is open. I have already added the property
android:windowSoftInputMode="adjustResize"
in my manifest, set
DecorFitsSystemWindows(window, false)
in my activity's
onCreate
, and finally assigned
windowInsets = WindowInsets.ime
in my modal. Despite this configuration, my keyboard still overlaps my input. I need help. Can someone assist me?
Copy code
<activity
    android:name=".MainActivity"
    android:exported="true"
    android:windowSoftInputMode="adjustNothing"
Copy code
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setDecorFitsSystemWindows(window, false)
Copy code
ModalBottomSheet(
    sheetState = sheetState,
    windowInsets = WindowInsets.ime
)
n
Is your model content scrollable?
t
@nuhkoca Yes, the content is scrollable. I enabled the
verticalScroll
in my box.
Copy code
ModalBottomSheet(
    onDismissRequest = { onEvent(OnMainIntent.OnCreateListBottomSheetStateChange) },
    sheetState = sheetState,
    windowInsets = WindowInsets.ime
) {
    Box(
        modifier = Modifier
            .fillMaxSize()
            .verticalScroll(state = rememberScrollState())
            .padding(
                bottom = 40.dp,
                end = 16.dp,
                start = 16.dp
            )
    ) {
        IconButton(modifier = Modifier
            .align(Alignment.TopEnd)
            .offset(x = (-10).dp, y = (-46).dp),
            onClick = {
                scope.launch { sheetState.hide() }.invokeOnCompletion {
                    if (!sheetState.isVisible) {
                        onEvent(OnCreateListBottomSheetStateChange)
                    }
                }
            }) {
            Icon(Icons.Filled.Clear, "Floating action button.")
        }

        Column(
            verticalArrangement = Arrangement.spacedBy(14.dp),
        ) {

            Form(
                formsName = "Titulo",
                label = "ex: Aniversario",
                maxLine = 1,
                value = uiState.title,
                onValueChange = {
                    onEvent(OnTitleChange(it))
                },
            )
            Form(
                formsName = stringResource(R.string.description_create_list_modal_sheet),
                label = "ex: Teremos cerca de 120 convidados, entre adultos e criancas",
                maxLine = 1,
                value = uiState.description,
                onValueChange = {
                    onEvent(OnDescriptionChange(it))
                },
            )

            Button(
                modifier = Modifier.fillMaxWidth(),
                onClick = {
                    onEvent(
                        OnCreateList(
                            MyListDto(
                                title = uiState.title,
                                description = uiState.description
                            )
                        )
                    )
                    onEvent(OnInitUi)
                    onEvent(OnCreateListBottomSheetStateChange)
                }
            ) {
                Text("Criar lista")
            }
        }
    }
}
n
I don’t think
Box
with a
verticalScroll
enabled would ever work. Try replacing
Box
to
Column
or wrap your content in a
Column
with
verticalScroll
enabled instead
t
Even changing the Box to a Column, this problem persists.