Last Updated on : 2024-06-05 03:14:35download
NavigatorLayout
is a basic layout that supports navigation routing and can easily handle switching between panel pages. Navigator
used at the underlying architecture of NavigatorLayout
is a component that organizes and manages the associations, nesting relationships, and transitions between multiple pages in the Tuya device control panel. For more information about Navigator
, see Navigator.
The procedure to use NavigatorLayout
are as follows:
React
components and inherit NavigatorLayout
provided by tuya-panel-kit
.renderScene
method to render the user pages and return a valid React
component.hookRoute
method to achieve finer routing control.First define the routing configuration, and then write the components inherited from NavigatorLayout
. The code logic is as follows:
Define the routing tables (routers
) of the two pages, page1
and page2
.
Obtain the Navigator
and the information about the current routing object with the renderScene
method.
When rendering the page, look up the corresponding page in the routing table according to the ID of the current route.
Note: if there is no corresponding page, the default homepage will be rendered.
import React from "react";
import { StyleSheet } from "react-native";
import { NavigatorLayout } from "tuya-panel-kit";
import Page from "./page";
import Home from "./home";
const routers = [
{
id: "page1",
title: "page1",
Scene: (props) => <Page {...props} num={1} />,
},
{
id: "page2",
title: "page2",
Scene: (props) => <Page {...props} num={2} />,
},
];
export default class MainLayout extends NavigatorLayout {
// eslint-disable-next-line
hookRoute(route) {
const theRoute = routers.find((r) => r.id === route.id);
return {
...route,
topbarStyle: { backgroundColor: "#ff6024" },
showOfflineView: true,
title: route.id === "main" ? "Basic Jump Usage" : theRoute.title,
};
}
renderScene(route, navigator) {
let Scene = <Home navigator={navigator} />;
const router = routers.find((r) => r.id === route.id);
if (router && router.Scene) {
const Component = router.Scene;
Scene = <Component navigator={navigator} {...route} />;
}
return Scene;
}
}
Create the implementation of page
and home
.
page
// page.js
import React from "react";
import { View, Text, StyleSheet } from "react-native";
import { Button } from "tuya-panel-kit";
// eslint-disable-next-line
export default ({ num, navigator }) => (
<View style={[styles.container, styles.center]}>
<Text style={styles.welcomeTxt}>This is Page {num}</Text>
<Button style={styles.btnStyle} onPress={() => navigator.pop()}>
<Text style={styles.navTxt}>Click to go back!</Text>
</Button>
</View>
);
home
// home.js
import React from "react";
import { View, StyleSheet, Text } from "react-native";
import { Button } from "tuya-panel-kit";
// eslint-disable-next-line
export default ({ navigator }) => (
<View style={[styles.container, styles.center]}>
<Text style={styles.welcomeTxt}>
Welcome to basic usage of NavigatorLayout
</Text>
{[1, 2].map((v) => (
<Button
style={styles.btnStyle}
key={v}
onPress={() => navigator.push({ id: `page${v}` })}
>
<Text style={styles.navTxt}>Go to page {v}</Text>
</Button>
))}
</View>
);
Achieve the jump between pages.
push
method of Navigator
.pop
method.Run yarn start
under the project directory, and enter the corresponding debugging address in the app. Then, you can view the page jump effect on the app.
Note: for the demo, see NavigatorLayout.
Default configuration of page transition animation
const SceneConfigs = {
...Navigator.SceneConfigs.HorizontalSwipeJump,
gestures: {
pop: {
...Navigator.SceneConfigs.FloatFromRight.gestures.pop,
},
},
};
Configuration of custom animation effect
Configuration of custom animation can achieve the following effects:
import React from 'react';
import { View, StyleSheet, Text } from 'react-native';
import { Button } from 'tuya-panel-kit';
import { Navigator } from 'react-native-deprecated-custom-components';
const sceneConfig = {
...Navigator.SceneConfigs.HorizontalSwipeJump,
gestures: {
pop: {
...Navigator.SceneConfigs.FloatFromRight.gestures.pop,
},
},
};
const RouterConfig = [
{
txt: `VerticalUpSwipeJump to page 1`,
transition: {
...sceneConfig,
...Navigator.SceneConfigs.VerticalUpSwipeJump
}
},
{
txt: `SwipeFromLeft to page 2`,
transition: {
...sceneConfig,
...Navigator.SceneConfigs.SwipeFromLeft
}
}
];
// eslint-disable-next-line
export default ({ navigator }) => (
<View style={[styles.container, styles.center]}>
<Text style={styles.welcomeTxt}>
Screen Transition Example!
</Text>
{
[1, 2].map(v => (
<Button
style={styles.btnStyle}
key={v}
onPress={() => navigator.push({
id: `page${v}`,
sceneConfigs: RouterConfig[v 1].transition,
})}
><Text style={styles.navTxt}>{RouterConfig[v 1].txt}</Text>
</Button>
))
}
</View>
);
VerticalUpSwipeJump
and SwipeFromLeft
effect
Note: for more information about custom transition animation, see Scene Transitions.
route
will have at least the following parameters:
TopBar
.TopBar
on the current page. The style of topbarStyle
is a JS object, and the value range is from the allowed values in React Native
StyleSheet
.ReactNative
color value string.FullView
background style.FullView
.hideFullView
to allow users to render FullView
.TopBar
.false
during development and debugging.navigator
API, see Navigator Methods.Note: the user needs to decide which subpage to render according to the value of the
route
object. The return value ofrenderScene
must be a valid React component, which will be used to render the current routed page.
hookRoute
function is used to modify the parameter values used for rendering in the route
. route
properties are the same as the route
in the renderScene
. You can set your own parameters.
Note: the following is the original
devInfo
definition. For the convenience of developers, thedevInfo
in the template provided by Tuya has been optimized.
devInfo
is a normal JS object, which contains a lot of device information, including but not limited to the following fields:
name: device name.
productId: product ID.
uiId: panel ID corresponding to the current product.
homeId: family ID to which the device belongs.
bv: hardware baseline version.
devId: device ID.
gwId: gateway ID. If it indicates the device, devId
is usually equal to gwId
.
ability: only used by Bluetooth devices. If it is a single-point Bluetooth device, the value is 5.
attribute: the ability mark of the product to which the device belongs. It usually indicates whether to activate certain services, such as Alexa voice control.
isOnline: specify whether it is online.
isLocalOnline: specify whether the local area network (LAN) is online.
isShare: specify whether to share the device.
isVDevice: specify whether it is a demo device.
networkType: the online type of the device.
schema: the data point (DP) definition of the product to which the device belongs. For more information about DP definition, see Terms.
capability: the capability type of the device, indicating the capabilities supported by the device. For example, it supports Zigbee, infrared, and Bluetooth. For more examples, see the following table.
Type | Wi-Fi | Wired cable | GPRS | NB-IoT | Bluetooth LE | Bluetooth LE mesh | Zigbee | Infrared | 433 | SIG mesh |
---|---|---|---|---|---|---|---|---|---|---|
Bit | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 |
Capability | 1 | 2 | 4 | 8 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback