chrisbanes/insetter

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

nonproto opened this issue · 5 comments

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)

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?

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)
        }

that would be super helpful

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)
}

thanks that actually worked out well