@tarojs/taro-h5 3.5.0-beta.1 → 3.5.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-h5",
3
- "version": "3.5.0-beta.1",
3
+ "version": "3.5.0-beta.4",
4
4
  "description": "Taro h5 framework",
5
5
  "browser": "dist/index.esm.js",
6
6
  "main:h5": "dist/index.js",
@@ -33,14 +33,14 @@
33
33
  "author": "O2Team",
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "@tarojs/api": "3.5.0-beta.1",
37
- "@tarojs/router": "3.5.0-beta.1",
38
- "@tarojs/runtime": "3.5.0-beta.1",
36
+ "@tarojs/api": "3.5.0-beta.4",
37
+ "@tarojs/router": "3.5.0-beta.4",
38
+ "@tarojs/runtime": "3.5.0-beta.4",
39
39
  "base64-js": "^1.3.0",
40
40
  "jsonp-retry": "^1.0.3",
41
41
  "mobile-detect": "^1.4.2",
42
42
  "query-string": "^7.1.1",
43
43
  "whatwg-fetch": "^3.4.0"
44
44
  },
45
- "gitHead": "ba9d945ccebb86f06edb7f845110526d92dc7b00"
45
+ "gitHead": "7aca7841ed7e2af1b182ff5d24e91f44730ce783"
46
46
  }
@@ -1,4 +1,39 @@
1
+ import Taro from '@tarojs/api'
2
+ import { parse } from 'query-string'
3
+
1
4
  import { temporarilyNotSupport } from '../../../utils'
5
+ import { CallbackManager } from '../../../utils/handler'
6
+
7
+ const appShowCallbackManager = new CallbackManager()
8
+ const appHideCallbackManager = new CallbackManager()
9
+
10
+ const getApp = () => {
11
+ const path = Taro.Current.page?.path
12
+ return {
13
+ /** 小程序切前台的路径 */
14
+ path: path?.substring(0, path.indexOf('?')),
15
+ /** 小程序切前台的 query 参数 */
16
+ query: parse(location.search),
17
+ /** 来源信息。 */
18
+ referrerInfo: {},
19
+ /** 小程序切前台的[场景值](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/scene.html) */
20
+ scene: 0,
21
+ /** shareTicket,详见[获取更多转发信息](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
22
+ shareTicket: ''
23
+ }
24
+ }
25
+
26
+ const appShowListener = () => {
27
+ if (document.visibilityState !== 'hidden') {
28
+ appShowCallbackManager.trigger(getApp())
29
+ }
30
+ }
31
+
32
+ const appHideListener = () => {
33
+ if (document.visibilityState === 'hidden') {
34
+ appHideCallbackManager.trigger(getApp())
35
+ }
36
+ }
2
37
 
3
38
  // 应用级事件
4
39
  export const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection')
@@ -7,13 +42,38 @@ export const onPageNotFound = temporarilyNotSupport('onPageNotFound')
7
42
  export const onError = temporarilyNotSupport('onError')
8
43
  export const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd')
9
44
  export const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin')
10
- export const onAppShow = temporarilyNotSupport('onAppShow')
11
- export const onAppHide = temporarilyNotSupport('onAppHide')
45
+
46
+ export const onAppShow: typeof Taro.onAppShow = callback => {
47
+ appShowCallbackManager.add(callback)
48
+ if (appShowCallbackManager.count() === 1) {
49
+ window.addEventListener('visibilitychange', appShowListener)
50
+ }
51
+ }
52
+
53
+ export const onAppHide: typeof Taro.onAppHide = callback => {
54
+ appHideCallbackManager.add(callback)
55
+ if (appHideCallbackManager.count() === 1) {
56
+ window.addEventListener('visibilitychange', appHideListener)
57
+ }
58
+ }
59
+
12
60
  export const offUnhandledRejection = temporarilyNotSupport('offUnhandledRejection')
13
61
  export const offThemeChange = temporarilyNotSupport('offThemeChange')
14
62
  export const offPageNotFound = temporarilyNotSupport('offPageNotFound')
15
63
  export const offError = temporarilyNotSupport('offError')
16
64
  export const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd')
17
65
  export const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin')
18
- export const offAppShow = temporarilyNotSupport('offAppShow')
19
- export const offAppHide = temporarilyNotSupport('offAppHide')
66
+
67
+ export const offAppShow: typeof Taro.offWindowResize = callback => {
68
+ appShowCallbackManager.remove(callback)
69
+ if (appShowCallbackManager.count() === 0) {
70
+ window.removeEventListener('visibilitychange', appShowListener)
71
+ }
72
+ }
73
+
74
+ export const offAppHide: typeof Taro.offWindowResize = callback => {
75
+ appHideCallbackManager.remove(callback)
76
+ if (appHideCallbackManager.count() === 0) {
77
+ window.removeEventListener('visibilitychange', appHideListener)
78
+ }
79
+ }
@@ -29,7 +29,7 @@ export class InnerAudioContext implements Taro.InnerAudioContext {
29
29
  get duration () { return this.Instance?.duration || 0 }
30
30
  set loop (e) { this.setProperty('loop', e) }
31
31
  get loop () { return this.Instance?.loop || false }
32
- get paused () { return this.Instance?.paused || true }
32
+ get paused () { return this.Instance?.paused ?? true }
33
33
  set src (e) { this.setProperty('src', e) }
34
34
  get src () { return this.Instance?.src || '' }
35
35
  set volume (e) { this.setProperty('volume', e) }
@@ -32,7 +32,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
32
32
  callbackManager.progressUpdate.trigger({
33
33
  progress: Math.round(loaded / total * 100),
34
34
  totalBytesSent: loaded,
35
- totalBytesExpectedToSent: total
35
+ totalBytesExpectedToSend: total
36
36
  })
37
37
  }
38
38
 
@@ -6,7 +6,7 @@ export class SocketTask {
6
6
  OPEN: number
7
7
  CLOSING: number
8
8
  CLOSED: number
9
- closeDetail: { code: any; reason: any }
9
+ closeDetail: { code: any, reason: any }
10
10
  _destroyWhenClose?: () => void
11
11
 
12
12
  constructor (url, protocols) {