Resource Management
Atlas allows the ability to manage resources inside a shared/resources common folder. It then automatically generates implementations for all platforms.
This allows a unified approach for assets, fonts, strings, colors, images, etc, for all platforms.
Getting started
First add the plugin to your project
_3plugins {_3 id("io.github.thearchitect123.atlasResourcesGenerator")_3}
To generate resources for your project, please make sure to add the xml file into the appropriate folders.
- shared/resources/strings/strings.xml
- shared/resources/colors/colors.xml
- shared/resources/fonts/fonts.xml
- shared/resources/images/ (all images are to be placed here, supports all image types)
Your folder structure should like this:
Then add the values into your xml files like this:
colors.xml
_7<Colors>_7 <color key="black">#000000</color>_7 <color key="white">#FFFFFF</color>_7 <color key="primary">#FF5722</color>_7 <color key="green">#00FF00</color>_7 <color key="secondary">#03A9F4</color>_7</Colors>
strings.xml
_7<AtlasStrings>_7 <string key="greeting">Hello there</string>_7 <string key="farewell">Goodbye</string>_7 <string key="welcomeMessage">Welcome to the app!</string>_7 <string key="errorMessage">Something went wrong</string>_7 <string key="confirm">Are you sure you want to continue?</string>_7</AtlasStrings>
You can then access your resources like this (in Android Kotlin):
_8val myString = AtlasStrings.greeting_8val colorResource = AtlasColors.primary_8_8// assuming you have an image file (in the images folder) called myImage.png or myImage.svg_8val imageResource = AtlasImages.myImage_8_8// assuming you have a font file called robotoBold.ttf_8val fontResource = AtlasColors.robotoBold
You can also directly access the resources in Swift, like this:
_4val myString = AtlasStrings.companion.greeting_4val colorResource = AtlasColors.companion.primary_4val imagesResource = AtlasImages.companion.myImage_4val fontsResource = AtlasFonts.companion.robotoBold