From 18239fb10ed8aac324cb984c444a5a4884f3f59a Mon Sep 17 00:00:00 2001 From: Teodor Grigor Date: Thu, 5 Oct 2023 00:23:30 +0300 Subject: [PATCH] Enhance Compose Modifier with Conditional Application --- ui/foundation/api/foundation.api | 1 + .../teogor/ceres/ui/foundation/ModifierExtensions.kt | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/ui/foundation/api/foundation.api b/ui/foundation/api/foundation.api index d445bd68..b8875ba1 100644 --- a/ui/foundation/api/foundation.api +++ b/ui/foundation/api/foundation.api @@ -1,4 +1,5 @@ public final class dev/teogor/ceres/ui/foundation/ModifierExtensionsKt { + public static final fun applyIf (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/Modifier; public static final fun clickable-GK2WfCU (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/foundation/Indication;ZLjava/lang/String;Landroidx/compose/ui/semantics/Role;ILkotlin/jvm/functions/Function0;)Landroidx/compose/ui/Modifier; public static synthetic fun clickable-GK2WfCU$default (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/foundation/Indication;ZLjava/lang/String;Landroidx/compose/ui/semantics/Role;ILkotlin/jvm/functions/Function0;ILjava/lang/Object;)Landroidx/compose/ui/Modifier; public static final fun clickable-oSLSa3U (Landroidx/compose/ui/Modifier;ZLjava/lang/String;Landroidx/compose/ui/semantics/Role;ILkotlin/jvm/functions/Function0;)Landroidx/compose/ui/Modifier; diff --git a/ui/foundation/src/main/kotlin/dev/teogor/ceres/ui/foundation/ModifierExtensions.kt b/ui/foundation/src/main/kotlin/dev/teogor/ceres/ui/foundation/ModifierExtensions.kt index 96968afc..75818807 100644 --- a/ui/foundation/src/main/kotlin/dev/teogor/ceres/ui/foundation/ModifierExtensions.kt +++ b/ui/foundation/src/main/kotlin/dev/teogor/ceres/ui/foundation/ModifierExtensions.kt @@ -23,6 +23,7 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.material.ripple.rememberRipple +import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.composed @@ -136,3 +137,12 @@ fun Modifier.sideClickable( } } } + +@Composable +fun Modifier.applyIf(condition: Boolean, block: @Composable Modifier.() -> Modifier): Modifier { + return if (condition) { + this + } else { + this.block() + } +}