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

Added extensions for padding and margins #51

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
)

}
}