# Custom tabBar
Custom tabBar allows developers to set tabBar styles more flexibly to meet more personalized scenarios.
In custom tabBar mode:
- To ensure compatibility with lower versions and distinguish which pages are tab pages, the relevant configuration items for tabBar must be fully declared, but these fields will not affect the rendering of the custom tabBar.
- Developers need to provide a custom component to render the tabBar, and all tabBar styles are rendered by this custom component. It is recommended to use
cover-view+cover-imagecomponents fixed at the bottom to ensure the tabBar has a relatively high hierarchy. - Interfaces related to tabBar styles, such as
ft.setTabBarItem, will become invalid. - The custom tabBar component instances under each tab page are different. The custom tabBar component instance of the current page can be obtained through the
getTabBarinterface under the custom component.
Please note
To implement the tab selected state, you need to obtain the component instance through the getTabBar interface on the current page and call setData to update the selected state. Refer to the code example at the bottom.
# 1. Usage Process
# 1.1 Configuration Information
- Specify the
customfield in thetabBaritem inapp.json, and complete the remainingtabBar-related configurations. - All tab pages must declare the
usingComponentsitem in their json, or it can be enabled globally inapp.json. Example:
{
"tabBar": {
"custom": true,
"color": "#000000",
"selectedColor": "#000000",
"backgroundColor": "#000000",
"list": [{
"pagePath": "page/component/index",
"text": "Component"
}, {
"pagePath": "page/API/index",
"text": "API"
}]
},
"usingComponents": {}
}
# 1.2 Add tabBar Code Files
Add the entry files in the code root directory:
custom-tab-bar/index.js
custom-tab-bar/index.json
custom-tab-bar/index.fxml
custom-tab-bar/index.ftss
# 1.3 Write tabBar Code
Write it as a custom component. This custom component completely takes over the rendering of the tabBar. Additionally, the custom component adds a getTabBar interface, which can obtain the custom tabBar component instance of the current page.