⌘K

Block Utilities

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.


Layout Utilities

findArrangementHorizontal(arrangement: String?): Arrangement.Horizontal

Maps a horizontal arrangement string to a Compose Arrangement.Horizontal.

fun findArrangementHorizontal(arrangement: String?): Arrangement.Horizontal
Parameters
  • arrangement: A string representing the arrangement (e.g., "start", "end", "center").
Returns

The mapped Arrangement.Horizontal.

findArrangementVertical(arrangement: String?): Arrangement.Vertical

Maps a vertical arrangement string to a Compose Arrangement.Vertical.

fun findArrangementVertical(arrangement: String?): Arrangement.Vertical
Parameters
  • arrangement: A string representing the arrangement (e.g., "top", "bottom", "center").
Returns

The mapped Arrangement.Vertical.

findAlignmentHorizontal(alignment: String?): Alignment.Horizontal

Maps a horizontal alignment string to a Compose Alignment.Horizontal.

fun findAlignmentHorizontal(alignment: String?): Alignment.Horizontal
Parameters
  • alignment: A string representing the alignment (e.g., "start", "end", "centerHorizontally").
Returns

The mapped Alignment.Horizontal.

findAlignmentVertical(alignment: String?): Alignment.Vertical

Maps a vertical alignment string to a Compose Alignment.Vertical.

fun findAlignmentVertical(alignment: String?): Alignment.Vertical
Parameters
  • alignment: A string representing the alignment (e.g., "top", "bottom", "centerVertically").
Returns

The mapped Alignment.Vertical.


Typography Utilities

fontFamilyMapper(fontFamily: String?): FontFamily

Maps a font family string to a Compose FontFamily.

fun fontFamilyMapper(fontFamily: String?): FontFamily
Parameters
  • fontFamily: A string representing the font family.
Returns

The mapped FontFamily.

fontWeightMapper(fontWeight: String?): FontWeight

Maps a font weight string to a Compose FontWeight.

fun fontWeightMapper(fontWeight: String?): FontWeight
Parameters
  • fontWeight: A string representing the font weight (e.g., "bold", "light").
Returns

The mapped FontWeight.

typographyBuilder(fontFamily: FontFamily, fontWeight: FontWeight, fontSize: TextUnit): TextStyle

Builds a Compose TextStyle based on provided parameters.

fun typographyBuilder(
    fontFamily: FontFamily,
    fontWeight: FontWeight,
    fontSize: TextUnit
): TextStyle
Parameters
  • fontFamily: The font family for the text.
  • fontWeight: The font weight for the text.
  • fontSize: The font size.
Returns

A TextStyle with the specified attributes.


Shape Utilities

shapeMapper(shapeName: String?, topStart: String?, topEnd: String?, bottomStart: String?, bottomEnd: String?): Shape

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(width: String?, height: String?): Modifier

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.

spacingMapper

Maps a list of padding values to Compose PaddingValues.

fun spacingMapper(paddings: List<String?>): PaddingValues
Parameters
  • paddings: A list of padding values (start, top, end, bottom).
Returns

The corresponding PaddingValues.


Content Utilities

scaleTypeMapper

Maps a scale type string to a Compose ContentScale.

fun scaleTypeMapper(scaleType: String?): ContentScale
Parameters
  • scaleType: A string representing the scale type (e.g., "fit", "crop").
Returns

The mapped ContentScale.