Application Configuration
1. Related Configuration
Operation Process
- In
src/global.config.ts, configurethemeLocationto specify the path of the variable configuration filetheme.json. For example, if you addtheme.jsonin the src directory, you need to configure"themeLocation":"theme.json". - Define related variables in
src/theme.json. - In the global configuration of
src/global.config.ts, the route configuration ofsrc/routes.config.ts, or the page configuration ofsrc/pages/${pageId}/index.config.ts, reference the variables with an@prefix.
The following three categories support variable configuration:
Global Configuration
- Under the
tuya.windowobject in the global configuration filesrc/global.config.ts:See MiniApp Configuration - app.json Global Configuration#window
- navigationBarBackgroundColor
- navigationBarTextStyle
- backgroundColor
- backgroundTextStyle
- backgroundColorTop
- backgroundColorBottom
Route Configuration
- Under the exported
tabBarobject in the route configuration filesrc/routes.config.ts:See MiniApp Configuration - app.json Global Configuration#tabbar
- color
- selectedColor
- backgroundColor
- borderStyle
- list
- iconPath
- selectedIconPath
Page Configuration
- Under the exported object in the page configuration file
src/pages/${pageId}/index.config.ts:- backgroundColor
- backgroundTextStyle
- navigationBarBackgroundColor
- navigationBarTextStyle
2. Variable Configuration File
theme.json is used to define variables related to color themes. You need to configure the path of theme.json in themeLocation first; otherwise, the variable configuration cannot be read.
The configuration file must include the following properties:
Both light and dark modes can define variables and values in the key: value format, for example:
After defining, you can reference these variables with an @ prefix in the related properties of global or page configuration, for example:
Integrating with Global Configuration
Integrating with Route Configuration
Integrating with Page Configuration
Once configured, the Ray framework will automatically display the colors corresponding to the theme based on the system theme.
3. Get Current System Theme
The getSystemInfo or getSystemInfoSync return result will include the theme attribute, with a value of either light or dark.
4. Listen for Theme Change Events
You can listen for theme change events using useAppEvent, as shown in the following code: