A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.

Overview

Apex

Apex is just a simple proof of concept to demonstrate how easily you can build your own UI Toolkit from scratch. This code base is most likely full of bugs and design mistakes but it should help you understand the basics of a UI Toolkit. It is meant as a learning and demonstration tool only.

Tested only in an emulator and only on API level 31.

Concepts

Widgets are called elements and are all instances of the Element class. Apex elements are not intended to be subclassed, instead you build widgets by adding components to an element. Each component has a single responsibility: layout, rendering, input event, or whatever else you want. Components can be anything, and in the current codebase some are classes, some are interfaces, some are enums.

For instance a Button is an Element with the following components:

  • A ButtonModel (text, click listener, etc.), the public API of a button
  • A RenderComponent, to render the button
  • A LayoutComponent, to compute its own size and position the text
  • A MotionInputComponent, to react the touch events and handle clicks
  • An InternalState, to track the pressed state of the button

Apex also offers Provider instances, which are roughly equivalent to Jetpack Compose's composition locals. The give access to global data throughout the tree: Resources, display density, the current theme, etc. Any Element can inject new providers or override existing providers by using the ProviderComponent component. MainActivity shows an example of using a ThemeProvider to modify the current theme.

Exercises for the reader

If you'd like to play with this codebase a bit, here are a few things you could try:

  • Optimize components lookup. Right now, every lookup iterates over a flat list. It's not a big deal since most elements will have a short list but this could be improved. Since it's intended that an element can own multiple components of the same type, you'd probable a data structure that maps component types to a list (a linked hashmap for instance)
  • Optimize providers handling. Every layout/render/motion input phase currently re-applies the providers. It's not very efficient. And the layout phase doesn't correctly apply the providers at every level of the tree
  • Take the MotionInputComponent from Button and make it a generic, reusable API so you can perform clicks on the Image widget in MainActivity as well
  • Track changes in data models to re-layout/re-draw only when needed
  • Don't relayout/redraw on every v-sync. It's wasteful
  • Reduce memory allocations (esp. generated by the many RectF and SizeF instances, among other things)
  • Cleanup the inline/noinline/crossinline and reified generic mess in the various helper functions
  • Make this a multi-platform UI Toolkit! Remove Android-specific APIs (Canvas, Bitmap, etc.) and use your own abstractions. For rendering use skiko

Screenshot

Not super exciting, but here it is:

Apex demo: a photo centered on screen with two buttons below, Previous and Next

License

See LICENSE.

You might also like...
Example project for using the Selenium toolkit with Kotlin, Maven, TestNg and the config is managed via a property file.

Selenium-Java-Toolkit-TestNg-Playground This is the sample-Project and show you how to use the Selenium-Toolkit. The Selenium-Toolkit is a Java based

Restful Toolkit for IntelliJ IDEA

restful-toolkit Template ToDo list Create a new IntelliJ Platform Plugin Template project. Get known with the template documentation. Verify the plugi

Server & Web App of Tolgee localization toolkit
Server & Web App of Tolgee localization toolkit

Server & Web App of Tolgee localization toolkit

Learn-kotlin - Learning more about Kotlin in various content

Kotlin study roadmap https://kotlinlang.org/docs/reference/ Getting Started Basi

A toy port scanner to help me (and you!) learn Kotlin + Akka.

kotlin-akka-portscan A toy program to help me (and you!) learn Kotlin + Akka. butwhy.gif When I want to learn a new language, I've found it helpful to

PlanetFacts - An educational android app for kids to learn about the planets in our solar system. Built with Kotlin.

PlanetFacts PlanetFacts is an offline simple, modern & material-designed educational Android application for kids. It contains basic facts with visual

Learn Kotlin, easy bites at a time
Learn Kotlin, easy bites at a time

Welcome! I hope you're having an amazing day! 🚀 This repository is a reference of how I think one should approach learning kotlin step-by-step. Insid

Learn how to make an app designed for single-screen devices shine when running on foldable and dual-screen devices

dcberlin21-workshop Make your app shine om foldable devices with the samples we have here. Related links SDK open-source code SDK samples (Kotlin) App

A project to learn about Reactive Microservices experimenting with architectures and patterns
A project to learn about Reactive Microservices experimenting with architectures and patterns

reactive-microservices-workshop Copyright © 2021 Aleix Morgadas - Licenced under CC BY-SA 4.0 A project to learn about Reactive Microservices experime

Comments
  • Generalizing rendering to be platform agnostic

    Generalizing rendering to be platform agnostic

    This is not a complete solution (it still uses Paint, Bitmap, etc), but starts down the path of using a generic rendering API that can be implemented by specific platforms (eg, Android)

    opened by chethaase 0
Owner
Romain Guy
Engineering director at Google on Android
Romain Guy
Buggy buggy kotlin MVVM starter project

贪吃蛇 - MVVM - Kotlin Introduciton project was inspired and initialized by youtube

null 0 Dec 28, 2021
A single screen app learn in google basic Android Development course.

Project: Lemonade App - Starter Code Starter code for the first independent project for Android Basics in Kotlin Introduction This is the starter code

Kaushal Raj 0 Dec 19, 2022
Basic-Android-Project - A Basic Android Project with proper structure and all necessary dependencies

Basic-Android-Project A Basic Android Project with proper structure and all nece

Ameer Hamza 2 Mar 18, 2022
DS-for-Kotlin - Some classic data sturctures write in kotlin for fun

DS-for-Kotlin Just write some classic data structure by kotlin during my leisure

ccyyxx 2 Jan 30, 2022
Exploring Kotlin Symbol Processing - KSP. This is just an experiment.

KSP example Exploring Kotlin Symbol Processing - KSP. This is just an experiment. Project contains 2 modules Processing Example Processing module is t

Merab Tato Kutalia 12 Aug 23, 2022
A sandbox where I will experiment with new techniques, concepts, and technologies.

A sandbox where I will experiment with new techniques, concepts, and technologies. Here you will find some DDD, CQRS, Clean Architecture, Event-Driven Architecture, Serverless, Microservices, RabbitMQ, gRPC, SOLID, Design Patterns, and more.

Jefferson Didi Silva 6 Nov 15, 2022
It is a fun project(android app), that contains everything about hip-hop.

Hip Hop School This is a fun project (android app). This app contains information about Hip Hop, like its history, beefs, etc. App Architecture An att

Jatin Vashisht 0 Dec 12, 2021
FirestoreCleanArchitectureApp is an app built with Kotlin and Firestore that displays data in real-time using the MVVM Architecture Pattern. For the UI it uses Jetpack Compose, Android's modern toolkit for building native UI.

FirestoreCleanArchitectureApp FirestoreCleanArchitectureApp is an app built with Kotlin and Cloud Firestore that displays data in real-time using Andr

Alex 66 Dec 15, 2022
Lucilla - Fast, efficient, in-memory Full Text Search for Kotlin

Lucilla Lucilla is an in-memory Full Text Search library for Kotlin. It allows t

Kshitij Chauhan 111 Jan 6, 2023