Skip to content

Commit abc3c60

Browse files
authored
Merge pull request #535 from panbibi/dev
doc:添加菜单路由管理文档
2 parents 8c3fe20 + 26ac496 commit abc3c60

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# 菜单路由管理
2+
3+
在项目根目录的`src / routes`配置菜单路由
4+
## 配置路由
5+
6+
```js
7+
import React from 'react';
8+
import {Icon} from '@uiw/react-native';
9+
import MyHome from '../pages/MyHome';
10+
import OrderHome from '../pages/OrderHome';
11+
import TransportHome from '../pages/TransportHome';
12+
13+
export default [
14+
{
15+
name: 'TransportHome',
16+
component: TransportHome,
17+
options: {
18+
title: '发货',
19+
tabBarIcon: () => {
20+
return <Icon name="inbox" size={22} />;
21+
},
22+
},
23+
},
24+
{
25+
name: 'OrderHome',
26+
component: OrderHome,
27+
options: {
28+
title: '订单',
29+
tabBarIcon: () => {
30+
return <Icon name="file-text" size={22} />;
31+
},
32+
},
33+
},
34+
{
35+
name: 'MyHome',
36+
component: MyHome,
37+
options: {
38+
title: '我的',
39+
tabBarIcon: () => {
40+
return <Icon name="user" size={22} />;
41+
},
42+
},
43+
},
44+
];
45+
46+
```
47+
48+
49+
## Options
50+
51+
### title
52+
53+
可以用作headerTitle的回退的字符串
54+
55+
### headerShown
56+
57+
是否显示或隐藏屏幕的标头。默认情况下显示头部。将此设置为false会隐藏标头。
58+
59+
### headerTintColor
60+
61+
为标题着色。更改后退按钮和标题的颜色。
62+
63+
### cardStyle
64+
65+
堆栈中卡片的样式对象。您可以在此处提供自定义背景色来代替默认背景色
66+
67+
### headerBackTitle
68+
69+
iOS上后退按钮使用的标题字符串。默认为前一个场景的headerTitle
70+
71+
路由配置完成后,访问页面即可看到效果,如需要配置 `title``tabBarIcon``header`等更多设置可以在这里找到[React Navigation](https://reactnavigation.org/docs/stack-navigator/)
72+
73+
## 路由跳转
74+
75+
```js
76+
import {View} from 'react-native';
77+
import { List, Icon} from '@uiw/react-native';
78+
79+
<List
80+
flat={true}
81+
data={[
82+
{title: '企业开票'},
83+
{title: '我的熟车'},
84+
{title: '设置', onPress: () => navigation.navigate('MyHomeSetting')},
85+
{title: '退出登录', onPress: () => navigation.replace('SignIn')},
86+
]}
87+
renderItem={({item, index}) => {
88+
return (
89+
<List.Item
90+
key={index}
91+
extra={<Icon name="right" fill="#abb0b5" size={14} />}
92+
size="large"
93+
paddingLeft={15}
94+
style={{borderBottomWidth: 0}}
95+
onPress={item.onPress || null}>
96+
<View>
97+
<Text>{item.title}</Text>
98+
</View>
99+
</List.Item>
100+
);
101+
}}
102+
/>
103+
```
104+
105+
106+
107+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Preview from 'src/component/Preview';
2+
import md from './README.md';
3+
4+
const transformImageUri = (url: string) => {
5+
const reqImage = (require as any).context!('./', true, /\.(png|gif|jpg|svg)$/);
6+
const urlAddr = reqImage(url);
7+
return urlAddr;
8+
};
9+
10+
const DEMO = () => (
11+
<Preview
12+
{...md}
13+
transformImageUri={transformImageUri}
14+
path="website/src/pages/docs/react-native-template/menu-route/README.md"
15+
/>
16+
);
17+
18+
export default DEMO;

website/src/routes/menus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const docsMenus: MenuData[] = [
8888
{ path: '/docs/unpack/android', name: 'Android(Mac) 打包' },
8989
{ divider: true, name: 'React Native Template' },
9090
{ path: '/docs/react-native-template/quickstart', name: '快速开始' },
91+
{ path: '/docs/react-native-template/menu-route', name: '菜单路由管理' },
9192
{ path: '/docs/react-native-template/new-page', name: '新增页面' },
9293
{ path: '/docs/react-native-template/mock-data', name: 'Mock 数据' },
9394
{ path: '/docs/react-native-template/log-management', name: '日志管理' },

website/src/routes/router.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export const routeData = [
6565
path: '/docs/react-native-template/quickstart',
6666
component: lazy(() => import('../pages/docs/react-native-template/quickstart')),
6767
},
68+
{
69+
path: '/docs/react-native-template/menu-route',
70+
component: lazy(() => import('../pages/docs/react-native-template/menu-route')),
71+
},
6872
{
6973
path: '/docs/react-native-template/new-page',
7074
component: lazy(() => import('../pages/docs/react-native-template/new-page')),

0 commit comments

Comments
 (0)