From f5aec2abc49c96b8daf036f463e1f6c664a0fe7f Mon Sep 17 00:00:00 2001 From: Ivan Morgillo Date: Mon, 23 Dec 2024 13:23:53 +0100 Subject: [PATCH] move the thenIf modifier from ui to foundation module reference: https://github.com/JetBrains/jewel/pull/736 --- platform/jewel/foundation/api/foundation.api | 5 ++++- .../jewel/foundation/modifier/ModifierExtensions.kt | 10 ++++++++++ .../org/jetbrains/jewel/ui/util/ModifierExtensions.kt | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 platform/jewel/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/ModifierExtensions.kt diff --git a/platform/jewel/foundation/api/foundation.api b/platform/jewel/foundation/api/foundation.api index d2af70d029b21..461f11fca6277 100644 --- a/platform/jewel/foundation/api/foundation.api +++ b/platform/jewel/foundation/api/foundation.api @@ -831,6 +831,10 @@ public final class org/jetbrains/jewel/foundation/modifier/BorderKt { public static synthetic fun border-QWjY48E$default (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FJLandroidx/compose/ui/graphics/Shape;FILjava/lang/Object;)Landroidx/compose/ui/Modifier; } +public final class org/jetbrains/jewel/foundation/modifier/ModifierExtensionsKt { + public static final fun thenIf (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier; +} + public final class org/jetbrains/jewel/foundation/modifier/OnHoverModifierKt { public static final fun onHover (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier; } @@ -1019,4 +1023,3 @@ public final class org/jetbrains/jewel/foundation/util/JewelLogger$Companion { public final fun getInstance (Ljava/lang/Class;)Lorg/jetbrains/jewel/foundation/util/JewelLogger; public final fun getInstance (Ljava/lang/String;)Lorg/jetbrains/jewel/foundation/util/JewelLogger; } - diff --git a/platform/jewel/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/ModifierExtensions.kt b/platform/jewel/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/ModifierExtensions.kt new file mode 100644 index 0000000000000..b87b71be5b205 --- /dev/null +++ b/platform/jewel/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/ModifierExtensions.kt @@ -0,0 +1,10 @@ +package org.jetbrains.jewel.foundation.modifier + +import androidx.compose.ui.Modifier + +/** + * Conditionally applies the [action] to the receiver [Modifier], if [precondition] is true. Returns the receiver as-is + * otherwise. + */ +public inline fun Modifier.thenIf(precondition: Boolean, action: Modifier.() -> Modifier): Modifier = + if (precondition) action() else this diff --git a/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/ModifierExtensions.kt b/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/ModifierExtensions.kt index 78ef442214377..1ab53a57b71a5 100644 --- a/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/ModifierExtensions.kt +++ b/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/ModifierExtensions.kt @@ -6,5 +6,9 @@ import androidx.compose.ui.Modifier * Conditionally applies the [action] to the receiver [Modifier], if [precondition] is true. Returns the receiver as-is * otherwise. */ +@Deprecated( + message = "This modifier has been moved to org.jetbrains.jewel.foundation.util. Please update your imports.", + ReplaceWith("thenIf(precondition, action)", "org.jetbrains.jewel.foundation.util"), +) public inline fun Modifier.thenIf(precondition: Boolean, action: Modifier.() -> Modifier): Modifier = if (precondition) action() else this