Skip to content

Instantly share code, notes, and snippets.

@ahmedhosnypro
Last active February 9, 2024 05:24
Show Gist options
  • Save ahmedhosnypro/46e45723941bcef49d13f1f4199856a5 to your computer and use it in GitHub Desktop.
Save ahmedhosnypro/46e45723941bcef49d13f1f4199856a5 to your computer and use it in GitHub Desktop.
Jetpack Compose, Border on One Side only: [topBorder, rightBorder, bottomBorder, leftBorder]
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
fun Modifier.topBorder(
color: Color,
height: Float,
) = this.drawWithContent {
drawContent()
drawLine(
color = color,
start = Offset(0f, 0f),
end = Offset(size.width, 0f),
strokeWidth = height,
)
}
fun Modifier.rightBorder(
color: Color,
width: Float,
) = this.drawWithContent {
drawContent()
drawLine(
color = color,
start = Offset(size.width, 0f),
end = Offset(size.width, size.height),
strokeWidth = width,
)
}
fun Modifier.bottomBorder(
color: Color,
height: Float,
) = this.drawWithContent {
drawContent()
drawLine(
color = color,
start = Offset(0f, size.height),
end = Offset(size.width, size.height),
strokeWidth = height,
)
}
fun Modifier.leftBorder(
color: Color,
width: Float,
) = this.drawWithContent {
drawContent()
drawLine(
color = color,
start = Offset(0f, 0f),
end = Offset(0f, size.height),
strokeWidth = width,
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment