Code Monkey home page Code Monkey logo

stylist's Introduction

Stylist Build Status

As Android apps grow, providing common styling across app themes becomes challenging. Typically, this results in copy-pasting style items across themes, monolithic themes, or complicated inheritance trees. Stylist is a highly-extensible platform for creating and maintaining an app’s base set of Android XML themes.

Overview

Stylist is a Gradle plugin written in Kotlin that generates a base set of Android XML themes. Stylist-generated themes are created using a stencil and trait system. Each theme is declared with a single stencil, which is comprised of sets of logically-grouped style items. All of this comes together to create an easily maintainable system of stencils and traits.

ThemeStencils: A 1:1 ratio of ThemeStencils to corresponding generated themes. Each ThemeStencil declares a theme name and parent theme plus any extra StyleItemGroups that should be included in addition to the globally applicable set.

StyleItemGroups: Each StyleItemGroup can be declared by multiple ThemeStencils and generate otherwise duplicated style items across all themes that include them. Common examples include default app colors, font sizes, and common dimension values. They are a logical groupings of custom theme attributes that get included in each theme that declares the group.

Usage

A simple ThemeStencilProvider that defines text sizes in Dark and Light themes would look like:

@AutoService(ThemeStencilProvider::class)
class SampleThemeStencilProvider : ThemeStencilProvider {

  private val textSizes = StyleItemGroup(
      StyleItem("textSizeSmall", "12dp"),
      StyleItem("textSizeMedium","16dp"),
      StyleItem("textSizeLarge", "20dp")
  )

  override fun stencils() = linkedSetOf(
      ThemeStencil("Theme.Sample.Dark", "Theme.AppCompat"),
      ThemeStencil("Theme.Sample.Light", "Theme.AppCompat.Light")
  )

  override fun globalStyleItemGroups() = linkedSetOf(
      textSizes
  )
}

Leaving you with a generated themes XML resource file like this:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
  <style name="Theme.Sample.Dark" parent="Theme.AppCompat">
    <item name="textSizeSmall">12dp</item>
    <item name="textSizeMedium">16dp</item>
    <item name="textSizeLarge">20dp</item>
  </style>
  <style name="Theme.Sample.Light" parent="Theme.AppCompat.Light">
    <item name="textSizeSmall">12dp</item>
    <item name="textSizeMedium">16dp</item>
    <item name="textSizeLarge">20dp</item>
  </style>
</resources>

This may look like a lot of boilerplate for simple style item shared by two themes, but it scales quite well when you want to have many custom color, dimension, and other style items on numerous app themes and custom theme attributes.

Download

Stylist Maven Central

classpath 'com.uber.stylist:stylist:0.0.2'

Stylist Core Maven Central

classpath 'com.uber.stylist:stylist-core:0.0.2'

Stylist API Maven Central

classpath 'com.uber.stylist:stylist-api:0.0.2'

License

Copyright (C) 2018 Uber Technologies

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

stylist's People

Contributors

jbarr21 avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylist's Issues

Support applying plugin to multiple modules

Depending on the project structure, it may be necessary to apply the plugin to multiple modules to create the required theme inheritance structure.

If we have a foundational layer (with Light & Dark) provided by module A and an intermediate layer (w/ Light & Dark) provided by module B, and then an App Layer that inherits from the intermediate layer

Currently, all ThemeStencilProviders found on the classpath will be generated into every module the plugin is applied to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.