Compose Multiplatform 🤔

·

4 min read

What is, how, and why compose multiplatform?

The team at JetBrains has been working on a way to work on cross-platform UI using Kotlin and deploy on multiple platforms including Android, Desktop, IOS, and Web. Compose multiplatform support for IOS is now currently (time of writing this article) in alpha.

Check out this Repo to see a fully implemented Compose multiplatform project template that shares the UI code for Android, Ios, and Desktop platforms

What

Compose Multiplatform is a declarative framework for sharing UIs across multiple platforms with Kotlin.

Why

Compose multiplatform comes with numerous benefits and in this article we will outline some of them just to see how well compose multiplatform can suit your personal or company project.

Here are some compose multiplatform benefits

  • Declarative UI: Compose Multiplatform uses a declarative approach to UI development.

  • State management: Compose Multiplatform provides built-in state management. This makes it easy to keep track of the state of your UI and update it as needed.

  • Reduced development time: Compose Multiplatform allows you to write your UI code once and share it across multiple platforms. This can save you a lot of time and effort, as you don't need to write separate UI code for each platform.

  • Increased code reuse: Compose Multiplatform uses composable functions to build UIs. Composable functions are small, reusable pieces of UI code that can be combined to create complex UIs. This can help you to increase code reuse and improve the maintainability of your code.

  • Improved performance: Compose Multiplatform is designed to be performant. It uses a number of techniques to optimize the performance of your UI, such as batching and caching. This can help you to create UIs that are responsive and smooth.

  • Interoperability: Compose Multiplatform is designed to be interoperable with native UI frameworks. This means that you can use Compose Multiplatform to build UIs that look and feel native on each platform.

Let's look at a scenario where a company needs a website, a desktop application for Windows/macOS platforms, an Android application, and an ios application. There are many ways to approach this scenario but compose multiplatform comes to your aid as it can allow you to have a mono repo that has all the code for all these platforms, and is especially great given the reduced development time, improved performance and all the benefits that compose multiplatform brings along.

Some extra benefits of having a mono repo codebase written in Kotlin with its UI leveraging compose multiplatform include:

  • You can create a single codebase for your app's UI that can be used to build applications for Android, iOS, web, and desktop platforms.

  • Allow sharing of code between different teams or projects by storing all of the code for your app in a single repository.

  • It is easier to manage and maintain your app's codebase by using a mono repo.

  • Guarantees improved performance of your app's UI by using Compose Multiplatform's built-in performance optimizations.

  • Allows for interoperability with native UI frameworks by using Compose Multiplatform's built-in interoperability features.

How

Compose multiplatform is fairly curated to make it easy to learn and adapt for developers. Especially if you are coming from an Android development background with is very easy to follow along.

Prerequisites

i. Xcode

ii. Android Studio

iii. Kotlin Multiplatform mobile plugin

iv. For you to work on a CMM project you will preferably need a macOs for you to be able to run the IOS code but you still can work without a Mac and test out the Desktop, Web, and Android platforms.

You also need to have an understanding of Kotlin and developing declarative UIs using jetpack compose.

We will discuss how fully in the next bit of this article meanwhile check out this repository that showcases how to use compose multiplatform. I have also attached screenshots of the application from that repository to showcase the power of compose multiplatform.

Android App

IOS App

Desktop App

Â