Premo helps to implement the presentation layer and share it on Android, iOS, Desktop and Web.

Last update: Aug 5, 2022

Premo

Maven Central License: MIT platform-android platform-ios platform-jvm platform-js

Premo is a Kotlin Multiplatform library that helps you implement the Presentation Layer and share it on Android, iOS, Desktop and Web. Focus on writing logic instead of solving common and boring UI related issues.

Here are some key features:

  • State holding — PresentationModel is a multiplatform version of the ViewModel.
  • Lifecycle — PresentationModel is lifecycle aware.
  • Navigation — navigate between PresentationModels instead of switching views.
  • Persistence — saving and restoring state after recreating a process.
  • Communication — send messages from children towards the root PresentationModel.

At the same time, the library provides freedom of choice:

  • Architecture — MVVM, PM, MVI or other.
  • UI — Jetpack Compose for Android and SwiftUI for iOS.

Table of Contents

Overview

The library is based on the ideas of the Presentation Model pattern described by Martin Fowler. The Presentation Model stores the state for presentation and coordinates with the domain model layer.

In practice, you will have not only one Presentation Model, but a composition of child Presentation Models. At the base, there will be a root Presentation Model, from which a tree of children will grow. Children can be pushed into the Stack Navigator, thus organizing the navigation stack.

Such a tree composition is well suited for a hierarchical view as well as for a composition of functions from declarative UI frameworks.

One interesting feature of the tree is that the child keeps a reference to the parent. This allows for messaging between Presentation Models. For example, when some event occurs in a child that requires a reaction from the parent. In this case, the child can send a message towards the root for one of the parents to handle it.

Navigation commands can be the such event. A Child PM sends a message and then its Parent PM can intercept this message and push the next Child PM into the Stack Navigator.

This way of navigation has several advantages:

  • Relieves the Child PM from the responsibility of what transition to make and allow the parents to decide.
  • Simplifies nested navigation when an event occurs deep in the hierarchy.

Installation

Add to the root gradle script:

allprojects {
    repositories {
        mavenCentral()
    }
}

Add dependencies to the shared multiplatform module:

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                api("me.dmdev.premo:premo:<latest_version>")
                api("me.dmdev.premo:premo-navigation:<latest_version>")
            }
        } 
    }
}

You will also need kotlinx serialization to implement the PmStateSaver. See sample for more details.

Attention! The library is in the pre-release alpha version. Stable work and backward compatibility are not guaranteed. API may be changed in the future.

Sample

Sample demonstrates:

  • Sharing presentation logic between Android, iOS, Desktop and Web.
  • Sharing Compose UI between Android and Desktop.
  • UI on Compose and SwiftUI.
  • Using StateFlow to implement MVVM (PM).
  • Simple Counter.
  • Stack navigation.
  • Bottom navigation with multistack.
  • Master-Detail navigation.
  • Saving and restoring the state after killing the process.

License

The MIT License (MIT)

Copyright (c) 2020-2022 Dmitriy Gorbunov ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

GitHub

https://github.com/dmdevgo/Premo
You might also like...

:closed_umbrella: An easy way to implement modern permission instructions popup.

:closed_umbrella: An easy way to implement modern permission instructions popup.

Needs An easy way to implement modern permission instructions popup. Needs can be fully customized and showing with animations. Download Gradle Add be

Aug 2, 2022

AdsManager - Easy way to implement Google Ads

AdsManager Easy way to implement Google Ads Implementaion: https://jitpack.io/#R

Jul 25, 2022

Oratio Library for Android Studio helps you simplify your Android TTS codes

Oratio Oratio is a library for Android Studio. This library is useful to a number of developers who are currently making apps using android TTS(Text-T

Oct 28, 2021

Utility for developers and QAs what helps minimize time wasting on writing the same data for testing over and over again. Made by Stfalcon

 Utility for developers and QAs what helps minimize time wasting on writing the same data for testing over and over again. Made by Stfalcon

Stfalcon Fixturer A Utility for developers and QAs which helps minimize time wasting on writing the same data for testing over and over again. You can

Nov 29, 2021

A light lib that helps and centralize logs in your application.

A light lib that helps and centralize logs in your application.

BadgeLog (Kotlin version) For the iOS swift version, see this page BadgeLog is an Android Kotlin library that helps you manage logs within your applic

Feb 8, 2022

A nice weather that helps you get all information including: current weather, hourly weather and also forecasts for 16 days

A nice weather that helps you get all information including: current weather, hourly weather and also forecasts for 16 days

WeatherForecast This is an ongoing project where I fetch all the weather data using Retrofit and Kotlin Coroutines over two APIs containing both curre

Jul 26, 2022

A sample project that helps to start building a Mobile Kotlin Multiplatform application

A sample project that helps to start building a Mobile Kotlin Multiplatform application

Mobile Kotlin multiplatform project template A sample project that helps to start building a Mobile Kotlin Multiplatform application. It establishes a

Oct 16, 2021

The Action helps you to send a message to a queue on a RabbitMQ running Server

Rabbit Sender Action This Action helps you to send a message to a queue on a RabbitMQ running Server. Inputs Arg Default Description RABBIT_USERNAME g

May 3, 2022
Comments
  • 1. Parcelable insted of JSON

    We use your library version 1.0.0 alpha 04 in android.

    You use JSON to saveState.

    We can use parcelable instead of JSON.

    It's possible to support parcelable for saving state? We have a bad experience with the speed of encode and decode JSON.

    Thanks.

    Reviewed by drdla49 at 2022-03-31 14:40
  • 2. Incompatibility with android/compose

    I tried to use your library but I have not been successful. The worst is it does not use NavHost/NavController inside, so I cannot inject viewModel that would be connected to one navigation destination.

    I tried to implement NavHost together with your library, but also had no luck. Mainly because I am unable to register all destinations inside NavHost.

    Or maybe I am missing something? Please let me know or provide a more complex example.

    Complex example: multi-module project, composables via DI, viewModel per compose screen

    Reviewed by lepicekmichal at 2022-05-04 15:14
Kotlin Multiplatform Sample - Android, iOS, Web, Desktop
Kotlin Multiplatform Sample - Android, iOS, Web, Desktop

KMP-Sample Kotlin Multiplatform Sample Android iOS Web (Compose for web) Desktop (Compose for desktop) ?? Structure Diagram ?? Build At least android

Mar 26, 2022
Link-converter - A web service that converts links between web url and deeplink for mobile and web applications

Deep Link Converter Linkleri, mobil ve web uygulamaları için web url ile deeplin

Apr 9, 2022
A mobile application developed for *Android* devices, aimed at 11th grade students in which they can take some basic training tests for presentation of external tests.

ApliKTest11 Application with Kit of questions and Knowledge Test for the preparation of the Saber Test. Description A mobile application developed for

Dec 13, 2021
An experimental UI toolkit for generating PowerPoint presentation files using Compose
An experimental UI toolkit for generating PowerPoint presentation files using Compose

ComposePPT An experimental UI toolkit for generating PowerPoint presentation files(.pptx) using Compose. Inspired by Glance and Mosaic. Why? This proj

Jul 31, 2022
A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

Oct 27, 2021
Unsplash application for Android, Desktop and Web. Built using Kotlin Multiplatform and Compose
Unsplash application for Android, Desktop and Web. Built using Kotlin Multiplatform and Compose

Unsplash Unsplash application for Android, Desktop and Web. Built using Kotlin Multiplatform and Compose with ❤️ ?? Presentation Set up the environmen

Jul 14, 2022
PackageReferenceComparison - Do app/module dependencies that share a dependency use the same Singleton ref?
PackageReferenceComparison - Do app/module dependencies that share a dependency use the same Singleton ref?

PackageReferenceComparison Do app/module dependencies that share a dependency us

Feb 3, 2022
:performing_arts: An easy, flexible way to implement veil skeletons and shimmering effect for Android.
:performing_arts: An easy, flexible way to implement veil skeletons and shimmering effect for Android.

AndroidVeil An easy, flexible way to implement veil skeletons and shimmering effect for Android. Download Gradle Add below codes to your root build.gr

Aug 3, 2022
In this project, I tried to understand and implement the architecture suggested by Android.
In this project, I tried to understand and implement the architecture suggested by Android.

Shopping App Bu projede, Android'in önerdiği modern mimariyi anlamaya ve uygulamaya çalıştım. Projede kullandığım teknolojiler, Room Retrofit Coroutin

Aug 2, 2022
This repository contains the article describing my attempt to implement a simple state reducer based on Kotlin Flow and an example app that uses it.
This repository contains the article describing my attempt to implement a simple state reducer based on Kotlin Flow and an example app that uses it.

This repository contains the article describing my attempt to implement a simple state reducer based on Kotlin Flow and an example app that uses it.

Jun 15, 2022