Compose Multiplatform

repository·master·Indexed 12 days ago

https://github.com/jetbrains/compose-multiplatform

A declarative UI framework by JetBrains for sharing UI code across Android, iOS, Desktop (JVM), and Web (Wasm/JS) using Kotlin. This documentation includes guides for running performance benchmarks, comparing version performance, and executing component test cases across supported platforms.

Tokens
33K
Snippets
106
Records
156
Agent score
98%

What's inside Compose Multiplatform

  1. Overview of Compose Multiplatform Benchmarks

    master

    The Compose Multiplatform benchmarks suite contains performance tests for various UI components and rendering scenarios across different platforms. Key benchmark categories include:

    • Animations: AnimatedVisibility (toggling visibility of images) and VisualEffects (complex particle animations).
    • Lazy Layouts: LazyGrid (various configurations including smooth scrolling and async tasks in items) and LazyList (complex implementations with pull-to-refresh).
    • Rendering & Graphics: CanvasDrawing (massive amounts of graphic shapes), HeavyShader (complex GPU shaders), and TextLayout (heavy text layout/rendering).
    • Component Stress Tests: MultipleComponents (comprehensive UI with layouts and animations) and TextLayout.
  2. Overview of Basic iOS Tests for Compose Multiplatform

    master

    This test application is designed to verify that fundamental features of Compose Multiplatform are functioning correctly on iOS. It serves as a baseline for ensuring core Compose capabilities work as expected on the iOS platform.

    Key Requirements & Details:

    • Deployment Target: iOS 13.0
    • Core Entry Point: The logic for the iOS implementation can be found in shared/src/iosMain/kotlin/main.ios.kt.
  3. Desktop-specific UI and System features

    master

    Compose Multiplatform for Desktop provides specialized APIs for desktop-class user experiences. Key areas of focus include:

    • Input & Interaction: Mouse events, hover states, keyboard support, and tab focus navigation.
    • UI Components: Scrolling, scrollbars, tooltips, context menus, and menu/tray/notifications.
    • Window Management: Top-level window management and building native distributions.
    • Interoperability & Testing: Swing interoperability and UI testing.
    • Navigation & Accessibility: Routing/navigation and accessibility support.
  4. Explore Compose Multiplatform samples

    master

    The examples/ directory contains several sample applications demonstrating different capabilities of Compose Multiplatform across Android, iOS, Desktop, and Web. Use these to understand implementation patterns for specific use cases like navigation, graphics, or networking.

    | Sample | Description | Platforms |
    | ------------------------------------ | -------------------------------------------------------------------------------------------- | --------------------- |
    | [Imageviewer](imageviewer) | Image Viewer application | Android, iOS, Desktop |
    | [Codeviewer](codeviewer) | File browser and code viewer application | Android, iOS, Desktop |
    | [Chat](chat) | A simple chat | Android, iOS, Desktop |
    | [Graphics2D](graphics-2d) | 2D Games and graphics examples | Android, iOS, Desktop |
    | [Nav Cupcake](nav_cupcake) | Multiscreen app to demonstrate the use of Compose Navigation | Android, iOS, Desktop |
    | [Issues tracker](issues) | GitHub issue tracker with an adaptive UI and ktor-client | Android, Desktop |
    | [HTML based samples](html/README.md) | Examples written with Compose HTML Library | |
  5. Explore HTML-based Compose Multiplatform samples

    master

    The examples/html directory contains several demonstration projects showcasing how Compose Multiplatform can be used in web environments. These samples cover different integration patterns, including standalone games, landing pages, and interoperability with existing web frameworks like React or vanilla JavaScript.

    ### Available Samples:
    * [compose-bird](compose-bird) - A simple game about a bird
    * [Landing page](landing) - A landing page built using Compose
    * [Compose with React](with-react) - Using compose-in-react and react-in-compose
    * [Composable in JS](compose-in-js) - Using HTML based Composables
  6. Compose Multiplatform Ecosystem Components

    master

    The Compose Multiplatform ecosystem consists of several key parts:

    • Core: The main development happens in the compose-multiplatform-core repository, where Jetpack Compose is adapted for iOS, Desktop, and Web targets.
    • Gradle Plugin: Used to integrate Compose Multiplatform into your build process.
    • IDEA Plugin: Provides IDE support within IntelliJ IDEA.
    • Skiko: The low-level rendering and event handling layer.
    • Examples: Reference implementations and usage patterns.
  7. Overview of Compose HTML library

    master

    The Compose HTML library enables building reactive user interfaces for the web using Kotlin. It allows you to express state, behavior, and logic using Compose concepts while providing a declarative HTML/CSS API for full layout control.

    Important Compatibility Note: The Compose HTML library does not currently support Kotlin/Wasm.

  8. Understand Compose Multiplatform benchmark modes

    master

    Benchmarks can be executed in different modes to measure different aspects of performance:

    • SIMPLE: Measures raw frame times without VSync. Best for quick checks of rendering performance. (Default)
    • VSYNC_EMULATION: Emulates VSync to estimate missed frames and provide CPU/GPU percentiles. (Default)
    • REAL: Uses actual VSync for accurate user-perceived performance (FPS, actual missed frames). Requires a device with a real display; may not work on headless devices.
    • START_UP: Measures application startup timing. It captures metrics from process start to the first frame and beyond, including:
      • timeToMain: Time from process start to application entry point (JVM/Desktop only).
      • timeFromMainToFirstFrame: Time from entry point to the first frame.
      • timeOfFirstFrame: Duration of the first frame.
      • timeToNthFrame: Time from the first frame to the Nth frame (default N=30).
      • longestFrames: The N longest frames during startup (default N=3).

    You can combine modes using a comma-separated list, e.g., modes=STARTUP,REAL.

    modes=SIMPLE,VSYNC_EMULATION,REAL,STARTUP
  9. Structure of a Composable test case

    master

    Each test case is a small, independent project located in the ./testcases directory. To ensure cross-module compilation is tested, every test case must consist of at least two modules:

    1. ...-lib module: Contains the test dependencies.
    2. ...-main module: Contains the actual tests that verify behavior.

    Behavioral verification is performed by creating a simple text Composition and comparing its text dump against an expected string value. The text Composition API is provided by the common module.

    @Test
    fun testExample2() = runTest {
        val root = composeText {
            TextLeafNode("Leaf")
            TextContainerNode("node") {
                TextLeafNode("child1")
                TextLeafNode("child2")
                TextLeafNode("child3")
            }
        }
    
        assertEquals("root:{Leaf, node:{child1, child2, child3}}", root.dump())
    }