compose-multiplatform
Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
Top Related Projects
A framework for building native applications using React
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
A framework for building native Windows apps with React.
A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.
Quick Overview
Compose Multiplatform is an extension of Jetpack Compose, Google's modern toolkit for building native UI. It allows developers to use Compose to create user interfaces for multiple platforms, including Android, iOS, desktop, and web applications, using a single codebase written in Kotlin.
Pros
- Shared codebase for multiple platforms, reducing development time and effort
- Declarative UI paradigm, making it easier to create and maintain complex user interfaces
- Seamless integration with existing Kotlin and Android projects
- Strong support from JetBrains, ensuring continued development and improvements
Cons
- Relatively new technology, which may lead to potential instability or lack of community resources
- Learning curve for developers unfamiliar with Compose or reactive programming concepts
- Limited third-party library support compared to more established frameworks
- Performance may not be as optimized as platform-specific solutions in some cases
Code Examples
- Creating a simple button:
Button(onClick = { /* Handle click */ }) {
Text("Click me")
}
- Implementing a list with LazyColumn:
LazyColumn {
items(itemsList) { item ->
Text(item.name)
}
}
- Creating a custom composable function:
@Composable
fun CustomCard(title: String, content: String) {
Card(
modifier = Modifier.padding(16.dp),
elevation = 4.dp
) {
Column(modifier = Modifier.padding(16.dp)) {
Text(text = title, style = MaterialTheme.typography.h6)
Spacer(modifier = Modifier.height(8.dp))
Text(text = content)
}
}
}
Getting Started
- Add the Compose Multiplatform plugin to your
build.gradle.kts
:
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
- Configure your Kotlin multiplatform targets:
kotlin {
jvm()
js(IR) {
browser()
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
}
}
}
}
- Create a simple composable function in your common source set:
@Composable
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
Button(onClick = { text = "Hello, Compose Multiplatform!" }) {
Text(text)
}
}
- Run the application on your desired platform using the appropriate Gradle task.
Competitor Comparisons
A framework for building native applications using React
Pros of React Native
- Larger ecosystem and community support
- More mature and battle-tested in production environments
- Extensive third-party libraries and components available
Cons of React Native
- Performance can be slower than native apps, especially for complex UIs
- Requires JavaScript bridge, which can introduce overhead
- Updating to new versions can be challenging due to potential breaking changes
Code Comparison
React Native:
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
const App = () => (
<View style={styles.container}>
<Text>Hello, React Native!</Text>
</View>
);
Compose Multiplatform:
import androidx.compose.foundation.layout.Box
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
@Composable
fun App() {
Box {
Text("Hello, Compose Multiplatform!")
}
}
Both frameworks aim to provide cross-platform development solutions, but they differ in their approach and target languages. React Native uses JavaScript and React paradigms, while Compose Multiplatform leverages Kotlin and a declarative UI approach. The code comparison shows the basic structure of a simple app in each framework, highlighting the syntax differences and the more concise nature of Compose Multiplatform.
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
Pros of Flutter
- More mature ecosystem with a larger community and extensive third-party packages
- Hot reload feature for faster development and iteration
- Comprehensive documentation and learning resources
Cons of Flutter
- Larger app sizes due to bundled runtime and dependencies
- Less native look and feel compared to platform-specific UI components
- Steeper learning curve for developers new to Dart programming language
Code Comparison
Flutter:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text('Hello, Flutter!'),
);
}
}
Compose Multiplatform:
@Composable
fun MyComposable() {
Text("Hello, Compose Multiplatform!")
}
Both frameworks use declarative UI paradigms, but Flutter uses Dart while Compose Multiplatform uses Kotlin. Flutter's syntax is more verbose, requiring a class definition and override, while Compose Multiplatform's approach is more concise with a simple function annotation.
A framework for building native Windows apps with React.
Pros of React Native Windows
- Leverages existing React Native knowledge for Windows development
- Strong backing from Microsoft, ensuring good Windows integration
- Large ecosystem of React Native libraries and components
Cons of React Native Windows
- Limited to Windows platform, less cross-platform than Compose Multiplatform
- Performance may be slower compared to native solutions like Compose
- Steeper learning curve for developers not familiar with React Native
Code Comparison
React Native Windows:
import React from 'react';
import { View, Text } from 'react-native';
const App = () => (
<View>
<Text>Hello, Windows!</Text>
</View>
);
Compose Multiplatform:
import androidx.compose.foundation.layout.Box
import androidx.compose.material.Text
import androidx.compose.ui.window.Window
fun main() = Window {
Box { Text("Hello, Multiplatform!") }
}
Both frameworks aim to simplify cross-platform development, but Compose Multiplatform offers a more native approach with Kotlin, while React Native Windows extends the React ecosystem to Windows. Compose provides better performance and wider platform support, whereas React Native Windows benefits from a larger community and existing React knowledge. The choice between them depends on the specific project requirements and team expertise.
A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
Pros of Ionic Framework
- Wider ecosystem and community support
- Extensive UI component library out-of-the-box
- Easier learning curve for web developers
Cons of Ionic Framework
- Performance may be slower compared to native solutions
- Less seamless integration with native platform features
- Potentially larger app size due to web-based approach
Code Comparison
Ionic Framework (Angular):
@Component({
selector: 'app-home',
template: `
<ion-content>
<ion-button (click)="handleClick()">Click me</ion-button>
</ion-content>
`
})
export class HomePage {
handleClick() {
console.log('Button clicked');
}
}
Compose Multiplatform:
@Composable
fun HomePage() {
Button(onClick = { println("Button clicked") }) {
Text("Click me")
}
}
The Ionic Framework example uses Angular with HTML-like syntax for UI components, while Compose Multiplatform utilizes Kotlin with a more declarative approach. Ionic's code may be more familiar to web developers, whereas Compose Multiplatform's syntax is closer to native mobile development paradigms.
An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
Pros of Expo
- Larger ecosystem and community support
- Easier setup and configuration for React Native projects
- Extensive documentation and learning resources
Cons of Expo
- Limited access to native modules and APIs
- Larger app size due to bundled libraries
- Potential performance overhead compared to bare React Native
Code Comparison
Expo (JavaScript/React):
import React from 'react';
import { View, Text } from 'react-native';
export default function App() {
return (
<View>
<Text>Hello, Expo!</Text>
</View>
);
}
Compose Multiplatform (Kotlin):
import androidx.compose.foundation.layout.Box
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
@Composable
fun App() {
Box {
Text("Hello, Compose Multiplatform!")
}
}
Compose Multiplatform offers a more concise and type-safe approach, while Expo provides a familiar React-like syntax. Compose Multiplatform's declarative UI paradigm aligns closely with modern UI development practices, whereas Expo leverages the widely-adopted React ecosystem. Both frameworks aim to simplify cross-platform development, but they cater to different language preferences and development workflows.
⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.
Pros of NativeScript
- Supports multiple programming languages (JavaScript, TypeScript, Angular, Vue.js)
- Direct access to native APIs without plugins
- Extensive marketplace with pre-built plugins and components
Cons of NativeScript
- Steeper learning curve for developers new to mobile development
- Smaller community compared to Compose Multiplatform
- Performance can be slower than native development in some cases
Code Comparison
NativeScript (XML):
<StackLayout>
<Label text="Hello, NativeScript!" />
<Button text="Click me" tap="onButtonTap" />
</StackLayout>
Compose Multiplatform (Kotlin):
@Composable
fun Greeting() {
Column {
Text("Hello, Compose Multiplatform!")
Button(onClick = { /* Handle click */ }) {
Text("Click me")
}
}
}
NativeScript uses XML-based layouts and separate logic files, while Compose Multiplatform employs a declarative UI approach with Kotlin. NativeScript's syntax is more familiar to web developers, whereas Compose Multiplatform's structure is closer to native mobile development patterns.
Both frameworks aim to simplify cross-platform development, but they cater to different developer preferences and project requirements. NativeScript offers flexibility in language choice and direct native API access, while Compose Multiplatform provides a more unified Kotlin-based approach with strong type safety and IDE support.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Compose Multiplatform
Compose Multiplatform is a declarative framework for sharing UIs across multiple platforms with Kotlin. It is based on Jetpack Compose and developed by JetBrains and open-source contributors.
You can choose the platforms across which to share your UIs using Compose Multiplatform:
For example, you can share UIs between iOS and Android or Windows and MacOS.
iOS
iOS support is in Beta. It is feature complete, and migration issues should be minimal. You may still encounter bugs, performance and developer experience issues, but not as much as in the Alpha stage. We would appreciate your feedback on it in the public Slack channel #compose-ios. If you face any issues, please report them on YouTrack.
Compose Multiplatform shares most of its API with Jetpack Compose, the Android UI framework developed by Google. You can use the same APIs to build user interfaces for both Android and iOS.
Since Compose is built on top of Kotlin Multiplatform, you can easily access native APIs, such as the Camera API, and embed complex native UI views, such as MKMapView.
Get started with Compose Multiplatform
Android
When Android is one of your targets, you can get the same experience for Android as if you were developing an Android app using Jetpack Compose.
Get started with Compose Multiplatform
Desktop
Compose Multiplatform targets the JVM and supports high-performance hardware-accelerated UI rendering on all major desktop platforms â macOS, Windows, and Linux.
It has desktop extensions for menus, keyboard shortcuts, window manipulation, and notification management.
Get started with Compose Multiplatform
We would appreciate your feedback on Compose Multiplatform in the public Slack channel #compose.
Web
Web support is in Alpha. It may change incompatibly and require manual migration in the future. We would appreciate your feedback on it in the public Slack channel #compose-web. If you face any issues, please report them on YouTrack.
You can experiment with sharing your mobile or desktop UIs with the web. Compose for Web is based on Kotlin/Wasm, the newest target for Kotlin Multiplatform projects. It allows Kotlin developers to run their code in the browser with all the benefits that WebAssembly has to offer, such as good and predictable performance for your applications.
Get started with Compose for Web
Libraries
Compose HTML
Compose HTML is a library targeting Kotlin/JS that provides Composable building blocks for creating web user interfaces with HTML and CSS.
Note that Compose HTML is not a multiplatform library. It can be used only with Kotlin/JS.
Learn more
Top Related Projects
A framework for building native applications using React
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
A framework for building native Windows apps with React.
A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot