Additional UI components for Compose Multiplatform including SplitPane layouts, resource loading, animated images, and UI tooling preview support
—
Multiplatform resource loading system with support for strings, images, fonts, and pluralization, including localization and resource qualification for building internationalized applications.
Load and format string resources with localization support.
/**
* Load a string resource in a Composable context
* @param resource String resource to load
* @return Localized string value
*/
@ExperimentalResourceApi
@Composable
fun stringResource(resource: StringResource): String
/**
* Load a formatted string resource with arguments in a Composable context
* @param resource String resource to load
* @param formatArgs Arguments for string formatting
* @return Formatted localized string value
*/
@ExperimentalResourceApi
@Composable
fun stringResource(resource: StringResource, vararg formatArgs: Any): String
/**
* Load a string resource outside of Composable context
* @param resource String resource to load
* @return Localized string value
*/
@ExperimentalResourceApi
suspend fun getString(resource: StringResource): String
/**
* Load a string resource with specific environment context
* @param environment Resource environment for qualification
* @param resource String resource to load
* @return Localized string value
*/
@ExperimentalResourceApi
suspend fun getString(environment: ResourceEnvironment, resource: StringResource): StringUsage Examples:
import org.jetbrains.compose.resources.*
@OptIn(ExperimentalResourceApi::class)
@Composable
fun WelcomeScreen() {
Column {
// Simple string resource
Text(stringResource(Res.string.welcome_title))
// Formatted string resource
val userName = "John"
Text(stringResource(Res.string.welcome_message, userName))
// Load string outside composable
LaunchedEffect(Unit) {
val loadedString = getString(Res.string.loading_message)
println(loadedString)
}
}
}Handle pluralization-aware string resources for different quantity contexts.
/**
* Load a plural string resource based on quantity in Composable context
* @param resource Plural string resource to load
* @param quantity Quantity to determine plural form
* @return Appropriate plural form of the string
*/
@ExperimentalResourceApi
@Composable
fun pluralStringResource(resource: PluralStringResource, quantity: Int): String
/**
* Load a formatted plural string resource with arguments in Composable context
* @param resource Plural string resource to load
* @param quantity Quantity to determine plural form
* @param formatArgs Arguments for string formatting
* @return Formatted plural form of the string
*/
@ExperimentalResourceApi
@Composable
fun pluralStringResource(resource: PluralStringResource, quantity: Int, vararg formatArgs: Any): String
/**
* Load a plural string resource outside of Composable context
* @param resource Plural string resource to load
* @param quantity Quantity to determine plural form
* @return Appropriate plural form of the string
*/
@ExperimentalResourceApi
suspend fun getPluralString(resource: PluralStringResource, quantity: Int): StringUsage Examples:
@OptIn(ExperimentalResourceApi::class)
@Composable
fun ItemCounter(itemCount: Int) {
// Handles "1 item" vs "5 items" automatically
Text(pluralStringResource(Res.plurals.item_count, itemCount, itemCount))
}Load images, vectors, and drawable resources with automatic format detection.
/**
* Load a drawable resource as a Painter (automatically detects format)
* @param resource Drawable resource to load
* @return Painter for the resource
*/
@ExperimentalResourceApi
@Composable
fun painterResource(resource: DrawableResource): Painter
/**
* Load a drawable resource as an ImageBitmap
* @param resource Drawable resource to load
* @return ImageBitmap representation
*/
@ExperimentalResourceApi
@Composable
fun imageResource(resource: DrawableResource): ImageBitmap
/**
* Load a vector drawable resource as an ImageVector
* @param resource Drawable resource to load (must be vector format)
* @return ImageVector representation
*/
@ExperimentalResourceApi
@Composable
fun vectorResource(resource: DrawableResource): ImageVector
/**
* Load drawable resource bytes with environment context
* @param environment Resource environment for qualification
* @param resource Drawable resource to load
* @return Raw bytes of the drawable resource
*/
@ExperimentalResourceApi
suspend fun getDrawableResourceBytes(environment: ResourceEnvironment, resource: DrawableResource): ByteArrayUsage Examples:
@OptIn(ExperimentalResourceApi::class)
@Composable
fun ImageGallery() {
Column {
// Load as Painter (recommended for most use cases)
Image(
painter = painterResource(Res.drawable.logo),
contentDescription = "App Logo",
modifier = Modifier.size(64.dp)
)
// Load as ImageBitmap for custom drawing
val imageBitmap = imageResource(Res.drawable.pattern)
Canvas(modifier = Modifier.size(100.dp)) {
drawImage(imageBitmap)
}
// Load vector specifically
Icon(
imageVector = vectorResource(Res.drawable.ic_star),
contentDescription = "Star Icon"
)
}
}Load font resources for typography with font weight and style variations.
/**
* Create a Font from a font resource
* @param resource Font resource to load
* @param weight Font weight
* @param style Font style
* @param variationSettings Font variation settings
* @return Font object for use in typography
*/
@ExperimentalResourceApi
@Composable
expect fun Font(
resource: FontResource,
weight: FontWeight = FontWeight.Normal,
style: FontStyle = FontStyle.Normal,
variationSettings: FontVariation.Settings = FontVariation.Settings()
): Font
/**
* Load font resource bytes with environment context
* @param environment Resource environment for qualification
* @param resource Font resource to load
* @return Raw bytes of the font resource
*/
@ExperimentalResourceApi
suspend fun getFontResourceBytes(environment: ResourceEnvironment, resource: FontResource): ByteArrayUsage Examples:
@OptIn(ExperimentalResourceApi::class)
@Composable
fun CustomTypography() {
val customFont = Font(
resource = Res.font.roboto_bold,
weight = FontWeight.Bold
)
val fontFamily = FontFamily(customFont)
Text(
text = "Custom Font Text",
fontFamily = fontFamily,
fontSize = 18.sp
)
}Manage resource qualification and localization contexts.
/**
* Get the current resource environment in Composable context
* @return Current ResourceEnvironment with system qualifiers
*/
@ExperimentalResourceApi
@Composable
fun rememberResourceEnvironment(): ResourceEnvironment
/**
* Get the system resource environment outside Composable context
* @return System ResourceEnvironment with default qualifiers
*/
@ExperimentalResourceApi
fun getSystemResourceEnvironment(): ResourceEnvironment
/**
* Resource environment containing qualification information for resource loading
*/
@ExperimentalResourceApi
class ResourceEnvironment {
// Implementation details are internal
}Usage Examples:
@OptIn(ExperimentalResourceApi::class)
@Composable
fun LocalizedContent() {
val environment = rememberResourceEnvironment()
LaunchedEffect(environment) {
// Load resources with specific environment
val localizedString = getString(environment, Res.string.title)
println("Current locale string: $localizedString")
}
}Core resource type definitions for type-safe resource access.
/**
* Represents a string resource
*/
@ExperimentalResourceApi
class StringResource
/**
* Represents a drawable/image resource
*/
@ExperimentalResourceApi
class DrawableResource
/**
* Represents a font resource
*/
@ExperimentalResourceApi
class FontResource
/**
* Represents a plural string resource with quantity-based forms
*/
@ExperimentalResourceApi
class PluralStringResourceInternal qualifier system for resource matching (advanced usage).
@InternalResourceApi
class LanguageQualifier
@InternalResourceApi
class RegionQualifier
@InternalResourceApi
class ThemeQualifier
@InternalResourceApi
class DensityQualifierNote: Internal APIs are subject to change and should not be used in production code.
Resources are typically accessed through a generated Res object:
// Generated resource access
Res.string.welcome_message // StringResource
Res.drawable.app_icon // DrawableResource
Res.font.custom_font // FontResource
Res.plurals.item_count // PluralStringResourceAll resource APIs are marked with @ExperimentalResourceApi and require opt-in:
@file:OptIn(ExperimentalResourceApi::class)or at usage sites:
@OptIn(ExperimentalResourceApi::class)
@Composable
fun MyComposable() {
// Resource usage
}Install with Tessl CLI
npx tessl i tessl/maven-org-jetbrains-compose-components--components