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

Overview

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.
You might also like...
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

: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

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

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.

Firebase with MVVM is a series of videos in which you will learn how to implement firebase with MVVM along with UI designs, GitHub branches, merging, and resolving conflicts.
Firebase with MVVM is a series of videos in which you will learn how to implement firebase with MVVM along with UI designs, GitHub branches, merging, and resolving conflicts.

In this project we will learn about Firebase Implementation with MVVM Architecture. It is a basic level Course and will go with project based approach so can understand better that how the things are working.

: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

AdsManager - Easy way to implement Google Ads

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

A android platform i.e, App that helps marriage/party halls and individuals to connect to the nearest places where this food could feed those in need and food wastage is minimised

(Muskan- The joy of giving by nature) , a android platform i.e, App that helps marriage/party halls and individuals to connect to the nearest places where this food could feed those in need and food wastage is minimised.

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

Comments
  • Parcelable insted of JSON

    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.

    opened by drdla49 6
  • Incompatibility with android/compose

    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

    opened by lepicekmichal 2
Releases(1.0.0-alpha.08)
  • 1.0.0-alpha.08(Dec 15, 2022)

    • Add iosSimulatorArm64 target.
    • Implemented DialogNavigator.
    • Fixed currentTopFlow property of StackNavigator.
    • Added default back handling for SetNavigator.
    • A bit of refactoring: improved extensions for navigators.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-alpha.07(Dec 11, 2022)

    • Kotlin is updated to 1.7.20.
    • Fixed the desktop sample.
    • Removed SystemBackMessage. Use BackMessage instead.
    • A bit of refactoring: renaming and using SAM interface.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-alpha.06(Jun 4, 2022)

  • 1.0.0-alpha.05(May 8, 2022)

    • Abstraction level support for implementing state persistence in different formats (Json, ProtoBuf, Parcelable) #6.
    • Added PmStateSaverFactory and BundleStateSaver.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-alpha.04(Jan 2, 2022)

  • 1.0.0-alpha.03(Dec 30, 2021)

  • 1.0.0-alpha.02(Dec 22, 2021)

    Premo

    • Kotlin is updated to 1.6.0.
    • Migrated to the new memory model.

    Premo-navigation

    • MasterDetailNavigator — implements adaptive navigation for Master-Detail views.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-alpha.01(Oct 24, 2021)

    First public release:

    Premo

    • PresentationModel — the base class for placing presentation logic.
    • PmLifecycle — represents the lifecycle of the Presentation Model.
    • PmMessageHandler — provide communication of Presentation Models. Allows you to send a message from the child Presentation Model towards the root Presentation Model.
    • PmStateHandler — handles the saved state of the Presentation Model.

    Premo-navigation

    • StackNavigator — allows you to organize a back stack of the Presentation Models.
    • SetNavigator — used to implement bottom navigation.
    Source code(tar.gz)
    Source code(zip)
Owner
Dmitriy Gorbunov
Lead Android Developer
Dmitriy Gorbunov
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

Jackson E J 11 Nov 10, 2022
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

Codename One 1.4k Jan 9, 2023
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

안홍범 14 Dec 13, 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

Muhammed Eren DURSUN 2 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

Mike Molina 0 Dec 13, 2021
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

Fatih Giriş 252 Dec 28, 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

Carlos Mota 3 Oct 27, 2021
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

Carlos Mota 15 Nov 11, 2022
🐘 Mastodon client for Android, iOS and Desktop (JVM)

MastodonX A multiplatform Mastodon client written in Kotlin for the amazing androiddev.social community and everyone else who enjoys #Fediverse Join o

null 372 Dec 28, 2022