Skip to content

Commit

Permalink
Make coerceEachDimensionAtLeast() public API
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Mar 14, 2021
1 parent a9fb90c commit 3160111
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions insets/api/insets.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public final class com/google/accompanist/insets/ComposeInsets {
public static final fun ProvideWindowInsets (ZLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
public static final fun ProvideWindowInsets (ZZLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
public static final fun coerceEachDimensionAtLeast (Lcom/google/accompanist/insets/Insets;Lcom/google/accompanist/insets/Insets;)Lcom/google/accompanist/insets/Insets;
public static final fun getLocalWindowInsets ()Landroidx/compose/runtime/ProvidableCompositionLocal;
public static final fun imePadding (Landroidx/compose/ui/Modifier;)Landroidx/compose/ui/Modifier;
public static final fun navigationBarsHeight-3ABfNKs (Landroidx/compose/ui/Modifier;F)Landroidx/compose/ui/Modifier;
Expand Down
23 changes: 16 additions & 7 deletions insets/src/main/java/com/google/accompanist/insets/Insets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,25 @@ private fun Insets.updateFrom(windowInsets: WindowInsetsCompat, type: Int) {
isVisible = windowInsets.isVisible(type)
}

internal fun Insets.coerceEachDimensionAtLeast(other: Insets): Insets {
// Fast path, no need to copy if `this` >= `other`
if (left >= other.left && top >= other.top && right >= other.right && bottom >= other.bottom) {
/**
* Ensures that each dimension is not less than corresponding dimension in the
* specified [minimumValue].
*
* @return this if every dimension is greater than or equal to the corresponding
* dimension value in [minimumValue], otherwise a copy of this with each dimension coerced with the
* corresponding dimension value in [minimumValue].
*/
fun Insets.coerceEachDimensionAtLeast(minimumValue: Insets): Insets {
// Fast path, no need to copy if: this >= minimumValue
if (left >= minimumValue.left && top >= minimumValue.top &&
right >= minimumValue.right && bottom >= minimumValue.bottom) {
return this
}
return copy(
left = left.coerceAtLeast(other.left),
top = top.coerceAtLeast(other.top),
right = right.coerceAtLeast(other.right),
bottom = bottom.coerceAtLeast(other.bottom),
left = left.coerceAtLeast(minimumValue.left),
top = top.coerceAtLeast(minimumValue.top),
right = right.coerceAtLeast(minimumValue.right),
bottom = bottom.coerceAtLeast(minimumValue.bottom),
)
}

Expand Down

0 comments on commit 3160111

Please sign in to comment.