This page contains a compilation of code conventions we try to maintain to keep a good code structure in our android modules. As a start the CONTRIBUTING needs to be followed.
SkapaImage. This is however not a complete component in the android library but merely a guide on how to implement one. This is because of its requirement of an external image fetching/rendering/caching library.Within each component file we strive to have the distribution as follows.
public components functions. Eg. PriceModule()private/internal functions that builds up the component such as implementations of different variants or orientations. Eg. private PriceModuleRegular() and private PriceModuleList()public enum classes/sealed classes used for variants. Eg. sealed class PriceModuleVariantprivate/internal data/enum/sealed classes and helper functions.private object *Props. The props object prefixed with the component name eg. PriceModuleProps usually contains sizing, padding, color tokens and other static values needed. Additionally functions used for styling different variants also live here. Eg. PriceModuleProps.style().@Preview() functions to render the component in the Design tab of Android Studio. These functions should generally be private.<componentName>Sample.kt file with a sample explaining how to use the component. The sample file should be referred in the component documentation as @sample net.ikea.skapa.ui.samples.<ComponentSampleFunction>.Components files should be placed in the net.ikea.skapa.ui.components package for design module. When adding new components they should start their journey with ExperimentalSkapaApi annotation added to all public functions. Read more in Annotations.
Apart from the Skapa components there are additional source code files that complements our offering.
Component sample files in net.ikea.skapa.ui.samples that showcases usage examples for each component.
Util files in the net.ikea.skapa.ui.util package and the net.ikea.skapa.ui.Util.kt file outside of that package. These are used as helper files and are either internal or public accompanied by the @InternalSkapaApi annotation, see Annotations.
This project also uses similar annotations as Compose Libraries use such as ExperimentalMaterialApi, ExperimentalComposeUiApi, ExperimentalFoundationApi where want an explicit OptIn to be able to use those functions and their limitations.
ExperimentalSkapaApi is used for work-in-progress components (and other functions) in all our packages (both stable packages and experimental package). Functions using this annotation and subject to change without notice.InternalSkapaApi is used to reuse functions between our own Skapa packages, projects outside of Skapa are allowed to use them but we do not guarantee their longevity.design-testBoth Unit and Snapshots tests are located in the design-test module with SkapaTestHelper as the entry point.
net.ikea.skapa.ui.components has the test wrapper for the components.net.ikea.skapa.ui.snapshots implementations of the Snapshot tests.net.ikea.skapa.ui.unittests implementations of the Unit tests.When adding tests, especially snapshot tests, try to test features combinations and avoid adding tests that overlap with other tests. Eg. try to combine testing several features in one test to reduce the total test suite duration.
Make sure to run tests in both Light and Dark mode. Check this file to get a better understanding how screenshot are run and updated /scripts/run-screenshot-test-light-dark.sh.
Also make sure to run the tests on compatible device /.github/workflows/test-pipeline.yml due to rendering differences with other device combinations.
Code conventions are maybe less important in the app code since it is not being exposed outside the team but we still try to maintain a good structure.
The code of the Demo app is split into a few different sections with main screen entrypoint being net.ikea.skapa.example.navigation.SkapaScreen.kt
foundation, icons, fonts modules.design moduleThe entrypoint for these screens is net.ikea.skapa.example.fragments.components.ComponentsScreen.kt. All components are ordered with the same grouping as in Skapa hub.