From 487f919882e6ff7778eede8f43b071023c031ccf Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Sun, 14 Mar 2021 14:22:22 +0000 Subject: [PATCH] Make coerceEachDimensionAtLeast() public API --- insets/api/insets.api | 1 + .../com/google/accompanist/insets/Insets.kt | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/insets/api/insets.api b/insets/api/insets.api index 75ae1dab1..39b79d26c 100644 --- a/insets/api/insets.api +++ b/insets/api/insets.api @@ -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; diff --git a/insets/src/main/java/com/google/accompanist/insets/Insets.kt b/insets/src/main/java/com/google/accompanist/insets/Insets.kt index 1c1e0bfda..b89e000e7 100644 --- a/insets/src/main/java/com/google/accompanist/insets/Insets.kt +++ b/insets/src/main/java/com/google/accompanist/insets/Insets.kt @@ -503,16 +503,26 @@ 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), ) }