Last active
February 9, 2024 05:24
-
-
Save ahmedhosnypro/46e45723941bcef49d13f1f4199856a5 to your computer and use it in GitHub Desktop.
Jetpack Compose, Border on One Side only: [topBorder, rightBorder, bottomBorder, leftBorder]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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