- Kotlin 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .github | ||
| compose-mds | ||
| example | ||
| goldenfiles | ||
| gradle | ||
| tool/sbb-icons | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| build.gradle.kts | ||
| CHANGELOG.md | ||
| CODE_OF_CONDUCT.md | ||
| CODING_STANDARDS.md | ||
| COMPONENT_MIGRATION.md | ||
| CONTRIBUTING.md | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| LICENSE.md | ||
| README.md | ||
| RELEASE.md | ||
| settings.gradle.kts | ||
Table Of Contents
Introduction
SBB Design System Mobile in Android Jetpack Compose.
This framework contains SBB (Swiss Federal Railways) UI elements for Android Jetpack Compose Apps. It allows an easy integration of SBB theming to your app.
Note: This plugin is still under development and some APIs might change. Feedback and Pull Requests are most welcome!
Please read CONTRIBUTING, CODING_STANDARDS and CODE_OF_CONDUCT if you want to contribute. Changes can be found in the CHANGELOG.
Getting-Started
To import the SBB Design System Mobile, please add the JitPack repository to your root settings.gradle.kts or build.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven {
url = uri("https://jitpack.io")
}
}
}
Next, declare the SBB Design System Mobile artifacts in libs.versions.toml.Check the available versions in
JitPack Packages.
[versions]
mds = "0.2.0"
[libraries]
mds-sbb = { group = "com.github.SchweizerischeBundesbahnen", name = "mds-android-compose", version.ref = "mds" }
Add the SBB Design System Mobile dependency to your app/build.gradle.kts:
dependencies {
implementation(libs.mds.sbb)
}
To use the Components in code, make sure to wrap the the App with a SBBTheme and Scaffold or Surface.
SBBTheme {
Scaffold {
MainPage(navController = rememberNavController())
}
}
To use the Components with the SBB Typography, please find the SBB Font, save it as resources and initialize the SBBTheme
val fontFamily = FontFamily(
Font(R.font.sbb_web_italic, FontWeight.Normal, FontStyle.Italic),
Font(R.font.sbb_web_bold, FontWeight.Bold),
Font(R.font.sbb_web_light, FontWeight.Light),
Font(R.font.sbb_web_roman, FontWeight.Normal),
Font(R.font.sbb_web_thin, FontWeight.Thin),
Font(R.font.sbb_web_ultra_light, FontWeight.ExtraLight)
)
SBBTheme(fontFamily = fontFamily) {
...
}
Golden File Screenshot Testing
This project uses Roborazzi for screenshot testing to
prevent unintended visual regressions. The tests generate "golden file" images from the @Preview
composables located in the example module and compare them against previously recorded versions.
Important:
- The
@Previewcomposables must not be declared asprivate, otherwise Roborazzi will ignore them.- When wrapping the preview in
SBBTheme, set the parameterincludeSurface = true— otherwise dark mode rendering will not work correctly.
Example:
@PreviewLightDark
@Composable
fun ExamplePagePreview() {
SBBTheme(includeSurface = true) {
ExamplePage()
}
}
All golden files are stored in the /goldenfiles directory at the root of the project.
Verifying and Updating Golden Files
To verify that your changes have not caused any visual regressions, run the verification task. This will compare newly generated screenshots with the existing golden files.
./gradlew :example:verifyRoborazziDebug
To update the golden files after making an intentional UI change, you must record the new versions. This will overwrite the existing files with the latest output.
./gradlew :example:recordRoborazziDebug
Workflow for UI Changes
Adding a New Component
- Create the new component in the
compose-mdslibrary. - In the
examplemodule, add a new file with one or more@Previewfunctions to showcase the component's different states. - Generate the initial golden file by running the record task:
./gradlew :example:recordRoborazziDebug - A new image file will be created in the
/goldenfilesdirectory. Review it to ensure it matches the component's design. - Commit the new component, the preview file, and the generated golden file.
Modifying an Existing Component
- Make your intended UI changes to a component in the
compose-mdslibrary. - Run the verification task. The test for the component you changed should fail.
./gradlew :example:verifyRoborazziDebugNote: If the test does not fail, your change is likely not covered by the existing
@Preview. You may need to adjust the preview to properly display the modification. - After confirming the test failure is expected, record the updated golden file:
./gradlew :example:recordRoborazziDebug - Review the modified image in the
/goldenfilesdirectory to ensure it correctly reflects your changes. - Commit your code changes along with the updated golden file.
License
This project is licensed under MIT.