Skip to content

Commit 4402282

Browse files
committed
feat(useupdatemanager): improve iconfont, add useUpdateManager hook
1 parent fa6e354 commit 4402282

File tree

16 files changed

+143
-32
lines changed

16 files changed

+143
-32
lines changed

packages/app/src/app.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default {
88
'pages/useArrayBufferToBase64/index',
99
'pages/useSystemInfo/index',
1010
'pages/useEvent/index',
11+
'pages/useUpdateManager/index',
1112
],
1213
window: {
1314
backgroundTextStyle: 'light',
2.59 KB
Binary file not shown.
1.64 KB
Binary file not shown.
1.27 KB
Binary file not shown.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@font-face {
2+
font-family: 'iconfont';
3+
src: url('../font/iconfont.ttf') format('truetype'),
4+
url('../font/iconfont.woff') format('woff'),
5+
url('../font/iconfont.woff2') format('woff2');
6+
}
7+
8+
.iconfont {
9+
font-family: 'iconfont' !important;
10+
font-size: 16px;
11+
font-style: normal;
12+
-webkit-font-smoothing: antialiased;
13+
-moz-osx-font-smoothing: grayscale;
14+
}
15+
16+
.iconfont-basic:before {
17+
content: '\e86e';
18+
}
19+
20+
.iconfont-environment:before {
21+
content: '\e60e';
22+
}
23+
24+
.iconfont-wechat:before {
25+
content: '\e609';
26+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
@import '../../app.less';
2+
@import '../../assets/style/icon.less';

packages/app/src/constant/index.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ export const List: APIList = [
1212
id: 'Basic',
1313
title: '基础Hooks',
1414
content: '包含事件、调试等',
15-
icon: 'filter',
15+
icon: 'basic',
1616
},
1717
{
1818
id: 'Environment',
1919
title: '环境Hooks',
2020
content: '包含环境判断等',
21-
icon: 'equalizer',
21+
icon: 'environment',
22+
},
23+
{
24+
id: 'Wechat',
25+
title: '小程序Hooks',
26+
content: '包含管理器、API等',
27+
icon: 'wechat',
2228
},
2329
];
2430

@@ -30,14 +36,11 @@ export interface APIChildrenItem {
3036
export enum APIChildrenName {
3137
basic = 'basic',
3238
environment = 'environment',
39+
wechat = 'wechat',
3340
}
3441

3542
export const ChildrenList: { [_: string]: APIChildrenItem[] } = {
3643
[APIChildrenName.basic]: [
37-
{
38-
id: 'useAPICheck',
39-
name: 'useAPICheck 判断是否可用',
40-
},
4144
{
4245
id: 'useEvent',
4346
name: 'useEvent 事件中心',
@@ -61,4 +64,14 @@ export const ChildrenList: { [_: string]: APIChildrenItem[] } = {
6164
name: 'useEnv 获取当前环境值',
6265
},
6366
],
67+
[APIChildrenName.wechat]: [
68+
{
69+
id: 'useAPICheck',
70+
name: 'useAPICheck 判断是否可用',
71+
},
72+
{
73+
id: 'useUpdateManager',
74+
name: 'useUpdateManager 更新',
75+
},
76+
],
6477
};

packages/app/src/pages/index/index.less

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '../../app.less';
2+
@import '../../assets/style/icon.less';
23

34
.page-index {
45
padding-top: 60px;

packages/app/src/pages/index/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ const Index = () => {
4949
data-name={item.title}
5050
onClick={() => handleLocation(item.id)}
5151
>
52-
<AtIcon value={item.icon} className="module-list__icon" />
52+
<AtIcon
53+
prefixClass="iconfont"
54+
value={item.icon}
55+
className="module-list__icon"
56+
/>
5357
<View className="module-list__info">
5458
<View className="title">{item.title}</View>
5559
<View className="content">{item.content}</View>

packages/app/src/pages/panel/index.less

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import url(../../style/mixins.less);
22
@import '../../app.less';
3+
@import '../../assets/style/icon.less';
34

45
/**
56
* 分类页样式

packages/app/src/pages/panel/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ const Panel = ({}: IPanelProps) => {
4040
return (
4141
<View className="page">
4242
<View className="panel-header">
43-
<AtIcon value={panelInfo.icon} className="panel-header__icon" />
43+
<AtIcon
44+
prefixClass="iconfont"
45+
value={panelInfo.icon}
46+
className="panel-header__icon"
47+
/>
4448
<View className="panel-header__title">{panelInfo.title}</View>
4549
</View>
4650
<View className="panel-body">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
navigationBarTitleText: 'useUpdateManager',
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { useCallback } from 'react';
2+
import { AtMessage, AtNoticebar } from 'taro-ui';
3+
import { View } from '@tarojs/components';
4+
import DocPage from '../../components/DocPage';
5+
6+
import { useEnv, useUpdateManager } from 'taro-hooks';
7+
import Taro, { ENV_TYPE } from '@tarojs/taro';
8+
9+
import 'taro-ui/dist/style/components/icon.scss';
10+
11+
export default () => {
12+
const env = useEnv();
13+
14+
const onCheckForUpdate = useCallback((res) => {
15+
Taro.atMessage({
16+
message: res.hasUpdate ? '有新版本' : '无新版本',
17+
});
18+
}, []);
19+
20+
const onUpdateReady = useCallback(() => {
21+
Taro.atMessage({
22+
message: '检查更新成功',
23+
});
24+
}, []);
25+
26+
const onUpdateFailed = useCallback(() => {
27+
Taro.atMessage({
28+
message: '检查更新失败',
29+
});
30+
}, []);
31+
32+
const updateManager = useUpdateManager({
33+
onCheckForUpdate,
34+
onUpdateReady,
35+
onUpdateFailed,
36+
});
37+
38+
return (
39+
<>
40+
{env !== ENV_TYPE.WEAPP && (
41+
<AtNoticebar>useUpdateManager 仅可以在小程序环境中使用</AtNoticebar>
42+
)}
43+
<AtMessage />
44+
<DocPage title="useUpdateManager 更新" panelTitle="useUpdateManager">
45+
<View>检查更新中....</View>
46+
</DocPage>
47+
</>
48+
);
49+
};

packages/hooks/src/useAPICheck/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ nav:
55
path: /hooks
66
order: 2
77
group:
8-
title: 基础
9-
path: /basic
8+
title: 小程序
9+
path: /wechat
1010
---
1111

1212
# useAPICheck

packages/hooks/src/useUpdateManager/index.md

+24-10
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,50 @@ nav:
55
path: /hooks
66
order: 2
77
group:
8-
title: 基础
9-
path: /basic
8+
title: 小程序
9+
path: /wechat
1010
---
1111

1212
# useUpdateManager
1313

14-
获取当前环境值
14+
获取全局唯一版本更新管理器
1515

1616
## 何时使用
1717

18-
当需要获取当前环境值做一些判断时
18+
管理小程序更新机制。
1919

2020
## API
2121

2222
```jsx | pure
23-
() => Taro.ENV_TYPE;
23+
const updateManager = useUpdateManager({
24+
onCheckForUpdate,
25+
onUpdateReady,
26+
onUpdateFailed,
27+
});
28+
```
29+
30+
## 入参说明
31+
32+
```tsx | pure
33+
function onCheckForUpdate(res) {}
34+
35+
function onUpdateReady() {}
36+
37+
function onUpdateFailed() {}
2438
```
2539

2640
## 返回值说明
2741

28-
| 返回值 | 说明 | 类型 |
29-
| ------ | ---------- | ---------- |
30-
| env | 当前环境值 | `ENV_TYPE` |
42+
| 返回值 | 说明 | 类型 |
43+
| ------------- | -------------- | --------------- |
44+
| updateManager | 更新管理器实例 | `UpdateManager` |
3145

3246
## 代码演示
3347

34-
<code src="@pages/useEnv" />
48+
<code src="@pages/useUpdateManager" />
3549

3650
## Hook 支持度
3751

3852
| 微信小程序 | H5 | ReactNative |
3953
| :--------: | :-: | :---------: |
40-
| ✔️ | ✔️ | ✔️ |
54+
| ✔️ | | |

packages/hooks/src/useUpdateManager/index.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import { ENV_TYPE, getUpdateManager, UpdateManager } from '@tarojs/taro';
2-
import { useCallback, useEffect, useRef, useState } from 'react';
2+
import { useCallback, useEffect, useRef } from 'react';
33
import useEnv from '../useEnv';
44

5-
export interface Options {
6-
applyUpdate: () => void;
7-
}
8-
95
export type Result = UpdateManager | {};
106

117
function useUpdateManager({
12-
applyUpdate,
138
onCheckForUpdate,
149
onUpdateReady,
1510
onUpdateFailed,
@@ -21,15 +16,14 @@ function useUpdateManager({
2116
if (env === ENV_TYPE.WEAPP) {
2217
const updateManagerInstance = getUpdateManager();
2318
addEventListener(updateManagerInstance);
24-
updateManager.current = getUpdateManager();
19+
updateManager.current = updateManagerInstance;
2520
}
26-
}, []);
21+
}, [env]);
2722

2823
const addEventListener = useCallback((updateManagerInstance) => {
29-
updateManagerInstance.applyUpdate = applyUpdate;
30-
updateManagerInstance.onCheckForUpdate = onCheckForUpdate;
31-
updateManagerInstance.onUpdateReady = onUpdateReady;
32-
updateManagerInstance.onUpdateFailed = onUpdateFailed;
24+
updateManagerInstance.onCheckForUpdate(onCheckForUpdate);
25+
updateManagerInstance.onUpdateReady(onUpdateReady);
26+
updateManagerInstance.onUpdateFailed(onUpdateFailed);
3327
}, []);
3428

3529
return updateManager;

0 commit comments

Comments
 (0)