accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

Wrong behavior with bottomSheet Composable and keyboard in AnimatedNavHost

Open bunjix opened this issue 2 years ago • 8 comments

Describe the bug

When using Navigation Material to display bottomSheet composable, I have an issue where the bottom sheet is not expanded when the content is too big and the keyboard opened.

To Reproduce

I've attached two video. The first one display a box in 16:9 ratio on top, and the content and when opening the keyboard it's ok. On the second video the ratio is now 4:3, resulting a bottom sheet too high. The bottomsheet is not appearing on top of the keyboard. That's my issue.

Expected behavior

The expected behavior in my cas is that the bottom sheet appear on top of the keyboard.

Screenshots?

https://user-images.githubusercontent.com/758587/138258691-76c001f3-0bfb-4afc-969f-1e9bb36dc434.mp4

https://user-images.githubusercontent.com/758587/138258379-b163487a-5726-4161-8c31-1b49b196b6e9.mov

Environment:

  • Android OS version: Android 12
  • Device: Pixel5
  • Accompanist version: 0.20.0

Additional context

The code for this sample:

object Destinations {
    const val home = "home"
    const val sheetInput = "sheetInput"

    object SheetResult {
        private const val root = "sheetResult"
        const val input = "input"
        const val route = "$root/{$input}"
        fun route(value: String) = "$root/$value"
    }
}

class MainActivity : ComponentActivity() {
    @OptIn(
        ExperimentalMaterialNavigationApi::class,
        ExperimentalAnimationApi::class,
        ExperimentalComposeUiApi::class
    )
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, false)
        setContent {
            NavigationBottomSheetInputTheme {
                ProvideWindowInsets {
                    val bottomSheetNavigator = rememberBottomSheetNavigator()
                    val navController = rememberAnimatedNavController()
                    navController.navigatorProvider += bottomSheetNavigator
                    ModalBottomSheetLayout(
                        bottomSheetNavigator,
                        modifier = Modifier.fillMaxSize(),
                    ) {
                        AnimatedNavHost(navController, Destinations.home,
                            enterTransition = { _, _ -> fadeIn(animationSpec = tween(300)) },
                            exitTransition = { _, _ -> fadeOut(animationSpec = tween(300)) }
                        ) {
                            composable(route = Destinations.home) {
                                Home(onclick = { navController.navigate(Destinations.sheetInput) })
                            }
                            addBottomSheet(navController)
                            composable(
                                route = Destinations.SheetResult.route,
                                arguments = listOf(
                                    navArgument(Destinations.SheetResult.input) { type = NavType.StringType },
                                )
                            ) { backStackEntry ->
                                val arguments = requireNotNull(backStackEntry.arguments)
                                Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
                                    Text(text = arguments.getString(Destinations.SheetResult.input, ""))
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @OptIn(ExperimentalMaterialNavigationApi::class, androidx.compose.ui.ExperimentalComposeUiApi::class)
    private fun NavGraphBuilder.addBottomSheet(navController: NavController) {
        bottomSheet(route = Destinations.sheetInput) {
            var input by remember { mutableStateOf("") }
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .navigationBarsWithImePadding()
                    .padding(20.dp),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.spacedBy(20.dp)
            ) {
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .aspectRatio(FailingRatio)
                        .background(Color.Blue)
                )
                OutlinedTextField(value = input, onValueChange = { text -> input = text })
                Button(onClick = {
                    navController.navigate(Destinations.SheetResult.route(input))
                }) {
                    Text("Continue")
                }
            }
        }
    }

    @Preview
    @Composable
    private fun Home(onclick: () -> Unit = {}) {
        Box(
            modifier = Modifier
                .fillMaxSize()
                .navigationBarsPadding(), contentAlignment = Alignment.Center
        ) {
            Button(onClick = onclick) {
                Text(text = "Sign-In")
            }
        }
    }
}

const val SuccessRatio = 16f/9f
const val FailingRatio = 4f/3f

bunjix avatar Oct 21 '21 10:10 bunjix

Thanks for the report! We will look into this in the next week but a fix might be delayed due to an upcoming refactoring. I'll keep this issue up-to-date :)

jossiwolf avatar Nov 04 '21 15:11 jossiwolf

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Dec 05 '21 03:12 github-actions[bot]

@jossiwolf did not tried the last update but do you know if this issue might be fixed?

bunjix avatar Dec 05 '21 06:12 bunjix

@bunjix I will run some tests again but still preparing the big refactoring; we haven't changed anything meanwhile so I don't expect it to be fixed. Sorry for the delay!

jossiwolf avatar Dec 06 '21 08:12 jossiwolf

@bunjix To clarify - does this only happen with AnimatedNavHost or with a regular NavHost as well? If it happens with a regular NavHost too, can you post the repro for that, please? :)

jossiwolf avatar Dec 15 '21 11:12 jossiwolf

@jossiwolf Just tried with a regular NavHost. Same result. Same repro for that issue. If you take my sample code and just change to use the NavHost and update import you will have exact same result.

bunjix avatar Dec 17 '21 08:12 bunjix

Hi @jossiwolf any idea? If I can help with more detail, let me know.

bunjix avatar Jan 14 '22 10:01 bunjix

Waiting on upstream work in Swipeable.

jossiwolf avatar Sep 23 '22 16:09 jossiwolf

v0.28.1 addresses this issue. Please let us know if you can still reproduce it with this version.

jossiwolf avatar Jan 12 '23 07:01 jossiwolf

It seems only v0.28.0 is released, then its all alpha with 0.29 for compose 1.4. Any way to get this sooner?

joakimtall avatar Mar 22 '23 18:03 joakimtall

v.0.29.1-alpha and subsequent versions address this.

jossiwolf avatar Mar 23 '23 11:03 jossiwolf

we are still facing the same issue in compose 1.5.3

ahmed2146 avatar Oct 23 '23 14:10 ahmed2146

@jossiwolf Hey, is there any updates about this issue? Still reproduces with bottom sheet and lazyColumn inside

dwane13 avatar Dec 13 '23 09:12 dwane13