Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Insets] Missing WindowInsets.navigationBarsWithIme #239

Closed
gustavkarlsson opened this issue Mar 13, 2021 · 3 comments · Fixed by #240
Closed

[Insets] Missing WindowInsets.navigationBarsWithIme #239

gustavkarlsson opened this issue Mar 13, 2021 · 3 comments · Fixed by #240

Comments

@gustavkarlsson
Copy link

Modifier.navigationBarsWithImePadding() is extremely helpful, but there does not appear to exist any equivalent for WindowInsets.

To get correct content padding for my LazyColumn I had to do this to work around it:

    val imeInsets = LocalWindowInsets.current.ime
    val navigationBarsInsets = LocalWindowInsets.current.navigationBars
    val insets = if (imeInsets.isVisible) {
        imeInsets
    } else navigationBarsInsets
    LazyColumn(contentPadding = insets.toPaddingValues()) {
        // Content
    }

Or, for a reusable version:

val WindowInsets.navigationBarsWithIme: Insets
    get() = if (ime.isVisible) ime else navigationBars
@chrisbanes
Copy link
Contributor

chrisbanes commented Mar 14, 2021

If you look at how navigationBarsWithImePadding() works, it's actually just:

val navigationBarsWithIme = LocalWindowInsets.current.let { 
    it.ime.coerceEachDimensionAtLeast(it.navigationBars)
}

coerceEachDimensionAtLeast() is currently an internal function, but we could make it public.

@gustavkarlsson
Copy link
Author

That would make it easier, yeah. I just thought since navigationBarsWithImePadding exists as a modifier, adding an equivalent on LocalWindowInsets.current would make it consistent, but I might be misunderstanding things here :)

Adding own extension property is easy enough.

@chrisbanes
Copy link
Contributor

The modifiers are different as it's difficult to compose custom logic in them (although still possible). They are also designed to cover common use-cases.

Reading LocalWindowInsets is definitely in the 'doing it manually' territory so I think the linked PR is fine. Similarly, I don't want to start creating combinations of insets in WindowInsets as it will lead to a combinational explosion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants