Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures

Related tags

Kotlin CatViewerDemo
Overview

CatViewerDemo

Android demo iOS demo
Android Demo iOS Demo

Kotlin Multiplatform Mobile demo for Android and iOS. App for viewing Cat pictures from Cats API.

This sample showcases:

Usage

I leave here some notes that might help anyone who would like to build it themselves.

Cats API key

The project is using a property named catsApiKey to retrieve the key for the API.

You can provide it through gradle.properties, for example.

Kotlin Multiplatform Mobile setup

You should follow KMM setup to build the application, both for Android and iOS.

Overview

The goal of the exercise was to build Kotlin Multiplatform Mobile applications for Android and iOS, with only UI written in platform-specific code (ComposeUI and SwiftUI).

Everything from ViewModel to Repository and data sources is shared.

Architecture

Architecture follows the standard blueprint proposed in Guide to app architecture.

Shared module

The shared module consists of Kotlin Multiplatform code that I use to share business and presentation logic between Android and iOS.

ViewModel

CatsViewModel is the class that UI platform-specific code interacts with. It prepares cats data displayed in the UI. It also listens to the actions that happen in UI.

It extends SharedViewModel that provides shared scope for coroutine work. I took inspiration from MOKO MVVM library, which I plan to use instead once there is more time.

Repository

CatsStore is responsible for providing Cats model data. It fetches data from CatsApi and to map it to model data used in application.

In the future, I might use the Mapper pattern for mapping data from external systems to domain models.

Data from CatsApi is intentionally not persisted, to provide up-to-date results.

CatsApi

CatsApi uses Ktor to fetch data from Cats API.

SettingsStorage

SettingsStorage provides platform specific implementations for key value storage. On Android it is Datastore.

CatViewerServiceLocator

All dependencies are provided by CatViewerServiceLocator. For such a small application, it perfectly serves its purpose.

For larger applications, I would recommend Hilt (DI library).

Android platform-specific UI

MainActivity is a single activity in the application as the only application entry point. Even with more screens, I would still recommend using single activity as screens can be represented as composable functions now.

CatsUI file and composable function currently represent the only screen in the application. I divided the file into multiple functions for clarity.

iOS platform specific UI

CatsView is single screen displaying list of Cats. Cats are represented by CatItem view. For filtering, view has been created and is displayed as a sheet.

CatsStore serves as adapter between Kotlin Flow world and SwiftUI.

Tests

Shared code has one test file with a bunch of basic unit tests. You can find them in CatsTest.

I test the shared code through the ViewModel interface and I use Fakes for external systems like networking and IO.

It allows us to test most of the business logic from a single interface. Once I add more logic to tested objects, I might need to write more isolated tests.

There is also one UI instrumentation test in the Android application module. It runs with dummy ComponentActivity provided by the test library. It allows us to test the UI in isolation.

Special thanks

This project was way simpler thanks to all the resources, libraries and projects I was able to find on this topic.

CatsAPI

First and foremost, thanks to the people that created and maintained a free public service API that I could use to showcase KMM.

John O'Reilly

His repositories that showcase Kotlin Multiplatform were crucial to my work.

Especially, repository that demonstrates paging. I could not use the same multiplatform paging library (time constraints), but I want to try it in the future.

Touchlab

People at Touchlab and all the resources they provide publicly were especially helpful for my understanding of how Kotlin native threading works.

Jetbrains and community

During the project, I was using Apple M1 Silicon and with it arm64 simulators. Support in libraries is getting better, but the community on #kotlin-lang Slack channel, was extremely helpful when I was fighting with this.

Others

Special thanks also to all people that share their solutions around Kotlin Multiplatform. It is hard to find any up-to-date resources, so every single one of them counts.

Thanks to all the Kotlin Multiplatform libraries out there. I used:

TODO

Some things were left undone.

GIFs

Coil on Android helps us with displaying GIFs, but this has not yet been implemented on iOS.

Caching

Coil on Android is already caching images on disk, but there is no caching of images on iOS.

Error Handling

There is almost no error handling implemented at the moment.

It would be nice to show errors when image loading fails, there is a network issue, etc.

Full-screen view

It would be nice to be able to display images on full screen.

I could showcase Navigation with Compose, since I would have another screen.

Continuous Integration

I believe that even when developing a project alone, Continuous Integration service can help.

I would at least know that the build, tests and static analysis run with every new commit.

Another advantage is that I can be sure that someone else (another machine) can build it.

GitHub should be able to provide this functionality.

UI improvements

There is a lot of work on UI.

One thing that stands out is filtering, I don't think it is intuitive at this point. But it is there primarily to show work with Flows, so it is OK for now.

Bugs

There are probably a lot of bugs, but one stands out.

Pagination, loading of new images is working nicely. But only when the user scrolls to the bottom of the list.

But new images are not loaded when the user gets to the bottom by filtering.

You might also like...
A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

A Kotlin Multiplatform Project using TMDB Api. Currently supports Android,iOS,Desktop and web platforms
A Kotlin Multiplatform Project using TMDB Api. Currently supports Android,iOS,Desktop and web platforms

A Kotlin Multiplatform Project using TMDB Api(https://www.themoviedb.org/). Currently this project is implemented in following platforms Andr

BlurHash support for iOS, Android and JVM via Kotlin Multiplatform
BlurHash support for iOS, Android and JVM via Kotlin Multiplatform

blurhash A Kotlin Multiplatform library to use blurhash in your Android App, iOS / Mac App & JVM Backend. Android iOS JVM Why? If you've tried using b

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Codename One - Cross Platform Native Apps with Java or Kotlin Codename One is a mobile first cross platform environment for Java and Kotlin developers

A Gradle plugin for Kotlin Multiplatform projects that generate a XCFramework for Apple targets or a FatFramework for iOS targets, and manages the publishing process in a CocoaPod Repository.

KMP Framework Bundler KMP Framework Bundler is a Gradle plugin for Kotlin Multiplatform projects that generate a XCFramework for Apple targets or a Fa

MangaKu App Powered by Kotlin Multiplatform Mobile, Jetpack Compose, and SwiftUI
MangaKu App Powered by Kotlin Multiplatform Mobile, Jetpack Compose, and SwiftUI

MangaKu 🤖 Introduction MangaKu App Powered by Kotlin Multiplatform Mobile, Jetpack Compose, and SwiftUI Module core: data and domain layer iosApp: io

Opinionated Redux-like implementation backed by Kotlin Coroutines and Kotlin Multiplatform Mobile

CoRed CoRed is Redux-like implementation that maintains the benefits of Redux's core idea without the boilerplate. No more action types, action creato

Runtime Mobile Security (RMS) 📱🔥  - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime
Runtime Mobile Security (RMS) 📱🔥 - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) 📱 🔥 by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Comments
  • Add `kotlin-multiplatform-mobile` topic

    Add `kotlin-multiplatform-mobile` topic

    The Kotlin team is now changing its approach to the Multiplatform mobile samples. The number of great projects is growing, and we can't keep adding them to the already huge table in the documentation.

    Instead, we decided to keep a handful of projects in the table and give a link to a handy search by the GitHub topic. To add the topic to your project, please use the kotlin-multiplatform-mobile tag in the About section of your GitHub repository.

    opened by danil-pavlov 1
  • Update Gradle to 7.4

    Update Gradle to 7.4

    • version catalogues are stable (not need to specify feature),
    • instead, add feature preview for typesafe project accessors,
    • use plugins from version catalogue (had to remove classpath deps),

    Big shout-out to https://github.com/code-with-the-italians/bundel for inspiration.

    opened by MartinRajniak 0
Owner
Martin Rajniak
Martin Rajniak
Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Location Service Manager for Kotlin Multiplatform Mobile iOS and android Features Provides simple permission settings Dramatically reduce the amount o

LINE 55 Dec 10, 2022
A local storage management library for Kotlin Multiplatform Mobile iOS and android

A local storage management library for Kotlin Multiplatform Mobile iOS and android Features iOS and Android local storage in one interface Provides ge

LINE 20 Oct 30, 2022
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Chris Russell 1 Feb 11, 2022
Ethereum Web3 implementation for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin web3 This is a Kotlin MultiPlatform library that ... Table of Contents Features Requirements Installation Usage Samples Set Up Locally C

IceRock Development 32 Aug 26, 2022
🍭 GithubSearchKMM - Github Repos Search - Android - iOS - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Dependency Injection, shared KMP ViewModel, Clean Architecture

GithubSearchKMM Github Repos Search - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Depend

Petrus Nguyễn Thái Học 50 Jan 7, 2023
Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

Kotchaphan Muangsan 3 Nov 15, 2022
KMM RSS Reader: an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile.

KMM RSS Reader This is an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile. It's a simple RSS reader, and you ca

Kotlin 1.4k Jan 4, 2023
Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

Gérard Paligot 98 Dec 15, 2022
Simple Kotlin Multiplatform PrayerTimes App for iOS and Android

Kotlin Multiplatform ___ _______ ___ / _ \_______ ___ _____ ___/_ __(_)_ _ ___ ___ / _ | __

Ahmed El-Helw 26 Nov 9, 2022
Crunch-Mobile - A Food Delivery Mobile App which uses Modern App Architecture Pattern, Firebase And a Simple Restful Api

Crunch-Mobile This is a Food Delivery Mobile App which uses Modern App Architect

Bright Ugwu 1 Jan 1, 2022