Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from mercuriy94/applyInsetExtenssions
Browse files Browse the repository at this point in the history
Added extensions for padding and margins
  • Loading branch information
chrisbanes authored Apr 27, 2020
2 parents 941b7a5 + e87d3f8 commit f058d7c
Showing 1 changed file with 118 additions and 1 deletion.
119 changes: 118 additions & 1 deletion ktx/src/main/java/dev/chrisbanes/insetter/viewinsetter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,121 @@ fun View.requestApplyInsetsWhenAttached() {
* @see Insetter.setEdgeToEdgeSystemUiFlags
*/
@RequiresApi(16)
fun View.setEdgeToEdgeSystemUiFlags(enabled: Boolean = true) = Insetter.setEdgeToEdgeSystemUiFlags(this, enabled)
fun View.setEdgeToEdgeSystemUiFlags(enabled: Boolean = true) =
Insetter.setEdgeToEdgeSystemUiFlags(this, enabled)

/**
* Apply system window insets to padding
*
* @param left apply left indent if true
* @param top apply in upper indent if true
* @param right apply in the right indent if true
* @param bottom apply in the bottom indent if true
* */
fun View.applySystemWindowInsetsToPadding(
left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false
) {

doOnApplyWindowInsets { view, insets, initialViewState ->
Insetter.applyInsetsToView(
view,
insets,
initialViewState,
Insetter.generateEnumSet(left, top, right, bottom),
null,
null,
null
)

}
}

/**
* Apply system window insets to margin
*
* @param left apply left indent if true
* @param top apply in upper indent if true
* @param right apply in the right indent if true
* @param bottom apply in the bottom indent if true
* */
fun View.applySystemWindowInsetsToMargin(
left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false
) {

doOnApplyWindowInsets { view, insets, initialViewState ->
Insetter.applyInsetsToView(
view,
insets,
initialViewState,
null,
Insetter.generateEnumSet(left, top, right, bottom),
null,
null
)

}
}

/**
* Apply system gesture insets to padding
*
* @param left apply left indent if true
* @param top apply in upper indent if true
* @param right apply in the right indent if true
* @param bottom apply in the bottom indent if true
* */
fun View.applySystemGestureInsetsToPadding(
left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false
) {

doOnApplyWindowInsets { view, insets, initialViewState ->
Insetter.applyInsetsToView(
view,
insets,
initialViewState,
null,
null,
Insetter.generateEnumSet(left, top, right, bottom),
null
)

}
}

/**
* Apply system gesture insets to margin
*
* @param left apply left indent if true
* @param top apply in upper indent if true
* @param right apply in the right indent if true
* @param bottom apply in the bottom indent if true
* */
fun View.applySystemGestureInsetsToMargin(
left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false
) {

doOnApplyWindowInsets { view, insets, initialViewState ->
Insetter.applyInsetsToView(
view,
insets,
initialViewState,
null,
null,
null,
Insetter.generateEnumSet(left, top, right, bottom)
)

}
}

0 comments on commit f058d7c

Please sign in to comment.