CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-compose-ui--ui-uikitsimarm64

Compose Multiplatform UI library for iOS Simulator ARM64 target providing declarative UI framework based on Jetpack Compose for multiplatform development

Pending
Overview
Eval results
Files

resources.mddocs/

Resource Management

Compose Multiplatform resource management system for handling strings, images, fonts, and other assets across multiple platforms with type-safe access and localization support.

Capabilities

String Resources

Type-safe string resource management with localization and pluralization support.

/**
 * Composable function to resolve and display a string resource
 * @param resource The string resource to display
 * @return The localized string value
 */
@Composable
fun stringResource(resource: StringResource): String

/**
 * Type-safe string resource representation
 */
@Immutable
data class StringResource(
    val key: String,
    val bundle: String = "strings"
) {
    companion object {
        /**
         * Create a string resource from a key
         */
        fun fromKey(key: String, bundle: String = "strings"): StringResource
    }
}

/**
 * Composable function for plural string resources
 * @param resource The plural string resource
 * @param quantity The quantity to determine plural form
 * @param formatArgs Optional format arguments for string interpolation
 * @return The localized plural string
 */
@Composable
fun pluralStringResource(
    resource: PluralStringResource,
    quantity: Int,
    vararg formatArgs: Any
): String

/**
 * Type-safe plural string resource representation
 */
@Immutable
data class PluralStringResource(
    val key: String,
    val bundle: String = "strings"
)

/**
 * Get string resource value without composable context
 * @param resource The string resource to resolve
 * @param resourceEnvironment Resource environment for resolution
 * @return The resolved string value
 */
fun getString(
    resource: StringResource,
    resourceEnvironment: ResourceEnvironment = LocalResourceEnvironment.current
): String

Usage Examples:

// Define string resources (typically in generated code)
object Res {
    object string {
        val app_name = StringResource("app_name")
        val welcome_message = StringResource("welcome_message")
        val item_count = PluralStringResource("item_count")
    }
}

// Use string resources in composables
@Composable
fun WelcomeScreen() {
    Column {
        Text(
            text = stringResource(Res.string.app_name),
            style = MaterialTheme.typography.headlineLarge
        )
        
        Text(
            text = stringResource(Res.string.welcome_message),
            style = MaterialTheme.typography.bodyLarge
        )
        
        val itemCount = 5
        Text(
            text = pluralStringResource(
                Res.string.item_count,
                quantity = itemCount,
                formatArgs = arrayOf(itemCount)
            )
        )
    }
}

// Use strings outside composables
fun getAppTitle(): String {
    return getString(Res.string.app_name)
}

Image Resources

Type-safe image resource management with support for vector graphics, raster images, and platform-specific assets.

/**
 * Composable function to load and display an image resource
 * @param resource The image resource to display
 * @param contentDescription Accessibility description
 * @param modifier Modifier for styling
 * @param alignment Alignment within the composable bounds
 * @param contentScale How to scale the image content
 * @param alpha Opacity of the image
 * @param colorFilter Color filter to apply to the image
 * @param filterQuality Quality of image filtering
 */
@Composable
fun Image(
    resource: DrawableResource,
    contentDescription: String?,
    modifier: Modifier = Modifier,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    filterQuality: FilterQuality = DrawScope.DefaultFilterQuality
)

/**
 * Load an image resource as a Painter
 * @param resource The image resource to load
 * @return Painter for the loaded image
 */
@Composable
fun painterResource(resource: DrawableResource): Painter

/**
 * Load an image resource as an ImageBitmap
 * @param resource The image resource to load
 * @return ImageBitmap of the loaded image
 */
@Composable
fun imageResource(resource: DrawableResource): ImageBitmap

/**
 * Load a vector image resource as an ImageVector
 * @param resource The vector image resource to load
 * @return ImageVector of the loaded vector graphic
 */
@Composable
fun vectorResource(resource: DrawableResource): ImageVector

/**
 * Type-safe drawable resource representation
 */
@Immutable
data class DrawableResource(
    val key: String,
    val bundle: String = "drawable"
)

Usage Examples:

// Define image resources (typically in generated code)
object Res {
    object drawable {
        val ic_launcher = DrawableResource("ic_launcher")
        val profile_placeholder = DrawableResource("profile_placeholder")
        val logo_vector = DrawableResource("logo_vector")
    }
}

// Use image resources
@Composable
fun ProfileScreen() {
    Column {
        // Vector image as icon
        Icon(
            imageVector = vectorResource(Res.drawable.logo_vector),
            contentDescription = "App Logo",
            modifier = Modifier.size(48.dp)
        )
        
        // Raster image
        Image(
            resource = Res.drawable.profile_placeholder,
            contentDescription = "Profile Picture",
            modifier = Modifier
                .size(120.dp)
                .clip(CircleShape),
            contentScale = ContentScale.Crop
        )
        
        // Using painter resource for custom drawing
        val painter = painterResource(Res.drawable.ic_launcher)
        Canvas(modifier = Modifier.size(100.dp)) {
            with(painter) {
                draw(Size(100.dp.toPx(), 100.dp.toPx()))
            }
        }
    }
}

Font Resources

Type-safe font resource management with support for custom fonts and font families.

/**
 * Load a font resource as a Font
 * @param resource The font resource to load
 * @param weight Font weight variant
 * @param style Font style variant
 * @return Font object for typography
 */
@Composable
fun fontResource(
    resource: FontResource,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal
): Font

/**
 * Create a font family from font resources
 * @param vararg fonts Font resources with their weights and styles
 * @return FontFamily containing the specified fonts
 */
fun fontFamilyResource(vararg fonts: Font): FontFamily

/**
 * Type-safe font resource representation
 */
@Immutable
data class FontResource(
    val key: String,
    val bundle: String = "font"
)

Usage Examples:

// Define font resources
object Res {
    object font {
        val roboto_regular = FontResource("roboto_regular")
        val roboto_bold = FontResource("roboto_bold")
        val custom_font = FontResource("custom_font")
    }
}

// Create custom font family
val RobotoFamily = fontFamilyResource(
    fontResource(Res.font.roboto_regular, FontWeight.Normal),
    fontResource(Res.font.roboto_bold, FontWeight.Bold)
)

// Use custom fonts in typography
@Composable
fun StyledText() {
    Column {
        Text(
            text = "Regular Text",
            fontFamily = RobotoFamily,
            fontWeight = FontWeight.Normal
        )
        
        Text(
            text = "Bold Text",
            fontFamily = RobotoFamily,
            fontWeight = FontWeight.Bold
        )
        
        Text(
            text = "Custom Font Text",
            fontFamily = fontFamilyResource(
                fontResource(Res.font.custom_font)
            )
        )
    }
}

Raw Resources

Access to raw resource files like JSON, XML, or binary data.

/**
 * Read raw resource content as a string
 * @param resource The raw resource to read
 * @return String content of the resource
 */
@Composable
suspend fun stringResource(resource: RawResource): String

/**
 * Read raw resource content as bytes
 * @param resource The raw resource to read
 * @return Byte array content of the resource
 */
@Composable
suspend fun bytesResource(resource: RawResource): ByteArray

/**
 * Type-safe raw resource representation
 */
@Immutable
data class RawResource(
    val key: String,
    val bundle: String = "raw"
)

Resource Environment

Resource resolution environment for handling different locales and configurations.

/**
 * Resource environment providing context for resource resolution
 */
@Immutable
data class ResourceEnvironment(
    val language: String,
    val region: String? = null,
    val theme: ResourceTheme = ResourceTheme.LIGHT,
    val density: ResourceDensity = ResourceDensity.MDPI
)

/**
 * Resource theme variants
 */
enum class ResourceTheme {
    LIGHT, DARK
}

/**
 * Resource density variants
 */
enum class ResourceDensity {
    LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI
}

/**
 * CompositionLocal for providing resource environment
 */
val LocalResourceEnvironment: ProvidableCompositionLocal<ResourceEnvironment>

/**
 * Get current resource environment
 */
@Composable
fun rememberResourceEnvironment(): ResourceEnvironment

Usage Examples:

// Provide custom resource environment
@Composable
fun LocalizedApp() {
    val resourceEnvironment = ResourceEnvironment(
        language = "es",
        region = "ES",
        theme = ResourceTheme.DARK
    )
    
    CompositionLocalProvider(
        LocalResourceEnvironment provides resourceEnvironment
    ) {
        MyApp()
    }
}

// Use resource environment for manual resolution
@Composable
fun ManualResourceResolution() {
    val environment = rememberResourceEnvironment()
    val appName = remember(environment) {
        getString(Res.string.app_name, environment)
    }
    
    Text(text = "App: $appName")
}

Resource Code Generation

Resource access is typically provided through generated code that creates type-safe resource references.

Generated Resource Structure:

// Generated by Compose Multiplatform Resource plugin
object Res {
    object string {
        val app_name: StringResource
        val welcome_message: StringResource
        val item_count: PluralStringResource
    }
    
    object drawable {
        val ic_launcher: DrawableResource
        val logo_vector: DrawableResource
        val profile_image: DrawableResource
    }
    
    object font {
        val custom_font_regular: FontResource
        val custom_font_bold: FontResource
    }
    
    object raw {
        val config_json: RawResource
        val sample_data: RawResource
    }
}

Resource Configuration

Build configuration for resource processing and generation.

Gradle Configuration Example:

compose {
    resources {
        // Resource directories
        resourcesPackage = "com.example.app.resources"
        
        // Generate resource classes
        generateResClass = always
        
        // Platform-specific resources
        publicResClass = true
        
        // Resource optimization
        optimizeImages = true
    }
}

Required Imports

// Core resource management
import org.jetbrains.compose.resources.*

// Resource types
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.FontResource
import org.jetbrains.compose.resources.RawResource

// Resource loading functions
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.vectorResource
import org.jetbrains.compose.resources.fontResource

// Resource environment
import org.jetbrains.compose.resources.ResourceEnvironment
import org.jetbrains.compose.resources.LocalResourceEnvironment

Install with Tessl CLI

npx tessl i tessl/maven-org-jetbrains-compose-ui--ui-uikitsimarm64

docs

composables.md

core-ui.md

graphics.md

index.md

input.md

ios-integration.md

layout.md

material-design.md

resources.md

state.md

text.md

window.md

tile.json