chrisbanes / insetter

Insetter is a library to help apps handle WindowInsets more easily
https://chrisbanes.github.io/insetter
Apache License 2.0
1.13k stars 42 forks source link

Request: Inset builder to have option to return the actual size #99

Closed nonproto closed 3 years ago

nonproto commented 3 years ago

I am using https://github.com/cashapp/contour in a project and it would be nice to have something like

val actualStatusBarsSize  = Insetter.builder().valueTop(statusBars =true).build().value

There are probably other uses cases outside of using contour where this could be helpful like

val navBarSize  = Insetter.builder().valueTop(navigationBars =true).build().value
view1.updatePadding(0,navBarSize,0,0)
view2.updatePadding(0,navBarSize,0,0)
chrisbanes commented 3 years ago

Hmmm, the API you outlined wouldn't really work, as insets are by definition asynchronous. I can imagine returning a Flow<Insets> which you'd then collect. Would that work?

chrisbanes commented 3 years ago

An example usage would be:

Insetter.builder()
        .valueTop(windowInsetTypesOf(navigationBars = true)
        .build()
        .collect { insets ->
            view1.updatePadding(0, insets.top, 0, 0)
            view2.updatePadding(0, insets.top, 0, 0)
        }
nonproto commented 3 years ago

that would be super helpful

chrisbanes commented 3 years ago

Although, at that point you wouldn't need Insetter at all. You could just do:

ViewCompat.setOnApplyWindowInsetsListener(rootView) { v, insets ->
    val i = insets.getInsets(windowInsetTypesOf(navigationBars = true))
    view1.updatePadding(0, i.top, 0, 0)
    view2.updatePadding(0, i.top, 0, 0)
}
nonproto commented 3 years ago

thanks that actually worked out well