google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

[System UI Controller] Keyboard not showing up on ModalBottomSheet #1610

Closed ayitinya closed 1 year ago

ayitinya commented 1 year ago

Description Adding implementation "com.google.accompanist:accompanist-systemuicontroller:0.31.0-alpha" to the dependencies causes the soft input keyboard to fail to open when focus is moved to a textfield in a modalbottomsheet

Steps to reproduce Using the empty compose material 3 template from idea 2023.1.1 include a modalbottomsheet with a textfield in it add implementation "com.google.accompanist:accompanist-systemuicontroller:0.31.0-alpha" to app dependencies

MainActivity.kt

                    Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
                    var openBottomSheet by rememberSaveable { mutableStateOf(false) }
                    var skipPartiallyExpanded by remember { mutableStateOf(false) }
                    val scope = rememberCoroutineScope()
                    val bottomSheetState = rememberModalBottomSheetState(
                        skipPartiallyExpanded = skipPartiallyExpanded
                    )

                    // App content
                    Column(
                        modifier = Modifier.fillMaxSize(),
                        horizontalAlignment = Alignment.CenterHorizontally,
                        verticalArrangement = Arrangement.Center
                    ) {
                        Row(
                            Modifier.toggleable(
                                value = skipPartiallyExpanded,
                                role = Role.Checkbox,
                                onValueChange = { checked -> skipPartiallyExpanded = checked }
                            )
                        ) {
                            Checkbox(checked = skipPartiallyExpanded, onCheckedChange = null)
                            Spacer(Modifier.width(16.dp))
                            Text("Skip partially expanded State")
                        }
                        Button(onClick = { openBottomSheet = !openBottomSheet }) {
                            Text(text = "Show Bottom Sheet")
                        }
                    }

                    // Sheet content
                    if (openBottomSheet) {
                        ModalBottomSheet(
                            onDismissRequest = { openBottomSheet = false },
                            sheetState = bottomSheetState,
                        ) {
                            Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
                                Button(
                                    // Note: If you provide logic outside of onDismissRequest to remove the sheet,
                                    // you must additionally handle intended state cleanup, if any.
                                    onClick = {
                                        scope.launch { bottomSheetState.hide() }.invokeOnCompletion {
                                            if (!bottomSheetState.isVisible) {
                                                openBottomSheet = false
                                            }
                                        }
                                    }
                                ) {
                                    Text("Hide Bottom Sheet")
                                }
                            }

                            var text by remember {
                                mutableStateOf("")
                            }

                            TextField(value = text, onValueChange = {text = it})
                        }
                    }
                }

dependencies

def compose_version = "1.4.3"

implementation 'androidx.core:core-ktx:1.10.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
    implementation 'androidx.activity:activity-compose:1.7.1'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.compose.material3:material3:1.1.0-rc01'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"

    implementation "com.google.accompanist:accompanist-systemuicontroller:0.31.0-alpha"

Expected behavior Keyboard should open when focus is on the textfield

Additional context Downgrading to 0.30.1 seems to fix the issue

alexvanyo commented 1 year ago

This is not directly caused by systemuicontroller, if downgrading accompanist solves the issue, then it's likely due to the underlying version of Compose also changing.

I think this might be https://issuetracker.google.com/issues/268380384? If there is still an issue on versions with the fix, then please create a new issue on the main Compose issue tracker.