Maximizing Mobile Code Reuse with Compose Multiplatform and MOKO Libraries
Mobile application development can be a complex and time-consuming process, requiring developers to write separate code for each platform they want to target. To help streamline this process, JetBrains recently released Compose Multiplatform, a UI framework that allows developers to write UI for Android, iOS (Alpha), Desktop, Web (Experimental) in Kotlin common code. While Compose Multiplatform is a powerful tool for creating cross-platform user interfaces, it has some limitations when it comes to handling non-UI mobile features like permissions, geolocation, and biometric authentication. To address these limitations, developers can turn to the MOKO libraries, a set of Kotlin Multiplatform Mobile (KMM) libraries that are designed to work seamlessly with Compose Multiplatform.
What Compose Multiplatform Allows You to Do
Compose Multiplatform provides a powerful UI framework that enables developers to create consistent and responsive user interfaces across multiple platforms using Kotlin common code. This means that developers can write a single codebase that can be used to create UIs for both Android and iOS platforms. With Compose Multiplatform, developers can use a declarative approach to build UI components, making it easier to create complex UIs with less code. Compose Multiplatform also provides support for animations, theming, and custom layouts, making it a versatile and flexible tool for creating cross-platform UIs. Starts from Compose Multiplatform 1.4.0 all material ui that was developer for Android now available for iOS too.
What Compose Multiplatform Does Not Do
While Compose Multiplatform is a powerful tool for creating cross-platform user interfaces, it has some limitations when it comes to handling non-UI mobile features like permissions, geolocation, and biometric authentication. For example, Compose Multiplatform does not handle Android configuration changes. Additionally, Compose Multiplatform does not provide built-in support for requesting runtime permissions or tracking geolocation on Android or iOS platforms. This is where the MOKO libraries come in.
How MOKO Complements Compose Multiplatform
The MOKO libraries are a set of KMM libraries that are designed to work seamlessly with Compose Multiplatform. These libraries can help developers to handle common mobile features in a cross-platform way, without having to write platform-specific code. Here are some of the key features of the MOKO libraries:
- moko-resources: This library provides support for managing shared resources, including images, fonts, strings, plurals, raw resources, and more. With moko-resources, developers can easily load resources from their shared code and use them in their Compose UI.
- moko-mvvm: This library provides support for implementing the MVVM pattern and handling Android configuration changes. With moko-mvvm, developers can create ViewModel classes that can be shared across multiple platforms, enabling them to handle view logic and state management in a consistent and efficient way.
- moko-permissions: This library provides support for requesting runtime permissions on Android and iOS.
- moko-media: This library provides support for selecting and displaying images on Android and iOS. With moko-media, developers can easily select images from their shared code and display them in their Compose UI, or send them to a server.
- moko-geo: This library provides support for tracking geolocation on Android and iOS. With moko-geo, developers can easily track the user’s location from their shared code, enabling them to create location-aware applications that work seamlessly across multiple platforms.
- moko-biometry: This library provides support for implementing biometric authentication on Android and iOS. With moko-biometry, developers can easily implement touch and face ID checks from their shared code, enabling them to create secure and efficient authentication flows across multiple platforms.
Where to Find MOKO Libraries and Compose Multiplatform Templates
Developers interested in using Compose Multiplatform and the MOKO libraries in their own projects can find more information and resources on the official MOKO website and the Compose Multiplatform website. In addition, the IceRock Development has configure several official Compose Multiplatform templates to work with the MOKO libraries.
Compose Multiplatform and the MOKO libraries offer developers a powerful set of tools for creating cross-platform mobile applications with maximum code reuse. With Compose Multiplatform, developers can write UI for Android and iOS in Kotlin common code, while the MOKO libraries provide support for common mobile features like permissions, geolocation, and biometric authentication. By leveraging these tools, developers can streamline their development process and create mobile applications that work seamlessly across multiple platforms, with less code and fewer bugs. If you’re interested in exploring Compose Multiplatform and the MOKO libraries for your own projects, be sure to check out the resources available on the MOKO website and the Compose Multiplatform documentation, and consider using one of the pre-configured templates to get started quickly and easily.