Last Updated on : 2025-07-29 03:05:04download
TopBar is the top toolbar integrated in FullView by default. It is called ActionBar in Android and UINavigationBar in iOS.
The new version of TopBar unifies the code of the Android and iOS operating systems, and splits out three components, TopBar.Container, TopBar.Content, and TopBar.Action. If the height is self-defined, the three components can be used for combined construction.
In addition, the height of TopBar is adapted to Android and iOS respectively, which can be obtained through TopBar.height:
Note: for more information, see Demo.
import React from "react";
import { View, Platform } from "react-native";
import { TYNative, TopBar } from "tuya-panel-kit";
const backIcon = Platform.OS === "ios" ? "backIos" : "backAndroid";
export default () => (
<View>
{/* Split version */}
<TopBar.Container background="#000">
<TopBar.Action
name={backIcon}
color="red"
onPress={TYNative.Navigator.pop}
/>
<TopBar.Content title="Title" />
<TopBar.Action
name="pen"
color="yellow"
onPress={TYNative.showDeviceMenu}
/>
</TopBar.Container>
{/* Encapsulation version */}
<TopBar
style={{ marginTop: 24 }}
background="#000"
title="Title"
color="red"
actions={[
{
name: "pen",
color: "yellow",
onPress: () => TYNative.showDeviceMenu(),
},
]}
onBack={TYNative.Navigator.pop}
/>
</View>
);
import React from "react";
import { View, Platform } from "react-native";
import { TYNative, TopBar } from "tuya-panel-kit";
const backIcon = Platform.OS === "ios" ? "backIos" : "backAndroid";
const linearBackground = {
stops: {
"0%": "red",
"100%": "yellow",
},
};
const radialBackground = {
stops: [
{
offset: "0%",
stopColor: "#ff0",
stopOpacity: "1",
},
{
offset: "100%",
stopColor: "#00f",
stopOpacity: "1",
},
],
};
export default () => (
<View>
{/* Split version */}
<TopBar.Container background={linearBackground}>
<TopBar.Action name={backIcon} onPress={TYNative.Navigator.pop} />
<TopBar.Content title="Title" />
</TopBar.Container>
{/* Encapsulation version */}
<TopBar
style={{ marginTop: 24 }}
background={radialBackground}
title="Title"
onBack={TYNative.Navigator.pop}
/>
</View>
);
import React from 'react';
import { View, Platform } from 'react-native';
import { TYNative, TopBar } from 'tuya-panel-kit';
const backIcon = Platform.OS === 'ios' ? 'backIos' : 'backAndroid';
export default () => (
<View>
{/* Split version */}
<TopBar.Container background="blue">
<TopBar.Action
name={backIcon}
onPress={TYNative.Navigator.pop}
/>
<TopBar.Action
source="Timing"
color="red"
onPress={() => {
TYNative.simpleTipDialog('click timing', () => {});
}}
/>
<TopBar.Content
title="Very Very Very Very Very Long Title"
subTitle="SubTitle"
onPress={() => {
TYNative.simpleTipDialog('click title', () => {});
}}
/>
{['plus', 'warning', 'edit'].map(v => (
<TopBar.Action
key={v}
name={v}
onPress={() => {
TYNative.simpleTipDialog(`click ${v}`, () => {});
}}
/>
))}
</TopBar.Container>
{/* Encapsulation version */}
<TopBar
style={{ marginTop: 24 }}
background="blue"
title="Very Very Very Very Very Long Title"
subTitle="SubTitle"
onPress={() => TYNative.simpleTipDialog('click title', () => {})}
leftActions={[{
name: backIcon,
onPress: TYNative.Navigator.pop,
}, {
source: 'Timing',
color: 'red',
onPress: () => TYNative.simpleTipDialog('click timing', () => {}),
}]}
actions={['plus', 'warning', 'edit'].map(v => ({
name: v,
onPress: () => TYNative.simpleTipDialog(`click ${v}`, () => {}),
}))}
/>
</View
);
The container style of the top toolbar internally handles the three StatusBar situations of iOS versions below and above iPhoneX, and Android. You can also define your own style.
| Type | Required | Default value |
|---|---|---|
| ViewPropTypes.style | No | null |
The style of the container content of the top toolbar.
| Type | Required | Default value |
|---|---|---|
| ViewPropTypes.style | No | null |
The background of the top toolbar container, which can be a solid color or a gradient color. For the format of the gradient color, see LinearGradient or RadialGradient.
| Type | Required | Default value |
|---|---|---|
string or object |
No | null |
The child elements of the top toolbar container, usually TopBar.Action and TopBar.Content. TopBar.Container automatically adapts to the position of these two components.
| Type | Required | Default value |
|---|---|---|
any |
No | null |
TopBar.Action is a main part of TopBar, which can be pictures, text, or IconFont. TopBar.Action will determine the type of action by itself based on the data source.
Note: If
nameordhas been set,IconFontwill be rendered first.
TopBar.Action style.
| Type | Required | Default value |
|---|---|---|
| ViewPropTypes.style | No | null |
TopBar.Action content style, which can be pictures, text, or IconFont.
| Type | Required | Default value |
|---|---|---|
| ImageStyleProps or Text.propTypes.style or IconFontProps | No | null |
TopBar.Action IconFont size.
| Type | Required | Default value |
|---|---|---|
number |
No | 26 |
The left and right margins of TopBar.Action.
Note: If you set the text type,
spacingwill be added to theactionas an extra width.
| Type | Required | Default value |
|---|---|---|
number |
No | 6 |
TopBar.Action content color, which can be the background color of the picture, text color, or IconFont color.
| Type | Required | Default value |
|---|---|---|
| ColorPropType | No | #fff |
TopBar.Action content.
image components.View.| Type | Required | Default value |
|---|---|---|
string or number or { uri } |
No | null |
Whether to disable or not.
| Type | Required | Default value |
|---|---|---|
boolean |
No | false |
TopBar background, which can be a specified color or gradient color.
| Type | Required | Default value |
|---|---|---|
string or object |
No |
TopBar.Action child element. If you do not enter it, TopBar.Action will automatically render the required child elements according to the type of source passed.
| Type | Required | Default value |
|---|---|---|
any |
No | null |
TopBar.Content is the central content component of TopBar.
TopBar.Content style.
| Type | Required | Default value |
|---|---|---|
| ViewPropTypes.style | No | null |
TopBar.Content title and subtitle color. The subtitle color is the color with 0.6 transparency.
| Type | Required | Default value |
|---|---|---|
| ColorPropType | No | #fff |
TopBar.Content title.
| Type | Required | Default value |
|---|---|---|
string |
No | ‘’ |
TopBar.Content title style.
| Type | Required | Default value |
|---|---|---|
| Text.propTypes.style | No | null |
TopBar.Content subtitle.
| Type | Required | Default value |
|---|---|---|
string |
No | ‘’ |
TopBar.Content subtitle style.
| Type | Required | Default value |
|---|---|---|
| Text.propTypes.style | No | null |
The position of TopBar.Content, which can be left-aligned, center-aligned and right-aligned.
| Type | Required | Default value |
|---|---|---|
enum: 'left','center','right' |
No | center |
The child element of TopBar.Content.
| Type | Required | Default value |
|---|---|---|
any |
No | null |
The click event of TopBar.Content.
| Type | Required | Default value |
|---|---|---|
() => void |
No | null |
TopBar is an encapsulated component that can be used when the degree of customization is low. In addition to the following parameters, TopBar props can also be inherited from TopBar.Content.
The container style of TopBar.Container internally handles the three StatusBar situations of iOS versions below and above iPhoneX, and Android. You can also define your own style of StatusBar.
| Type | Required | Default value |
|---|---|---|
| ViewPropTypes.style | No | null |
TopBar.Container container content style.
| Type | Required | Default value |
|---|---|---|
| ViewPropTypes.style | No | null |
TopBar.Container container background, which can be a specified color or gradient color. For the format of gradient color, see LinearGradient or RadialGradient.
| Type | Required | Default value |
|---|---|---|
string or object |
No | None |
TopBar.Action content color, which can be the background color of the picture, text color, or IconFont color.
| Type | Required | Default value |
|---|---|---|
| ColorPropType | No | #fff |
The left toolbar configuration of TopBar. If it is null, it will render the default return buttons for iOS and Android.
| Type | Required | Default value |
|---|---|---|
array |
No | null |
The right toolbar configuration of TopBar. The objects in the array will be passed to TopBar.Action as props.
| Type | Required | Default value |
|---|---|---|
array |
No | null |
Return event.
| Type | Required | Default value |
|---|---|---|
() => void |
No | null |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback