Skip to content

Commit

Permalink
Refactor Modifier.applyIf for Better Composability
Browse files Browse the repository at this point in the history
  • Loading branch information
teogor committed Oct 4, 2023
1 parent 2a24d51 commit 6efebab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ui/foundation/api/foundation.api
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

0 comments on commit 6efebab

Please sign in to comment.