BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Google Jetpack Compose Goes 1.0, JetBrains Launches Compose Multiplatform Alpha

Google Jetpack Compose Goes 1.0, JetBrains Launches Compose Multiplatform Alpha

This item in japanese

Jetpack Compose, Google's Kotlin-based declarative UI framework for Android, has now reached stability at version 1.0, which also brings a few new tools to improve developer experience. While Google's Compose only supports Android, Kotlin maker JetBrains announced its Compose Multiplatform, which aims to extend Compose to the Desktop and the Web.

Jetpack Compose aims to accelerate UI development for Android apps by allowing programmers to define their UIs using a declarative style. In other words, developers create UIs by combining composable elements which adapt to changes to the app state. According to Google, Compose enables the creation of user interfaces with a significant reduction of code. To make its adoption easier for existing projects, it is possible to integrate Compose progressively and embed it within Views or vice versa.

This is an example of how you can place a simple Compose Text widget inside a standard Android activity:

class MyActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // ...

        val greeting = findViewById<ComposeView>(R.id.greeting)
        greeting.setContent {
            MdcTheme { // or AppCompatTheme
                Greeting()
            }
        }
    }
}

@Composable
private fun Greeting() {
    Text(
        text = stringResource(R.string.greeting),
        style = MaterialTheme.typography.h5,
        modifier = Modifier
            .fillMaxWidth()
            .padding(horizontal = dimensionResource(R.dimen.margin_small))
            .wrapContentWidth(Alignment.CenterHorizontally)
    )
}

With the 1.0 release, Compose is getting a few new tools, including Compose Preview. Aimed to simplify the creation of UI components, Compose Preview allows you to see your composables in different states, themes, etc., all at the same time, without needing to install and run a test app on a device or emulator. Compose Preview is also able to run a component preview on a physical device in isolation, so you can test it interactively. All of these new features are available in Android Studio Arctic Fox.

As mentioned, on the heels of Google's announcement, Jetbrains has released Compose Multiplatform alpha. Compose Multiplatform includes Compose for Desktop and Compose for Web and leverages Kotlin Multiplatform to support a number of different platforms. Compose Desktop uses Google's Skia library to draw UI widgets on Windows, macOS, and Linux. This provides a unified experience across all supported OSes at the expense of each platform native look and feel, similar to Flutter's approach and contrary to React Native's.

According to the Kotlin team, using Compose Multiplatform should provide a number of benefits in comparison with Electron apps, namely reduced memory consumption, installation size, and UI rendering performance.

With its alpha release, Compose Multiplatform is also getting a new Android Studio plugin, which includes support for showing component preview in the IDE, as well as a number of additional features.

Compose Multiplatform is still an early alpha release, so JetBrains is only making it available to write proof-of-concept implementations and getting ready for the first stable release, which should come out sometime this year.

Rate this Article

Adoption
Style

BT