refactor: organize utils

This commit is contained in:
2023-11-14 01:45:01 +08:00
parent fa09ae3142
commit f00badc5c8
2 changed files with 13 additions and 11 deletions

View File

@@ -21,24 +21,14 @@
*/ */
package com.highcapable.flexiui.utils package com.highcapable.flexiui.utils
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.runtime.Stable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.isSpecified import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.isSpecified import androidx.compose.ui.unit.isSpecified
inline fun Dp.orElse() = if (isSpecified) this else null inline fun Dp.orElse() = if (isSpecified) this else null
inline fun Color.orElse() = if (isSpecified) this else null inline fun Color.orElse() = if (isSpecified) this else null
inline fun TextUnit.orElse() = if (isSpecified) this else null inline fun TextUnit.orElse() = if (isSpecified) this else null
@Stable
fun Modifier.borderOrNot(border: BorderStroke, shape: Shape = RectangleShape) = border.takeIf { it.width > 0.dp }?.let { border(it, shape) } ?: this

View File

@@ -0,0 +1,12 @@
package com.highcapable.flexiui.utils
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.runtime.Stable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp
@Stable
fun Modifier.borderOrNot(border: BorderStroke, shape: Shape = RectangleShape) = border.takeIf { it.width > 0.dp }?.let { border(it, shape) } ?: this