From 6efebabadbd991f5630e93ef250d40b66a67a4c9 Mon Sep 17 00:00:00 2001 From: Teodor Grigor Date: Thu, 5 Oct 2023 00:51:22 +0300 Subject: [PATCH] Refactor Modifier.applyIf for Better Composability --- ui/foundation/api/foundation.api | 2 +- .../dev/teogor/ceres/ui/foundation/ModifierExtensions.kt | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ui/foundation/api/foundation.api b/ui/foundation/api/foundation.api index b8875ba1..49f9ac8d 100644 --- a/ui/foundation/api/foundation.api +++ b/ui/foundation/api/foundation.api @@ -1,5 +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 applyIf (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function1;)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 75818807..e6d0ea15 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,7 +23,6 @@ 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 @@ -138,11 +137,10 @@ fun Modifier.sideClickable( } } -@Composable -fun Modifier.applyIf(condition: Boolean, block: @Composable Modifier.() -> Modifier): Modifier { +fun Modifier.applyIf(condition: Boolean, block: Modifier.() -> Modifier): Modifier { return if (condition) { - this + this.then(block()) } else { - this.block() + this } }