• Stars
    star
    2,018
  • Rank 21,930 (Top 0.5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”¦ Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements

Showkase

Showkase Version Compatible with Compose

Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements. With minimal configuration it generates a UI browser that helps you easily find your components, colors & typography. It also renders your components in common situations like dark mode, right-to-left layouts, and scaled fonts which help in finding issues early.

Why should you use Showkase?

  • When using component based UI toolkits (like React, Compose, Flutter, etc), our codebase often ends up with hundreds of components that are hard to discover, visualize, search and organize.
  • Showkase eliminates the manual work of maintaining a UI preview/browser app that each company is forced to build in order to maintain their design system.
  • Since all the available UI elements are now easily searchable and discoverable, there is better reuse of UI elements in your repo. This makes it useful for maintaining consistency across your app. The biggest problem for enforcing a design system is discoverability and Showkase hopefully solves that problem for your team.
  • It allows you to quickly visualize @Composable components, Color properties and TextStyle (Typography) as you are building them. The goal is to improve the turnaround time in creating production-ready UI elements.
  • Showkase aids in catching common UI issues early with the help of auto-generated permutations of your components.

Features

  • Super simple setup
  • Support for visualizing composables(@ShowkaseComposable), colors(@ShowkaseColor) & typography(@ShowkaseTypography).
  • First class support for @Preview annotation. If you are already using @Preview for previews in Android Studio, using Showkase is even easier as all those components are included in the Showkase browser.
  • Support for top level, class, object & companion object functions and properties to be annotated with the Showkase annotations.
  • 5 Permutations are auto created for each composable (Basic Example, Dark Mode, RTL, Font Scaled, Display Scaled. Look in the gif above for examples)'. More to be added in the future!
  • Support for searching a Showkase UI element by name or group.
  • KDoc support that shows the documentation that you added for a component in the Showkase browser.
  • Multi-module support for showcasing UI elements across multiple modules.
  • Support for constraining a component with a custom height/width using additional parameters in the annotation.
  • Descriptive error messages so that the users of the library can fix any incorrect setup.
  • Incremental annotation processor that makes the code-gen more performant.

Installation

Using Showkase is straightforward and takes just a couple of minutes to get started.

Step 1: Add the dependency to your module's build.gradle file. If you have a multi-module setup, add this dependency to all the modules with UI elements that should be displayed inside the Showkase browser.

Showkase supports both ksp and kapt. By default, it uses kapt as we only recently added ksp support.

If you are using kapt

implementation "com.airbnb.android:showkase:1.0.0-beta18"
kapt "com.airbnb.android:showkase-processor:1.0.0-beta18"

If you are using ksp

implementation "com.airbnb.android:showkase:1.0.0-beta18"
ksp "com.airbnb.android:showkase-processor:1.0.0-beta18"

Step 2: Add the relevant annotations for every UI element that should be a part of the Showkase browser.

For @Composable components, you can either use the @Preview annotation that Compose comes with or use the @ShowkaseComposable annotation:

@Preview(name = "Custom name for component", group = "Custom group name")
@Composable
fun MyComponent() { ... }

// or

@ShowkaseComposable(name = "Name of component", group = "Group Name")
@Composable
fun MyComponent() { ... }

For Color properties, you can add the @ShowkaseColor annotation to the field:

@ShowkaseColor(name = "Primary Color", group = "Material Design")
val primaryColor = Color(0xFF6200EE)

For TextStyle properties that are useful for typography, you can add the @ShowkaseTypography annotation to the field:

@ShowkaseTypography(name = "Custom name for style", group = "Custom group name")
val h1 = TextStyle(
    fontWeight = FontWeight.Light,
    fontSize = 96.sp,
    letterSpacing = (-1.5).sp
)

Step 3: Define an implementation of the ShowkaseRootModule interface in your root module. If your setup involves only a single module, add this implementation in that module. Ensure that this implementation is also annotated with the @ShowkaseRoot annotation.

@ShowkaseRoot
class MyRootModule: ShowkaseRootModule

Step 4: Showkase is now ready for use! Showkase comes with an Activity that you need to start for accessing the UI browser. Typically you would start this activity from the debug menu of your app but you are free to start this from any place you like! A nice helper extension function getBrowserIntent is generated for you so you might have to build the app once before it's available for use. Just start the intent and that's all you need to do for accessing Showkase!

startActivity(Showkase.getBrowserIntent(context))

Documentation

1. @ShowkaseComposable

Used to annotate @Composable functions that should be displayed inside the Showkase browser. If you are using the @Preview annotation with your @Composable function already then you don't need to use this annotation. Showkase has first class support for @Preview.

Here's how you would use it with your @Composable function:

@ShowkaseComposable(name = "Name", group = "Group")
@Composable
fun MyComposable() {
    .......
    .......
}

Name and group are optional. Look at the properties section to understand the behavior when you don't pass any properties.

Note: Make sure that you add this annotation to only those functions that meet the following criteria:

  • Functions that don't have any parameters
  • If it does have a parameter, it has to be annotated with @PreviewParameter that is provided a PreviewParameterProvider implementation.
  • Stacked @Preview and ShowkaseComposable annotations are only supported with KSP at the moment. This is because of this issue.
  • If you use @Preview to generate UI in the Showkase app, you have to make them internal or public functions. If you would like to have private previews, but skip them in during compilation, you can add skipPrivatePreviewcompiler flag:

If you use KSP:

ksp {
 arg("skipPrivatePreviews", "true")
}

If you use KAPT:

kapt {
 arguments {
  arg("skipPrivatePreviews", "true")
 }
}

This is identical to how @Preview works in Compose as well so Showkase just adheres to the same rules.

// Consider a simple data class
data class Person(
    val name: String,
    val age: Int
)

// In order to pass a person object as a parameter to our composable function, we will annotate 
// our parameter with `@PreviewParameter` and pass a `PreviewParameterProvider` implementation.
@ShowkaseComposable(name = "Name", group = "Group") or @Preview(name = "Name", group = "Group")
@Composable
fun MyComposable(
    @PreviewParameter(provider = ParameterProvider::class) person: Person
) {
    ...
}

class ParameterProvider : PreviewParameterProvider<Person> {
    override val values: Sequence<Person>
        get() = sequenceOf(
            Person("John", 12),
            Person("Doe", 20)
        )

    override val count: Int
        get() = super.count
}

// Since we return 2 objects through our ParameterProvider, Showkase will create 2 previews 
// for this single composable function. Each preview will have it's own parameter that's passed 
// to it - Person("John", 12) for the first preview and Person("Doe", 20) for the second one. 
// This is an effective way to preview your composables against different sets of data.

Alternatively, you could simply wrap your function inside another function that doesn't accept any parameters -

@Composable
fun MyComposable(name: String) {
    .......
    .......
}

In order to make this function compatible with Showkase, you could further wrap this function inside a method that doesn't accept parameters in the following way:

@ShowkaseComposable(name = "Name", group = "Group")
@Composable
fun MyComposablePreview() {
    MyComposable("Name")
}
Representing component styles in Showkase

There are usecases where you might have a component that supports multiple styles. Consider the following example where you have a CustomButton composable and it supports 3 different sizes - Large/Medium/Small. You want to be able to document this in Showkase so that your team can visualize what these different styles look like in action. One option would be to treat them as 3 separate components. However this isn't ideal. ShowkaseComposable offers two properties that help you represent this information better - styleName & defaultStyle. Using these properties allow you to describe all the styles offered by a given Composable component in an organized manner as they are shown on the same screen in the Showkase browser.

Here's what the usage would actually look like for this example -

// Actual component
@Composable
fun CustomButton(
    size: ButtonSize,
    ...
)

// Previews
@ShowkaseComposable(name = "CustomButton", group = "Buttons", defaultStyle = true)
@Composable
fun Preview_CustomButton_Large() {
    CustomButton(size = ButtonSize.Large)
}

@ShowkaseComposable(name = "CustomButton", group = "Buttons", styleName = "Medium size")
@Composable
fun Preview_CustomButton_Medium() {
    CustomButton(size = ButtonSize.Medium)
}

@ShowkaseComposable(name = "CustomButton", group = "Buttons", styleName = "Small size")
@Composable
fun Preview_CustomButton_Small() {
    CustomButton(size = ButtonSize.Small)
}

@ShowkaseComposable currently supports the following properties:
Property Name Description
name The name that should be used to describe your @Composable function. If you don't pass any value, the name of the composable function is used as the name.
group The grouping key that will be used to group it with other @Composable functions. This is useful for better organization and discoverability of your components. If you don't pass any value for the group, the name of the class that wraps this function is used as the group name. If the function is a top level function, the composable is added to a "Default Group".
widthDp The width that your component will be rendered inside the Showkase browser. Use this to restrict the size of your preview inside the Showkase browser.
heightDp The height that your component will be rendered inside the Showkase browser. Use this to restrict the size of your preview inside the Showkase browser.
skip Setting this to true will skip this composable from rendering in the Showkase browser. A good use case for this would be when you want to have composable with @Preview but want to stop Showkase from picking it up and rendering it in its browser
styleName The name of the style that a given composable represents. This is useful for scenarios where a given component has multiple style variants and you want to organize them through Showkase for better discoverability.
defaultStyle A boolean value to denote whether the current composable is using its default style (or the only style if the composable doesn't have other style variants)
2. @ShowkaseColor

Used to annotate Color properties that should be presented inside the Showkase browser. Here's how you would use it with your Color fields:

@ShowkaseColor(name = "Name", group = "Group")
val redColor = Color.Red

@ShowkaseColor("Primary", "Light Colors")
val primaryColor = Color(0xFF6200EE)

Name and group are optional. Look at the properties section below to understand the behavior when you don't pass any properties.

@ShowkaseColor currently supports the following properties:
Property Name Description
name The name that should be used to describe your Color fields. If you don't pass any value, the name of the color field is used as the name.
group The grouping key that will be used to group it with other Color fields. This is useful for better organization and discoverability of your colors. If you don't pass any value for the group, the name of the class that wraps this field is used as the group name. If the field is a top level field, the color is added to a "Default Group".
3. @ShowkaseTypography

Used to annotate TextStyle properties that should be presented inside the Showkase browser. Here's how you would use it with your TextStyle fields:

@ShowkaseTypography(name = "Name", group = "Group")
val h1 = TextStyle(
    fontWeight = FontWeight.Light,
    fontSize = 96.sp,
    letterSpacing = (-1.5).sp
)

Name and group are optional. Look at the properties section below to understand the behavior when you don't pass any properties.

@ShowkaseTypography currently supports the following properties:
Property Name Description
name The name that should be used to describe your TextStyle fields. If you don't pass any value, the name of the textStyle field is used as the name.
group The grouping key that will be used to group it with other TextStyle fields. This is useful for better organization and discoverability of your typography. If you don't pass any value for the group, the name of the class that wraps this field is used as the group name. If the field is a top level field, the textStyle is added to a "Default Group".
4. @ShowkaseRoot

Used to annotate the ShowkaseRootModule implementation class. This is needed to let Showkase know more about the module that is going to be the root module for aggregating all the Showkase supported UI elements across all the different modules(if you are using a multi-module project). If you are only using a single module in your project, add it to that module. You are allowed to have only one @ShowkaseRoot per module.

Here's an example of how you would use it:

@ShowkaseRoot
class MyRootModule: ShowkaseRootModule

Note: The root module is the main module of your app that has a dependency on all other modules in the app. This is relevant because we generate the Showkase related classes in the package of the root module and we need to be able to access the UI elements across all the sub modules. This is only possible from the root module as it typically has a dependency on all the sub-modules.

5. Showkase Object

The Showkase object is the receiver for all the helper methods that this library generates. Currently there are a few extension functions that are generated with the Showkase object as the receiver. In order to get access to these functions, you need to build the app once so that the methods can be generated for your use.

Extension function Description
getBrowserIntent Helper function that return an intent to start the ShowkaseBrowser activity.
getMetadata Helper function that's give's you access to Showkase metadata. This contains data about all the composables, colors and typography in your codebase that's rendered in the Showkase Browser.
// Example Usage

val intent = Showkase.getBrowserIntent(context)
startActivity(intent)

val metadata = Showkase.getMetadata()
val components = metadata.componentList
val colors= metadata.colorList
val typography = metadata.typographyList

Frequently Asked Questions

Is Airbnb using Jetpack Compose in their main app? Airbnb has been one of the earliest adopters of Jetpack Compose and has been using it in production since early 2021. Compose is a really critical pillar of our overall Android strategy and we continue to heavily invest in building more tooling on top of it. We spoke about our experience of using Jetpack Compose at Google I/O 2022.
Can I contribute to this library? Pull requests are welcome! We'd love help improving this library. Feel free to browse through open issues to look for things that need work. If you have a feature request or bug, please open a new issue so we can track it.
How do I provide feedback? The issues tab is the best place to do that.
Why can't we have a single annotation like `Showkase` for all the UI elements? Why did you create a different annotation for each UI element(@ShowkaseComposable for composables, @ShowkaseColor for colors & @ShowkaseTypography for text styles)? This was done mostly for future proofing. Even though these annotations have the same properties right now, it's possible that they will diverge as we add more features. Once more people start using this library, we will get a more clear idea about whether that needs to happen or not. If we find that it didn't evolve the way we expected, we will consider consildating these annotations.
I would like to customize my component browser. Can this library still be useful? We provide a nice helper function that gives you access to the metadata of all your UI elements that are configured to work with Showkase. You can use `Showkase.getMetadata()` to get access to it and then use it in whatever way you see fit.

Coming Soon!

Here are some ideas that we are thinking about. We are also not limited to these and would love to learn more about your use cases.

  • Support for passing a @PreviewParameter parameter to @Preview/@ShowkaseComposable components. (See https://github.com/airbnb/Showkase#1-showkasecomposable)
  • Hooks for screenshot testing. Since all your components are a part of the Showkase browser, this would be a good opportunity to make this a part of your CI and detect diffs in components. (The getMetadata method can be useful to accomplish this. More info here - https://github.com/airbnb/Showkase#5-showkase-object)
  • Support for other UI elements that are a part of your design system (like icons, spacing, etc)
  • Generating a web version of the Showkase browser with documentation, search and screenshots.

Contributing

Pull requests are welcome! We'd love help improving this library. Feel free to browse through open issues to look for things that need work. If you have a feature request or bug, please open a new issue so we can track it.

License

Copyright 2022 Airbnb, Inc.

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.

More Repositories

1

javascript

JavaScript Style Guide
JavaScript
141,845
star
2

lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
Java
34,600
star
3

lottie-web

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
JavaScript
29,564
star
4

lottie-ios

An iOS library to natively render After Effects vector animations
Swift
24,897
star
5

visx

🐯 visx | visualization components
TypeScript
18,609
star
6

react-sketchapp

render React components to Sketch βš›οΈπŸ’Ž
TypeScript
14,951
star
7

react-dates

An easily internationalizable, mobile-friendly datepicker library for the web
JavaScript
11,630
star
8

epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
Java
8,426
star
9

css

A mostly reasonable approach to CSS and Sass.
6,869
star
10

hypernova

A service for server-side rendering your JavaScript views
JavaScript
5,824
star
11

mavericks

Mavericks: Android on Autopilot
Kotlin
5,741
star
12

knowledge-repo

A next-generation curated knowledge sharing platform for data scientists and other technical professions.
Python
5,432
star
13

ts-migrate

A tool to help migrate JavaScript code quickly and conveniently to TypeScript
TypeScript
5,307
star
14

aerosolve

A machine learning package built for humans.
Scala
4,790
star
15

DeepLinkDispatch

A simple, annotation-based library for making deep link handling better on Android
Java
4,356
star
16

lottie

Lottie documentation for http://airbnb.io/lottie.
HTML
4,289
star
17

ruby

Ruby Style Guide
Ruby
3,711
star
18

polyglot.js

Give your JavaScript the ability to speak many languages.
JavaScript
3,644
star
19

MagazineLayout

A collection view layout capable of laying out views in vertically scrolling grids and lists.
Swift
3,232
star
20

native-navigation

Native navigation library for React Native applications
Java
3,127
star
21

streamalert

StreamAlert is a serverless, realtime data analysis framework which empowers you to ingest, analyze, and alert on data from any environment, using datasources and alerting logic you define.
Python
2,825
star
22

infinity

UITableViews for the web (DEPRECATED)
JavaScript
2,809
star
23

airpal

Web UI for PrestoDB.
Java
2,760
star
24

HorizonCalendar

A declarative, performant, iOS calendar UI component that supports use cases ranging from simple date pickers all the way up to fully-featured calendar apps.
Swift
2,656
star
25

swift

Airbnb's Swift Style Guide
Markdown
2,239
star
26

synapse

A transparent service discovery framework for connecting an SOA
Ruby
2,067
star
27

paris

Define and apply styles to Android views programmatically
Kotlin
1,894
star
28

AirMapView

A view abstraction to provide a map user interface with various underlying map providers
Java
1,861
star
29

react-with-styles

Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation
JavaScript
1,697
star
30

rheostat

Rheostat is a www, mobile, and accessible slider component built with React
JavaScript
1,692
star
31

binaryalert

BinaryAlert: Serverless, Real-time & Retroactive Malware Detection.
Python
1,382
star
32

epoxy-ios

Epoxy is a suite of declarative UI APIs for building UIKit applications in Swift
Swift
1,142
star
33

nerve

A service registration daemon that performs health checks; companion to airbnb/synapse
Ruby
942
star
34

okreplay

πŸ“Ό Record and replay OkHttp network interaction in your tests.
Groovy
775
star
35

RxGroups

Easily group RxJava Observables together and tie them to your Android Activity lifecycle
Java
693
star
36

prop-types

Custom React PropType validators that we use at Airbnb.
JavaScript
672
star
37

react-outside-click-handler

OutsideClickHandler component for React.
JavaScript
603
star
38

ResilientDecoding

This package makes your Decodable types resilient to decoding errors and allows you to inspect those errors.
Swift
580
star
39

babel-plugin-dynamic-import-node

Babel plugin to transpile import() to a deferred require(), for node
JavaScript
575
star
40

kafkat

KafkaT-ool
Ruby
504
star
41

babel-plugin-dynamic-import-webpack

Babel plugin to transpile import() to require.ensure, for Webpack
JavaScript
500
star
42

chronon

Chronon is a data platform for serving for AI/ML applications.
Scala
479
star
43

babel-plugin-inline-react-svg

A babel plugin that optimizes and inlines SVGs for your React Components.
JavaScript
474
star
44

lunar

πŸŒ— React toolkit and design language for Airbnb open source and internal projects.
TypeScript
461
star
45

BuckSample

An example app showing how Buck can be used to build a simple iOS app.
Objective-C
459
star
46

SpinalTap

Change Data Capture (CDC) service
Java
428
star
47

artificial-adversary

πŸ—£οΈ Tool to generate adversarial text examples and test machine learning models against them
Python
390
star
48

dynein

Airbnb's Open-source Distributed Delayed Job QueueingΒ System
Java
383
star
49

hammerspace

Off-heap large object storage
Ruby
364
star
50

trebuchet

Trebuchet launches features at people
Ruby
313
star
51

reair

ReAir is a collection of easy-to-use tools for replicating tables and partitions between Hive data warehouses.
Java
278
star
52

zonify

a command line tool for generating DNS records from EC2 instances
Ruby
270
star
53

ottr

Serverless Public Key Infrastructure Framework
Python
266
star
54

omniduct

A toolkit providing a uniform interface for connecting to and extracting data from a wide variety of (potentially remote) data stores (including HDFS, Hive, Presto, MySQL, etc).
Python
249
star
55

hypernova-react

React bindings for Hypernova.
JavaScript
248
star
56

smartstack-cookbook

The chef recipes for running and testing Airbnb's SmartStack
Ruby
244
star
57

interferon

Signaling you about infrastructure or application issues
Ruby
239
star
58

prop-types-exact

For use with React PropTypes. Will error on any prop not explicitly specified.
JavaScript
237
star
59

backpack

A pack of UI components for Backbone projects. Grab your backpack and enjoy the Views.
HTML
223
star
60

babel-preset-airbnb

A babel preset for transforming your JavaScript for Airbnb
JavaScript
222
star
61

goji-js

React ❀️ Mini Program
TypeScript
213
star
62

react-with-direction

Components to provide and consume RTL or LTR direction in React
JavaScript
192
star
63

stemcell

Airbnb's EC2 instance creation and bootstrapping tool
Ruby
185
star
64

hypernova-ruby

Ruby client for Hypernova.
Ruby
141
star
65

kafka-statsd-metrics2

Send Kafka Metrics to StatsD.
Java
135
star
66

optica

A tool for keeping track of nodes in your infrastructure
Ruby
134
star
67

sparsam

Fast Thrift Bindings for Ruby
C++
125
star
68

js-shims

JS language shims used by Airbnb.
JavaScript
123
star
69

browser-shims

Browser and JS shims used by Airbnb.
JavaScript
118
star
70

bossbat

Stupid simple distributed job scheduling in node, backed by redis.
JavaScript
118
star
71

nimbus

Centralized CLI for JavaScript and TypeScript developer tools.
TypeScript
118
star
72

lottie-spm

Swift Package Manager support for Lottie, an iOS library to natively render After Effects vector animations
Ruby
106
star
73

twitter-commons-sample

A sample REST service based on Twitter Commons
Java
103
star
74

is-touch-device

Is the current JS environment a touch device?
JavaScript
90
star
75

rudolph

A serverless sync server for Santa, built on AWS
Go
73
star
76

hypernova-node

node.js client for Hypernova
JavaScript
73
star
77

plog

Fire-and-forget UDP logging service with custom Netty pipelines & extensive monitoring
Java
72
star
78

cloud-maker

Building castles in the sky
Ruby
67
star
79

react-create-hoc

Create a React Higher-Order Component (HOC) following best practices.
JavaScript
66
star
80

vulnture

Python
65
star
81

deline

An ES6 template tag that strips unwanted newlines from strings.
JavaScript
63
star
82

react-with-styles-interface-react-native

Interface to use react-with-styles with React Native
JavaScript
63
star
83

sputnik

Scala
61
star
84

mocha-wrap

Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Mocha tests.
JavaScript
54
star
85

react-with-styles-interface-aphrodite

Interface to use react-with-styles with Aphrodite
JavaScript
54
star
86

eslint-plugin-react-with-styles

ESLint plugin for react-with-styles
JavaScript
49
star
87

sssp

Software distribution by way of S3 signed URLs
Haskell
47
star
88

alerts

An example alerts repo, for use with airbnb/interferon.
Ruby
46
star
89

apple-tv-auth

Example application to demonstrate how to build Apple TV style authentication.
Ruby
44
star
90

airbnb-spark-thrift

A library for loadling Thrift data into Spark SQL
Scala
43
star
91

jest-wrap

Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.
JavaScript
39
star
92

billow

Query AWS data without API credentials. Don't wait for a response.
Java
38
star
93

gosal

A Sal client written in Go
Go
36
star
94

backbone.baseview

DEPRECATED: A simple base view class for Backbone.View
JavaScript
34
star
95

anotherlens

News Deeply X Airbnb.Design - Another Lens
HTML
33
star
96

eslint-plugin-miniprogram

TypeScript
33
star
97

react-component-variations

JavaScript
33
star
98

react-with-styles-interface-css

πŸ“ƒ CSS interface for react-with-styles
JavaScript
31
star
99

appear

reveal terminal programs in the gui
Ruby
29
star
100

puppet-munki

Puppet
29
star