source-apps

source

The Source library for Android

Available on maven central

Add the library dependency

Add the dependency to build.gradle.kts for the consuming module.

In build.gradle.kts:

implementation("com.gu.source:source-android:<version>")

In version catalog:

[versions]
source = "<version>"

[libraries]
source = { module = "com.gu.source:source-android", version.ref = "source" }

[!note] See here if you need to build and bundle the library as a local repository.

Using the library

The library provides design presets and components.

The design presets are available name spaced under the com.gu.Source object, e.g. Source.Typography.HeadlineBold15.

Full API documentation is available here.


Typography presets

Typography presets include fontFamily, fontSize, lineHeight, fontWeight, fontStyle in a single token. All typography tokens with their previews are listed here

The library bundles app font files, so they are not separately required in consumer apps.

Use typography presets directly in a Text component.

Text(
    text = "The world's leading liberal voice",
    // Using Source typography preset
    style = Source.Typography.TextEgyptianItalic14,
)

Core palette colours

Core palette colours are available for direct use in components through Source.Palette. Preview all available colours here.

Text(
    text = "The world's leading liberal voice",
    // Using Source palette colours
    color = Source.Palette.Brand400,
)

Buttons

Four core button components are available - SourceButton, SourceIconButton, PlainSourceButton and SourceBaseIconButton.

See here for full details of the button components.

Core theme Reader revenue theme
Core themed text only buttons Reader revenue themed text only buttons

Chips

Chip components are typically used for filter, tags, or actions in a concise format.

See here for full details of the chip components.


Pager progress components

Three pager progress components are available:

  1. PagerProgressIndicator - a set of indicators to signify progress as a user progresses through the items in the pager
  2. PagerProgressButtons - buttons to allow user to go to next/previous page in a pager
  3. PagerProgressBar - a higher level component that combines the above two and has different phone and tablet behaviour.

See here for more details on pager progress components.

Progress bar for tablets


Alert banners

The AlertBanner component is used to display alerts at the top of the screen. It supports three alert priorites - Neutral, Info and Error. The three alert priorities have different display styles corresponding to Source specifications.

Usage example
AlertBanner(
    text = "This is an alert banner",
    priority = AlertBanner.Priority.Info,
    onMessageClick = { /* Handle action */ },
    onDismiss = { /* Handle dismiss */ },
    modifier = Modifier.fillMaxWidth(),
)

Alert banner variants


Building and using directly

As a bundled repo

  1. Build the library Run
    ./gradlew :source:publishReleasePublicationToGusourceRepository
    

    This will produce the library output at /source/build/gusource/.

  2. Copy the built library to the news app Copy the library the built folder from /source/build/gusource/ to the android-news-app/src/main/libs/maven folder in the android-news-app repo.

  3. Update the version number in the news app If the library version has changed, update it in the version catalog for the news app.

From maven local

  1. Build the library Run
    ./gradlew :source:publishToMavenLocal
    

    This will publish the library to your local maven repository.

  2. Update the version number in the news app If the library version has changed, update it in the version catalog for the news app.

  3. Ensure you have mavenLocal declared first in your repositories
    repositories {
        mavenLocal()
        mavenCentral()
        google()
    }
    

Other notes

  1. We use the com.gu package name and group id so we can use the Guardian’s Sonatype infra for signing and publishing the library. See this comment for reference.