Styles define properties used to configure views based on the device type and current orientation. They allow you to specify layouts, colors and other view properties for different devices and orientations.
Quick guide
Style files are JSON files stored in the ./style directory.
./style/
└── detailViewStyle.json
A style file can look like this:
{
"name": "detailViewStyle",
"content": {
"content": {
"portrait": {
"layoutName": {
"phone": "detailViewPortrait",
"tab7": "detailViewTabPortrait",
"tab12": "detailViewTabPortrait"
},
"backgroundColor": "#f3f3f3"
},
"landscape": {
"layoutName": {
"phone": "detailViewLandscape",
"tab7": "detailViewTabLandscape",
"tab12": "detailViewTabLandscape"
},
"backgroundColor": "#f3f3f3"
},
"orientation": {
"phone": "all",
"tab7": "all",
"tab12": "all"
}
}
}
}
In this example, the style defines different layouts for portrait and landscape orientations. The background color is set, and all orientations are allowed for each device type.
A style can also extend another style by specifying the parent field. The parent style provides the base configuration, which is merged with the current style.
Style files
./style directory
Style files are stored in the ./style directory. Each file defines a named style.
./style/
├── detailViewStyle.json
└── homeViewStyle.json
Style file structure
Each style file is a JSON file containing a name field and a content object.
name: The name of the style. It must match the file name.
content: The style configuration.
parent (optional): The name of the parent style.
content: Contains the style properties.
The style properties can be defined for the default configuration, portrait orientation or landscape orientation.
default: Defines the default style values.
portrait: Defines style values for portrait orientation.
landscape: Defines style values for landscape orientation.
orientation: Defines the allowed orientations for each device type.
The default key can also be used to define fallback values instead of specifying individual device types or orientations.
Orientation
The orientation field defines which orientations are allowed for each device type.
The following values are supported:
| Value | Description |
|---|
all | All orientations are allowed. |
portrait | Only portrait orientation is allowed. |
landscape | Only landscape orientation is allowed. |
portraitSensor | Portrait and reverse portrait orientations are allowed. |
landscapeSensor | Landscape and reverse landscape orientations are allowed. |
Style Values
The following table lists all available style values.
For legacy reasons, not all style values support device-specific configuration. For example, backgroundColor must be defined directly within the orientation configuration.
This is indicated by the Allows Device Type column in the table.
| Key | Type | Description | Default Value | Allows Device Type |
|---|
layoutName | String | The name of the layout to be used. | null | true |
menuWidth | UnitSize | Opens the view as a side menu and defines its width. | null | true |
backgroundColor | Color | The background color of the view. | null | true |
bottombarBackgroundColor | Color | The background color of the bottom bar. | null | true |
loadingBackgroundColor | Color | The background color displayed while the loading indicator is visible. | null | true |
loadingSpinnerColor | Color | The color of the loading spinner. | null | true |
statusbarBackgroundColor | Color | The background color of the status bar. | null | true |
navbarBackgroundColor | Color | The background color of the navigation bar. | null | true |
navbarDisabled | Boolean | Defines whether the navigation bar is disabled. | null | true |
navbarElevation | Integer | Defines the elevation of the navigation bar. A drop shadow is applied when a value is set. | null | true |
navbarHeights | UnitSize | The height of the navigation bar. | null | true |
navbarLayout | String | The name of the layout to be used for the navigation bar. | null | true |
tabbarBackgroundColor | Color | The background color of the tab bar. | null | false |
tabbarBackgroundImageActive | String | The URL of the image to be used as the active image if the view is part of a tab view. | null | false |
tabbarBackgroundImageInactive | String | The URL of the image to be used as the inactive image if the view is part of a tab view. | null | false |
tabbarBackgroundImageActiveScaleType | ScaleType | The scale type of the active image if the view is part of a tab view. | null | false |
tabbarBackgroundImageInactiveScaleType | ScaleType | The scale type of the inactive image if the view is part of a tab view. | null | false |
tabbarHeights | UnitSize | The height of the tab bar. | null | true |
tabbarLayout | String | The name of the layout to be used for the tab bar. | null | true |
Usage
A named style can be applied when creating a view using the showView action. Specify the style name using the namedStyle parameter.
{
"type": "showView",
"params": {
"layout": "detailView",
"staticTemplate": "detailView",
"namedStyle": "detailViewStyle"
}
}
In this example, the view uses the detailViewStyle style.
Troubleshooting
If a style is not applied as expected, check the following:
- Is the style file stored in the
./style directory?
- Is the intended style referenced using the
namedStyle parameter in the showView action?
- Is the correct layout defined for the current device type and orientation?
- If the style extends a parent style, are the inherited values and overrides configured correctly?