Skip to content

Commit

Permalink
fix: conditional modifiers not working as expected (#1439)
Browse files Browse the repository at this point in the history
Co-authored-by: Francois ADAM <francois.adam@adevinta.com>
Co-authored-by: spark-ui-bot <spark-ui-bot@users.noreply.github.com>

(cherry picked from commit 217bccd)
Signed-off-by: Scott Rayapoullé <scott.rayapoulle@adevinta.com>
  • Loading branch information
3 people authored and soulcramer committed Jan 29, 2025
1 parent 98705f2 commit 80b1649
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import androidx.compose.ui.Modifier
* @param builder the modifier(s) to apply when [predicate] is true
*/
public inline fun Modifier.ifTrue(predicate: Boolean, builder: Modifier.() -> Modifier): Modifier =
then(if (predicate) this.builder() else Modifier)
then(if (predicate) this.builder() else this)

/**
* Modifier to make it easy to conditionally add a modifier based on [predicate]
Expand All @@ -51,7 +51,7 @@ public inline fun Modifier.ifTrue(predicate: Boolean, builder: Modifier.() -> Mo
* @param builder the modifier(s) to apply when [predicate] is false
*/
public inline fun Modifier.ifFalse(predicate: Boolean, builder: Modifier.() -> Modifier): Modifier =
then(if (!predicate) this.builder() else Modifier)
then(if (!predicate) this.builder() else this)

/**
* Modifier to make it easy to conditionally add a modifier based on [value] nullability
Expand All @@ -66,7 +66,7 @@ public inline fun Modifier.ifFalse(predicate: Boolean, builder: Modifier.() -> M
* @param builder the modifier(s) to apply when [value] is not null
*/
public inline fun <T : Any> Modifier.ifNotNull(value: T?, builder: Modifier.(T) -> Modifier): Modifier =
then(if (value != null) this.builder(value) else Modifier)
then(if (value != null) this.builder(value) else this)

/**
* Modifier to make it easy to conditionally add a modifier based on [value] nullability
Expand All @@ -81,4 +81,4 @@ public inline fun <T : Any> Modifier.ifNotNull(value: T?, builder: Modifier.(T)
* @param builder the modifier(s) to apply when [value] is null
*/
public inline fun <T : Any> Modifier.ifNull(value: T?, builder: Modifier.() -> Modifier): Modifier =
then(if (value == null) this.builder() else Modifier)
then(if (value == null) this.builder() else this)

0 comments on commit 80b1649

Please sign in to comment.