CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-compose-runtime--runtime-uikitx64

Compose Multiplatform runtime library for iOS UIKit x64 target providing core runtime functionality for declarative UI framework integration.

Pending
Overview
Eval results
Files

composition-lifecycle.mddocs/

Composition and Lifecycle

Composition management and lifecycle control for building and managing UI component trees. Handles component creation, updates, disposal, and memory management throughout the lifecycle of composable functions.

Capabilities

Composable Annotation

The fundamental annotation that marks functions as composable, enabling them to participate in the Compose runtime.

/**
 * Marks a function as composable, allowing it to call other composable functions
 * and participate in recomposition
 */
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
@Retention(AnnotationRetention.BINARY)
annotation class Composable

Usage Examples:

@Composable
fun MyButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier
) {
    Button(onClick = onClick, modifier = modifier) {
        Text(text)
    }
}

@Composable
fun UserProfile(user: User) {
    Column {
        Text("Name: ${user.name}")
        Text("Email: ${user.email}")
        MyButton("Edit Profile", onClick = { /* edit logic */ })
    }
}

Remember Functions

Functions for persisting values across recompositions, essential for maintaining state and expensive computations.

/**
 * Remembers a value across recompositions with no keys
 * @param calculation Function to compute the initial value
 * @return The remembered value
 */
inline fun <T> remember(crossinline calculation: () -> T): T

/**
 * Remembers a value with one key dependency
 * @param key1 Key that determines when to recalculate
 * @param calculation Function to compute the value
 * @return The remembered value, recalculated when key changes
 */
inline fun <T> remember(
    key1: Any?,
    crossinline calculation: () -> T
): T

/**
 * Remembers a value with two key dependencies
 * @param key1 First key dependency
 * @param key2 Second key dependency
 * @param calculation Function to compute the value
 * @return The remembered value, recalculated when any key changes
 */
inline fun <T> remember(
    key1: Any?,
    key2: Any?,
    crossinline calculation: () -> T
): T

/**
 * Remembers a value with three key dependencies
 * @param key1 First key dependency
 * @param key2 Second key dependency
 * @param key3 Third key dependency
 * @param calculation Function to compute the value
 * @return The remembered value, recalculated when any key changes
 */
inline fun <T> remember(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    crossinline calculation: () -> T
): T

/**
 * Remembers a value with multiple key dependencies
 * @param keys Variable number of key dependencies
 * @param calculation Function to compute the value
 * @return The remembered value, recalculated when any key changes
 */
inline fun <T> remember(
    vararg keys: Any?,
    crossinline calculation: () -> T
): T

Usage Examples:

@Composable
fun ExpensiveComputationExample(data: List<Int>) {
    // Remember expensive computation result
    val processedData = remember(data) {
        data.map { it * it }.sorted() // Only recalculates when data changes
    }
    
    // Remember object creation
    val textStyle = remember {
        TextStyle(fontSize = 16.sp, fontWeight = FontWeight.Bold)
    }
    
    // Remember with multiple keys
    val filteredItems = remember(data, filter, sortOrder) {
        data.filter(filter).sortedWith(sortOrder)
    }
    
    LazyColumn {
        items(processedData) { item ->
            Text("$item", style = textStyle)
        }
    }
}

Recomposition Control

Functions and interfaces for controlling when and how recomposition occurs.

/**
 * Returns the current recompose scope, which can be used to invalidate the current composition
 * @return Current RecomposeScope or null if not in composition
 */
val currentRecomposeScope: RecomposeScope?

/**
 * Interface for controlling recomposition of a specific scope
 */
interface RecomposeScope {
    /**
     * Invalidates this scope, causing it to be recomposed on the next recomposition
     */
    fun invalidate()
}

/**
 * Invalidates the current recompose scope, causing recomposition
 */
fun invalidate(): Unit

Usage Examples:

@Composable
fun ManualRecompositionExample() {
    val scope = currentRecomposeScope
    
    Button(onClick = {
        // Manually trigger recomposition
        scope?.invalidate()
    }) {
        Text("Force Recompose")
    }
}

Composition Context

Classes for managing composition execution and hierarchy.

/**
 * Context for composition operations, providing access to composition-wide state
 */
abstract class CompositionContext {
    /** Unique identifier for this composition context */
    abstract val id: Int
    
    /** Parent composition context, if any */
    abstract val parent: CompositionContext?
}

/**
 * Represents a composition tree and its lifecycle
 */
interface Composition {
    /** Applies changes to the composition */
    fun applyChanges()
    
    /** Disposes the composition and releases resources */
    fun dispose()
    
    /** Whether this composition has pending changes */
    val hasInvalidations: Boolean
}

/**
 * A Composition that provides additional control over composition execution
 */
interface ControlledComposition : Composition {
    /** Composes the composition with the given content */
    fun compose(content: @Composable () -> Unit)
    
    /** Forces recomposition of invalidated content */
    fun recompose(): Boolean
    
    /** Number of pending invalidations */
    val invalidationCount: Int
}

Composition Creation

Functions for creating new composition instances.

/**
 * Creates a new Composition
 * @param applier The applier that will receive composition changes  
 * @param parent Parent CompositionContext for hierarchical compositions
 * @return New Composition instance
 */
fun Composition(
    applier: Applier<*>,
    parent: CompositionContext? = null
): ControlledComposition

/**
 * Creates a new Composition with additional configuration
 * @param applier The applier that will receive composition changes
 * @param parent Parent CompositionContext for hierarchical compositions
 * @param onDispose Callback invoked when composition is disposed
 * @return New Composition instance
 */
fun Composition(
    applier: Applier<*>,
    parent: CompositionContext? = null,
    onDispose: (() -> Unit)? = null
): ControlledComposition

Applier Interface

Interface for applying composition changes to a tree structure.

/**
 * Applies composition changes to a tree of nodes
 * @param Node The type of nodes in the tree
 */
interface Applier<Node> {
    /** The current node being modified */
    val current: Node
    
    /** Insert nodes at the specified index in the current node */
    fun insertTopDown(index: Int, instance: Node)
    
    /** Insert nodes from bottom up */
    fun insertBottomUp(index: Int, instance: Node)
    
    /** Remove nodes starting at index */
    fun remove(index: Int, count: Int)
    
    /** Move nodes from one position to another */
    fun move(from: Int, to: Int, count: Int)
    
    /** Clear all child nodes */
    fun clear()
    
    /** Move down to a child node */
    fun down(node: Node)
    
    /** Move up to the parent node */
    fun up()
}

Advanced Composition

Recomposition Optimization

/**
 * Information about recomposition for debugging and optimization
 */
interface RecompositionInfo {
    /** Number of times this scope has recomposed */
    val recomposeCount: Int
    
    /** Number of times this scope has been skipped */
    val skipCount: Int
}

/**
 * Gets recomposition information for the current scope
 * @return RecompositionInfo for debugging
 */
@Composable
fun currentRecompositionInfo(): RecompositionInfo

Composition Debugging

/**
 * Provides debugging information about the current composition
 */
object CompositionTracing {
    /** Whether composition tracing is enabled */
    var isEnabled: Boolean
    
    /** Begin tracing a composition section */
    fun beginSection(name: String)
    
    /** End the current composition section */
    fun endSection()
}

iOS Platform Integration

UIKit Integration

/**
 * Creates a UIViewController that hosts Compose content
 * @param content The composable content to display
 * @return UIViewController containing the Compose UI
 */
fun ComposeUIViewController(content: @Composable () -> Unit): UIViewController

/**
 * Platform-specific composition context for iOS
 */
class IOSCompositionContext : CompositionContext {
    /** The UIView hosting the composition */
    val hostView: UIView
    
    /** Main thread dispatcher for iOS */
    val mainDispatcher: CoroutineDispatcher
}

Performance Considerations

  • Remember Keys: Use appropriate keys to control when values are recalculated
  • Composition Scoping: Keep composable functions focused and avoid large composition trees
  • State Hoisting: Hoist state only when necessary to minimize recomposition scope
  • Skippable Composables: Design composables to be skippable by avoiding reading state unnecessarily
  • Composition Debugging: Use composition tracing to identify performance bottlenecks

Install with Tessl CLI

npx tessl i tessl/maven-org-jetbrains-compose-runtime--runtime-uikitx64

docs

composition-lifecycle.md

composition-local.md

effects.md

index.md

ios-integration.md

snapshot-system.md

state-management.md

tile.json