Building Desktop Apps with Compose Multi-platform

Building desktop with mobile app development

UI framework made by JetBrains to simplify desktop application development using Kotlin with a functional API. It allows extensive UI code sharing between Android, Desktop, and Web. It targets the JAVA VIRTUAL MACHINE MACHINE (JVM) and thus can be used to build cross-platform GUI apps. It’s based on the jetpack compose declarative UI Toolkit made by Google for Android. Fast reactive Desktop and Web UI framework for Kotlin based on Google’s modern toolkit brought to you by JetBrains.

To create desktop user interfaces with Kotlin Compose for Desktop provides a reactive and declarative approach. No templating language, extensible markup language (XML), or other is required. Combine composable functions to build your user interface, enjoy full tooling support from your integrated development environment (IDE) and build a system.

Design user interfaces with the help of Kotlin will improve speed, promote lesser bugs, better tooling support, and more concise and robust code. This can be easily achieved using a declarative UI model based on composable functions, which take in parameters to describe the UI logic without returning anything and must be free of side effects.

Compose Multi-platform for Desktop Features

Distributions can be created with a single click with the help of native applications. Compose for Desktop targets the JVM and supports high-performance, hardware-accelerated UI rendering on all major desktop platforms like macOS, Windows, Linux, etc., leveraging the powerful native graphics library.

It has various features that enhance your project’s market value,

Such as -

  • Powerful and better text supply.

  • Layout support for various languages.

  • Desktop extensions for menus, windows, notification management, and more.

  • Android Compose compatibility at the UI element level.

  • Hardware-accelerated rendering with Skia.

  • Excellent AWT and Swing interoperability.

  • Support for creating standalone application bundles.

We can share UI code between desktop and Android apps. Google introduced this in 2021. Kotlin uses Kotlin for creating fast reactive UIs with no XMLs or templating language. This blog’s main aim is to build apps with Compose Multiplatform for Desktop, various concepts, and code snippets applicable to this.

Steps to follow while setting up compose:

Compose Multi-platform involve various setup processes during app buildup such as -

First, we need to download the compose for the desktop project started from the official GitHub.

After downloading, we need to import the project into IntelliJ IDEA.

We need to choose Gradle and after that select Finish.

Open src/main/kotlin/main.kt, and override the content

Open the terminal from the project’s root directory, and launch: Gradle run. You can also launch the run Gradle task directly from IntelliJ IDEA.

At last launch the ‘run’ Gradle task.

In the end, compose for Desktop Hello World.

Let’s check all the above processes in detail that involves during Compose Multi-platform so that you can easily design your applications.

Apps with Better User Interfaces

Compose Multiplatform is declarative. Hence the UI structure of your app reflects your code, and you don’t need to worry about things to view or developing UI refreshing logic. Since the framework takes care of all of that for you, creating UIs is genuinely a pleasure. In this example, the content of the label will be updated once the content of the TextField is edited with no additional code:

It’s easy to get started with Compose Multiplatform, mainly if you’ve used a declarative UI framework like React or Jetpack Compose by Google before.

Mobile Apps Having Better Runtime Performance

Modern user interfaces are performance-sensitive, and we go to great lengths to improve Compose Multiplatform. It uses Skia, a well-optimized graphics library used by many performance-sensitive applications, including modern browsers. All major hardware acceleration engines on the Desktop, such as DirectX, Metal, and OpenGL supported by Compose Multiplatform. Compose comes with an optimized software renderer for environments where hardware acceleration is not available.

Short Iteration Without a Rebuild

One of the most time-consuming tasks in UI development is rebuilding an application to make it look perfect. The Compose Multiplatform IDEA plugin streamlines this process. It allows you to fine-tune your components of the UI and create multiple iterations of them without having to rebuild or restart the application.

Proper Delivering Apps

Bringing an application to its users requires proper development and proper packaging. This is another area where Compose Multiplatform assists. Its Gradle plugin supports application packaging to the MSI, dmg, and deb formats, including signing and notarization for MacOS. Suppose you’re working on Desktop applications that already have a user interface built with typical Java UI frameworks. In that case, you don’t need to rewrite your code from scratch to make it work with Compose Multiplatform.

Interoperability and Running UI

The ability of computer systems or software to exchange and make use of information known as Ineteroperbility Jetpack Compose, Android’s modern toolkit for building native UIs created by Google, is continually gaining popularity among mobile developers. If you’ve used it before, it will be effortless to use Compose Multiplatform, as these two frameworks share a large part of their APIs.

We provide excellent interoperability, meaning you can add UI components written with Compose to your existing Java UI. You can also add your current Java controls to your new app you build with Compose Multiplatform. In IntelliJ IDEA 2021, you can create a simple Compose Multiplatform project in just a few clicks.

Compose for Web Target

Beyond the Desktop, Compose Multiplatform gives you a powerful, declarative Kotlin/JS API for working with the Document Object Model (DOM). It has all the features you want and need in a modern web framework, including a comprehensive DOM API, built-in CSS-in-JS support, support for SVGs, typed inputs, and many others. The web target for Compose Multiplatform is written in pure Kotlin and takes full advantage of the language’s type system and idioms. From other Kotlin targets, this allows you to use the same development workflow you may already use.

Multiplatform Support Directly

Using Compose Multiplatform, you’re not limited to targeting Desktop and Web Platforms supported directly. You can also target Android using the well-known UI Framework Jetpack Compose, developed by Google. These two frameworks share standard APIs and Core, giving them perfect interoperability. This means you don’t have to re-write familiar UI and state management code. Just write it once and then reuse it on as many platforms as necessary.

If you have an existing Android application that you want to bring to the desktop or web, Compose Multiplatform helps you do so with minimal effort. It allows you to manage all your application targets from a single Kotlin project. To quickly start building an app that targets multiple platforms with Compose, you can use the Kotlin Project Wizard in IntelliJ IDEA 2021. And even if you don’t need to develop a multiplatform application right now, your knowledge and expertise from one platform will benefit another.

Real Production Experience of mobile Apps

Even though Compose Multiplatform hasn’t gone live until today, some production applications already use it. For example, JetBrains started adopting Compose Multiplatform in the Jetbrains Toolbox App in early 2021. This management application for JetBrains IDEs is used by more than 1,000,000 monthly active users and was fully migrated from C++ and Electron to Compose Multiplatform.

Wrapping Up

With Compose Multiplatform, Kotlin developers now have a robust framework to create beautiful UIs for desktop and web applications. Now is the perfect time to give Compose Multiplatform a try! More information about Compose Multiplatform is available on JetBrain’s website. The easiest way to get started is to look at the official tutorials Using the Kotlin Project Wizard built into IntelliJ IDEA 2021. You can create your first Compose Multiplatform project and build declarative user interfaces with Kotlin. We hope you enjoy this! Thanks for your valuable time.

Did you find this article valuable?

Support Quokka Labs' Blogs by becoming a sponsor. Any amount is appreciated!