Adjustment of theme is done through theme variables. These variables can be set through Shoutem builder, which interprets the variables schema.
Variables schema file is nothing else than Shoutem flavored JSON Schema.
Example:
{
"formats": {
"font": {
"title": "Font",
"default": {
"fontFamily": "Rubicon",
"fontStyle": "normal",
"fontWeight": "normal",
"fontSize": 20,
"color": "rgba(255,255,255,1)"
},
"constraints": {
"fontFamily": {
"enum": [ "normal", "Rubicon"]
},
"fontStyle": {
"enum": ["normal", "italic"]
},
"fontWeight": {
"enum": ["normal", "bold", "100", "200", "300", "400", "500", "600", "700", "800", "900"]
},
"fontSize": {
"minimum": 12,
"maximum": 42
}
}
}
},
"properties": {
"primaryColor": {
"type": "string",
"format": "color",
"title": "Primary color",
"default": "rgba(12, 111, 34, 0.5)"
},
"textFont": {
"type": "object",
"format": "font",
"title": "Text font",
"default": {
"fontFamily": "Rubicon",
"fontStyle": "normal",
"fontWeight": "regular",
"fontSize": 15,
"color": "rgba(255,255,255,1)"
}
}
},
"layout": {
"sections": [{
"title": "Colors",
"properties": ["primaryColor"]
}, {
"title": "Text",
"properties": ["textFont"]
}]
}
}
It’s properties
are the variable descriptors - they describe the variable to the Shoutem builder. For now, there are only 2 types of variables:
"type": "string", "format": "color"
"type": "object", "format": "font"
Based on what the type is, descriptor has different fields. However, some fields are shared:
false
.There is also field formats
. It is used to describe default values and constraints of specific format.
Each variable of the same format thus inherits values defined in formats
, but can also override each field with its own value.
Variable of type color will result in color picker in interface for customizing theme.
String. One of the React Native supported Color formats.
Currently, there are no additional properties variable descriptor supports.
Variable of type font will result in complex control in interface for customizing theme.
Object with following fields:
{
"fontFamily": "Rubicon",
"fontStyle": "normal",
"fontWeight": "normal",
"fontSize": 20,
"color": "rgba(255,255,255,1)"
}
constraints.fontFamily
field. Defaults to “Rubicon”.constraints.fontSize
field. Defaults to “normal”.constraints.fontWeight
field. Defaults to “normal”."rgba(0,0,0,1)"
Font variable descriptor defines additional property constraints
, which describes values that are available for each field:
"normal", "Rubicon"
."normal", "italic"
."normal", "bold", "100", "200", "300", "400", "500", "600", "700", "800", "900"
."minimum"
- defaults to 12 and "maximum"
- defaults to 42.