Block Utils
This document outlines the utility functions and extensions provided by the NativeblocksFoundation package for simplifying block-based UI development in Android using Kotlin and Jetpack Compose.
Extensions and Utility Functions
General Utilities
isHttpUrl()
Checks if a string is a valid HTTP or HTTPS URL.
fun String?.isHttpUrl(): Boolean
Returns
true if the string is a valid URL, otherwise false.
Shape Utilities
shapeMapper
Maps shape parameters to a Compose Shape.
fun shapeMapper(
shapeName: String?,
topStart: String?,
topEnd: String?,
bottomStart: String?,
bottomEnd: String?
): Shape
Parameters
- shapeName: The name of the shape (e.g., "circle", "rectangle").
- topStart, topEnd, bottomStart, bottomEnd: Corner radius values.
Returns
The constructed Shape.
Modifier Utilities
Modifier.widthAndHeight
Applies width and height modifiers based on string values.
fun Modifier.widthAndHeight(width: String?, height: String?): Modifier
Parameters
- width: The width value (e.g., "match", "wrap", or a numeric value).
- height: The height value (e.g., "match", "wrap", or a numeric value).
Returns
A Modifier with the applied dimensions.
Modifier.blockWeight
Applies width and height modifiers based on string values.
fun Modifier.blockWeight(weight: Float, scope: Any?): Modifier
Parameters
- weight: The weight to apply, must be a positive float to take effect.
- scope: scope The layout scope in which this modifier is applied; either [RowScope] or [ColumnScope]. If the scope is not one of these, no weight will be applied.
Returns
A Modifier with the applied dimensions.